1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
open Prog
open Utils
open PrintCommon
open Arch_decl
type asm_element =
| Label of string
| Dwarf of string
| Instr of string * string list
| Byte of string
let iwidth = 4
type asm = asm_element list
let fmt name params =
match params with
| [] -> Format.fprintf fmt "\t%s" name
| _ -> Format.fprintf fmt "\t%-*s\t%s" iwidth name (String.concat ", " params)
let pp_label fmt name =
Format.fprintf fmt "%s:" name
let pp_instr fmt name params =
match params with
| [] -> Format.fprintf fmt "\t%s" name
| _ -> Format.fprintf fmt "\t%-*s\t%s" iwidth name (String.concat ", " params)
let fmt =
Format.fprintf fmt "// %s" comment
let pp_byte fmt byte =
Format.fprintf fmt "\t.byte\t%s" byte
let pp_dwarf fmt (dwarf: string) =
Format.fprintf fmt "\t%s" dwarf
let pp_asm_element fmt asm_element =
match asm_element with
| Header (name, params) ->
pp_header fmt name params
| Label name ->
pp_label fmt name
| Dwarf locs ->
pp_dwarf fmt locs
| Instr (name, params) ->
pp_instr fmt name params
| Comment content ->
pp_comment fmt content
| Byte data ->
pp_byte fmt data
let pp_asm_line fmt =
Format.fprintf fmt "%a\n%!" pp_asm_element
let pp_asm fmt asm =
List.iter (pp_asm_line fmt) asm