Style more consistent, replace capitalization with camel case
This commit is contained in:
@ -142,19 +142,19 @@ end
|
||||
|
||||
let convert_cfgrisc_risci (i: CfgRISC.RISCSimpleStatements.t list) :
|
||||
(RISCAssembly.risci list) =
|
||||
let rec helper (i: CfgRISC.RISCSimpleStatements.t)
|
||||
let rec aux (i: CfgRISC.RISCSimpleStatements.t)
|
||||
: RISCAssembly.risci =
|
||||
match i with
|
||||
| Nop -> Nop
|
||||
| BRegOp (brop, r1, r2, r3) -> BRegOp (helper_brop brop,
|
||||
| BRegOp (brop, r1, r2, r3) -> BRegOp (aux_brop brop,
|
||||
{index = r1.index},
|
||||
{index = r2.index},
|
||||
{index = r3.index})
|
||||
| BImmOp (biop, r1, imm, r3) -> BImmOp (helper_biop biop,
|
||||
| BImmOp (biop, r1, imm, r3) -> BImmOp (aux_biop biop,
|
||||
{index = r1.index},
|
||||
imm,
|
||||
{index = r3.index})
|
||||
| URegOp (urop, r1, r3) -> URegOp (helper_urop urop,
|
||||
| URegOp (urop, r1, r3) -> URegOp (aux_urop urop,
|
||||
{index = r1.index},
|
||||
{index = r3.index})
|
||||
| Load (r1, r3) -> Load ({index = r1.index},
|
||||
@ -163,7 +163,7 @@ let convert_cfgrisc_risci (i: CfgRISC.RISCSimpleStatements.t list) :
|
||||
{index = r3.index})
|
||||
| Store (r1, r3) -> Store ({index = r1.index},
|
||||
{index = r3.index})
|
||||
and helper_brop (brop: CfgRISC.RISCSimpleStatements.brop)
|
||||
and aux_brop (brop: CfgRISC.RISCSimpleStatements.brop)
|
||||
: RISCAssembly.brop =
|
||||
match brop with
|
||||
| Add -> Add
|
||||
@ -179,7 +179,7 @@ let convert_cfgrisc_risci (i: CfgRISC.RISCSimpleStatements.t list) :
|
||||
| LessEq -> LessEq
|
||||
| More -> More
|
||||
| MoreEq -> MoreEq
|
||||
and helper_biop (biop: CfgRISC.RISCSimpleStatements.biop)
|
||||
and aux_biop (biop: CfgRISC.RISCSimpleStatements.biop)
|
||||
: RISCAssembly.biop =
|
||||
match biop with
|
||||
| AddI -> AddI
|
||||
@ -195,16 +195,16 @@ let convert_cfgrisc_risci (i: CfgRISC.RISCSimpleStatements.t list) :
|
||||
| LessEqI -> LessEqI
|
||||
| MoreI -> MoreI
|
||||
| MoreEqI -> MoreEqI
|
||||
and helper_urop (urop: CfgRISC.RISCSimpleStatements.urop)
|
||||
and aux_urop (urop: CfgRISC.RISCSimpleStatements.urop)
|
||||
: RISCAssembly.urop =
|
||||
match urop with
|
||||
| Not -> Not
|
||||
| Copy -> Copy
|
||||
| Rand -> Rand
|
||||
in
|
||||
List.map helper i
|
||||
List.map aux i
|
||||
|
||||
let nextCommonSuccessor
|
||||
let next_common_successor
|
||||
(prg: CfgRISC.RISCCfg.t)
|
||||
(node1: Cfg.Node.t)
|
||||
(node2: Cfg.Node.t)
|
||||
@ -231,30 +231,35 @@ let nextCommonSuccessor
|
||||
| a::_ -> Some a
|
||||
|
||||
|
||||
let rec helper
|
||||
let rec helper_convert
|
||||
(prg: CfgRISC.RISCCfg.t)
|
||||
(currentnode: Cfg.Node.t)
|
||||
(alreadyVisited: Cfg.Node.t list)
|
||||
(current_node: Cfg.Node.t)
|
||||
(already_visited: Cfg.Node.t list)
|
||||
: (RISCAssembly.risci list) * (Cfg.Node.t list) =
|
||||
(* takes the program, the current node and a list of already visited nodes to
|
||||
compute the linearized three address instructions and the list of
|
||||
previoulsy visited nodes plus the newly visited nodes. Stops as soon if
|
||||
node has already been visited or if no nodes are next *)
|
||||
if List.mem currentnode alreadyVisited then
|
||||
([], alreadyVisited)
|
||||
if List.mem current_node already_visited then
|
||||
([], already_visited)
|
||||
else (
|
||||
let nextnodes = (Cfg.NodeMap.find_opt currentnode prg.edges) in
|
||||
let nextnodes = (Cfg.NodeMap.find_opt current_node prg.edges) in
|
||||
let currentcode =
|
||||
(match (Cfg.NodeMap.find_opt currentnode prg.content) with
|
||||
(match (Cfg.NodeMap.find_opt current_node prg.content) with
|
||||
| None -> []
|
||||
| Some x -> convert_cfgrisc_risci x)
|
||||
in
|
||||
match nextnodes with
|
||||
| Some (nextnode1, None) ->
|
||||
let res, vis = (helper prg nextnode1 (currentnode :: alreadyVisited)) in
|
||||
let res, vis =
|
||||
helper_convert
|
||||
prg
|
||||
nextnode1
|
||||
(current_node :: already_visited)
|
||||
in
|
||||
(currentcode @ res, vis)
|
||||
| Some (nextnode1, Some nextnode2) -> (
|
||||
let ncs = nextCommonSuccessor prg nextnode1 nextnode2 in
|
||||
let ncs = next_common_successor prg nextnode1 nextnode2 in
|
||||
match ncs with
|
||||
| None -> (* should never happen since the terminal node should always be
|
||||
rechable *)
|
||||
@ -267,11 +272,11 @@ let rec helper
|
||||
let label3 = nextLabel () in
|
||||
|
||||
let res1, _ =
|
||||
(helper prg nextnode1
|
||||
(currentnode :: nextnode2 :: alreadyVisited)) in
|
||||
(helper_convert prg nextnode1
|
||||
(current_node :: nextnode2 :: already_visited)) in
|
||||
let res2, vis2 =
|
||||
(helper prg nextnode2
|
||||
(currentnode :: nextnode1 :: alreadyVisited)) in
|
||||
(helper_convert prg nextnode2
|
||||
(current_node :: nextnode1 :: already_visited)) in
|
||||
|
||||
match List.nth currentcode ((List.length currentcode) - 1) with
|
||||
| BRegOp (_, _, _, r)
|
||||
@ -296,9 +301,15 @@ let rec helper
|
||||
let label3 = nextLabel () in
|
||||
|
||||
let res1, vis1 =
|
||||
(helper prg nextnode1 (currentnode :: ncs :: alreadyVisited)) in
|
||||
let res2, _ = (helper prg nextnode2 vis1) in
|
||||
let res3, vis3 = (helper prg ncs (currentnode :: alreadyVisited)) in
|
||||
helper_convert
|
||||
prg
|
||||
nextnode1
|
||||
(current_node :: ncs :: already_visited)
|
||||
in
|
||||
let res2, _ = helper_convert prg nextnode2 vis1 in
|
||||
let res3, vis3 =
|
||||
helper_convert prg ncs (current_node :: already_visited)
|
||||
in
|
||||
match List.nth currentcode ((List.length currentcode) - 1) with
|
||||
| BRegOp (_, _, _, r)
|
||||
| BImmOp (_, _, _, r)
|
||||
@ -319,15 +330,15 @@ let rec helper
|
||||
| _ -> failwith "Missing instruction at branch"
|
||||
)
|
||||
)
|
||||
| None -> (currentcode, currentnode :: alreadyVisited)
|
||||
| None -> (currentcode, current_node :: already_visited)
|
||||
)
|
||||
|
||||
let convert (prg: CfgRISC.RISCCfg.t) : RISCAssembly.t =
|
||||
{code = (helper prg (Option.get prg.initial) [] |> fst |>
|
||||
{code = (helper_convert prg (Option.get prg.initial) [] |> fst |>
|
||||
List.append ([Label "main"] : RISCAssembly.risci list));
|
||||
inputval = prg.inputVal;
|
||||
inputval = prg.input_val;
|
||||
inputoutputreg =
|
||||
match prg.inputOutputVar with
|
||||
match prg.input_output_var with
|
||||
None -> None
|
||||
| Some (i, o) -> Some ({index = i}, {index = o})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user