This repository has been archived on 2022-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
compilateurMIPS/baselib.ml
2022-12-09 16:58:17 +01:00

24 lines
728 B
OCaml

open Ast
open Mips
module Env = Map.Make (String)
let _types_ =
Env.of_seq
(List.to_seq
[ "%add", Func_t (Int_t, [ Int_t; Int_t ])
; "%sub", Func_t (Int_t, [ Int_t; Int_t ])
; "%mul", Func_t (Int_t, [ Int_t; Int_t ])
; "%div", Func_t (Int_t, [ Int_t; Int_t ])
])
;;
let builtins =
List.fold_left
(fun env (fn, impl) -> Env.add fn impl env)
Env.empty
[ "%add", [ Lw (T0, Mem (SP, 4)); Lw (T1, Mem (SP, 0)); Add (V0, T0, T1) ]
; "%sub", [ Lw (T0, Mem (SP, 4)); Lw (T1, Mem (SP, 0)); Sub (V0, T0, T1) ]
; "%mul", [ Lw (T0, Mem (SP, 4)); Lw (T1, Mem (SP, 0)); Mul (V0, T0, T1) ]
; "%div", [ Lw (T0, Mem (SP, 4)); Lw (T1, Mem (SP, 0)); Div (V0, T0, T1) ]
]
;;