Ignore:
Timestamp:
Jan 19, 2011, 6:23:27 PM (9 years ago)
Author:
campbell
Message:

Port memory spaces changes to latest prototype compiler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.3/8051-memoryspaces-branch/cparser/Cutil.ml

    r453 r460  
    7272  | TInt(ik, a) -> TInt(ik, add_attributes attr a)
    7373  | TFloat(fk, a) -> TFloat(fk, add_attributes attr a)
    74   | TPtr(ty, a) -> TPtr(ty, add_attributes attr a)
    75   | TArray(ty, sz, a) -> TArray(add_attributes_type attr ty, sz, a)
     74  | TPtr(sp, ty, a) -> TPtr(sp, ty, add_attributes attr a)
     75  | TArray(sp, ty, sz, a) -> TArray(sp, add_attributes_type attr ty, sz, a)
    7676  | TFun(ty, params, vararg, a) -> TFun(ty, params, vararg, add_attributes attr
    7777a)
     
    9696  | TInt(ik, a) -> a
    9797  | TFloat(fk, a) -> a
    98   | TPtr(ty, a) -> a
    99   | TArray(ty, sz, a) -> a              (* correct? *)
     98  | TPtr(_, ty, a) -> a
     99  | TArray(_, ty, sz, a) -> a              (* correct? *)
    100100  | TFun(ty, params, vararg, a) -> a
    101101  | TNamed(s, a) -> attributes_of_type env (unroll env t)
     
    111111  | TInt(ik, a) -> TInt(ik, f a)
    112112  | TFloat(fk, a) -> TFloat(fk, f a)
    113   | TPtr(ty, a) -> TPtr(ty, f a)
    114   | TArray(ty, sz, a) ->
    115       TArray(change_attributes_type env f ty, sz, a)
     113  | TPtr(sp, ty, a) -> TPtr(sp, ty, f a)
     114  | TArray(sp, ty, sz, a) ->
     115      TArray(sp, change_attributes_type env f ty, sz, a)
    116116  | TFun(ty, params, vararg, a) -> TFun(ty, params, vararg, f a)
    117117  | TNamed(s, a) ->
     
    167167    | TFloat(fk1, a1), TFloat(fk2, a2) ->
    168168        TFloat(comp_base fk1 fk2, comp_attr a1 a2)
    169     | TPtr(ty1, a1), TPtr(ty2, a2) ->
    170         TPtr(comp ty1 ty2, comp_attr a1 a2)
    171     | TArray(ty1, sz1, a1), TArray(ty2, sz2, a2) ->
    172         TArray(comp ty1 ty2, comp_array_size sz1 sz2, comp_attr a1 a2)
     169    | TPtr(sp1, ty1, a1), TPtr(sp2, ty2, a2) when sp1 = sp2 ->
     170        TPtr(sp1, comp ty1 ty2, comp_attr a1 a2)
     171    | TArray(sp1, ty1, sz1, a1), TArray(sp2, ty2, sz2, a2) when sp1 = sp2 ->
     172        TArray(sp1, comp ty1 ty2, comp_array_size sz1 sz2, comp_attr a1 a2)
    173173    | TFun(ty1, params1, vararg1, a1), TFun(ty2, params2, vararg2, a2) ->
    174174        let (params, vararg) =
     
    245245  | TInt(ik, _) -> Some(alignof_ikind ik)
    246246  | TFloat(fk, _) -> Some(alignof_fkind fk)
    247   | TPtr(_, _) -> Some(!config.alignof_ptr)
    248   | TArray(ty, _, _) -> alignof env ty
     247  | TPtr(_, _, _) -> Some(!config.alignof_ptr)
     248  | TArray(_, ty, _, _) -> alignof env ty
    249249  | TFun(_, _, _, _) -> !config.alignof_fun
    250250  | TNamed(_, _) -> alignof env (unroll env t)
     
    303303  | TInt(ik, _) -> Some(sizeof_ikind ik)
    304304  | TFloat(fk, _) -> Some(sizeof_fkind fk)
    305   | TPtr(_, _) -> Some(!config.sizeof_ptr)
    306   | TArray(ty, None, _) -> None
    307   | TArray(ty, Some n, _) as t' ->
     305  | TPtr(_, _, _) -> Some(!config.sizeof_ptr) (* FIXME *)
     306  | TArray(_, ty, None, _) -> None
     307  | TArray(_, ty, Some n, _) as t' ->
    308308      begin match sizeof env ty with
    309309      | None -> None
     
    344344let sizeof_struct env members =
    345345  let rec sizeof_rec ofs = function
    346   | [] | [ { fld_typ = TArray(_, None, _) } ] ->
     346  | [] | [ { fld_typ = TArray(_, _, None, _) } ] ->
    347347      (* C99: ty[] allowed as last field *)
    348348      begin match alignof_struct_union env members with
     
    473473let pointer_decay env t =
    474474  match unroll env t with
    475   | TArray(ty, _, _) -> TPtr(ty, [])
    476   | TFun _ as ty -> TPtr(ty, [])
     475  | TArray(sp, ty, _, _) -> TPtr(sp, ty, [])
     476  | TFun _ as ty -> TPtr(Code, ty, [])
    477477  | t -> t
    478478
     
    490490      end
    491491  (* Arrays and functions decay automatically to pointers *)
    492   | TArray(ty, _, _) -> TPtr(ty, [])
    493   | TFun _ as ty -> TPtr(ty, [])
     492  | TArray(sp, ty, _, _) -> TPtr(sp, ty, [])
     493  | TFun _ as ty -> TPtr(Code, ty, [])
    494494  (* Other types are not changed *)
    495495  | t -> t
     
    541541  (* Other types are not changed *)
    542542  match unroll env t with
    543   | TArray(ty, _, _) -> TPtr(ty, [])
    544   | TFun _ as ty -> TPtr(ty, [])
     543  | TArray(sp, ty, _, _) -> TPtr(sp, ty, [])
     544  | TFun _ as ty -> TPtr(Code, ty, [])
    545545  | _ -> t (* preserve typedefs *)
    546546
     
    585585  | CInt(_, ik, _) -> TInt(ik, [])
    586586  | CFloat(_, fk, _) -> TFloat(fk, [])
    587   | CStr _ -> TPtr(TInt(IChar, []), [])          (* XXX or array? const? *)
    588   | CWStr _ -> TPtr(TInt(wchar_ikind, []), [])   (* XXX or array? const? *)
     587  | CStr _ -> TPtr(Code, TInt(IChar, []), [])          (* XXX or array? const? *)
     588  | CWStr _ -> TPtr(Code, TInt(wchar_ikind, []), [])   (* XXX or array? const? *)
    589589  | CEnum(_, _) -> TInt(IInt, [])
    590590
     
    613613(* Check that an assignment is allowed *)
    614614
     615let valid_pointer_conv from tto =
     616  match from, tto with
     617  | Any, _
     618  | _, Any -> true
     619  | f, t -> f = t
     620
    615621let valid_assignment env from tto =
    616622  match pointer_decay env from.etyp, pointer_decay env tto with
    617623  | (TInt _ | TFloat _), (TInt _ | TFloat _) -> true
    618624  | TInt _, TPtr _ -> is_literal_0 from
    619   | TPtr(ty, _), TPtr(ty', _) ->
    620       incl_attributes (attributes_of_type env ty) (attributes_of_type env ty')
     625  | TPtr(sp, ty, _), TPtr(sp', ty', _) ->
     626      valid_pointer_conv sp sp'
     627      && incl_attributes (attributes_of_type env ty) (attributes_of_type env ty')
    621628      && (is_void_type env ty || is_void_type env ty'
    622629          || compatible_types env
     
    644651
    645652let intconst v ik =
    646   { edesc = EConst(CInt(v, ik, "")); etyp = TInt(ik, []) }
     653  { edesc = EConst(CInt(v, ik, "")); etyp = TInt(ik, []); espace = Code }
    647654
    648655(* Construct a float constant *)
    649656
    650657let floatconst v fk =
    651   { edesc = EConst(CFloat(v, fk, "")); etyp = TFloat(fk, []) }
     658  { edesc = EConst(CFloat(v, fk, "")); etyp = TFloat(fk, []); espace = Code }
    652659
    653660(* Construct the literal "0" with void * type *)
    654661
    655662let nullconst =
    656   { edesc = EConst(CInt(0L, ptr_t_ikind, "0")); etyp = TPtr(TVoid [], []) }
     663  { edesc = EConst(CInt(0L, ptr_t_ikind, "0")); etyp = TPtr(Any, TVoid [], []); espace = Code } (* XXX *)
    657664
    658665(* Construct a sequence *)
     
    668675
    669676let sassign loc lv rv =
    670   { sdesc = Sdo {edesc = EBinop(Oassign, lv, rv, lv.etyp); etyp = lv.etyp};
     677  { sdesc = Sdo {edesc = EBinop(Oassign, lv, rv, lv.etyp); etyp = lv.etyp; espace = lv.espace};
    671678    sloc = loc }
    672679
Note: See TracChangeset for help on using the changeset viewer.