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/StructAssign.ml

    r453 r460  
    2929
    3030let memcpy_type =
    31   TFun(TPtr(TVoid [], []),
    32        Some [(Env.fresh_ident "", TPtr(TVoid [], []));
    33              (Env.fresh_ident "", TPtr(TVoid [AConst], []));
     31  TFun(TPtr(Any,TVoid [], []),
     32       Some [(Env.fresh_ident "", TPtr(Any,TVoid [], []));
     33             (Env.fresh_ident "", TPtr(Any,TVoid [AConst], []));
    3434             (Env.fresh_ident "", TInt(size_t_ikind, []))],
    3535       false, [])
     
    4343  | Some id ->
    4444      id
     45
     46let space_of_ty = function
     47| TArray(space, _, _, _)
     48| TPtr(space, _, _) -> space
     49| _ -> Any
    4550
    4651let transf_assign env loc lhs rhs =
     
    6368    | TUnion(id, attr) ->
    6469        raise Exit
    65     | TArray(ty_elt, Some sz, attr) ->
    66         transf_array l r ty_elt 0L sz
    67     | TArray(ty_elt, None, attr) ->
     70    | TArray(space, ty_elt, Some sz, attr) ->
     71        transf_array space l (space_of_ty (unroll env r.etyp)) r ty_elt 0L sz
     72    | TArray(space, ty_elt, None, attr) ->
    6873        error "%a: Error: array of unknown size" formatloc loc;
    6974        sskip                           (* will be ignored later *)
     
    7479    | [] -> sskip
    7580    | f :: fl ->
    76         sseq loc (transf {edesc = EUnop(Odot f.fld_name, l); etyp = f.fld_typ}
    77                          {edesc = EUnop(Odot f.fld_name, r); etyp = f.fld_typ})
     81        sseq loc (transf {edesc = EUnop(Odot f.fld_name, l); etyp = f.fld_typ; espace = l.espace}
     82                         {edesc = EUnop(Odot f.fld_name, r); etyp = f.fld_typ; espace = r.espace})
    7883                 (transf_struct l r fl)
    7984
    80   and transf_array l r ty idx sz =
     85  and transf_array lsp l rsp r ty idx sz =
    8186    if idx >= sz then sskip else begin
    8287      let e = intconst idx size_t_ikind in
    83       sseq loc (transf {edesc = EBinop(Oindex, l, e, ty); etyp = ty}
    84                        {edesc = EBinop(Oindex, r, e, ty); etyp = ty})
    85                (transf_array l r ty (Int64.add idx 1L) sz)
     88      sseq loc (transf {edesc = EBinop(Oindex, l, e, ty); etyp = ty; espace = lsp}
     89                       {edesc = EBinop(Oindex, r, e, ty); etyp = ty; espace = rsp})
     90               (transf_array lsp l rsp r ty (Int64.add idx 1L) sz)
    8691    end
    8792  in
     
    9095    transf lhs rhs
    9196  with Exit ->
    92     let memcpy = {edesc = EVar(memcpy_ident()); etyp = memcpy_type} in
    93     let e_lhs = {edesc = EUnop(Oaddrof, lhs); etyp = TPtr(lhs.etyp, [])} in
    94     let e_rhs = {edesc = EUnop(Oaddrof, rhs); etyp = TPtr(rhs.etyp, [])} in
    95     let e_size = {edesc = ESizeof(lhs.etyp); etyp = TInt(size_t_ikind, [])} in
     97    let memcpy = {edesc = EVar(memcpy_ident()); etyp = memcpy_type; espace = Any} in
     98    (* XXX: casts required? *)
     99    let e_lhs = {edesc = EUnop(Oaddrof, lhs); etyp = TPtr(Any, lhs.etyp, []); espace = Any} in
     100    let e_rhs = {edesc = EUnop(Oaddrof, rhs); etyp = TPtr(Any, rhs.etyp, []); espace = Any} in
     101    let e_size = {edesc = ESizeof(lhs.etyp); etyp = TInt(size_t_ikind, []); espace = Any} in
    96102    {sdesc = Sdo {edesc = ECall(memcpy, [e_lhs; e_rhs; e_size]);
    97                   etyp = TVoid[]};
     103                  etyp = TVoid[]; espace = Any};
    98104     sloc = loc}
    99105
     
    137143  | None -> p'
    138144  | Some id ->
    139       {gdesc = Gdecl(Storage_extern, id, memcpy_type, None); gloc = no_loc}
     145      {gdesc = Gdecl(Code, (Storage_extern, id, memcpy_type, None)); gloc = no_loc}
    140146      :: p'
    141147
Note: See TracChangeset for help on using the changeset viewer.