Ignore:
Timestamp:
Mar 2, 2011, 3:27:41 PM (9 years ago)
Author:
ayache
Message:

Update of D2.2 from Paris.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/RTL/RTLInterpret.ml

    r486 r619  
    4141type state =
    4242  | State of stack_frame list * RTL.graph * Label.t * Val.t (* sp *) *
    43              local_env * Val.t (* carry *) * memory * AST.trace
     43             local_env * Val.t (* carry *) * memory * CostLabel.t list
    4444  | CallState of stack_frame list * RTL.function_def *
    45                  Val.t list (* args *) * memory * AST.trace
     45                 Val.t list (* args *) * memory * CostLabel.t list
    4646  | ReturnState of stack_frame list * Val.t list (* return values *) *
    47                    memory * AST.trace
     47                   memory * CostLabel.t list
    4848
    4949
     
    101101    (mem   : memory)
    102102    (stmt  : RTL.statement)
    103     (t     : AST.trace) :
     103    (t     : CostLabel.t list) :
    104104    state = match stmt with
    105105
     
    269269    (args  : Val.t list)
    270270    (mem   : memory)
    271     (t     : AST.trace) :
     271    (t     : CostLabel.t list) :
    272272    state =
    273273  match f_def with
     
    286286    (ret_vals : Val.t list)
    287287    (mem      : memory)
    288     (t        : AST.trace) :
     288    (t        : CostLabel.t list) :
    289289    state =
    290290  let f i lenv r = Register.Map.add r (List.nth ret_vals i) lenv in
     
    311311    (Register.print r) (Val.to_string v))
    312312
    313 let rec iter_small_step st = match small_step st with
     313let compute_result vs =
     314  try
     315    let v = MiscPottier.last vs in
     316    if Val.is_int v then IntValue.Int8.cast (Val.to_int_repr v)
     317    else IntValue.Int8.zero
     318  with Not_found -> IntValue.Int8.zero
     319
     320let rec iter_small_step print_result st = match small_step st with
    314321(*
     322  (* <DEBUG> *)
    315323  | ReturnState ([], vs, mem, t) ->
    316324    Mem.print mem ;
     
    331339    Printf.printf "Carry = %s\n\n%!" (Val.to_string carry) ;
    332340    iter_small_step st'
     341  (* </DEBUG> *)
    333342*)
    334343  | ReturnState ([], vs, mem, t) ->
    335 (*
    336     Printf.printf "Return: %s\n%!" (print_ret_vals vs) ;
    337 *)
    338     List.rev t
    339   | st' -> iter_small_step st'
     344    let (res, cost_labels) as trace = (compute_result vs, List.rev t) in
     345    if print_result then
     346      Printf.printf "RTL: %s\n%!" (IntValue.Int8.to_string res) ;
     347    trace
     348  | st' -> iter_small_step print_result st'
    340349
    341350
     
    357366(* Interpret the program only if it has a main. *)
    358367
    359 let interpret p = match p.RTL.main with
    360   | None -> []
     368let interpret print_result p = match p.RTL.main with
     369  | None -> (IntValue.Int8.zero, [])
    361370  | Some main ->
    362371    let mem = init_mem p in
    363372    let main_def = find_function mem main in
    364373    let st = CallState ([], main_def, [], mem, []) in
    365     iter_small_step st
     374    iter_small_step print_result st
Note: See TracChangeset for help on using the changeset viewer.