|
@@ -32,25 +32,21 @@ let rec var_init = function
|
|
|
let rec trav inits node = match node with
|
|
let rec trav inits node = match node with
|
|
|
(* translate scalar array initialisation to ArrayScalar node,
|
|
(* translate scalar array initialisation to ArrayScalar node,
|
|
|
* for easy replacement later on *)
|
|
* for easy replacement later on *)
|
|
|
- | VarDec (ArrayDef _ as vtype, name,
|
|
|
|
|
- Some (BoolConst _ as v), loc) :: t
|
|
|
|
|
- | VarDec (ArrayDef _ as vtype, name,
|
|
|
|
|
- Some (FloatConst _ as v), loc) :: t
|
|
|
|
|
- | VarDec (ArrayDef _ as vtype, name,
|
|
|
|
|
- Some (IntConst _ as v), loc) :: t ->
|
|
|
|
|
|
|
+ | VarDec (Array _ as vtype, name, Some (BoolConst _ as v), loc) :: t
|
|
|
|
|
+ | VarDec (Array _ as vtype, name, Some (FloatConst _ as v), loc) :: t
|
|
|
|
|
+ | VarDec (Array _ as vtype, name, Some (IntConst _ as v), loc) :: t ->
|
|
|
let init = Some (ArrayInit (ArrayScalar v, vtype)) in
|
|
let init = Some (ArrayInit (ArrayScalar v, vtype)) in
|
|
|
trav inits (VarDec (vtype, name, init, loc) :: t)
|
|
trav inits (VarDec (vtype, name, init, loc) :: t)
|
|
|
|
|
|
|
|
(* Wrap ArrayConst in ArrayInit to pass dimensions *)
|
|
(* Wrap ArrayConst in ArrayInit to pass dimensions *)
|
|
|
- | VarDec (ArrayDef _ as vtype, name,
|
|
|
|
|
- Some (ArrayConst _ as v), loc) :: t ->
|
|
|
|
|
|
|
+ | VarDec (Array _ as vtype, name, Some (ArrayConst _ as v), loc) :: t ->
|
|
|
let init = Some (ArrayInit (v, vtype)) in
|
|
let init = Some (ArrayInit (v, vtype)) in
|
|
|
trav inits (VarDec (vtype, name, init, loc) :: t)
|
|
trav inits (VarDec (vtype, name, init, loc) :: t)
|
|
|
|
|
|
|
|
| VarDec (ctype, name, init, loc) as dec :: tl ->
|
|
| 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, dec, loc)]
|
|
|
|
|
|
|
+ | Array (_, dims) -> [Allocate (name, dims, dec, loc)]
|
|
|
| _ -> []
|
|
| _ -> []
|
|
|
in
|
|
in
|
|
|
(* initialisation: create assign statement *)
|
|
(* initialisation: create assign statement *)
|
|
@@ -126,7 +122,7 @@ let for_to_while node =
|
|
|
|
|
|
|
|
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, None, ArrayInit (ArrayScalar value, ArrayDef (_, dims)), loc) ->
|
|
|
|
|
|
|
+ | Assign (name, None, ArrayInit (ArrayScalar value, Array (_, dims)), loc) ->
|
|
|
let rec add_loop indices = function
|
|
let rec add_loop indices = function
|
|
|
| [] ->
|
|
| [] ->
|
|
|
Assign (name, Some indices, value, loc)
|
|
Assign (name, Some indices, value, loc)
|
|
@@ -140,7 +136,7 @@ let rec array_init = function
|
|
|
(* Transform array constant inisialisation into separate assign statements
|
|
(* Transform array constant inisialisation into separate assign statements
|
|
|
* for all entries in the constant array *)
|
|
* for all entries in the constant array *)
|
|
|
(* TODO: only allow when array dimensions are constant? *)
|
|
(* TODO: only allow when array dimensions are constant? *)
|
|
|
- | Assign (name, None, ArrayInit (ArrayConst _ as value, ArrayDef (_, dims)), loc) ->
|
|
|
|
|
|
|
+ | Assign (name, None, ArrayInit (ArrayConst _ as value, Array (_, dims)), loc) ->
|
|
|
let ndims = list_size dims in
|
|
let ndims = list_size dims in
|
|
|
let rec make_assigns depth i indices = function
|
|
let rec make_assigns depth i indices = function
|
|
|
| [] -> []
|
|
| [] -> []
|