Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/asmjit.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern assembler_div_reg: (ptr<?>, ptr<?>) -> int
extern assembler_mod_reg: (ptr<?>, ptr<?>) -> int
extern assembler_cqo_reg: (ptr<?>) -> int
extern assembler_cdq_reg: (ptr<?>) -> int
extern assembler_nop: (ptr<?>) -> int
extern assembler_and_reg: (ptr<?>, ptr<?>, ptr<?>) -> int
extern assembler_and_int: (ptr<?>, ptr<?>, int) -> int
extern assembler_or_reg: (ptr<?>, ptr<?>, ptr<?>) -> int
Expand Down Expand Up @@ -186,7 +187,7 @@ public lostanza deftype MemPtr :
;------------------------------------------------------------
defmethod equal? (a:Gp, b:Gp) -> True|False :
id(a) == id(b)

defmethod equal? (a:Xmm, b:Xmm) -> True|False :
id(a) == id(b)

Expand Down Expand Up @@ -697,6 +698,9 @@ public lostanza defn btr (a:ref<Assembler>, dst:ref<Gp>, src:ref<Gp>) -> ref<Gp>
public lostanza defn btr (a:ref<Assembler>, ptr:ref<MemPtr>, src:ref<Gp>) -> ref<Gp> :
call-c assembler_btr_ptr_reg(a.value, ptr.value, src.value)
return src
public lostanza defn nop (a:ref<Assembler>) -> ref<False> :
call-c assembler_nop(a.value)
return false

;------------------------------------------------------------
;-------------------- Comparisons and Jumps -----------------
Expand Down Expand Up @@ -912,4 +916,3 @@ public lostanza defn ucomiss (a:ref<Assembler>, x:ref<Xmm>, y:ref<Xmm>) -> ref<F
public lostanza defn ucomisd (a:ref<Assembler>, x:ref<Xmm>, y:ref<Xmm>) -> ref<False> :
call-c assembler_ucomisd(a.value, x.value, y.value)
return false

23 changes: 19 additions & 4 deletions compiler/code-table.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defpackage stz/code-table :
;============================================================
;This contains all the generated code for the functions
;loaded into the virtual machine, as well as any additional
;tables for performing the code encoding.
;tables for performing the code encoding.

public deftype CodeTable

