From c37a7fe1bcd93360f66c76084a8babd37b82bdda Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 13 Dec 2022 15:00:39 +0100 Subject: [PATCH] add prefix for user defined fn to avoid conflict with mips instrs --- compiler.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler.ml b/compiler.ml index 08f5e1c..6a3ff6d 100644 --- a/compiler.ml +++ b/compiler.ml @@ -11,6 +11,8 @@ type info = ; ret : string (* Return *) } +let puf = "f_" (* prefix user function *) + let compile_value = function | Void -> [ Li (V0, 0) ] | Int n -> [ Li (V0, n) ] @@ -31,7 +33,7 @@ let rec compile_expr env = function @ if Env.mem f Baselib.builtins then Env.find f Baselib.builtins - else [ Jal f; Addi (SP, SP, 4 * List.length args) ] + else [ Jal (puf ^ f); Addi (SP, SP, 4 * List.length args) ] ;; let compile_instr info = function @@ -65,8 +67,9 @@ let compile_def (Func (name, args, body)) counter = } body in + let lbl_puf = if name = "main" then "" else puf in ( compiled.cnt - , [ Label name + , [ Label (lbl_puf ^ name) ; Addi (SP, SP, -compiled.fpo) ; Sw (RA, Mem (SP, compiled.fpo - 4)) ; Sw (FP, Mem (SP, compiled.fpo - 8))