Ignore:
Timestamp:
Feb 9, 2011, 6:22:34 PM (8 years ago)
Author:
campbell
Message:

Pointer fixes for the temporary version of the compiler that can output matita
terms.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.3/8051-memoryspaces-branch/src/clight/clightFromC.ml

    r461 r489  
    211211    | C.TFloat(fk, a) ->
    212212        Tfloat(convertFkind fk)
    213     | C.TPtr(_,C.TStruct(id, _), _) when List.mem id seen ->
    214         Tcomp_ptr("struct " ^ id.name)
    215     | C.TPtr(_,C.TUnion(id, _), _) when List.mem id seen ->
    216         Tcomp_ptr("union " ^ id.name)
     213    | C.TPtr(r,C.TStruct(id, _), _) when List.mem id seen ->
     214        Tcomp_ptr(convertSpace r,"struct " ^ id.name)
     215    | C.TPtr(r,C.TUnion(id, _), _) when List.mem id seen ->
     216        Tcomp_ptr(convertSpace r,"union " ^ id.name)
    217217    | C.TPtr(sp,ty, a) ->
    218218        Tpointer(convertSpace sp, convertTyp seen ty)
     
    283283  | C.EConst(C.CInt(i, _, _)) ->
    284284      Expr(Econst_int( convertInt i), ty)
    285   | C.EConst(C.CNull _) ->
    286       Expr(Econst_int( convertInt 0L), ty)
     285  | C.EConst(C.CNull r) ->
     286      Expr(Ecast (Tpointer (convertSpace r, Tvoid), ezero), ty)
    287287  | C.EConst(C.CFloat(f, _, _)) ->
    288288      Expr(Econst_float f, ty)
     
    625625    | { edesc = C.EVar id; etyp = ty } ->
    626626        begin match Cutil.unroll env ty with
    627         | C.TArray _ | C.TFun _ -> Some id
     627        | C.TArray (r,_,_,_) -> Some (id,r) | C.TFun _ -> Some (id, C.Code)
    628628        | _ -> None
    629629        end
    630     | {edesc = C.EUnop(C.Oaddrof, {edesc = C.EVar id})} -> Some id
    631     | {edesc = C.ECast(ty, e)} -> reduceInitExpr e
     630    | {edesc = C.EUnop(C.Oaddrof, {edesc = C.EVar id}); etyp = ty} ->
     631         begin match Cutil.unroll env ty with
     632         | C.TPtr (r,_,_) -> Some (id,r)
     633         | _ -> assert false
     634         end
     635    | {edesc = C.ECast(ty, e)} ->
     636         begin match reduceInitExpr e with
     637         | Some (id,_) ->
     638           begin match Cutil.unroll env ty with
     639                 | C.TPtr (r,_,_) | C.TArray(r,_,_,_) -> Some (id,r)
     640                 | _ -> assert false
     641                 end
     642         | None -> None
     643         end
    632644    | _ -> None in
    633645
     
    635647  | Init_single e ->
    636648      begin match reduceInitExpr e with
    637       | Some id ->
     649      | Some (id,r) ->
    638650          check_align 4;
    639           emit 4 (Init_addrof( id.name, 0))
     651          emit 4 (Init_addrof(convertSpace r, id.name, 0))
    640652      | None ->
    641653      match Ceval.constant_expr env ty e with
     
    652664          end
    653665      | Some(C.CNull sp) ->
    654           let z = convertInt 0L in
    655           begin match sp with
    656           | C.Any   -> emit 3 (Init_int24 z)
     666          let s =
     667            (match sp with
     668          | C.Any   -> 3
    657669          | C.Data
    658670          | C.IData
    659           | C.PData -> emit 1 (Init_int8 z)
     671          | C.PData -> 1
    660672          | C.XData
    661           | C.Code  -> emit 2 (Init_int16 z)
    662           end
     673          | C.Code  -> 2
     674          ) in
     675          emit s (Init_null (convertSpace sp))
    663676      | Some(C.CFloat(v, fk, _)) ->
    664677          begin match convertFkind fk with
     
    673686          check_align 4;
    674687          let id = name_for_string_literal env s in
    675           emit 4 (Init_addrof(id, 0))
     688          let r = match  Cutil.unroll env ty with
     689                  | TPtr (r,_,_) | TArray (r,_,_,_) -> r
     690                  | _ -> assert false
     691          in
     692          emit 4 (Init_addrof(convertSpace r,id, 0))
    676693      | Some(C.CWStr _) ->
    677694          unsupported "wide character strings"
Note: See TracChangeset for help on using the changeset viewer.