Skip to content

Commit

Permalink
make all sizeof calls in codegen use types
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Nov 18, 2024
1 parent f053767 commit df33749
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
if (dest.storage == OnStack and p.config.selectedGC != gcGo) or not usesWriteBarrier(p.config):
let rad = addrLoc(p.config, dest)
let ras = addrLoc(p.config, src)
let rd = rdLoc(dest)
let td = getTypeDesc(p.module, dest.t)
p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"),
cCast("void*", rad),
cCast(ptrConstType("void"), ras),
cSizeof(rd))
cSizeof(td))
else:
let rad = addrLoc(p.config, dest)
let ras = addrLoc(p.config, src)
Expand Down Expand Up @@ -2553,7 +2553,7 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) =
p.s(cpsLocals).addField(name = "source", typ = srcTyp)
p.s(cpsLocals).addCallStmt(cgsymValue(p.module, "nimZeroMem"),
cAddr("LOC" & lbl),
cSizeof("LOC" & lbl))
cIntValue(destsize))
else:
p.s(cpsLocals).addVarWithType(kind = Local, name = "LOC" & lbl):
p.s(cpsLocals).addUnionType():
Expand Down
11 changes: 6 additions & 5 deletions compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ proc genVarTuple(p: BProc, n: PNode) =
typ = "NIM_BOOL",
initializer = "NIM_FALSE")
for curr in hcrGlobals:
let rc = rdLoc(curr.loc)
let tc = getTypeDesc(p.module, curr.loc.t)
p.s(cpsLocals).addInPlaceOp(BitOr, "NIM_BOOL",
hcrCond,
cCall("hcrRegisterGlobal",
getModuleDllPath(p.module, n[0].sym),
'"' & curr.loc.snippet & '"',
cSizeof(rc),
cSizeof(tc),
curr.tp,
cCast("void**", cAddr(curr.loc.snippet))))

Expand Down Expand Up @@ -434,11 +434,11 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) =
if forHcr and targetProc.blocks.len > 3 and v.owner.kind == skModule:
# put it in the locals section - mainly because of loops which
# use the var in a call to resetLoc() in the statements section
let rv = rdLoc(v.loc)
let tv = getTypeDesc(p.module, v.loc.t)
p.s(cpsLocals).addCallStmt("hcrRegisterGlobal",
getModuleDllPath(p.module, v),
'"' & v.loc.snippet & '"',
cSizeof(rv),
cSizeof(tv),
traverseProc,
cCast("void**", cAddr(v.loc.snippet)))
# nothing special left to do later on - let's avoid closing and reopening blocks
Expand All @@ -449,12 +449,13 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) =
# be able to re-run it but without the top level code - just the init of globals
var hcrInit = default(IfBuilder)
if forHcr:
let tv = getTypeDesc(p.module, v.loc.t)
startBlockWith(targetProc):
hcrInit = initIfStmt(p.s(cpsStmts))
initElifBranch(p.s(cpsStmts), hcrInit, cCall("hcrRegisterGlobal",
getModuleDllPath(p.module, v),
'"' & v.loc.snippet & '"',
cSizeof(rdLoc(v.loc)),
cSizeof(tv),
traverseProc,
cCast("void**", cAddr(v.loc.snippet))))
if value.kind != nkEmpty and valueAsRope.len == 0:
Expand Down

0 comments on commit df33749

Please sign in to comment.