|
@@ -28,13 +28,13 @@ let for_to_while node =
|
|
|
noloc
|
|
noloc
|
|
|
) in
|
|
) in
|
|
|
Block [
|
|
Block [
|
|
|
- Assign (_i, start, locof start);
|
|
|
|
|
- Assign (_stop, stop, locof stop);
|
|
|
|
|
- Assign (_step, step, locof step);
|
|
|
|
|
|
|
+ Assign (_i, None, start, locof start);
|
|
|
|
|
+ Assign (_stop, None, stop, locof stop);
|
|
|
|
|
+ Assign (_step, None, step, locof step);
|
|
|
While (cond, traverse (Block (
|
|
While (cond, traverse (Block (
|
|
|
(* TODO: check for illegal assigments of counter in body *)
|
|
(* TODO: check for illegal assigments of counter in body *)
|
|
|
block_body (replace_var counter _i body) @
|
|
block_body (replace_var counter _i body) @
|
|
|
- [Assign (_i, Binop (Add, vi, vstep, noloc), noloc)]
|
|
|
|
|
|
|
+ [Assign (_i, None, Binop (Add, vi, vstep, noloc), noloc)]
|
|
|
)), loc);
|
|
)), loc);
|
|
|
]
|
|
]
|
|
|
|
|
|
|
@@ -49,7 +49,7 @@ let rec var_init = function
|
|
|
let decls = flatten_blocks (List.map var_init decls) in
|
|
let decls = flatten_blocks (List.map var_init decls) in
|
|
|
let rec trav assigns = function
|
|
let rec trav assigns = function
|
|
|
| [] -> (assigns, [])
|
|
| [] -> (assigns, [])
|
|
|
- | (Assign (_, _, _) as h) :: t -> trav (assigns @ [h]) t
|
|
|
|
|
|
|
+ | (Assign _ as h) :: t -> trav (assigns @ [h]) t
|
|
|
| h :: t ->
|
|
| h :: t ->
|
|
|
let (assigns, decls) = trav assigns t in
|
|
let (assigns, decls) = trav assigns t in
|
|
|
(assigns, (h :: decls))
|
|
(assigns, (h :: decls))
|
|
@@ -65,7 +65,7 @@ let rec var_init = function
|
|
|
(* Move global variable initialisations to exported __init function *)
|
|
(* Move global variable initialisations to exported __init function *)
|
|
|
| GlobalDef (export, ctype, name, Some init, loc) ->
|
|
| GlobalDef (export, ctype, name, Some init, loc) ->
|
|
|
Block [GlobalDef (export, ctype, name, None, loc);
|
|
Block [GlobalDef (export, ctype, name, None, loc);
|
|
|
- Assign (name, init, locof init)]
|
|
|
|
|
|
|
+ Assign (name, None, init, locof init)]
|
|
|
|
|
|
|
|
(* Split local variable initialisations in declaration and assignment *)
|
|
(* Split local variable initialisations in declaration and assignment *)
|
|
|
| FunDef (export, ret_type, name, params, Block body, loc) ->
|
|
| FunDef (export, ret_type, name, params, Block body, loc) ->
|
|
@@ -81,18 +81,18 @@ let rec var_init = function
|
|
|
Some ((IntConst (_, l)) as v), loc) :: t ->
|
|
Some ((IntConst (_, l)) as v), loc) :: t ->
|
|
|
trav inits (VarDec (vtype, name, Some (ArrayScalar (v, l)), loc) :: t)
|
|
trav inits (VarDec (vtype, name, Some (ArrayScalar (v, l)), loc) :: t)
|
|
|
|
|
|
|
|
- | VarDec (ctype, name, init, loc) :: t ->
|
|
|
|
|
|
|
+ | VarDec (ctype, name, init, loc) as dec :: tl ->
|
|
|
(* array definition: create __allocate statement *)
|
|
(* array definition: create __allocate statement *)
|
|
|
let alloc = match ctype with
|
|
let alloc = match ctype with
|
|
|
- | ArrayDef (_, dims) -> [Allocate (name, dims, loc)]
|
|
|
|
|
|
|
+ | ArrayDef (_, dims) -> [Allocate (name, dims, dec, loc)]
|
|
|
| _ -> []
|
|
| _ -> []
|
|
|
in
|
|
in
|
|
|
(* initialisation: create assign statement *)
|
|
(* initialisation: create assign statement *)
|
|
|
let add = match init with
|
|
let add = match init with
|
|
|
- | Some value -> alloc @ [Assign (name, value, loc)]
|
|
|
|
|
|
|
+ | Some value -> alloc @ [Assign (name, None, value, loc)]
|
|
|
| None -> alloc
|
|
| None -> alloc
|
|
|
in
|
|
in
|
|
|
- VarDec (ctype, name, None, loc) :: (trav (inits @ add) t)
|
|
|
|
|
|
|
+ VarDec (ctype, name, None, loc) :: (trav (inits @ add) tl)
|
|
|
|
|
|
|
|
(* initialisations need to be placed after local functions *)
|
|
(* initialisations need to be placed after local functions *)
|
|
|
| (FunDef (_, _, _, _, _, _) as h) :: t ->
|
|
| (FunDef (_, _, _, _, _, _) as h) :: t ->
|
|
@@ -115,10 +115,10 @@ let rec var_init = function
|
|
|
(*
|
|
(*
|
|
|
let rec array_init = function
|
|
let rec array_init = function
|
|
|
(* transform scalar assignment into nested for loops *)
|
|
(* transform scalar assignment into nested for loops *)
|
|
|
- | Assign (name, ArrayScalar (value)) ->
|
|
|
|
|
|
|
+ | Assign (name, None, ArrayScalar (value), loc) ->
|
|
|
let rec add_loop indices = function
|
|
let rec add_loop indices = function
|
|
|
| [] ->
|
|
| [] ->
|
|
|
- Assign (Deref (name, indices), value)
|
|
|
|
|
|
|
+ Assign (name, indices, value, loc)
|
|
|
| dim :: rest ->
|
|
| dim :: rest ->
|
|
|
let counter = fresh_var "counter" in
|
|
let counter = fresh_var "counter" in
|
|
|
let ind = (indices @ [Var counter]) in
|
|
let ind = (indices @ [Var counter]) in
|
|
@@ -126,7 +126,7 @@ let rec array_init = function
|
|
|
in
|
|
in
|
|
|
add_loop [] dims
|
|
add_loop [] dims
|
|
|
|
|
|
|
|
- | Assign (name, ArrayConst (dims)) -> Block []
|
|
|
|
|
|
|
+ | Assign (name, None, ArrayConst (dims), loc) -> Block []
|
|
|
|
|
|
|
|
| node -> transform array_init node
|
|
| node -> transform array_init node
|
|
|
*)
|
|
*)
|