Ignore:
Timestamp:
Apr 4, 2011, 5:18:15 PM (9 years ago)
Author:
ayache
Message:

New memory model and bug fixes in 8051 branch. Added primitive operations in interpreters from Clight to LIN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/cminor/cminorPointers.ml

    r486 r740  
    44
    55
    6 (** [is_pointer ptrs e] returns true iff the expression [e] represents an
     6(** [is_pointer ptrs e] returns true only if the expression [e] represents an
    77    address when considering that the variables in the set [ptrs] are
    88    pointers. *)
     
    1515  | Cminor.Op1 (AST.Op_ptrofint, _) -> true
    1616  | Cminor.Op2 (AST.Op_addp, _, _) | Cminor.Op2 (AST.Op_subp, _, _) -> true
    17   | Cminor.Mem (Memory.MQ_pointer, _) -> true
    1817  | Cminor.Cond (_, e2, e3) -> (is_pointer ptrs e2) || (is_pointer ptrs e3)
    1918  | Cminor.Exp_cost (_, e) -> is_pointer ptrs e
     
    109108    statement, if any. [ptrs] is a set of already known pointer variables.  *)
    110109
    111 let statement_pointers type_ret stmt ptrs =
     110let statement_pointers ret_type stmt ptrs =
    112111  CminorFold.statement_left (fun _ _ -> StringTools.Set.empty)
    113     (f_statement_pointers type_ret ptrs) stmt
     112    (f_statement_pointers ret_type ptrs) stmt
     113
     114
     115(** [init_pointer def] returns the local variables or parameters of a function
     116    that can be deduced as pointers from the signature and the declarations of
     117    the function. *)
     118
     119let init_pointers def =
     120  let ptrs = StringTools.Set.empty in
     121  (* Adding the parameter pointers. *)
     122  let f ptrs x = function
     123    | AST.Sig_ptr -> StringTools.Set.add x ptrs
     124    | _ -> ptrs in
     125  let ptrs =
     126    List.fold_left2 f ptrs def.Cminor.f_params def.Cminor.f_sig.AST.args in
     127  (* Adding the local pointers. *)
     128  let f ptrs x =
     129    if List.mem x def.Cminor.f_ptrs then StringTools.Set.add x ptrs
     130    else
     131      if StringTools.Set.mem x ptrs then
     132        (* Case where a parameter with the same name is a pointer. Thus, for the
     133           moment, it is in [ptrs]. But only the local can be seen inside the
     134           function and it is not a pointer, so we have to remove it. *)
     135        StringTools.Set.remove x ptrs
     136      else ptrs in
     137  List.fold_left f ptrs def.Cminor.f_vars
    114138
    115139
     
    126150  (* The pointers of a function are found by iterating one step of collecting
    127151     the pointers until a fixpoint is reached. *)
     152  let ptrs = init_pointers def in
    128153  let ptrs =
    129154    fixpoint
    130       (statement_pointers def.Cminor.f_sig.AST.res def.Cminor.f_body)
    131       StringTools.Set.empty in
     155      (statement_pointers def.Cminor.f_sig.AST.res def.Cminor.f_body) ptrs in
    132156  let ptrs = StringTools.Set.fold (fun x l -> x :: l) ptrs [] in
    133157  { def with Cminor.f_ptrs = ptrs }
Note: See TracChangeset for help on using the changeset viewer.