Changeset 631


Ignore:
Timestamp:
Mar 4, 2011, 2:00:33 AM (9 years ago)
Author:
ayache
Message:

Some bugs fixed in D2.2.

Location:
Deliverables/D2.2/8051/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/ASM/ASMCosts.ml

    r630 r631  
    3838let treat mem costs pc =
    3939  let (inst, next_pc, inst_cost) = ASMInterpret.fetch mem pc in
     40(*
     41  (* <DEBUG> *)
     42  Printf.printf "%s%s: %s\n%!"
     43    (if BitVectors.WordMap.mem pc costs then
     44        BitVectors.WordMap.find pc costs ^ ": "
     45     else "")
     46    (BitVectors.string_of_vect pc)
     47    (Pretty.pp_instruction inst) ;
     48  (* </DEBUG> *)
     49*)
    4050  let next_pcs = match inst_nature pc inst with
    4151    | Return -> []
    4252    | Goto pc -> [pc]
    4353    | Branch pc2 ->
    44       let pc1 =
    45         snd (BitVectors.half_add pc (BitVectors.vect_of_int 1 `Sixteen)) in
    46       [pc1 ; pc2]
    47     | _ -> [next_pc] in
     54      [next_pc ; pc2]
     55    | Direct_fun_call _ | Other -> [next_pc] in
    4856  (inst_cost, next_pcs)
    4957
     
    6169  let rec aux = function
    6270    | [] -> 0
    63     | [pc] when BitVectors.WordMap.mem pc costs -> 0
     71    | [pc] when BitVectors.WordMap.mem pc costs ->0
    6472    | [pc] -> full_cost pc
    6573    | [pc1 ; pc2] when BitVectors.WordMap.mem pc1 costs &&
     
    8492let traverse_code mem p =
    8593  let rec aux pc code =
    86     let _,newpc,_ = ASMInterpret.fetch mem pc in
     94    let inst,newpc,_ = ASMInterpret.fetch mem pc in
     95(*
     96    (* <DEBUG> *)
     97    Printf.printf "Traversing %s: %s\n%!"
     98      (BitVectors.string_of_vect pc) (Pretty.pp_instruction inst) ;
     99    (* </DEBUG> *)
     100*)
    87101    match code with
    88102      | [] -> CostLabel.Map.empty
     
    129143
    130144let compute p =
     145(*
     146  (* <DEBUG> *)
     147  Printf.printf "%s\n\n%!" (Pretty.print_program p) ;
     148  (* </DEBUG> *)
     149*)
    131150  let mem = ASMInterpret.load_code_memory p.ASM.code in
    132151  let costs_mapping = traverse_code mem p in
  • Deliverables/D2.2/8051/src/ASM/ASMInterpret.ml

    r627 r631  
    991991            And, for ever label appearing after the location of the jump in code
    992992            memory, we must increment by 5, as we added two new instructions. *)
    993          let offset, jmp_address, translated_jump =
     993        let to_ljmp = `REL (vect_of_int 2 `Eight) in
     994        let offset = 5 in
     995         let jmp_address, translated_jump =
    994996           match i with
    995997             `JC (`Label a) ->
    996998               let address = StringTools.Map.find a labels in
    997                let reconstructed = `JC (`REL (vect_of_int 2 `Eight)) in
    998                  5, address, reconstructed
     999               let reconstructed = `JC to_ljmp in
     1000                 address, reconstructed
    9991001           | `JNC (`Label a) ->
    10001002               let address = StringTools.Map.find a labels in
    1001                let reconstructed = `JNC (`REL (vect_of_int 2 `Eight)) in
    1002                  5, address, reconstructed
     1003               let reconstructed = `JNC to_ljmp in
     1004                 address, reconstructed
    10031005           | `JB (b, `Label a) ->
    10041006               let address = StringTools.Map.find a labels in
    1005                let reconstructed = `JB (b, `REL (vect_of_int 2 `Eight)) in
    1006                  5, address, reconstructed
     1007               let reconstructed = `JB (b, to_ljmp) in
     1008                 address, reconstructed
    10071009           | `JNB (b, `Label a) ->
    10081010               let address = StringTools.Map.find a labels in
    1009                let reconstructed = `JNB (b, `REL (vect_of_int 2 `Eight)) in
    1010                  5, address, reconstructed
     1011               let reconstructed = `JNB (b, to_ljmp) in
     1012                 address, reconstructed
    10111013           | `JBC (b, `Label a) ->
    10121014               let address = StringTools.Map.find a labels in
    1013                let reconstructed = `JBC (b, `REL (vect_of_int 2 `Eight)) in
    1014                  5, address, reconstructed
     1015               let reconstructed = `JBC (b, to_ljmp) in
     1016                 address, reconstructed
    10151017           | `JZ (`Label a) ->
    10161018               let address = StringTools.Map.find a labels in
    1017                let reconstructed = `JZ (`REL (vect_of_int 2 `Eight)) in
    1018                  5, address, reconstructed
     1019               let reconstructed = `JZ (to_ljmp) in
     1020                 address, reconstructed
    10191021           | `JNZ (`Label a) ->
    10201022               let address = StringTools.Map.find a labels in
    1021                let reconstructed = `JNZ (`REL (vect_of_int 2 `Eight)) in
    1022                  5, address, reconstructed
     1023               let reconstructed = `JNZ (to_ljmp) in
     1024                 address, reconstructed
    10231025           | `CJNE (args, `Label a) ->
    10241026               let address = StringTools.Map.find a labels in
    1025                let reconstructed = `CJNE (args, `REL (vect_of_int 2 `Eight)) in
    1026                  5, address, reconstructed
     1027               let reconstructed = `CJNE (args, to_ljmp) in
     1028                 address, reconstructed
    10271029           | `DJNZ (args, `Label a) ->
    10281030               let address = StringTools.Map.find a labels in
    1029                let reconstructed = `DJNZ (args, `REL (vect_of_int 2 `Eight)) in
    1030                  5, address, reconstructed
     1031               let reconstructed = `DJNZ (args, to_ljmp) in
     1032                 address, reconstructed
    10311033         in
    10321034           let sjmp, jmp = `SJMP (`REL (vect_of_int 3 `Eight)), `LJMP (`ADDR16 jmp_address) in
  • Deliverables/D2.2/8051/src/ASM/ASMInterpret.mli

    r619 r631  
    124124   the processor never halts. *)
    125125val execute: (status -> unit) -> status -> status
    126  
     126
    127127val fetch: Physical.WordMap.map -> word -> ASM.instruction * word * int
    128128
  • Deliverables/D2.2/8051/src/LIN/LINToASM.ml

    r624 r631  
    3333  | LIN.St_label lbl -> [`Label lbl]
    3434  | LIN.St_comment _ -> []
    35   | LIN.St_cost lbl -> [`Cost lbl]
     35  | LIN.St_cost lbl -> [`Cost lbl ; `NOP (* TODO: hack! Need to make the difference between cost labels and regular labels. *)]
    3636  | LIN.St_int (r, i) ->
    3737    [`MOV (`U3 (I8051.reg_addr r, data_of_int i))]
     
    107107          let tmp_lbl = Label.Gen.fresh tmp_universe in
    108108          [`WithLabel (`JZ (`Label tmp_lbl)) ;
    109            `Cost cost_lbl ; `Jmp lbl ;
     109           `Cost cost_lbl ; `NOP (* TODO: hack! Need to make the difference between cost labels and regular labels. *) ; `Jmp lbl ;
    110110           `Label tmp_lbl] @
    111111            (aux code'))
Note: See TracChangeset for help on using the changeset viewer.