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

31 lines
1.1 KiB
OCaml
Raw Normal View History

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-13 14:36:45 +01:00
; "puti", Func_t (Void_t, [ Int_t ])
; "puts", Func_t (Void_t, [ Str_t ])
; "geti", Func_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:58:17 +01:00
[ "%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) ]
2022-12-10 17:06:08 +01:00
; "puti", [ Lw (A0, Mem (SP, 0)); Li (V0, Syscall.print_int); Syscall ]
2022-12-13 14:36:45 +01:00
; "puts", [ Lw (A0, Mem (SP, 0)); Li (V0, Syscall.print_str); Syscall ]
; "geti", [ Lw (A0, Mem (SP, 0)); Li (V0, Syscall.read_int); Syscall ]
2022-12-09 16:12:32 +01:00
]
2022-12-09 14:45:59 +01:00
;;