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/ERTL/ERTLInterpret.ml

    r486 r619  
    5555      renv   : hdw_reg_env ;
    5656      mem    : memory ;
    57       trace  : AST.trace }
     57      trace  : CostLabel.t list }
    5858
    5959
     
    448448    (Val.to_string st.pc) (current_label lbls_offs st) ;
    449449  Printf.printf "SP: %s\n%!"
    450     (Val.to_string (Val.merge [I8051.RegisterMap.find I8051.sph st.renv ;
    451                                I8051.RegisterMap.find I8051.spl st.renv])) ;
     450    (Val.to_string (Val.merge [get_reg (Hdw I8051.sph) st ;
     451                               get_reg (Hdw I8051.spl) st])) ;
    452452  Printf.printf "ISP: %s%!" (Val.to_string st.isp) ;
    453453  print_lenv st.lenv ;
     
    456456  Printf.printf "\n%!"
    457457
    458 let rec iter_small_step lbls_offs st = match fetch_stmt lbls_offs st with
    459   | ERTL.St_return ret_regs when st.st_frs = [] ->
    460 (*
    461     print_state lbls_offs st ;
    462     let res = fetch_result st.renv ret_regs in
    463     Printf.printf "Return: %s\n%!" (Val.to_string res) ;
    464 *)
    465     List.rev st.trace
    466   | stmt ->
    467 (*
    468     print_state lbls_offs st ;
    469 *)
    470     let st' = interpret_stmt lbls_offs st stmt in
    471     iter_small_step lbls_offs st'
     458let compute_result st ret_regs =
     459  try
     460    let v = get_reg (Psd (MiscPottier.last ret_regs)) st in
     461    if Val.is_int v then IntValue.Int8.cast (Val.to_int_repr v)
     462    else IntValue.Int8.zero
     463  with Not_found -> IntValue.Int8.zero
     464
     465let rec iter_small_step print_result lbls_offs st =
     466  match fetch_stmt lbls_offs st with
     467    | ERTL.St_return ret_regs when st.st_frs = [] ->
     468      let (res, cost_labels) as trace =
     469        (compute_result st ret_regs, List.rev st.trace) in
     470      if print_result then
     471        Printf.printf "ERTL: %s\n%!" (IntValue.Int8.to_string res) ;
     472      trace
     473    | stmt ->
     474    (*
     475      print_state lbls_offs st ;
     476    *)
     477      let st' = interpret_stmt lbls_offs st stmt in
     478      iter_small_step print_result lbls_offs st'
    472479
    473480
     
    530537   - Initialize the carry flag to 0. *)
    531538
    532 let interpret p = match p.ERTL.main with
    533   | None -> []
     539let interpret print_result p = match p.ERTL.main with
     540  | None -> (IntValue.Int8.zero (* TODO *), [])
    534541  | Some main ->
    535542    let lbls_offs = labels_offsets p in
     
    541548    let st = init_main_call lbls_offs st main in
    542549    let st = change_carry st Val.zero in
    543     iter_small_step lbls_offs st
     550    iter_small_step print_result lbls_offs st
Note: See TracChangeset for help on using the changeset viewer.