summaryrefslogtreecommitdiff
path: root/il.sig
blob: 9e994a33f445e301f44da88b793f0bcf324e323b (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
signature IL = sig

  structure P: PARSER
  structure PP: PPC
  structure D: DYNARRAY

  datatype vregClass = VR4 | VR8

  type vreg = int
  type label = int

  datatype setArg = SaVReg of vreg | SaConst of word |
    SaAddr of P.nid * word

  datatype accessClass = AC1 | AC2 | AC4 | AC8

  datatype cmpOp =
    Cmpeq | Cmpneq |
    Cmpul | Cmpug | Cmpule | Cmpuge |
    Cmpsl | Cmpsg | Cmpsle | Cmpsge

  datatype irIns =
      IrSet of vreg * setArg
    | IrAdd of vreg * vreg * vreg
    | IrSub of vreg * vreg * vreg
    | IrMul of vreg * vreg * vreg
    | IrIMul of vreg * vreg * vreg
    | IrDiv of vreg * vreg * vreg
    | IrIDiv of vreg * vreg * vreg
    | IrMod of vreg * vreg * vreg
    | IrIMod of vreg * vreg * vreg
    | IrShr of vreg * vreg * vreg
    | IrShl of vreg * vreg * vreg
    | IrSar of vreg * vreg * vreg
    | IrAnd of vreg * vreg * vreg
    | IrOr of vreg * vreg * vreg
    | IrXor of vreg * vreg * vreg

    | IrCmp of cmpOp * vreg * vreg * vreg

    | IrExtZero of vreg * vreg * accessClass
    | IrExtSign of vreg * vreg * accessClass
    | IrLoad of vreg * vreg * accessClass (* %1 <- [%2] *)
    | IrStore of vreg * vreg * accessClass (* [%1] <- %2 *)

    | IrJmpc of cmpOp * vreg * vreg * label
    | IrJz of vreg * label
    | IrJnz of vreg * label
    | IrJmp of label

    | IrRet of vreg option
    | IrAlloc of vreg * word * int option
    | IrCopy of vreg * label * word
    | IrFcall of vreg * vreg * vreg list

    | IrNopLabel of label
    | IrNop of string

  datatype ev = Reg of vreg | Addr of vreg

  datatype regType =
    RtReg |
    RtRem |
    RtConst of word |
    RtAddrConst of int * word

  type regInfo = {
    class: vregClass,
    use: int list,
    defs: int list,
    t: regType,
    canFold: bool
  }

  val Pwc: (vregClass, word, 'a, 'b, 'c) a2printer
  val Pac: (accessClass, 'a, 'b, 'c) a1printer
  val Pl: (label, 'a, 'b, 'c) a1printer

  val wrapTo8: word -> word

  datatype funcType = FtLeaf | FtNonLeaf

  datatype funcInfo = Fi of {
    name: int,
    paramNum: int,
    localBound: int,
    t: funcType,
    vregs: regInfo D.t,
    ops: (irIns option * (label * label) option) D.t,
    labels: int option D.t
  }

  datatype ctx = Ctx of {
    objs: P.objDef list,
    objsZI: P.objDef list,
    extSyms: P.nid list,
    globSyms: P.nid list,
    funcInfos: funcInfo list,
    strlits: int list
  }

  val createCtx: P.progInfo -> string option -> ctx
end