Ignore:
Timestamp:
Oct 11, 2011, 5:42:20 PM (9 years ago)
Author:
tranquil
Message:
  • changed implementation of constant indexings with extensible arrays
  • work on ASM completed
  • next: optimizations!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051-indexed-labels-branch/src/ASM/ASMInterpret.ml

    r1349 r1357  
    132132  exit_addr   : BitVectors.word;
    133133       
     134(*
    134135        ind_0s      : int BitVectors.WordMap.t;
    135136  ind_incs    : int BitVectors.WordMap.t;
    136137  cost_labels : CostLabel.t BitVectors.WordMap.t
     138*)     
    137139}
    138140
     
    287289
    288290  exit_addr = BitVectors.zero `Sixteen;
     291(*
    289292  ind_0s = BitVectors.WordMap.empty;
    290293  ind_incs = BitVectors.WordMap.empty;
    291294  cost_labels = BitVectors.WordMap.empty
     295*)
    292296}
    293297
     
    19811985let load_program p =
    19821986  let st = load p.ASM.code initialize in
    1983   { st with exit_addr = p.ASM.exit_addr ; cost_labels = p.ASM.cost_labels }
     1987  { st with exit_addr = p.ASM.exit_addr (* ; cost_labels = p.ASM.cost_labels *)}
    19841988
    19851989type cost_trace = {
     
    19881992}
    19891993
    1990 (* TODO: indexes *)
    1991 let observe_trace trace st =
    1992         let update_ct_labels =
    1993           try
    1994                         let cost_label = BitVectors.WordMap.find st.pc st.cost_labels in
    1995             trace.ct_labels <- cost_label :: trace.ct_labels
    1996           with Not_found -> () in
    1997         update_ct_labels;
     1994(* TODO: supposing only one index reset or increment per instruction *)
     1995let update_indexes trace p st =
     1996  try
     1997    let i = BitVectors.WordMap.find st.pc p.ASM.inds in
     1998                CostLabel.enter_loop trace.ct_inds i
     1999  with Not_found -> ();
     2000  try
     2001    let i = BitVectors.WordMap.find st.pc p.ASM.incs in
     2002    CostLabel.continue_loop trace.ct_inds i
     2003  with Not_found -> ();
     2004  let instr,_,_ = fetch st.code_memory st.pc in
     2005        match instr with
     2006                | `ACALL _ | `LCALL _ ->
     2007      trace.ct_inds <- CostLabel.new_const_ind trace.ct_inds
     2008                | `RET ->
     2009                        trace.ct_inds <- CostLabel.forget_const_ind trace.ct_inds
     2010                | _ -> ()
     2011
     2012let update_labels trace p st =
     2013  try
     2014    let cost_label = BitVectors.WordMap.find st.pc p.cost_labels in
     2015        let ind = CostLabel.curr_const_ind trace.ct_inds in
     2016        let cost_label = CostLabel.ev_indexing ind cost_label in
     2017        trace.ct_labels <- cost_label :: trace.ct_labels
     2018  with Not_found -> ()
     2019
     2020
     2021
     2022let update_trace trace p st =
     2023        update_labels trace p st;
     2024        update_indexes trace p st;
    19982025  if st.pc = st.exit_addr (* <=> end of program *) then raise Halt else st
    19992026
     
    20142041    let st = load_program p in
    20152042    let trace = {ct_labels = []; ct_inds = []} in
    2016     let callback = observe_trace trace in
     2043    let callback = update_trace trace p in
    20172044    let st = execute callback st in
    20182045    let res = result st in
Note: See TracChangeset for help on using the changeset viewer.