Better styling for miniImp
This commit is contained in:
@ -18,7 +18,8 @@ module RISCArchitecture = struct
|
||||
}
|
||||
end
|
||||
|
||||
let convert (prg: RISC.RISCAssembly.t) : RISC.RISCAssembly.risci list CodeMap.t =
|
||||
let convert (prg: RISC.RISCAssembly.t)
|
||||
: RISC.RISCAssembly.risci list CodeMap.t =
|
||||
(* takes as input a sequence of RISC commands and computes a map to the right
|
||||
labels for easier execution *)
|
||||
let rec helper
|
||||
@ -101,7 +102,9 @@ let reduce_instructions (prg: RISCArchitecture.t) (lo: string list) : int =
|
||||
| Some i ->
|
||||
if i + 1 < (List.length lo) then
|
||||
helper
|
||||
prg (CodeMap.find (List.nth lo (i+1)) prg.code) (List.nth lo (i+1))
|
||||
prg
|
||||
(CodeMap.find (List.nth lo (i+1)) prg.code)
|
||||
(List.nth lo (i+1))
|
||||
else
|
||||
prg
|
||||
)
|
||||
@ -113,7 +116,7 @@ let reduce_instructions (prg: RISCArchitecture.t) (lo: string list) : int =
|
||||
(RegisterMap.find {index = r2.index} prg.registers)
|
||||
in
|
||||
helper { prg with
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers }
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers}
|
||||
tl current_label
|
||||
)
|
||||
| BImmOp (biop, r1, i, r3) :: tl -> (
|
||||
@ -122,7 +125,7 @@ let reduce_instructions (prg: RISCArchitecture.t) (lo: string list) : int =
|
||||
i
|
||||
in
|
||||
helper { prg with
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers }
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers}
|
||||
tl current_label
|
||||
)
|
||||
| URegOp (urop, r1, r3) :: tl -> (
|
||||
@ -160,20 +163,23 @@ let reduce_instructions (prg: RISCArchitecture.t) (lo: string list) : int =
|
||||
prg.memory
|
||||
in
|
||||
helper { prg with
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers }
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers}
|
||||
tl current_label
|
||||
)
|
||||
| LoadI (i, r3) :: tl -> (
|
||||
let n = i
|
||||
in
|
||||
helper { prg with
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers }
|
||||
registers = RegisterMap.add {index = r3.index} n prg.registers}
|
||||
tl current_label
|
||||
)
|
||||
| Store (r1, r3) :: tl -> (
|
||||
let n = RegisterMap.find {index = r1.index} prg.registers in
|
||||
let n1 = RegisterMap.find {index = r3.index} prg.registers in
|
||||
helper {prg with memory = MemoryMap.add n1 n prg.memory} tl current_label
|
||||
helper
|
||||
{ prg with memory = MemoryMap.add n1 n prg.memory }
|
||||
tl
|
||||
current_label
|
||||
)
|
||||
| Jump l :: _ -> helper prg (CodeMap.find l prg.code) l
|
||||
| CJump (r, l1, l2) :: _ -> (
|
||||
|
||||
Reference in New Issue
Block a user