rreil-pretty.ml 3.81 KB
Newer Older
mb0's avatar
Up.    
mb0 committed
1
2
3
# vim:filetype=sml:ts=3:sw=3:expandtab

# The following functions need to be defined elsewhere:
mb0's avatar
Up.    
mb0 committed
4
#   - arch-show-id
mb0's avatar
Up.    
mb0 committed
5

mb0's avatar
Up.    
mb0 committed
6
export = rreil-pretty rreil-pretty-rev rreil-pretty-stmt
mb0's avatar
Up.    
mb0 committed
7

mb0's avatar
Up.    
mb0 committed
8
val rreil-pretty-stmt s = rreil-show-stmt s
mb0's avatar
Up.    
mb0 committed
9
val rreil-pretty ss = rreil-show-stmts ss
mb0's avatar
Up.    
mb0 committed
10
val rreil-pretty-rev ss = rreil-show-stmts (rreil-stmts-rev ss)
mb0's avatar
Up.    
mb0 committed
11

mb0's avatar
Up.    
mb0 committed
12
val rreil-show-stmts ss =
mb0's avatar
Up.    
mb0 committed
13
14
   case ss of  
      SEM_NIL: ""
mb0's avatar
Up.    
mb0 committed
15
    | SEM_CONS x: rreil-show-stmt x.hd +++ "\n" +++ rreil-show-stmts x.tl
mb0's avatar
Up.    
mb0 committed
16
17
   end

mb0's avatar
Up.    
mb0 committed
18
val rreil-show-stmt s =
mb0's avatar
Up.    
mb0 committed
19
   case s of
mb0's avatar
Up.    
mb0 committed
20
      SEM_ASSIGN x: rreil-show-var x.lhs +++ " = " +++ rreil-show-op x.rhs 
mb0's avatar
Up.    
mb0 committed
21
    | SEM_LOAD x: rreil-show-var x.lhs +++ " = " +++ rreil-show-ptrderef x.size x.address
mb0's avatar
Up.    
mb0 committed
22
    | SEM_STORE x: "*" +++ rreil-show-address x.address +++ " = " +++ rreil-show-op x.rhs
mb0's avatar
Up.    
mb0 committed
23
    | SEM_LABEL x: rreil-show-label x.label
mb0's avatar
Up.    
mb0 committed
24
25
26
27
    | SEM_IF_GOTO_LABEL x: "if (" +++ rreil-show-linear x.cond +++ ") goto label " +++ rreil-show-label x.label
    | SEM_IF_GOTO x: "if (" +++ rreil-show-linear x.cond +++ ") goto " +++ rreil-show-linear x.target
    | SEM_CALL x: "if (" +++ rreil-show-linear x.cond +++ ") call " +++ rreil-show-address x.target
    | SEM_RETURN x: "if (" +++ rreil-show-linear x.cond +++ ") return " +++ rreil-show-address x.target
mb0's avatar
Up.    
mb0 committed
28
29
   end

mb0's avatar
Up.    
mb0 committed
30
val rreil-show-label l = "l" +++ showint l +++ ":"
mb0's avatar
Up.    
mb0 committed
31

mb0's avatar
Up.    
mb0 committed
32
val rreil-show-op op =
mb0's avatar
Up.    
mb0 committed
33
   case op of
