source: src/LTL/LTLToLIN.ma @ 1149

Last change on this file since 1149 was 1149, checked in by mulligan, 8 years ago

changes to get everything type checking again after changing names of registers in i8051

File size: 4.7 KB
Line 
1include "LTL/LTL.ma".
2include "LIN/LIN.ma".
3include "utilities/BitVectorTrieSet.ma".
4include "common/Graphs.ma".
5
6axiom LTLTag: String.
7
8definition translate_statement: ∀globals. ltl_statement globals → pre_lin_statement globals ≝
9  λglobals: list ident.
10  λs: ltl_statement globals.
11    match s with
12    [ joint_st_return ⇒ joint_st_return ? globals
13    | joint_st_sequential instr _ ⇒ joint_st_sequential ? globals instr it
14    | joint_st_goto l ⇒ joint_st_goto ? globals l
15    ].
16   
17definition require: label → BitVectorTrieSet 16 → BitVectorTrieSet 16 ≝
18  λl: label.
19  λg: BitVectorTrieSet 16.
20    set_insert ? (word_of_identifier ? l) g.
21   
22definition mark: label → BitVectorTrieSet 16 → BitVectorTrieSet 16 ≝
23  λl: label.
24  λg: BitVectorTrieSet 16.
25    set_insert ? (word_of_identifier ? l) g.
26   
27definition marked: label → BitVectorTrieSet 16 → bool ≝
28  λl: label.
29  λg: BitVectorTrieSet 16.
30    set_member ? (word_of_identifier ? l) g.
31   
32(* alias id "lookupn" = "cic:/matita/cerco/common/Identifiers/lookup.def(3)". *)
33   
34definition graph_lookup ≝
35  λglobals: list ident.
36  λl: label.
37  λgr: ltl_statement_graph globals.
38    lookup LabelTag ? gr (an_identifier LabelTag (word_of_identifier ? l)).
39   
40definition fetch: ∀globals: list ident. label → ltl_statement_graph globals → option (ltl_statement globals) ≝
41  λglobals: list ident.
42  λl: label.
43  λg: ltl_statement_graph globals.
44    graph_lookup globals l g.
45
46definition foo ≝
47  λl2, visited, required, globals, generated, g, n.
48  λvisit:
49  ∀globals: list ident.
50  ∀g: ltl_statement_graph globals.
51  ∀required: BitVectorTrieSet 16.
52  ∀visited: BitVectorTrieSet 16.
53  ∀generated: list (pre_lin_statement globals).
54  ∀l: label.
55  ∀n: nat.
56    BitVectorTrieSet 16 × (list (pre_lin_statement globals)).
57  if marked l2 visited then
58    〈require l2 required, (joint_st_goto ? globals l2) :: generated〉
59  else
60   visit globals g required visited generated l2 n.
61
62(* XXX: look at this.  way too complicated to understand whether it is correct,
63   in my opinion.
64*)
65let rec visit
66  (globals: list ident) (g: ltl_statement_graph globals)
67  (required: BitVectorTrieSet 16) (visited: BitVectorTrieSet 16)
68  (generated: list (pre_lin_statement globals)) (l: label) (n: nat)
69    on n: BitVectorTrieSet 16 × (list (pre_lin_statement globals)) ≝
70  match n with
71  [ O ⇒ 〈required, generated〉
72  | S n' ⇒
73    let visited' ≝ mark l visited in
74    match fetch globals l g with
75    [ None ⇒ 〈required, generated〉 (* dpm: correct? *)
76    | Some statement ⇒
77      let translated_statement ≝ translate_statement globals statement in
78      let generated'' ≝ translated_statement :: generated in
79      match statement with
80      [ joint_st_sequential instr l2 ⇒
81        match instr with
82        [ joint_instr_cond_acc l1 ⇒
83              let required' ≝
84                if marked l2 visited' then
85                  require l2 required
86                else
87                  required in
88              let 〈required', generated''〉 ≝
89               foo l2 visited' required' globals generated'' g n' visit (*
90                if marked l2 visited' then
91                  〈required', (Joint_St_Goto ? globals l2) :: generated''〉
92                else
93                  visit globals g required' visited' generated'' l2 n'*) in
94              let required'' ≝ require l1 required' in
95                if ¬(marked l1 visited') then
96                  visit globals g required'' visited' generated'' l1 n'
97                else
98                  〈required', generated''〉
99          | _ ⇒
100            let required' ≝
101              if marked l2 visited' then
102                require l2 required
103              else
104                required in
105            if marked l2 visited' then
106              〈required', joint_st_goto ? globals l2 :: generated''〉
107            else
108              visit globals g required' visited' generated'' l2 n'
109          ]
110        | joint_st_return ⇒ 〈required, generated''〉 (* dpm: correct? *)
111    | joint_st_goto l ⇒
112       let required' ≝
113         if marked l visited' then
114           require l required
115         else
116           required
117       in
118         if marked l visited' then
119           〈required', joint_st_goto ? globals l :: generated''〉
120         else
121           visit globals g required' visited' generated'' l n'
122    ]
123  ]
124].
125
126(*
127definition translate_graph ≝
128  λglobals: list Identifier.
129  λg: LTLStatementGraph globals.
130  λentry: Identifier.
131    let visited ≝ set_empty ? in
132    let required ≝ set_insert ? entry (set_empty ?) in
133    let 〈required', translated〉 ≝ visit globals g required visited [ ] entry in
134    let reversed ≝ rev ? translated in
135      filter (λs: PreLINStatement globals. ?) reversed.
136*)
Note: See TracBrowser for help on using the repository browser.