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/src/clight/clightPrinter.ml

    r453 r460  
    1919open AST
    2020open Clight
     21
     22let name_space = function
     23  | Any -> ""
     24  | Data -> "__data "
     25  | IData -> "__idata "
     26  | PData -> "__pdata "
     27  | XData -> "__xdata "
     28  | Code -> "__code "
     29
    2130
    2231let name_unop = function
     
    7887  if String.length id > 0 && id.[0] = '*' then "(" ^ id ^ ")" else id
    7988
    80 let rec name_cdecl id ty =
     89(* Use Any for the space when nothing should appear. *)
     90
     91let rec name_cdecl sp id ty =
     92  let ssp = name_space sp in
    8193  match ty with
    8294  | Tvoid ->
    83       "void" ^ name_optid id
     95      ssp ^ "void" ^ name_optid id
    8496  | Tint(sz, sg) ->
    85       name_inttype sz sg ^ name_optid id
     97      ssp ^ name_inttype sz sg ^ name_optid id
    8698  | Tfloat sz ->
    87       name_floattype sz ^ name_optid id
    88   | Tpointer t ->
    89       name_cdecl ("*" ^ id) t
    90   | Tarray(t, n) ->
     99      ssp ^ name_floattype sz ^ name_optid id
     100  | Tpointer (sp',t) ->
     101      name_cdecl sp' ("* " ^ ssp ^ id) t
     102  | Tarray(sp', t, n) ->
     103      if sp <> sp' then eprintf "Array %s has wrong memory space.\n%!" id;
    91104      name_cdecl
     105        sp'
    92106        (sprintf "%s[%ld]" (parenthesize_if_pointer id) (Int32.of_int n))
    93107        t
    94108  | Tfunction(args, res) ->
    95109      let b = Buffer.create 20 in
     110      Buffer.add_string b ssp;
    96111      if id = ""
    97112      then Buffer.add_string b "(*)"
     
    106121          | t1::tl ->
    107122              if not first then Buffer.add_string b ", ";
    108               Buffer.add_string b (name_cdecl "" t1);
     123              Buffer.add_string b (name_cdecl Any "" t1);
    109124              add_args false tl in
    110125          add_args true args
    111126      end;
    112127      Buffer.add_char b ')';
    113       name_cdecl (Buffer.contents b) res
     128      name_cdecl Any (Buffer.contents b) res
    114129  | Tstruct(name, fld) ->
    115       name ^ name_optid id
     130      ssp ^ name ^ name_optid id
    116131  | Tunion(name, fld) ->
    117       name ^ name_optid id
     132      ssp ^ name ^ name_optid id
    118133  | Tcomp_ptr name ->
    119       name ^ " *" ^ id
     134      ssp ^ name ^ " *" ^ id
    120135
    121136(* Type *)
    122137
    123 let name_type ty = name_cdecl "" ty
     138let name_type ty = name_cdecl Any "" ty
    124139
    125140(* Expressions *)
     
    322337      | (id, ty) :: rem ->
    323338          if not first then Buffer.add_string b ", ";
    324           Buffer.add_string b (name_cdecl id ty);
     339          Buffer.add_string b (name_cdecl Any id ty);
    325340          add_params false rem in
    326341      add_params true params
     
    331346let print_function p id f =
    332347  fprintf p "%s@ "
    333             (name_cdecl (name_function_parameters id f.fn_params)
     348            (name_cdecl Any
     349                        (name_function_parameters id f.fn_params)
    334350                        f.fn_return);
    335351  fprintf p "@[<v 2>{@ ";
    336352  List.iter
    337353    (fun ((id, ty)) ->
    338       fprintf p "%s;@ " (name_cdecl id ty))
     354      fprintf p "%s;@ " (name_cdecl Any id ty))
    339355    f.fn_vars;
    340356  print_stmt p f.fn_body;
     
    345361  | External(_, args, res) ->
    346362      fprintf p "extern %s;@ @ "
    347                 (name_cdecl id (Tfunction(args, res)))
     363                (name_cdecl Any id (Tfunction(args, res)))
    348364  | Internal f ->
    349365      print_function p id f
     
    393409let re_string_literal = Str.regexp "__stringlit_[0-9]+"
    394410
    395 let print_globvar p (((id, init), ty)) =
     411let print_globvar p ((((id, init), sp), ty)) =
    396412  match init with
    397413  | [] ->
    398414      fprintf p "extern %s;@ @ "
    399               (name_cdecl id ty)
     415              (name_cdecl sp id ty)
    400416  | [Init_space _] ->
    401417      fprintf p "%s;@ @ "
    402               (name_cdecl id ty)
     418              (name_cdecl sp id ty)
    403419  | [init] ->
    404420      fprintf p "@[<hov 2>%s = %a;@]@ @ "
    405               (name_cdecl id ty) print_init1 init
     421              (name_cdecl sp id ty) print_init1 init
    406422  | _ ->
    407423      fprintf p "@[<hov 2>%s = "
    408               (name_cdecl id ty);
     424              (name_cdecl sp id ty);
    409425      if Str.string_match re_string_literal id 0
    410426      && List.for_all (function Init_int8 _ -> true | _ -> false) init
     
    424440  | Tint(sz, sg) -> ()
    425441  | Tfloat sz -> ()
    426   | Tpointer t -> collect_type t
    427   | Tarray(t, n) -> collect_type t
     442  | Tpointer (_,t) -> collect_type t
     443  | Tarray(_, t, n) -> collect_type t
    428444  | Tfunction(args, res) -> collect_type_list args; collect_type res
    429445  | Tstruct(id, fld) -> register_struct_union id fld; collect_fields fld
     
    512528  | [] -> ()
    513529  | (id, ty)::rem ->
    514       fprintf p "@ %s;" (name_cdecl id ty);
     530      fprintf p "@ %s;" (name_cdecl Any id ty);
    515531      print_fields rem in
    516532  print_fields fld;
Note: See TracChangeset for help on using the changeset viewer.