1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Sviluppo: 2008-2010 *)
21 (* ********************************************************************** *)
23 include "emulator/translation/HC05_translation.ma".
24 include "emulator/translation/HC08_translation.ma".
25 include "emulator/translation/HCS08_translation.ma".
26 include "emulator/translation/RS08_translation.ma".
27 include "emulator/translation/IP2022_translation.ma".
29 (* ******************************************************* *)
30 (* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
31 (* ******************************************************* *)
33 (* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
34 ndefinition MA_check ≝
37 return λm.(aux_im_type m) → Type
39 [ HC05 ⇒ HC05_MA_check
40 | HC08 ⇒ HC08_MA_check
41 | HCS08 ⇒ HCS08_MA_check
42 | RS08 ⇒ RS08_MA_check
43 | IP2022 ⇒ IP2022_MA_check
46 (* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
47 MA_check i → list (t_byte8 m) *)
48 ndefinition args_picker ≝
51 return λm.Πi:(aux_im_type m).MA_check m i → ?
53 [ HC05 ⇒ HC05_args_picker
54 | HC08 ⇒ HC08_args_picker
55 | HCS08 ⇒ HCS08_args_picker
56 | RS08 ⇒ RS08_args_picker
57 | IP2022 ⇒ IP2022_args_picker
60 (* trasformatore finale: mcu+opcode+instr_mode+args → list (t_byte8 m) *)
61 nlet rec bytes_of_pseudo_instr_mode_param_aux (m:mcu_type) (o:aux_op_type m) (i:aux_im_type m) (p:MA_check m i)
62 (param:list (aux_table_type m)) on param ≝
64 [ nil ⇒ None ? | cons hd tl ⇒
65 match (eq_op m o (fst4T … hd)) ⊗ (eq_im m i (snd4T … hd)) with
66 [ true ⇒ match thd4T … hd with
68 Some ? ([ (TByte m isab) ]@(args_picker m i p))
70 Some ? ([ (TByte m (cnH ? isaw)) ; (TByte m (cnL ? isaw)) ]@(args_picker m i p))
72 | false ⇒ bytes_of_pseudo_instr_mode_param_aux m o i p tl ]].
74 ndefinition bytes_of_pseudo_instr_mode_param ≝
75 λm:mcu_type.λo:aux_op_type m.λi:aux_im_type m.λp:MA_check m i.
76 bytes_of_pseudo_instr_mode_param_aux m o i p (opcode_table m).
78 (* ****************************** *)
79 (* APPROCCIO COMPILAZIONE AL VOLO *)
80 (* ****************************** *)
82 (* ausiliario di compile *)
83 ndefinition defined_option ≝
90 (* compila solo se l'intera istruzione+modalita'+argomenti ha riscontro nelle tabelle *)
92 λmcu:mcu_type.λi:aux_im_type mcu.λop:aux_op_type mcu.λarg:MA_check mcu i.
93 match bytes_of_pseudo_instr_mode_param mcu op i arg
94 return λres:option ?.defined_option ? res → ?
96 [ None ⇒ λp:defined_option ? (None ?).False_rect_Type0 ? p
97 | Some x ⇒ λp:defined_option ? (Some ? x).x
100 (* detipatore del compilato: (t_byte8 m) → byte8 *)
101 nlet rec source_to_byte8_aux (m:mcu_type) (p2:list byte8) (p1:list (t_byte8 m)) on p1 ≝
104 | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_aux m (p2@[b]) tl ]
107 ndefinition source_to_byte8 ≝ λm:mcu_type.source_to_byte8_aux m [].