source: Deliverables/D4.1/Test.ml @ 448

Last change on this file since 448 was 448, checked in by mulligan, 10 years ago

Got Intel HEX format exportation working.

File size: 1.6 KB
Line 
1open BitVectors;;
2open ASMInterpret;;
3open Util;;
4open IntelHex;;
5open Pretty;;
6
7let hex = IntelHex.intel_hex_of_file Sys.argv.(1) in
8let mem = IntelHex.process_intel_hex hex in
9let status = ASMInterpret.load_mem mem ASMInterpret.initialize in
10let _ = file_of_intel_hex "hex_test_out.hex" (pack_exported_code_memory 12 114 status.code_memory) in
11let mem' = IntelHex.process_intel_hex (IntelHex.intel_hex_of_file "hex_test_out.hex") in
12let _ = assert (Physical.WordMap.equal (=) mem mem') in
13let status = ASMInterpret.load_mem mem ASMInterpret.initialize in
14let observe status =
15 let pc = status.ASMInterpret.pc in
16 let instr,_,_ = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
17   let _ = prerr_string (BitVectors.hex_string_of_vect pc) in
18   let _ = prerr_endline (": " ^ pp_instruction instr) in
19    (* match instr with
20       `SJMP (`REL b) ->
21          if int_of_vect b = 254 || int_of_vect b = 0 then*)
22            prerr_endline <*> string_of_status $ status
23(*          else
24            ()
25     | _ -> ()*)
26in
27(* DPM: for debugging! *)
28let mem_pretty_print status =
29  let rec aux status pc =
30    let instr, pc', cost = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
31      prerr_string $ ((hex_string_of_vect pc) ^ ": ");
32      prerr_string $ (pp_instruction instr) ^ " ";
33      prerr_endline $ string_of_int cost;
34      if int_of_vect pc' > 200 then (* DPM: hardcoded on a case-by-case basis *)
35        ()
36      else
37        aux status pc'
38  in
39    aux status status.ASMInterpret.pc;
40    prerr_endline "-------------------------------------"
41in
42 mem_pretty_print status;
43 ASMInterpret.execute observe status
44;;
Note: See TracBrowser for help on using the repository browser.