Style more consistent, replace capitalization with camel case
This commit is contained in:
@ -21,7 +21,7 @@ let variables_frequency (instr : RISCCfg.elt) : (Variable.t * int) list =
|
||||
let add_one = (fun x -> match x with None -> Some 1 | Some x -> Some (x + 1))
|
||||
in
|
||||
|
||||
let helper (acc: int VariableMap.t) (instr: RISCCfg.elt) : int VariableMap.t =
|
||||
let aux (acc: int VariableMap.t) (instr: RISCCfg.elt) : int VariableMap.t =
|
||||
match instr with
|
||||
| Nop ->
|
||||
acc
|
||||
@ -39,7 +39,7 @@ let variables_frequency (instr : RISCCfg.elt) : (Variable.t * int) list =
|
||||
VariableMap.update r3.index add_one acc
|
||||
in
|
||||
|
||||
helper VariableMap.empty instr |> VariableMap.to_list
|
||||
aux VariableMap.empty instr |> VariableMap.to_list
|
||||
|
||||
(* computes syntactic frequency of all variables in the code *)
|
||||
let variables_all_frequency (instructions : RISCCfg.elt list)
|
||||
@ -52,7 +52,7 @@ let variables_all_frequency (instructions : RISCCfg.elt list)
|
||||
VariableMap.empty instructions |> VariableMap.to_list
|
||||
|
||||
|
||||
let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
let reduce_registers (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
(if n < 4 then (
|
||||
failwith "ReduceRegisters: number of registers too small"
|
||||
) else ());
|
||||
@ -68,7 +68,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
|
||||
(* add one to in and out variables *)
|
||||
let all_variables =
|
||||
match cfg.inputOutputVar with
|
||||
match cfg.input_output_var with
|
||||
| None -> all_variables
|
||||
| Some (i, _o) -> (
|
||||
match List.assoc_opt i all_variables with
|
||||
@ -78,7 +78,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
in
|
||||
|
||||
let all_variables =
|
||||
match cfg.inputOutputVar with
|
||||
match cfg.input_output_var with
|
||||
| None -> all_variables
|
||||
| Some (_i, o) -> (
|
||||
match List.assoc_opt o all_variables with
|
||||
@ -89,7 +89,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
|
||||
(* replace each operation with a list of operations that have the new
|
||||
registers or load from memory *)
|
||||
let replaceregisters
|
||||
let replace_registers
|
||||
(remappedregisters: Variable.t VariableMap.t)
|
||||
(memorymap: int VariableMap.t)
|
||||
(temporaryregisters: Variable.t list)
|
||||
@ -315,7 +315,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
cfg with
|
||||
content = Cfg.NodeMap.map
|
||||
( fun x ->
|
||||
replaceregisters
|
||||
replace_registers
|
||||
most_frequent_mapping
|
||||
least_frequent_mapping
|
||||
["1"; "2"]
|
||||
@ -323,10 +323,10 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
) cfg.content}
|
||||
in
|
||||
|
||||
if newcfg.inputOutputVar = None
|
||||
if newcfg.input_output_var = None
|
||||
then newcfg (* if no input or output variables we ignore *)
|
||||
else
|
||||
let i, o = Option.get newcfg.inputOutputVar in
|
||||
let i, o = Option.get newcfg.input_output_var in
|
||||
match (VariableMap.find_opt i most_frequent_mapping,
|
||||
VariableMap.find_opt o most_frequent_mapping,
|
||||
VariableMap.find_opt i least_frequent_mapping,
|
||||
@ -335,15 +335,15 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
newcfg.terminal )
|
||||
with (*we check if in and out are simply remapped or are put in memory*)
|
||||
| Some i, Some o, _, _, _, _ ->
|
||||
{ newcfg with inputOutputVar = Some (i, o) }
|
||||
{ newcfg with input_output_var = Some (i, o) }
|
||||
| Some i, None, _, Some _, _, None ->
|
||||
(* we check for the terminal node, if not present we are very confused
|
||||
and dont modify the out variable *)
|
||||
{ newcfg with inputOutputVar = Some (i, o)}
|
||||
{ newcfg with input_output_var = Some (i, o)}
|
||||
| Some i, None, _, Some mo, _, Some n ->
|
||||
(* since the output simbol is in memory we need to first retrive it
|
||||
and then put the result in a temporary register *)
|
||||
let terminalcontent = (
|
||||
let terminal_content = (
|
||||
match Cfg.NodeMap.find_opt n newcfg.content with
|
||||
| None -> []
|
||||
| Some x -> x
|
||||
@ -351,14 +351,14 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
Load ({index = "2"}, {index = "2"})]
|
||||
in
|
||||
let content =
|
||||
Cfg.NodeMap.add n terminalcontent newcfg.content
|
||||
Cfg.NodeMap.add n terminal_content newcfg.content
|
||||
in
|
||||
{ newcfg with
|
||||
inputOutputVar = Some (i, "2");
|
||||
input_output_var = Some (i, "2");
|
||||
content = content
|
||||
}
|
||||
| None, Some o, Some _, _, _, None ->
|
||||
{ newcfg with inputOutputVar = Some (i, o) }
|
||||
{ newcfg with input_output_var = Some (i, o) }
|
||||
| None, Some o, Some mi, _, _, Some n -> (
|
||||
(* the input simbol should be stored in memory *)
|
||||
let initialcontent =
|
||||
@ -371,12 +371,12 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
in
|
||||
let content = Cfg.NodeMap.add n initialcontent newcfg.content in
|
||||
{ newcfg with
|
||||
inputOutputVar = Some ("1", o);
|
||||
input_output_var = Some ("1", o);
|
||||
content = content
|
||||
}
|
||||
)
|
||||
| None, None, Some _, Some _, None, None ->
|
||||
{ newcfg with inputOutputVar = Some (i, o) }
|
||||
{ newcfg with input_output_var = Some (i, o) }
|
||||
| None, None, Some _, Some mo, None, Some n ->
|
||||
(* both simbols should be in memory *)
|
||||
let terminalcontent = (
|
||||
@ -390,7 +390,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
Cfg.NodeMap.add n terminalcontent newcfg.content
|
||||
in
|
||||
{ newcfg with
|
||||
inputOutputVar = Some (i, "2");
|
||||
input_output_var = Some (i, "2");
|
||||
content = content
|
||||
}
|
||||
| None, None, Some mi, Some _, Some n, None ->
|
||||
@ -405,7 +405,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
in
|
||||
let content = Cfg.NodeMap.add n initialcontent newcfg.content in
|
||||
{ newcfg with
|
||||
inputOutputVar = Some ("1", o);
|
||||
input_output_var = Some ("1", o);
|
||||
content = content
|
||||
}
|
||||
| None, None, Some mi, Some mo, Some ni, Some no ->
|
||||
@ -432,7 +432,7 @@ let reduceregisters (n: int) (cfg: RISCCfg.t) : RISCCfg.t =
|
||||
Cfg.NodeMap.add no terminalcontent content
|
||||
in
|
||||
{ newcfg with
|
||||
inputOutputVar = Some ("1", "2");
|
||||
input_output_var = Some ("1", "2");
|
||||
content = content
|
||||
}
|
||||
| _ -> failwith ("ReduceRegisters: fail to partition a set, some" ^
|
||||
|
||||
Reference in New Issue
Block a user