Ignore:
Timestamp:
Sep 22, 2010, 11:49:45 AM (9 years ago)
Author:
mulligan
Message:

Fixing type errors in execute1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/ASMInterpret.ml

    r100 r101  
    1 open BitVectors;;
    2 open ASM;;
    3 open Physical;;
    4 
    5 exception Fetch_exception of string
    6 exception CodeTooLarge
     1exception Fetch_exception of string;;
     2exception CodeTooLarge;;
     3exception Halt;;
    74
    85type time = int;;
     
    666663
    667664let assembly l =
    668  let pc,labels =
     665 let pc,labels,costs =
    669666  List.fold_left
    670    (fun ((pc,labels) as acc) i ->
     667   (fun (pc,labels,costs) i ->
    671668     match i with
    672         `Label s -> pc, StringMap.add s pc labels
    673       | `Cost _ -> acc
     669        `Label s -> pc, StringMap.add s pc labels, costs
     670      | `Cost s -> pc, labels, StringMap.add s pc costs
    674671      | `Jmp s
    675       | `Call s -> pc + 3, labels  (*CSC: very stupid: always expand to worst opcode *)
     672      | `Call s -> pc + 3, labels, costs  (*CSC: very stupid: always expand to worst opcode *)
    676673      | #instruction as i ->
    677674        let i',pc',_ = fetch (load_code_memory (assembly1 i)) (vect_of_int 0 `Sixteen) in
    678675         assert (i = i');
    679          (pc + int_of_vect pc',labels)
    680    ) (0,StringMap.empty) l
     676         (pc + int_of_vect pc',labels, costs)
     677   ) (0,StringMap.empty,StringMap.empty) l
    681678 in
    682679  if pc >= 65536 then
    683680   raise CodeTooLarge
    684681  else
     682    assert false
     683(*
     684    let instr = ((List.filter (function `Label _ | `Cost _ | `Jmp _ | `Call _ -> false | _ -> true) l) : instruction list) in
     685      List.flatten (List.map
     686         (function
     687            `Label s -> []
     688          | `Cost s -> []
     689          | `Jmp s | `Call s ->
     690              let pc_offset = StringMap.find s labels in
     691              let i,_,_ = fetch (load_code_memory (List.map assembly1 instr)) (vect_of_int pc_offset `Eight) in
     692                i
     693          | #instruction as i -> assembly1 i) l)
     694*)
    685695;;
    686696
     
    847857  match instr with
    848858     `ADD (`A,d1) ->
    849       let v,c,ac,ov =
    850        add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) false
    851       in
    852        set_flags (set_arg8 status v `A) c (Some ac) ov
     859        let v,c,ac,ov =
     860          add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) false
     861        in
     862          set_flags (set_arg8 status v `A) c (Some ac) ov
     863   | `ADDC (`A,d1) ->
     864        let v,c,ac,ov =
     865          add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (get_cy_flag status)
     866        in
     867          set_flags (set_arg8 status v `A) c (Some ac) ov
    853868(*
    854    | ADDC (`A,d1) ->
    855       let v,c,ac,ov =
    856        add8_with_c (get_arg_8 status `A) (get_arg_8 status d1) (carr status)
    857       in
    858        set_flags (set_arg8 status v `A) c (Some ac) ov
    859869   | SUBB (`A,d1) ->
    860870      let v,c,ac,ov =
     
    12081218         status
    12091219 | NOP -> status
     1220*)
     1221 | _ -> assert false
    12101222;;
    1211 *) | _ -> assert false
    1212 
    1213 exception Hold;;
    12141223
    12151224let rec execute f s =
     
    12171226 let cont =
    12181227  try f s; true
    1219   with Hold -> false
     1228  with Halt -> false
    12201229 in
    12211230  if cont then execute f s
Note: See TracChangeset for help on using the changeset viewer.