Ignore:
Timestamp:
Oct 10, 2011, 11:32:44 PM (9 years ago)
Author:
tranquil
Message:
  • work on LIN completed
  • small implementation of extensible arrays
File:
1 edited

Legend:

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

    r1291 r1349  
    131131
    132132  exit_addr   : BitVectors.word;
     133       
     134        ind_0s      : int BitVectors.WordMap.t;
     135  ind_incs    : int BitVectors.WordMap.t;
    133136  cost_labels : CostLabel.t BitVectors.WordMap.t
    134137}
     
    284287
    285288  exit_addr = BitVectors.zero `Sixteen;
     289  ind_0s = BitVectors.WordMap.empty;
     290  ind_incs = BitVectors.WordMap.empty;
    286291  cost_labels = BitVectors.WordMap.empty
    287292}
     
    950955   ) (StringTools.Map.empty,0) p.ASM.ppreamble
    951956 in
    952  let pc,exit_addr,labels,costs =
     957 let pc,exit_addr,labels,inds,incs,costs =
    953958  List.fold_left
    954    (fun (pc,exit_addr,labels,costs) i ->
     959   (fun (pc,exit_addr,labels,inds,incs,costs) i ->
    955960     match i with
    956         `Label s when s = p.ASM.pexit_label -> pc, pc, StringTools.Map.add s pc labels, costs
    957       | `Label s -> pc, exit_addr, StringTools.Map.add s pc labels, costs
    958       | `Cost s -> pc, exit_addr, labels, BitVectors.WordMap.add pc s costs
    959       | `Mov (_,_) -> (snd (half_add pc (vect_of_int 1 `Sixteen))), exit_addr, labels, costs
     961        `Label s when s = p.ASM.pexit_label -> pc, pc, StringTools.Map.add s pc labels, inds, incs, costs
     962      | `Label s -> pc, exit_addr, StringTools.Map.add s pc labels, inds, incs, costs
     963      | `Cost s -> pc, exit_addr, labels, inds, incs, BitVectors.WordMap.add pc s costs
     964                        | `Index i -> pc, exit_addr, labels, BitVectors.WordMap.add pc i inds, incs, costs
     965      | `Inc i -> pc, exit_addr, labels, inds, BitVectors.WordMap.add pc i incs, costs
     966      | `Mov (_,_) -> (snd (half_add pc (vect_of_int 1 `Sixteen))), exit_addr, labels, inds, incs, costs
    960967      | `Jmp _
    961       | `Call _ -> (snd (half_add pc (BitVectors.vect_of_int 3 `Sixteen))), exit_addr, labels, costs
     968      | `Call _ -> (snd (half_add pc (BitVectors.vect_of_int 3 `Sixteen))), exit_addr, labels, inds, incs, costs
    962969      (*CSC: very stupid: always expand to worst opcode *)
    963970      | `WithLabel i ->
     
    967974        assert (fake_jump = i');
    968975        let pc' = snd (half_add pc' (vect_of_int 5 `Sixteen)) in
    969           (snd (half_add pc pc'), exit_addr, labels, costs)
     976          (snd (half_add pc pc'), exit_addr, labels, inds, incs, costs)
    970977      | #instruction as i ->
    971978        let i',pc',_ = fetch (load_code_memory (assembly1 i)) (vect_of_int 0 `Sixteen) in
    972979         assert (i = i');
    973          (snd (half_add pc pc'),exit_addr,labels, costs)
     980         (snd (half_add pc pc'),exit_addr,labels, inds, incs, costs)
    974981   )
    975982    (BitVectors.zero `Sixteen,BitVectors.zero `Sixteen,
    976      StringTools.Map.empty, BitVectors.WordMap.empty) p.ASM.pcode
     983     StringTools.Map.empty, BitVectors.WordMap.empty, BitVectors.WordMap.empty,
     984                 BitVectors.WordMap.empty) p.ASM.pcode
    977985 in
    978986 let code =
     
    980988     (function
    981989        `Label _
    982       | `Cost _ -> []
     990      | `Cost _
     991                        | `Index _
     992                        | `Inc _ -> []
    983993      | `WithLabel i ->
    984994         (* We need to expand a conditional jump to a label to a machine language
     
    10451055            assembly1 (`LCALL (`ADDR16 pc_offset ))
    10461056      | #instruction as i -> assembly1 i) p.ASM.pcode) in
    1047  { ASM.code = code ; ASM.cost_labels = costs ;
     1057 { ASM.code = code ; ASM.inds = inds; ASM.incs = incs; ASM.cost_labels = costs ;
    10481058   ASM.exit_addr = exit_addr ; ASM.has_main = p.ASM.phas_main }
    10491059;;
     
    19731983  { st with exit_addr = p.ASM.exit_addr ; cost_labels = p.ASM.cost_labels }
    19741984
    1975 let observe_trace trace_ref st =
    1976   let cost_label =
    1977     if BitVectors.WordMap.mem st.pc st.cost_labels then
    1978       [BitVectors.WordMap.find st.pc st.cost_labels]
    1979     else [] in
    1980   trace_ref := cost_label @ !trace_ref ;
     1985type cost_trace = {
     1986        mutable ct_labels : CostLabel.t list;
     1987        mutable ct_inds   : CostLabel.const_indexing list;
     1988}
     1989
     1990(* TODO: indexes *)
     1991let 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;
    19811998  if st.pc = st.exit_addr (* <=> end of program *) then raise Halt else st
    19821999
     
    19962013  if p.ASM.has_main then
    19972014    let st = load_program p in
    1998     let trace = ref [] in
     2015    let trace = {ct_labels = []; ct_inds = []} in
    19992016    let callback = observe_trace trace in
    20002017    let st = execute callback st in
     
    20022019    if debug then
    20032020      Printf.printf "Result = %s\n%!" (IntValue.Int32.to_string res) ;
    2004     (res, List.rev !trace)
     2021    (res, List.rev trace.ct_labels)
    20052022  else (IntValue.Int32.zero, [])
Note: See TracChangeset for help on using the changeset viewer.