2022-12-06 20:39:15 +01:00
|
|
|
open Ast
|
2022-12-09 14:45:59 +01:00
|
|
|
open Mips
|
2022-12-06 22:22:48 +01:00
|
|
|
module Env = Map.Make (String)
|
2022-12-06 20:39:15 +01:00
|
|
|
|
2022-12-09 16:12:32 +01:00
|
|
|
let _types_ =
|
|
|
|
Env.of_seq
|
|
|
|
(List.to_seq
|
|
|
|
[ "%add", Func_t (Int_t, [ Int_t; Int_t ])
|
2022-12-09 16:39:44 +01:00
|
|
|
; "%sub", Func_t (Int_t, [ Int_t; Int_t ])
|
2022-12-09 16:12:32 +01:00
|
|
|
; "%mul", Func_t (Int_t, [ Int_t; Int_t ])
|
2022-12-09 16:39:44 +01:00
|
|
|
; "%div", Func_t (Int_t, [ Int_t; Int_t ])
|
2022-12-09 16:12:32 +01:00
|
|
|
])
|
|
|
|
;;
|
2022-12-09 14:45:59 +01:00
|
|
|
|
|
|
|
let builtins =
|
|
|
|
List.fold_left
|
|
|
|
(fun env (fn, impl) -> Env.add fn impl env)
|
|
|
|
Env.empty
|
2022-12-09 16:12:32 +01:00
|
|
|
[ "%add", [ Lw (T0, Mem (SP, 0)); Lw (T1, Mem (SP, 4)); Add (V0, T0, T1) ]
|
2022-12-09 16:39:44 +01:00
|
|
|
; "%sub", [ Lw (T0, Mem (SP, 0)); Lw (T1, Mem (SP, 4)); Sub (V0, T0, T1) ]
|
2022-12-09 16:12:32 +01:00
|
|
|
; "%mul", [ Lw (T0, Mem (SP, 0)); Lw (T1, Mem (SP, 4)); Mul (V0, T0, T1) ]
|
2022-12-09 16:39:44 +01:00
|
|
|
; "%div", [ Lw (T0, Mem (SP, 0)); Lw (T1, Mem (SP, 4)); Div (V0, T1, T0) ]
|
2022-12-09 16:40:34 +01:00
|
|
|
(* %div: reversal of T1 and T0 ?? *)
|
2022-12-09 16:12:32 +01:00
|
|
|
]
|
2022-12-09 14:45:59 +01:00
|
|
|
;;
|