Implementing cfg for risc
This commit is contained in:
@ -76,8 +76,8 @@ let rec convert_c (prevcfg: SSCfg.t) (prg: Types.c_exp) : SSCfg.t =
|
||||
cfg2
|
||||
| If (b, c1, c2) ->
|
||||
let convertedb = convert_b b in
|
||||
let cfg1 = convert_c (SSCfg.create ()) c1 in
|
||||
let cfg2 = convert_c (SSCfg.create ()) c2 in
|
||||
let cfg1 = convert_c SSCfg.empty c1 in
|
||||
let cfg2 = convert_c SSCfg.empty c2 in
|
||||
let entrynode = Node.create () in
|
||||
let exitnode = Node.create () in
|
||||
let newcfg = SSCfg.merge cfg1 cfg2 entrynode exitnode in
|
||||
@ -88,7 +88,7 @@ let rec convert_c (prevcfg: SSCfg.t) (prg: Types.c_exp) : SSCfg.t =
|
||||
NodeMap.add_to_list exitnode (SimpleSkip) }
|
||||
| While (b, c) ->
|
||||
let convertedb = convert_b b in
|
||||
let cfg = convert_c (SSCfg.create ()) c in
|
||||
let cfg = convert_c SSCfg.empty c in
|
||||
let cfginitial = Option.get cfg.initial in
|
||||
let cfgterminal = Option.get cfg.terminal in
|
||||
let entrynode = Node.create () in
|
||||
@ -109,17 +109,17 @@ let rec convert_c (prevcfg: SSCfg.t) (prg: Types.c_exp) : SSCfg.t =
|
||||
NodeMap.add_to_list exitnode guardnode |>
|
||||
NodeMap.add_to_list guardnode cfgterminal;
|
||||
inputVal = prevcfg.inputVal;
|
||||
outputVal = prevcfg.outputVal;
|
||||
inputOutputVar = prevcfg.inputOutputVar;
|
||||
initial = Some entrynode;
|
||||
terminal = Some exitnode;
|
||||
content = NodeMap.add_to_list guardnode (SimpleGuard (convertedb)) cfg.content |>
|
||||
NodeMap.add_to_list exitnode (SimpleSkip)
|
||||
} |> SSCfg.concat prevcfg
|
||||
| For (assignment, guard, increment, body) ->
|
||||
let cfgassignment = convert_c (SSCfg.create ()) assignment in
|
||||
let cfgassignment = convert_c SSCfg.empty assignment in
|
||||
let convertedguard = convert_b guard in
|
||||
let cfgincrement = convert_c (SSCfg.create ()) increment in
|
||||
let cfgbody = convert_c (SSCfg.create ()) body in
|
||||
let cfgincrement = convert_c SSCfg.empty increment in
|
||||
let cfgbody = convert_c SSCfg.empty body in
|
||||
|
||||
let prevassignment = SSCfg.concat prevcfg cfgassignment in
|
||||
let bodyincrement = SSCfg.concat cfgbody cfgincrement in
|
||||
@ -141,7 +141,7 @@ let rec convert_c (prevcfg: SSCfg.t) (prg: Types.c_exp) : SSCfg.t =
|
||||
NodeMap.add_to_list exitnode guardnode |>
|
||||
NodeMap.add_to_list guardnode cfgterminal;
|
||||
inputVal = prevcfg.inputVal;
|
||||
outputVal = prevcfg.outputVal;
|
||||
inputOutputVar = prevcfg.inputOutputVar;
|
||||
initial = Some guardnode;
|
||||
terminal = Some exitnode;
|
||||
content = NodeMap.add_to_list guardnode (SimpleGuard (convertedguard)) bodyincrement.content |>
|
||||
@ -174,9 +174,9 @@ and convert_a (prg: Types.a_exp) : SimpleStatements.simpleArithmetic =
|
||||
| Rand (a) -> SimpleRand (convert_a a)
|
||||
|
||||
let convert (prg: Types.p_exp) : SSCfg.t =
|
||||
let result =
|
||||
match prg with
|
||||
| Main (_, _, exp) ->
|
||||
convert_c (SSCfg.create ()) exp
|
||||
in
|
||||
{result with inputVal = None; outputVal = None}
|
||||
match prg with
|
||||
| Main (i, o, exp) ->
|
||||
{(convert_c SSCfg.empty exp) with inputOutputVar = Some (i, o)}
|
||||
|
||||
let convert_io (prg: Types.p_exp) (i: int) : SSCfg.t =
|
||||
{(convert prg) with inputVal = Some i}
|
||||
|
||||
Reference in New Issue
Block a user