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

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

Debugging hex output. Seems mcu8051 really doesn't like what's been spat out.

File size: 1.4 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-output-test.hex" (pack_exported_code_memory 16 128 status.code_memory) in
11let observe status =
12 let pc = status.ASMInterpret.pc in
13 let instr,_,_ = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
14   let _ = prerr_string (BitVectors.hex_string_of_vect pc) in
15   let _ = prerr_endline (": " ^ pp_instruction instr) in
16    (* match instr with
17       `SJMP (`REL b) ->
18          if int_of_vect b = 254 || int_of_vect b = 0 then*)
19            prerr_endline <*> string_of_status $ status
20(*          else
21            ()
22     | _ -> ()*)
23in
24(* DPM: for debugging! *)
25let mem_pretty_print status =
26  let rec aux status pc =
27    let instr, pc', cost = ASMInterpret.fetch status.ASMInterpret.code_memory pc in
28      prerr_string $ ((hex_string_of_vect pc) ^ ": ");
29      prerr_string $ (pp_instruction instr) ^ " ";
30      prerr_endline $ string_of_int cost;
31      if int_of_vect pc' > 200 then (* DPM: hardcoded on a case-by-case basis *)
32        ()
33      else
34        aux status pc'
35  in
36    aux status status.ASMInterpret.pc;
37    prerr_endline "-------------------------------------"
38in
39 mem_pretty_print status;
40 ASMInterpret.execute observe status
41;;
Note: See TracBrowser for help on using the repository browser.