File: CODECONSSIG.sml

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (261 lines) | stat: -rw-r--r-- 9,561 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
(*
    Copyright (c) David C.J. Matthews 2009, 2012
    
    Derived from original code:

    Copyright (c) 2000
        Cambridge University Technical Services Limited

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*)

signature CODECONSSIG =
sig
    type machineWord = Address.machineWord
    type short = Address.short
    type address = Address.address
    type code
    eqtype reg   (* Machine registers *)
    
    datatype argType = ArgGeneral | ArgFP

    val sameCode: code * code -> bool

    val regNone:     reg option
    val regClosure:  reg
    val regStackPtr: reg

    (* For vector indexing we provide a numbering for the registers. *)
    val regs:   int
    val regN:   int -> reg
    val nReg:   reg -> int

    val regRepr: reg -> string

    val argRegs: argType list -> reg option list
    val resultReg: argType -> reg

    structure RegSet:
    sig
        eqtype regSet
        val singleton: reg -> regSet
        val allRegisters: regSet (* All registers: data, address, floating pt. *)
        val generalRegisters: regSet (* Registers checked by the GC. *)
        val floatingPtRegisters: regSet
        val noRegisters: regSet
        val isAllRegs: regSet->bool
        val regSetUnion: regSet * regSet -> regSet
        val regSetIntersect: regSet * regSet -> regSet
        val listToSet: reg list -> regSet
        val setToList: regSet -> reg list
        val regSetMinus: regSet * regSet -> regSet
        val inSet: reg * regSet -> bool
        val cardinality: regSet -> int
        val regSetRepr: regSet -> string
        val oneOf: regSet -> reg
    end
    val getRegisterSet: Word.word -> RegSet.regSet

    type addrs
    val addrZero: addrs

    (* Operations. *)
    type 'a instrs
    val instrVeclen: 'a instrs
    val instrVecflags: 'a instrs
    val instrGetFirstLong: 'a instrs
    val instrStringLength: 'a instrs

    val instrAddA: 'a instrs
    and instrSubA: 'a instrs
    and instrMulA: 'a instrs
    and instrAddW: 'a instrs
    and instrSubW: 'a instrs
    and instrMulW: 'a instrs
    and instrDivW: 'a instrs
    and instrModW: 'a instrs
    and instrOrW: 'a instrs
    and instrAndW: 'a instrs
    and instrXorW: 'a instrs
    and instrLoad: 'a instrs
    and instrLoadB: 'a instrs
    and instrUpshiftW: 'a instrs    (* logical shift left *)
    and instrDownshiftW: 'a instrs  (* logical shift right *)
    and instrDownshiftArithW: 'a instrs  (* arithmetic shift right *)
    and instrSetStringLength: 'a instrs
    and instrThreadSelf: 'a instrs
    and instrAtomicIncr: 'a instrs
    and instrAtomicDecr: 'a instrs
    and instrStoreW: 'a instrs
    and instrStoreB: 'a instrs
    and instrLockSeg: 'a instrs
    and instrAddFP: 'a instrs
    and instrSubFP: 'a instrs
    and instrMulFP: 'a instrs
    and instrDivFP: 'a instrs
    and instrAbsFP: 'a instrs
    and instrNegFP: 'a instrs
    and instrIntToRealFP: 'a instrs
    and instrRealToIntFP: 'a instrs
    and instrSqrtFP: 'a instrs
    and instrSinFP: 'a instrs
    and instrCosFP: 'a instrs
    and instrAtanFP: 'a instrs
    and instrExpFP: 'a instrs
    and instrLnFP: 'a instrs
    and instrAllocStore: 'a instrs
    and instrMoveBytes: 'a instrs
    and instrMoveWords: 'a instrs

    (* Check whether an operation is implemented and, if appropriate, remove
       constant values into the instruction part. *)
    type negotiation
    val checkAndReduce: 'a instrs * 'a list * ('a -> machineWord option) -> (negotiation * 'a list) option

    val isPushI: machineWord -> bool

    type 'a tests
    val testNeqW:  'a tests
    val testEqW:   'a tests
    val testGeqW:  'a tests
    val testGtW:   'a tests
    val testLeqW:  'a tests
    val testLtW:   'a tests
    val testNeqA:  'a tests
    val testEqA:   'a tests
    val testGeqA:  'a tests
    val testGtA:   'a tests
    val testLeqA:  'a tests
    val testLtA:   'a tests
    val Short:     'a tests
    val Long:      'a tests
    val testNeqFP: 'a tests
    val testEqFP:  'a tests
    val testGeqFP: 'a tests
    val testGtFP:  'a tests
    val testLeqFP: 'a tests
    val testLtFP:  'a tests
    val byteVecEq: 'a tests
    and byteVecNe: 'a tests

    type forwardLabel
    and  backwardLabel

    (* Compare and branch for fixed and arbitrary precision. *)
    type negotiateTests
    val checkAndReduceBranches: 'a tests * 'a list * ('a -> machineWord option) -> (negotiateTests * 'a list) option

    datatype callKinds =
        Recursive
    |   ConstantClosure of machineWord
    |   ConstantCode of machineWord
    |   CodeFun of code
    |   FullCall

    val procName:   code -> string      (* Name of the procedure. *)

    type operation
    type operations = operation list

    val moveRegisterToRegister: reg(*source*) * reg(*dest*) -> operations
    and moveMemoryToRegister: reg (*base*) * int (*offset*) * reg (*dest*) -> operations
    and moveConstantToRegister: machineWord * reg -> operations
    and moveCodeRefToRegister: code * reg -> operations (* The address of another function *)
    and moveStackAddress: int * reg -> operations (* Offset within the stack. *)

    val pushRegisterToStack: reg -> operations
    and pushConstantToStack: machineWord -> operations
    and pushMemoryToStack: reg * int -> operations
    
    val storeRegisterToStack: reg * int -> operations
    and storeConstantToStack: machineWord * int -> operations

    val allocStore: { size: int, flags: Word8.word, output: reg } -> operations
    val allocationComplete: operations
    val callFunction: callKinds -> operations
    val jumpToFunction: callKinds  -> operations
    val returnFromFunction: int -> operations
    val raiseException: operations
    val uncondBranch: unit -> operations * forwardLabel
    val resetStack: int -> operations
    val backJumpLabel: unit -> operations * backwardLabel
    val jumpBack: backwardLabel -> operations
    val interruptCheck: operations
    val forwardJumpLabel: forwardLabel -> operations
    val loadHandlerAddress: { handlerLab: addrs ref, output: reg } -> operations
    val startHandler: { handlerLab: addrs ref } -> operations
    val indexedCase:
            { testReg: reg, workReg: reg, minCase: word, maxCase: word,
              isArbitrary: bool, isExhaustive: bool } -> operations * forwardLabel list * forwardLabel
    val activeRegister: reg -> operations
    val freeRegister: reg -> operations
    val pushToReserveSpace: operations
    val loadCurrentHandler: reg -> operations
    val storeToHandler: reg -> operations
    val pushCurrentHandler: operations

    val printOperation: operation * (string -> unit) -> unit

    datatype regHint = UseReg of RegSet.regSet | NoHint | NoResult

    (* These are almost the same as source values except that a value
       may be in more than one register. *)
    datatype actionSource =
        ActLiteralSource of machineWord
    |   ActInRegisterSet of { modifiable: RegSet.regSet, readable: RegSet.regSet}
    |   ActBaseOffset of reg * int
    |   ActCodeRefSource of code (* The address of another function *)
    |   ActStackAddress of int (* Offset within the stack. *)

    datatype argAction =
        ActionDone of (* The output register if any and the final operation. *)
            { outReg: reg option, operation: operations }
    |   ActionLockRegister of (* Lock the register of an argument. *)
            { argNo: int, reg: reg, willOverwrite: bool, next: nextAction }
    |   ActionLoadArg of (* Load an argument into a register. *)
            { argNo: int, regSet: RegSet.regSet, willOverwrite: bool, next: nextAction }
    |   ActionGetWorkReg of (* Get a work/result register. *)
            { regSet: RegSet.regSet, setReg: reg -> nextAction }

    withtype nextAction = actionSource list -> argAction

    (* Negotiate arguments *)
    val negotiateArguments: negotiation * regHint -> nextAction
    val negotiateTestArguments: negotiateTests -> nextAction * forwardLabel

    val codeCreate: bool * string * machineWord * Universal.universal list -> code  (* makes the initial segment. *)
    (* Code generate operations and construct the final code. *)
    val copyCode: code * operations * int * RegSet.regSet * bool -> address

    val codeAddress: code -> address option
    val addCompletionHook: code * (code * machineWord -> unit) -> unit

    structure Sharing:
    sig
        type code           = code
        and  'a instrs      = 'a instrs
        and  negotiation    = negotiation
        and  negotiateTests = negotiateTests
        and  reg            = reg
        and  'a tests       = 'a tests
        and  addrs          = addrs
        and  operation      = operation
        and  regHint        = regHint
        and  argAction      = argAction
        and  regSet         = RegSet.regSet
        and  backwardLabel  = backwardLabel
        and  forwardLabel  = forwardLabel
    end
end;