Changeset 101
- Timestamp:
- Sep 22, 2010, 11:49:45 AM (10 years ago)
- Location:
- Deliverables/D4.1
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Deliverables/D4.1/ASM.mli
r100 r101 1 open BitVectors;;2 open Physical;;3 4 1 type ('a,'b) union2 = [ `U1 of 'a | `U2 of 'b ] 5 2 type ('a,'b,'c) union3 = [ `U1 of 'a | `U2 of 'b | `U3 of 'c ] -
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 1 exception Fetch_exception of string;; 2 exception CodeTooLarge;; 3 exception Halt;; 7 4 8 5 type time = int;; … … 666 663 667 664 let assembly l = 668 let pc,labels =665 let pc,labels,costs = 669 666 List.fold_left 670 (fun ( (pc,labels) as acc) i ->667 (fun (pc,labels,costs) i -> 671 668 match i with 672 `Label s -> pc, StringMap.add s pc labels 673 | `Cost _ -> acc669 `Label s -> pc, StringMap.add s pc labels, costs 670 | `Cost s -> pc, labels, StringMap.add s pc costs 674 671 | `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 *) 676 673 | #instruction as i -> 677 674 let i',pc',_ = fetch (load_code_memory (assembly1 i)) (vect_of_int 0 `Sixteen) in 678 675 assert (i = i'); 679 (pc + int_of_vect pc',labels )680 ) (0,StringMap.empty ) l676 (pc + int_of_vect pc',labels, costs) 677 ) (0,StringMap.empty,StringMap.empty) l 681 678 in 682 679 if pc >= 65536 then 683 680 raise CodeTooLarge 684 681 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 *) 685 695 ;; 686 696 … … 847 857 match instr with 848 858 `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 853 868 (* 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 in858 set_flags (set_arg8 status v `A) c (Some ac) ov859 869 | SUBB (`A,d1) -> 860 870 let v,c,ac,ov = … … 1208 1218 status 1209 1219 | NOP -> status 1220 *) 1221 | _ -> assert false 1210 1222 ;; 1211 *) | _ -> assert false1212 1213 exception Hold;;1214 1223 1215 1224 let rec execute f s = … … 1217 1226 let cont = 1218 1227 try f s; true 1219 with H old-> false1228 with Halt -> false 1220 1229 in 1221 1230 if cont then execute f s -
Deliverables/D4.1/ASMInterpret.mli
r100 r101 9 9 val load: BitVectors.byte list -> status -> status 10 10 11 exception H old(* to be raised to stop execution *)11 exception Halt (* to be raised to stop execution *) 12 12 13 13 (* the callback function is used to observe the execution -
Deliverables/D4.1/physical.ml
r97 r101 1 open BitVectors;;2 3 1 exception Byte7_conversion 4 2
Note: See TracChangeset
for help on using the changeset viewer.