Expand All @@ -37,6 +37,9 @@ public defmulti load-function (t:CodeTable,
public defstruct LoadedFunction :
address:Long
trace-entries:Vector<TraceTableEntry>
safepoint-entries:Vector<SafepointTableEntry>
local-var-context:Vector<NamedLocalVar>
local-var-map-entries:Vector<LocalVarMapEntry>

;Represents the entry for use during backtraces.
public defstruct TraceTableEntry :
Expand All @@ -45,6 +48,18 @@ public defstruct TraceTableEntry :
with:
printer => true

public defstruct SafepointTableEntry :
pc: Long
id: Int
with:
printer => true

public defstruct LocalVarMapEntry :
pc: Long
indices: Tuple<Int> ;Sorted in increasing order, in local-var-context
with:
printer => true

;============================================================
;================== Launch ==================================
;============================================================
Expand Down Expand Up @@ -80,7 +95,7 @@ public deftype EncodingResolver
;- live: The set of locals that are live at the moment.
public defmulti liveness-map (r:EncodingResolver, live:Seqable<Int>, num-locals:Int) -> Int

;Return the number of bytes used for the tag word of each object.
;Return the number of bytes used for the tag word of each object.
public defmulti object-header-size (r:EncodingResolver) -> Int

;Return the number of bytes used to store an object on the heap.
Expand Down Expand Up @@ -120,10 +135,10 @@ public defmulti marker? (r:EncodingResolver, n:Int) -> True|False
public defmulti tagbits (r:EncodingResolver, typeid:Int) -> Int

;Return the address of the given extern address.
public defmulti extern-address (r:EncodingResolver, id:Int) -> Long
public defmulti extern-address (r:EncodingResolver, id:Int) -> Long

;Return the address of the given extern defn address.
public defmulti extern-defn-address (r:EncodingResolver, id:Int) -> Long
public defmulti extern-defn-address (r:EncodingResolver, id:Int) -> Long

;------------------------------------------------------------
;----------------------- Convenience ------------------------
Expand Down
11 changes: 10 additions & 1 deletion compiler/cvm-code-table.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ lostanza defmethod load-function (table:ref<CVMCodeTable>,

;Add the offset to the trace entries so that we know their absolute position.
val relocated-trace-entries = add-offset(trace-entries(encoded-function), new Long{offset})
val relocated-safepoint-entries = add-offset(safepoint-entries(encoded-function), new Long{offset})
val relocated-local-var-map-entries = add-offset(local-var-map-entries(encoded-function), new Long{offset})

;Return the new loaded function
return LoadedFunction(new Long{offset}, relocated-trace-entries)
return LoadedFunction(new Long{offset}, relocated-trace-entries, relocated-safepoint-entries,
local-var-context(encoded-function), relocated-local-var-map-entries)

;Add 'offset' to the 'pc' of every entry in 'trace-entries' and return
;the result.
defn add-offset (trace-entries:Seqable<TraceTableEntry>, offset:Long) -> Vector<TraceTableEntry> :
to-vector<TraceTableEntry> $ for e in trace-entries seq :
TraceTableEntry(pc(e) + offset, entry(e))
defn add-offset (safepoint-entries:Seqable<SafepointTableEntry>, offset:Long) -> Vector<SafepointTableEntry> :
to-vector<SafepointTableEntry> $ for e in safepoint-entries seq :
SafepointTableEntry(pc(e) + offset, id(e))
defn add-offset (local-var-map-entries:Seqable<LocalVarMapEntry>, offset:Long) -> Vector<LocalVarMapEntry> :
to-vector<LocalVarMapEntry> $ for e in local-var-map-entries seq :
LocalVarMapEntry(pc(e) + offset, indices(e))

;============================================================
;================== Launch ==================================
Expand Down
10 changes: 8 additions & 2 deletions compiler/cvm-encoder.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ defpackage stz/cvm-encoder :
public defstruct EncodedFunction :
buffer: ByteBuffer
trace-entries: Vector<TraceTableEntry>
safepoint-entries: Vector<SafepointTableEntry>
local-var-context:Vector<NamedLocalVar>
local-var-map-entries:Vector<LocalVarMapEntry>

public defn encode (func:VMFunction,
resolver:EncodingResolver,
backend:Backend) -> EncodedFunction :
;Encode instructions into this byte buffer
val buffer = ByteBuffer()

;All instructions are sized to be multiples of 4 bytes, and thus
;we use address / 4 as a "position" in the instruction stream.
defn buffer-pos () : write-position(buffer) / 4

;Accumulate file information entries for implementing
;stack traces.
val trace-entry-table = Vector<TraceTableEntry>()
val safepoint-entry-table = Vector<SafepointTableEntry>()
defn record-trace-entry (entry:StackTraceInfo|False) :
match(entry:StackTraceInfo) :
add(trace-entry-table, TraceTableEntry(to-long(write-position(buffer)), entry))
val local-var-context = Vector<NamedLocalVar>()
val local-var-maps = Vector<LocalVarMapEntry>()

;Delay the generation of this instruction,
;Instruction takes up the given number of 'instruction-words'.
Expand Down Expand Up @@ -698,7 +704,7 @@ public defn encode (func:VMFunction,
;Use delayed actions and encode instructions
within delay-actions() :
encode(func as VMMultifn|VMFunc)
EncodedFunction(buffer, trace-entry-table)
EncodedFunction(buffer, trace-entry-table, safepoint-entry-table, local-var-context, local-var-maps)

;============================================================
;====================== Utilities ===========================
Expand Down
7 changes: 7 additions & 0 deletions compiler/dl-ir.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,13 @@ public val CORE-FULL-LIST-ID = register $ core-typeid(`FullList)
public val CORE-NIL-LIST-ID = register $ core-typeid(`NilList)
public val CORE-STRING-ID = register $ core-typeid(`String)
public val CORE-SYMBOL-ID = register $ core-typeid(`Symbol)
public val CORE-STRING-SYMBOL-ID = register $ core-typeid(`StringSymbol)
public val CORE-BYTE-ARRAY-ID = register $ core-typeid(`ByteArray)
public val CORE-CHAR-ARRAY-ID = register $ core-typeid(`CharArray)
public val CORE-INT-ARRAY-ID = register $ core-typeid(`IntArray)
public val CORE-LONG-ARRAY-ID = register $ core-typeid(`LongArray)
public val CORE-FLOAT-ARRAY-ID = register $ core-typeid(`FloatArray)
public val CORE-DOUBLE-ARRAY-ID = register $ core-typeid(`DoubleArray)
public val CORE-UNIQUE-ID = register $ core-typeid(`Unique)
public val CORE-MAYBE-ID = register $ core-typeid(`Maybe)
public val CORE-ONE-ID = register $ core-typeid(`One)
Expand Down
11 changes: 6 additions & 5 deletions compiler/jit-code-table.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public defstruct JITStubs :

public defn JITCodeTable (resolver:EncodingResolver, backend:Backend) -> JITCodeTable :
val runtime = jit-runtime-new()
val stubs = make-jit-stubs(runtime, resolver, backend)
val stubs = make-jit-stubs(runtime, resolver, backend)
#JITCodeTable(runtime, stubs)

;============================================================
Expand All @@ -52,12 +52,13 @@ defmethod load-function (table:JITCodeTable,
val oldf = get?(funcs(table), fid)
match(oldf:Func) :
release(runtime(table), oldf)

;Add the function into the table so that we can release them later.
put<Func>(funcs(table), fid, func(encoded-function))

;Return the loaded function
LoadedFunction(value(func(encoded-function)), trace-entries(encoded-function))
LoadedFunction(value(func(encoded-function)), trace-entries(encoded-function), safepoint-entries(encoded-function),
local-var-context(encoded-function), local-var-maps(encoded-function))

;============================================================
;================== Launch ==================================
Expand All @@ -68,7 +69,7 @@ lostanza defmethod launch (vmstate-address:ref<Long>, table:ref<JITCodeTable>, f
val fptr = launch as ptr<( (ptr<VMState>, long, long) -> int )>
val vmstate = vmstate-address.value as ptr<VMState>
call-c [fptr](vmstate, call-prim crsp() as long, func-id.value)
return false
return false

;============================================================
;===================== Free =================================
Expand Down Expand Up @@ -96,6 +97,6 @@ defn put<T> (xs:Vector<T|False>, k:Int, v:T) :
if k >= length(xs) :
lengthen(xs, k + 1, false)
xs[k] = v

defn get?<?T> (xs:Vector<?T>, k:Int) -> T|False :
if k < length(xs) : xs[k]
Loading