From: Siraaj Khandkar Date: Thu, 22 Aug 2019 19:09:13 +0000 (-0400) Subject: WIP X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=3b1bffdb6bf39ea0e4817aefa9a5cc3167433c4f;p=tiger.ml.git WIP --- diff --git a/compiler/src/lib/tiger/tiger_frame_sig.ml b/compiler/src/lib/tiger/tiger_frame_sig.ml index 2da5d57..5ab7718 100644 --- a/compiler/src/lib/tiger/tiger_frame_sig.ml +++ b/compiler/src/lib/tiger/tiger_frame_sig.ml @@ -3,7 +3,11 @@ module type S = sig type access - val word_size : int + val word_size : + int + + val pointer : + Tiger_temp.Temp.t val make : name:Tiger_temp.Label.t -> formals:bool list -> t @@ -16,4 +20,7 @@ module type S = sig val alloc_local : t -> escapes:bool -> access + + val exp : + access:access -> pointer:Tiger_tree.exp -> Tiger_tree.exp end diff --git a/compiler/src/lib/tiger/tiger_mips_frame.ml b/compiler/src/lib/tiger/tiger_mips_frame.ml index 4131702..f373b0e 100644 --- a/compiler/src/lib/tiger/tiger_mips_frame.ml +++ b/compiler/src/lib/tiger/tiger_mips_frame.ml @@ -1,6 +1,7 @@ module List = ListLabels module Temp = Tiger_temp +module T = Tiger_tree type access = | InFrame of {offset_from_frame_pointer : int} @@ -19,6 +20,8 @@ type t = ; instructions : unit (* TODO: instructions for view shift *) } +let pointer = Temp.Temp.gen () + let word_size_bits = 32 let word_size_bytes = word_size_bits / 8 let word_size = word_size_bytes @@ -57,3 +60,12 @@ let make ~name ~formals = ; locals_count ; instructions = () (* TODO: instructions for view shift *) } + +(*failwith ("NOT IMPLEMENTED: " ^ __MODULE__ ^ ".exp")*) + +let exp ~access ~pointer = + match access with + | InReg {register} -> + T.TEMP register + | InFrame {offset_from_frame_pointer} -> + T.MEM (T.BINOP (T.PLUS, pointer, T.CONST offset_from_frame_pointer)) diff --git a/compiler/src/lib/tiger/tiger_translate.ml b/compiler/src/lib/tiger/tiger_translate.ml index 483335a..9295df9 100644 --- a/compiler/src/lib/tiger/tiger_translate.ml +++ b/compiler/src/lib/tiger/tiger_translate.ml @@ -47,13 +47,13 @@ type exp = type access = (* must know about static links *) - { level : Level.t - ; frame_access : Frame.access + { level : Level.t + ; access : Frame.access } let alloc_local ~level ~escapes = { level - ; frame_access = Frame.alloc_local (Level.frame level) ~escapes + ; access = Frame.alloc_local (Level.frame level) ~escapes } let formals ~level = @@ -62,6 +62,9 @@ let formals ~level = alloc_local ~level ~escapes ) +let not_implemented func = + failwith (Printf.sprintf "Not implemented: %s.%s" __MODULE__ func) + let rec seq = function (* TODO: Is appending 0 OK? How else can the empty case be handled? *) | [] -> T.EXP (T.CONST 0) @@ -100,3 +103,7 @@ let unCx = function | Cx g -> g let dummy__FIXME = Ex (T.CONST 0) + +let simple_var {level; access} = + let pointer = not_implemented "simple_var frame pointer" in + Ex (Frame.exp ~access ~pointer) diff --git a/compiler/src/lib/tiger/tiger_translate.mli b/compiler/src/lib/tiger/tiger_translate.mli index ca4b0b2..5250b50 100644 --- a/compiler/src/lib/tiger/tiger_translate.mli +++ b/compiler/src/lib/tiger/tiger_translate.mli @@ -24,3 +24,5 @@ val unNx : exp -> Tiger_tree.stm val unCx : exp -> gen_stm val dummy__FIXME : exp (* FIXME: Remove dummy when real is ready *) + +val simple_var : access -> exp