Skip to content

Commit

Permalink
Fix bug in space calculation for global table.
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed May 8, 2024
2 parents 34a4c63 + 13eaf38 commit 72e7420
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ci/build-stanza-version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# like 1.23.45
#
# Use version 0.17.56 to compile 0.18.0
0.18.62
0.18.69
2 changes: 1 addition & 1 deletion compiler/params.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public defn compiler-flags () :
to-tuple(COMPILE-FLAGS)

;========= Stanza Configuration ========
public val STANZA-VERSION = [0 18 69]
public val STANZA-VERSION = [0 18 70]
public var STANZA-INSTALL-DIR:String = ""
public var OUTPUT-PLATFORM:Symbol = `platform
public var STANZA-PKG-DIRS:List<String> = List()
Expand Down
41 changes: 27 additions & 14 deletions compiler/stitcher-global-table.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public defn GlobalTable (stubs:AsmStubs) -> GlobalTable :

;Emit all the globals
defn emit-table (emitter:CodeEmitter) -> False :
defn E (x:Ins) : emit(emitter,x)

;Holds the current size of the entire emitted table.
val counter = Counter(0)

Expand All @@ -76,8 +74,19 @@ public defn GlobalTable (stubs:AsmStubs) -> GlobalTable :
;Accumulate all roots here.
val all-roots = Vector<Int>()

;Emit DefSpace if sz > 0.
defn EDefSpace? (sz:Int) :
;Emit an instruction.
defn E (x:Ins) : emit(emitter,x)

;Emit an instruction and increment counter by
;the given size.
defn E (x:Ins -- size:Int) :
E(x)
next(counter, size)

;Emit space to advance the table to the given
;offset.
defn advance-to-offset (offset:Int) :
val sz = advance-to(counter,offset)
E(DefSpace(sz)) when sz > 0

;Emit the global table itself.
Expand All @@ -89,28 +98,32 @@ public defn GlobalTable (stubs:AsmStubs) -> GlobalTable :
(item:GlobalInfo) :
info = item
(item:Padding) :
E(DefSpace(size(item)))
next(counter, size(item))
E(DefSpace(size(item)), size = size(item))
(item:VMGlobal) :
E(Comment(description(info, id(item), value(counter))))
if empty?(roots(item)) :
E(DefSpace(size(item)))
next(counter, size(item))
E(DefSpace(size(item)), size = size(item))
else :
;Retrieve the offset for the global.
val offset = value(counter)

;Sanity check: Ensure that global is 8-byte aligned.
if offset % 8 != 0 :
fatal("Global has roots but is not 8-byte aligned.")


;Emit a void marker for each root in the global.
for root in roots(item) do :
val root-offset = offset + 8 * root
;Advance to the offset for the given root,
;and emit the void marker.
val root-offset = offset + 8 * root
advance-to-offset(root-offset)
E(void-marker, size = 8)

;Register the index of the root into the all-roots vector.
add(all-roots, root-offset / 8)
EDefSpace?(advance-to(counter, root-offset))
E(void-marker)
val end = offset + size(item)
EDefSpace?(advance-to(counter, end))

;Advance to the end of the constant.
advance-to-offset(offset + size(item))
E(DefText())
E(Comment("End of Global Table"))

Expand Down

0 comments on commit 72e7420

Please sign in to comment.