|
@@ -1,6 +1,7 @@
|
|
|
open Types
|
|
open Types
|
|
|
open Util
|
|
open Util
|
|
|
|
|
|
|
|
|
|
+(* Pass array dimensions explicitly to functions *)
|
|
|
let rec expand_dims = function
|
|
let rec expand_dims = function
|
|
|
(* Flatten Block nodes returned by transformations below *)
|
|
(* Flatten Block nodes returned by transformations below *)
|
|
|
| FunDef (export, ret_type, name, params, body, ann) ->
|
|
| FunDef (export, ret_type, name, params, body, ann) ->
|
|
@@ -28,7 +29,7 @@ let rec expand_dims = function
|
|
|
| Arg (VarUse (VarDec (ArrayDims (ctype, dims), name, None, decann), None, ann)) ->
|
|
| Arg (VarUse (VarDec (ArrayDims (ctype, dims), name, None, decann), None, ann)) ->
|
|
|
let rec do_expand = function
|
|
let rec do_expand = function
|
|
|
| [] ->
|
|
| [] ->
|
|
|
- (* Remove the (now obsolete dimensions fromt the type) *)
|
|
|
|
|
|
|
+ (* Remove the (now obsolete dimensions from the type) *)
|
|
|
let dec = VarDec (Array ctype, name, None, decann) in
|
|
let dec = VarDec (Array ctype, name, None, decann) in
|
|
|
[VarUse (dec, None, ann)]
|
|
[VarUse (dec, None, ann)]
|
|
|
| hd :: tl ->
|
|
| hd :: tl ->
|
|
@@ -40,10 +41,6 @@ let rec expand_dims = function
|
|
|
in
|
|
in
|
|
|
Block (do_expand dims)
|
|
Block (do_expand dims)
|
|
|
|
|
|
|
|
- (* Simplify array types in declarations *)
|
|
|
|
|
- | VarDec (ArrayDims (ctype, _), name, None, ann) ->
|
|
|
|
|
- VarDec (Array ctype, name, None, ann)
|
|
|
|
|
-
|
|
|
|
|
| node -> transform_children expand_dims node
|
|
| node -> transform_children expand_dims node
|
|
|
|
|
|
|
|
let rec multiply = function
|
|
let rec multiply = function
|
|
@@ -71,10 +68,16 @@ let rec expand depth dims =
|
|
|
in
|
|
in
|
|
|
do_expand (List.map use_dim (List.tl dims))
|
|
do_expand (List.map use_dim (List.tl dims))
|
|
|
|
|
|
|
|
|
|
+(* Transform multi-dimensional arrays into one-dimensional arrays in row-major
|
|
|
|
|
+ * order *)
|
|
|
and dim_reduce depth = function
|
|
and dim_reduce depth = function
|
|
|
| Allocate (dec, dims, ann) ->
|
|
| Allocate (dec, dims, ann) ->
|
|
|
Allocate (dec, [multiply dims], ann)
|
|
Allocate (dec, [multiply dims], ann)
|
|
|
|
|
|
|
|
|
|
+ (* Simplify array types in declarations *)
|
|
|
|
|
+ | VarDec (ArrayDims (ctype, _), name, None, ann) ->
|
|
|
|
|
+ VarDec (Array ctype, name, None, ann)
|
|
|
|
|
+
|
|
|
(* Increase nesting depth when goiing into function *)
|
|
(* Increase nesting depth when goiing into function *)
|
|
|
| FunDef (export, ret_type, name, params, body, ann) ->
|
|
| FunDef (export, ret_type, name, params, body, ann) ->
|
|
|
let trav = dim_reduce (depth + 1) in
|
|
let trav = dim_reduce (depth + 1) in
|