From c550b098050bef3033a11adc309063f37c2b0669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Fri, 9 Sep 2011 13:54:29 +0200 Subject: [PATCH] Fixed code generated for alias types to arrays --- compiler/obc/c/c.ml | 7 ------- compiler/obc/c/cgen.ml | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/obc/c/c.ml b/compiler/obc/c/c.ml index 80dd431..245bcd8 100644 --- a/compiler/obc/c/c.ml +++ b/compiler/obc/c/c.ml @@ -345,13 +345,6 @@ let output_cfile dir (filen, cfile_desc) = let output dir cprog = List.iter (output_cfile dir) cprog -(** Returns the type of a pointer to a type, except for - types which are already pointers. *) -let pointer_to ty = - match ty with - | Cty_arr _ | Cty_ptr _ -> ty - | _ -> Cty_ptr ty - (** Returns whether a type is a pointer. *) let is_pointer_type = function | Cty_arr _ | Cty_ptr _ -> true diff --git a/compiler/obc/c/cgen.ml b/compiler/obc/c/cgen.ml index c0136d2..05ec641 100644 --- a/compiler/obc/c/cgen.ml +++ b/compiler/obc/c/cgen.ml @@ -115,10 +115,24 @@ let copname = function let cvar_of_vd vd = name vd.v_ident, ctype_of_otype vd.v_type +(** Returns the type of a pointer to a type, except for + types which are already pointers. *) +let pointer_type ty cty = + match Modules.unalias_type ty with + | Tarray _ -> cty + | _ -> Cty_ptr cty + +(** Returns the expression to use e as an argument of + a function expecting a pointer as argument. *) +let address_of ty e = + match Modules.unalias_type ty with + | Tarray _ -> e + | _ -> Caddrof e + let inputlist_of_ovarlist vl = let cvar_of_ovar vd = let ty = ctype_of_otype vd.v_type in - let ty = if vd.v_mutable then pointer_to ty else ty in + let ty = if vd.v_mutable then pointer_type vd.v_type ty else ty in name vd.v_ident, ty in List.map cvar_of_ovar vl @@ -197,13 +211,6 @@ and create_affect_stm dest src ty = | _ -> [Caffect (dest, src)]) | _ -> [Caffect (dest, src)] -(** Returns the expression to use e as an argument of - a function expecting a pointer as argument. *) -let address_of ty e = - match ty with - | Tarray _ -> e - | _ -> Caddrof e - let rec cexpr_of_static_exp se = match se.se_desc with | Sint i -> Cconst (Ccint i)