mb0's avatar
Up.    
mb0 committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      SEM_LIN x: rreil-show-arity1 x
    | SEM_BSWAP x: "bswap" +++ rreil-show-arity1 x
    | SEM_MUL x: "mul" +++ rreil-show-arity2 x
    | SEM_DIV x: "div" +++ rreil-show-arity2 x
    | SEM_DIVS x: "divs" +++ rreil-show-arity2 x
    | SEM_MOD x: "mod" +++ rreil-show-arity2 x
    | SEM_SHL x: "shl" +++ rreil-show-arity2 x
    | SEM_SHR x: "shr" +++ rreil-show-arity2 x
    | SEM_SHRS x: "shrs" +++ rreil-show-arity2 x
    | SEM_AND x: "and" +++ rreil-show-arity2 x
    | SEM_OR x: "or" +++ rreil-show-arity2 x
    | SEM_XOR x: "xor" +++ rreil-show-arity2 x
    | SEM_SX x: "sx[" +++ showint x.fromsize +++ "." +++ showint x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ ")"
    | SEM_ZX x: "zx[" +++ showint x.fromsize +++ "." +++ showint x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ ")"
    | SEM_CMPEQ x: "==" +++ rreil-show-cmp x
    | SEM_CMPNEQ x: "/=" +++ rreil-show-cmp x
    | SEM_CMPLES x: "<=s" +++ rreil-show-cmp x
    | SEM_CMPLEU x: "<=u" +++ rreil-show-cmp x
    | SEM_CMPLTS x: "<s" +++ rreil-show-cmp x
    | SEM_CMPLTU x: "<u" +++ rreil-show-cmp x
mb0's avatar
Up.    
mb0 committed
54
    | SEM_ARB x: "arbitrary[" +++ showint x.size +++ "]"
mb0's avatar
Up.    
mb0 committed
55
56
   end

mb0's avatar
Up.    
mb0 committed
57
58
59
60
61
62
val rreil-show-arity1 x = "[" +++ showint x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ ")"
val rreil-show-arity2 x = "[" +++ showint x.size +++ "](" +++ rreil-show-linear x.opnd1 +++ "," +++ rreil-show-linear x.opnd2 +++ ")"
val rreil-show-cmp x = "[" +++ showint x.size +++ ".1](" +++ rreil-show-linear x.opnd1 +++ "," +++ rreil-show-linear x.opnd2 +++ ")"
val rreil-show-ptrderef sz addr = "*[" +++ showint addr.size +++ "." +++ showint sz +++ "](" +++ rreil-show-linear addr.address +++ ")"
val rreil-show-address addr = "[" +++ showint addr.size +++ "](" +++ rreil-show-linear addr.address +++ ")"
val rreil-show-var x =
mb0's avatar
Up.    
mb0 committed
63
   case x.offset of
mb0's avatar
Up.    
mb0 committed
64
65
      0: rreil-show-id x.id
    | o: rreil-show-id x.id +++ "/" +++ showint o
mb0's avatar
Up.    
mb0 committed
66
67
   end

mb0's avatar
Up.    
mb0 committed
68
val rreil-show-linear lin = 
mb0's avatar
Up.    
mb0 committed
69
   case lin of
mb0's avatar
Up.    
mb0 committed
70
      SEM_LIN_VAR x: rreil-show-var x
mb0's avatar
Up.    
mb0 committed
71
    | SEM_LIN_IMM x: showint x.imm
mb0's avatar
Up.    
mb0 committed
72
73
    | SEM_LIN_ADD x: rreil-show-linear x.opnd1 +++ "+" +++ rreil-show-linear x.opnd2
    | SEM_LIN_SUB x: rreil-show-linear x.opnd1 +++ "-" +++ rreil-show-linear x.opnd2
mb0's avatar
Up.    
mb0 committed
74
75
76
    | SEM_LIN_SCALE x:
         case x.imm of
            0: ""
mb0's avatar
Up.    
mb0 committed
77
78
          | 1: rreil-show-linear x.opnd
          | s: showint s +++ "*" +++ rreil-show-linear x.opnd
mb0's avatar
Up.    
mb0 committed
79
80
81
         end
   end

mb0's avatar
Up.    
mb0 committed
82
val rreil-show-id id =
mb0's avatar
Up.    
mb0 committed
83
84
85
86
87
88
89
90
   case id of
    | VIRT_EQ: "EQ"
    | VIRT_NEQ: "NEQ"
    | VIRT_LES: "LES"
    | VIRT_LEU: "LEU"
    | VIRT_LTS: "LTS"
    | VIRT_LTU: "LTU"
    | VIRT_T x: "T" +++ showint x
Axel Simon's avatar
Axel Simon committed
91
    | _: arch-show-id id
mb0's avatar
Up.    
mb0 committed
92
   end