]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/contribs/ng_assembly/emulator/translation/translation.ma
mod change (-x)
[helm.git] / matitaB / matita / contribs / ng_assembly / emulator / translation / translation.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "emulator/translation/Freescale_translation.ma".
24 include "emulator/translation/IP2022_translation.ma".
25
26 (* ******************************************************* *)
27 (* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
28 (* ******************************************************* *)
29
30 (* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
31 ndefinition MA_check ≝
32 λmcu:mcu_type.
33  match mcu
34   return λm.(aux_im_type m) → Type
35  with
36   [ HC05 ⇒ Freescale_MA_check
37   | HC08 ⇒ Freescale_MA_check
38   | HCS08 ⇒ Freescale_MA_check
39   | RS08 ⇒ Freescale_MA_check
40   | IP2022 ⇒ IP2022_MA_check
41   ].
42
43 (* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
44    MA_check i → list (t_byte8 m) *)
45 ndefinition args_picker ≝
46 λmcu:mcu_type.
47  match mcu
48   return λm.Πi:(aux_im_type m).MA_check m i → ?
49  with
50   [ HC05 ⇒ Freescale_args_picker HC05
51   | HC08 ⇒ Freescale_args_picker HC08
52   | HCS08 ⇒ Freescale_args_picker HCS08
53   | RS08 ⇒ Freescale_args_picker RS08
54   | IP2022 ⇒ IP2022_args_picker
55   ].
56
57 (* trasformatore finale: mcu+opcode+instr_mode+args → list (t_byte8 m) *)
58 nlet rec bytes_of_pseudo_instr_mode_param_aux (m:mcu_type) (o:aux_pseudo_type m) (i:aux_im_type m) (p:MA_check m i)
59                                              (param:list (aux_table_type m)) on param ≝
60  match param with
61  [ nil ⇒ None ? | cons hd tl ⇒
62   match (eq_pseudo m o (fst4T … hd)) ⊗ (eq_im m i (snd4T … hd)) with
63    [ true ⇒ match thd4T … hd with 
64     [ Byte isab ⇒ 
65      Some ? ([ (TByte m isab) ]@(args_picker m i p))
66     | Word isaw ⇒
67      Some ? ([ (TByte m (cnH ? isaw)) ; (TByte m (cnL ? isaw)) ]@(args_picker m i p))
68     ]
69    | false ⇒ bytes_of_pseudo_instr_mode_param_aux m o i p tl ]].
70
71 ndefinition bytes_of_pseudo_instr_mode_param ≝
72 λm:mcu_type.λo:aux_pseudo_type m.λi:aux_im_type m.λp:MA_check m i.
73 bytes_of_pseudo_instr_mode_param_aux m o i p (opcode_table m).
74
75 (* ****************************** *)
76 (* APPROCCIO COMPILAZIONE AL VOLO *)
77 (* ****************************** *)
78
79 (* ausiliario di compile *)
80 ndefinition defined_option ≝
81  λT:Type.λo:option T.
82   match o with
83    [ None ⇒ False
84    | Some _ ⇒ True
85    ].
86
87 (* compila solo se l'intera istruzione+modalita'+argomenti ha riscontro nelle tabelle *)
88 ndefinition compile ≝
89 λmcu:mcu_type.λi:aux_im_type mcu.λop:aux_pseudo_type mcu.λarg:MA_check mcu i.
90  match bytes_of_pseudo_instr_mode_param mcu op i arg
91   return λres:option ?.defined_option ? res → ?
92  with
93   [ None ⇒ λp:defined_option ? (None ?).False_rect_Type0 ? p
94   | Some x ⇒ λp:defined_option ? (Some ? x).x
95   ].
96
97 (* detipatore del compilato: (t_byte8 m) → byte8 *)
98 nlet rec source_to_byte8_aux (m:mcu_type) (p2:list byte8) (p1:list (t_byte8 m))  on p1 ≝
99  match p1 with
100   [ nil ⇒ p2
101   | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_aux m (p2@[b]) tl ]
102   ].
103
104 ndefinition source_to_byte8 ≝ λm:mcu_type.source_to_byte8_aux m [].