1 | include "Cminor/semantics.ma". |
---|
2 | include "common/Animation.ma". |
---|
3 | |
---|
4 | definition id_get_input := ident_of_nat 0. |
---|
5 | definition f_get_input := External internal_function (mk_external_function id_get_input (mk_signature [] (Some ? (ASTint I32 Signed)))). |
---|
6 | definition id_main := ident_of_nat 1. |
---|
7 | definition id_main_tmp0 := ident_of_nat 5. |
---|
8 | definition id_main_r := ident_of_nat 6. |
---|
9 | definition id_main_j := ident_of_nat 7. |
---|
10 | definition id_main_i := ident_of_nat 8. |
---|
11 | definition C_cost2 := costlabel_of_nat 4. |
---|
12 | definition C_cost0 := costlabel_of_nat 3. |
---|
13 | definition C_cost1 := costlabel_of_nat 2. |
---|
14 | definition f_main := Internal ? (mk_internal_function |
---|
15 | (mk_signature [] (Some ? (ASTint I32 Signed))) |
---|
16 | [] |
---|
17 | [id_main_tmp0; id_main_r; id_main_j; id_main_i] |
---|
18 | [] |
---|
19 | 0 ( |
---|
20 | St_cost C_cost2 ( |
---|
21 | St_seq ( |
---|
22 | St_call (Some ? id_main_i) (Cst (Oaddrsymbol id_get_input (repr 0))) [] |
---|
23 | ) ( |
---|
24 | St_seq ( |
---|
25 | St_assign id_main_r (Cst (Ointconst (repr 1))) |
---|
26 | ) ( |
---|
27 | St_seq ( |
---|
28 | St_seq ( |
---|
29 | St_seq ( |
---|
30 | St_assign id_main_j (Cst (Ointconst (repr 2))) |
---|
31 | ) ( |
---|
32 | St_block ( |
---|
33 | St_loop ( |
---|
34 | St_seq ( |
---|
35 | St_ifthenelse (Op1 Onotbool (Op2 (Ocmp Cle) (Id id_main_j) (Id id_main_i))) ( |
---|
36 | St_exit 0 |
---|
37 | ) ( |
---|
38 | St_skip ) |
---|
39 | ) ( |
---|
40 | St_seq ( |
---|
41 | St_block ( |
---|
42 | St_cost C_cost0 ( |
---|
43 | St_assign id_main_r (Op2 Omul (Id id_main_r) (Id id_main_j)) |
---|
44 | ) |
---|
45 | ) |
---|
46 | ) ( |
---|
47 | St_assign id_main_j (Op2 Oadd (Id id_main_j) (Cst (Ointconst (repr 1)))) |
---|
48 | ) |
---|
49 | ) |
---|
50 | ) |
---|
51 | ) |
---|
52 | ) |
---|
53 | ) ( |
---|
54 | St_cost C_cost1 ( |
---|
55 | St_skip ) |
---|
56 | ) |
---|
57 | ) ( |
---|
58 | St_return (Some ? (Id id_main_r)) |
---|
59 | ) |
---|
60 | ) |
---|
61 | ) |
---|
62 | ) |
---|
63 | |
---|
64 | )). |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | definition myprog : Cminor_program := |
---|
69 | mk_program ?? [ |
---|
70 | (pair ?? id_get_input f_get_input); |
---|
71 | (pair ?? id_main f_main) |
---|
72 | ] id_main |
---|
73 | [] |
---|
74 | . |
---|
75 | |
---|
76 | example exec: finishes_with (repr 120) ? (exec_up_to Cminor_fullexec myprog 100 [EVint (repr 5)]). |
---|
77 | normalize (* you can examine the result here *) |
---|
78 | @refl qed. |
---|
79 | |
---|
80 | include "Cminor/toRTLabs.ma". |
---|
81 | include "RTLabs/semantics.ma". |
---|
82 | |
---|
83 | example execRTL: finishes_with (repr 120) ? (do myprog' ← cminor_init_to_rtlabs myprog; exec_up_to RTLabs_fullexec myprog' 1000 [EVint (repr 5)]). |
---|
84 | normalize (* you can examine the result here *) |
---|
85 | @refl |
---|
86 | qed. |
---|
87 | |
---|