source: src/joint/Joint.ma @ 1270

Last change on this file since 1270 was 1270, checked in by sacerdot, 9 years ago

Making RTL syntax an instance of Joint.

File size: 6.1 KB
Line 
1include "ASM/I8051.ma".
2include "common/CostLabel.ma".
3include "common/AST.ma".
4include "common/Registers.ma".
5include "utilities/sigma.ma". (* CSC: Only for Sigma type projections *)
6include "common/Graphs.ma".
7
8record params__: Type[1] ≝
9 { acc_a_reg: Type[0]
10 ; acc_b_reg: Type[0]
11 ; dpl_reg: Type[0]
12 ; dph_reg: Type[0]
13 ; pair_reg: Type[0]
14 ; generic_reg: Type[0]
15 ; call_args: Type[0]
16 ; call_dest: Type[0]
17 
18 ; extend_statements: Type[0]
19 
20 ; resultT: Type[0]
21 ; localsT: Type[0]
22 ; paramsT: Type[0]
23 }.
24
25record params_: Type[1] ≝
26 { pars__:> params__
27 ; succ: Type[0]
28 }.
29
30inductive joint_instruction (p:params__) (globals: list ident): Type[0] ≝
31  | joint_instr_comment: String → joint_instruction p globals
32  | joint_instr_cost_label: costlabel → joint_instruction p globals
33  | joint_instr_int: generic_reg p → Byte → joint_instruction p globals
34  | joint_instr_move: pair_reg p → joint_instruction p globals
35  | joint_instr_pop: acc_a_reg p → joint_instruction p globals
36  | joint_instr_push: acc_a_reg p → joint_instruction p globals
37  | joint_instr_address: ∀i: ident. (member i (eq_identifier ?) globals) → dpl_reg p → dph_reg p → joint_instruction p globals
38  | joint_instr_opaccs: OpAccs → acc_a_reg p → acc_b_reg p → joint_instruction p globals
39  | joint_instr_op1: Op1 → acc_a_reg p → acc_a_reg p → joint_instruction p globals
40  | joint_instr_op2: Op2 → acc_a_reg p → acc_a_reg p → generic_reg p → joint_instruction p globals
41  | joint_instr_clear_carry: joint_instruction p globals
42  | joint_instr_set_carry: joint_instruction p globals
43  | joint_instr_load: acc_a_reg p → dpl_reg p → dph_reg p → joint_instruction p globals
44  | joint_instr_store: dpl_reg p → dph_reg p → acc_a_reg p → joint_instruction p globals
45  | joint_instr_call_id: ident → call_args p → call_dest p → joint_instruction p globals
46  | joint_instr_cond: acc_a_reg p → label → joint_instruction p globals
47  | joint_instr_extension: extend_statements p → joint_instruction p globals.
48
49inductive joint_statement (p:params_) (globals: list ident): Type[0] ≝
50  | joint_st_sequential: joint_instruction p globals → succ p → joint_statement p globals
51  | joint_st_goto: label → joint_statement p globals
52  | joint_st_return: joint_statement p globals.
53
54
55record params (globals: list ident): Type[1] ≝
56 { pars_:> params_
57 ; codeT: Type[0]
58 ; lookup: codeT → label → option (joint_statement pars_ globals)
59 }.
60
61include alias "common/Graphs.ma". (* To pick the right lookup *)
62
63(* One common instantiation of params via Graphs of joint_statements *)
64definition graph_params: params_ → ∀globals: list ident. params globals ≝
65 λparams_,globals. mk_params globals params_ (graph (joint_statement params_ globals)) (lookup …).
66
67record joint_internal_function (globals: list ident) (p:params globals) : Type[0] ≝
68{ joint_if_luniverse: universe LabelTag;    (*CSC: used only for compilation*)
69  joint_if_runiverse: universe RegisterTag; (*CSC: used only for compilation*)
70(*  joint_if_sig: signature;  -- dropped in front end *)
71  joint_if_result   : resultT p;
72  joint_if_params   : paramsT p;
73  joint_if_locals   : localsT p;
74(*CSC: XXXXX stacksize unused for LTL-...*)
75  joint_if_stacksize: nat;
76  joint_if_code     : codeT … p;
77(*CSC: XXXXX entry unused for LIN, but invariant in that case... *)
78  joint_if_entry    : Σl: label. lookup … joint_if_code l ≠ None ?;
79(*CSC: XXXXX exit only used up to RTL (and only for tailcall removal) *)
80  joint_if_exit     : Σl: label. lookup … joint_if_code l ≠ None ?
81}.
82
83(* Currified form *)
84definition set_joint_if_exit ≝
85  λglobals,pars.
86  λexit: label.
87  λp:joint_internal_function globals pars.
88  λprf: lookup … (joint_if_code … p) exit ≠ None ?.
89   mk_joint_internal_function globals pars
90    (joint_if_luniverse … p) (joint_if_runiverse … p) (joint_if_result … p)
91    (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p)
92    (joint_if_code … p) (joint_if_entry … p) (dp … exit prf).
93
94definition set_luniverse ≝
95  λglobals,pars.
96  λp : joint_internal_function globals pars.
97  λluniverse: universe LabelTag.
98   mk_joint_internal_function globals pars
99    luniverse (joint_if_runiverse … p) (joint_if_result … p)
100    (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p)
101    (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p).
102
103definition set_runiverse ≝
104  λglobals,pars.
105  λp : joint_internal_function globals pars.
106  λruniverse: universe RegisterTag.
107   mk_joint_internal_function globals pars
108    (joint_if_luniverse … p) runiverse (joint_if_result … p)
109    (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p)
110    (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p).
111
112(* Specialized for graph_params *)
113definition add_graph ≝
114  λpars_,globals.λl:label.λstmt.λp:joint_internal_function globals (graph_params pars_ globals).
115   let code ≝ add … (joint_if_code ?? p) l stmt in
116    mk_joint_internal_function … (graph_params pars_ globals)
117     (joint_if_luniverse … p) (joint_if_runiverse … p) (joint_if_result … p)
118     (joint_if_params … p) (joint_if_locals … p) (joint_if_stacksize … p)
119     code (pi1 ?? (joint_if_entry … p)) (pi1 … (joint_if_exit … p)).
120  normalize nodelta;
121  [ cases (joint_if_entry … p) | cases (joint_if_exit … p)]
122  #LBL #LBL_PRF @graph_add_lookup @LBL_PRF
123qed.
124
125definition set_locals ≝
126  λglobals,pars.
127  λp : joint_internal_function globals pars.
128  λlocals.
129   mk_joint_internal_function globals pars
130    (joint_if_luniverse … p) (joint_if_runiverse … p) (joint_if_result … p)
131    (joint_if_params … p) locals (joint_if_stacksize … p)
132    (joint_if_code … p) (joint_if_entry … p) (joint_if_exit … p).
133
134definition joint_function ≝ λp,globals. fundef (joint_internal_function p globals).
135
136definition joint_program ≝
137 λp:∀globals.params globals. program (λglobals. joint_function globals (p globals)) nat.
138
139(****************************************************************************)
140
141(* Used in LTL and LIN *) 
142inductive registers_move: Type[0] ≝
143 | from_acc: Register → registers_move
144 | to_acc: Register → registers_move.
Note: See TracBrowser for help on using the repository browser.