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

Last change on this file since 450 was 450, checked in by mulligan, 9 years ago

Comment added for Nicolas.

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