proper indentation in the generated C code
This commit is contained in:
parent
e2d38a57ec
commit
df1ec09399
6 changed files with 235 additions and 212 deletions
|
|
@ -33,16 +33,14 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, pl: PRope) =
|
||||||
# reset before pass as 'result' var:
|
# reset before pass as 'result' var:
|
||||||
resetLoc(p, d)
|
resetLoc(p, d)
|
||||||
app(pl, addrLoc(d))
|
app(pl, addrLoc(d))
|
||||||
app(pl, ")")
|
appf(pl, ");$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
else:
|
else:
|
||||||
var tmp: TLoc
|
var tmp: TLoc
|
||||||
getTemp(p, typ.sons[0], tmp)
|
getTemp(p, typ.sons[0], tmp)
|
||||||
app(pl, addrLoc(tmp))
|
app(pl, addrLoc(tmp))
|
||||||
app(pl, ")")
|
appf(pl, ");$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
genAssignment(p, d, tmp, {}) # no need for deep copying
|
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
app(pl, ")")
|
app(pl, ")")
|
||||||
|
|
@ -53,9 +51,8 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, pl: PRope) =
|
||||||
list.r = pl
|
list.r = pl
|
||||||
genAssignment(p, d, list, {}) # no need for deep copying
|
genAssignment(p, d, list, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
app(pl, ")")
|
appf(pl, ");$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
|
|
||||||
proc isInCurrentFrame(p: BProc, n: PNode): bool =
|
proc isInCurrentFrame(p: BProc, n: PNode): bool =
|
||||||
# checks if `n` is an expression that refers to the current frame;
|
# checks if `n` is an expression that refers to the current frame;
|
||||||
|
|
@ -148,7 +145,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
proc addComma(r: PRope): PRope =
|
proc addComma(r: PRope): PRope =
|
||||||
result = if r == nil: r else: con(r, ", ")
|
result = if r == nil: r else: con(r, ", ")
|
||||||
|
|
||||||
const CallPattern = "$1.ClEnv? $1.ClPrc($3$1.ClEnv) : (($4)($1.ClPrc))($2)"
|
const CallPattern = "$1.ClEnv? $1.ClPrc($3$1.ClEnv) : (($4)($1.ClPrc))($2);$n"
|
||||||
var op: TLoc
|
var op: TLoc
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var pl: PRope
|
var pl: PRope
|
||||||
|
|
@ -166,7 +163,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
if i < length - 1: app(pl, ", ")
|
if i < length - 1: app(pl, ", ")
|
||||||
|
|
||||||
template genCallPattern =
|
template genCallPattern =
|
||||||
appf(p.s(cpsStmts), CallPattern, op.r, pl, pl.addComma, rawProc)
|
lineF(p, cpsStmts, CallPattern, op.r, pl, pl.addComma, rawProc)
|
||||||
|
|
||||||
let rawProc = getRawProcType(p, typ)
|
let rawProc = getRawProcType(p, typ)
|
||||||
if typ.sons[0] != nil:
|
if typ.sons[0] != nil:
|
||||||
|
|
@ -181,13 +178,11 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
resetLoc(p, d)
|
resetLoc(p, d)
|
||||||
app(pl, addrLoc(d))
|
app(pl, addrLoc(d))
|
||||||
genCallPattern()
|
genCallPattern()
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
else:
|
else:
|
||||||
var tmp: TLoc
|
var tmp: TLoc
|
||||||
getTemp(p, typ.sons[0], tmp)
|
getTemp(p, typ.sons[0], tmp)
|
||||||
app(pl, addrLoc(tmp))
|
app(pl, addrLoc(tmp))
|
||||||
genCallPattern()
|
genCallPattern()
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
genAssignment(p, d, tmp, {}) # no need for deep copying
|
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
if d.k == locNone: getTemp(p, typ.sons[0], d)
|
if d.k == locNone: getTemp(p, typ.sons[0], d)
|
||||||
|
|
@ -198,7 +193,6 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
genAssignment(p, d, list, {}) # no need for deep copying
|
genAssignment(p, d, list, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
genCallPattern()
|
genCallPattern()
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
|
|
||||||
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
var op, a: TLoc
|
var op, a: TLoc
|
||||||
|
|
@ -264,16 +258,14 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
if d.k == locNone: getTemp(p, typ.sons[0], d)
|
if d.k == locNone: getTemp(p, typ.sons[0], d)
|
||||||
app(pl, "Result: ")
|
app(pl, "Result: ")
|
||||||
app(pl, addrLoc(d))
|
app(pl, addrLoc(d))
|
||||||
app(pl, "]")
|
appf(pl, "];$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
else:
|
else:
|
||||||
var tmp: TLoc
|
var tmp: TLoc
|
||||||
getTemp(p, typ.sons[0], tmp)
|
getTemp(p, typ.sons[0], tmp)
|
||||||
app(pl, addrLoc(tmp))
|
app(pl, addrLoc(tmp))
|
||||||
app(pl, "]")
|
appf(pl, "];$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
genAssignment(p, d, tmp, {}) # no need for deep copying
|
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
app(pl, "]")
|
app(pl, "]")
|
||||||
|
|
@ -284,9 +276,8 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
list.r = pl
|
list.r = pl
|
||||||
genAssignment(p, d, list, {}) # no need for deep copying
|
genAssignment(p, d, list, {}) # no need for deep copying
|
||||||
else:
|
else:
|
||||||
app(pl, "]")
|
appf(pl, "];$n")
|
||||||
app(p.s(cpsStmts), pl)
|
line(p, cpsStmts, pl)
|
||||||
appf(p.s(cpsStmts), ";$n")
|
|
||||||
|
|
||||||
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if e.sons[0].typ.callConv == ccClosure:
|
if e.sons[0].typ.callConv == ccClosure:
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ proc getStorageLoc(n: PNode): TStorageLoc =
|
||||||
|
|
||||||
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
||||||
appf(p.s(cpsStmts), "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
lineF(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
if needToKeepAlive in flags: keepAlive(p, dest)
|
||||||
elif dest.s == OnHeap:
|
elif dest.s == OnHeap:
|
||||||
# location is on heap
|
# location is on heap
|
||||||
|
|
@ -168,25 +168,25 @@ proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
#
|
#
|
||||||
# if afSrcIsNotNil in flags:
|
# if afSrcIsNotNil in flags:
|
||||||
# UseMagic(p.module, 'nimGCref')
|
# UseMagic(p.module, 'nimGCref')
|
||||||
# appf(p.s[cpsStmts], 'nimGCref($1);$n', [rdLoc(src)])
|
# lineF(p, cpsStmts, 'nimGCref($1);$n', [rdLoc(src)])
|
||||||
# elif afSrcIsNil notin flags:
|
# elif afSrcIsNil notin flags:
|
||||||
# UseMagic(p.module, 'nimGCref')
|
# UseMagic(p.module, 'nimGCref')
|
||||||
# appf(p.s[cpsStmts], 'if ($1) nimGCref($1);$n', [rdLoc(src)])
|
# lineF(p, cpsStmts, 'if ($1) nimGCref($1);$n', [rdLoc(src)])
|
||||||
# if afDestIsNotNil in flags:
|
# if afDestIsNotNil in flags:
|
||||||
# UseMagic(p.module, 'nimGCunref')
|
# UseMagic(p.module, 'nimGCunref')
|
||||||
# appf(p.s[cpsStmts], 'nimGCunref($1);$n', [rdLoc(dest)])
|
# lineF(p, cpsStmts, 'nimGCunref($1);$n', [rdLoc(dest)])
|
||||||
# elif afDestIsNil notin flags:
|
# elif afDestIsNil notin flags:
|
||||||
# UseMagic(p.module, 'nimGCunref')
|
# UseMagic(p.module, 'nimGCunref')
|
||||||
# appf(p.s[cpsStmts], 'if ($1) nimGCunref($1);$n', [rdLoc(dest)])
|
# lineF(p, cpsStmts, 'if ($1) nimGCunref($1);$n', [rdLoc(dest)])
|
||||||
# appf(p.s[cpsStmts], '$1 = $2;$n', [rdLoc(dest), rdLoc(src)])
|
# lineF(p, cpsStmts, '$1 = $2;$n', [rdLoc(dest), rdLoc(src)])
|
||||||
if canFormAcycle(dest.t):
|
if canFormAcycle(dest.t):
|
||||||
appcg(p.module, p.s(cpsStmts), "#asgnRef((void**) $1, $2);$n",
|
lineCg(p, cpsStmts, "#asgnRef((void**) $1, $2);$n",
|
||||||
[addrLoc(dest), rdLoc(src)])
|
[addrLoc(dest), rdLoc(src)])
|
||||||
else:
|
else:
|
||||||
appcg(p.module, p.s(cpsStmts), "#asgnRefNoCycle((void**) $1, $2);$n",
|
lineCg(p, cpsStmts, "#asgnRefNoCycle((void**) $1, $2);$n",
|
||||||
[addrLoc(dest), rdLoc(src)])
|
[addrLoc(dest), rdLoc(src)])
|
||||||
else:
|
else:
|
||||||
appcg(p.module, p.s(cpsStmts), "#unsureAsgnRef((void**) $1, $2);$n",
|
lineCg(p, cpsStmts, "#unsureAsgnRef((void**) $1, $2);$n",
|
||||||
[addrLoc(dest), rdLoc(src)])
|
[addrLoc(dest), rdLoc(src)])
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
if needToKeepAlive in flags: keepAlive(p, dest)
|
||||||
|
|
||||||
|
|
@ -200,15 +200,15 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if needToCopy notin flags or
|
if needToCopy notin flags or
|
||||||
tfShallow in skipTypes(dest.t, abstractVarRange).flags:
|
tfShallow in skipTypes(dest.t, abstractVarRange).flags:
|
||||||
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||||
[addrLoc(dest), addrLoc(src), rdLoc(dest)])
|
[addrLoc(dest), addrLoc(src), rdLoc(dest)])
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
if needToKeepAlive in flags: keepAlive(p, dest)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#genericShallowAssign((void*)$1, (void*)$2, $3);$n",
|
lineCg(p, cpsStmts, "#genericShallowAssign((void*)$1, (void*)$2, $3);$n",
|
||||||
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#genericAssign((void*)$1, (void*)$2, $3);$n",
|
lineCg(p, cpsStmts, "#genericAssign((void*)$1, (void*)$2, $3);$n",
|
||||||
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
||||||
|
|
||||||
proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
|
|
@ -216,7 +216,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
# the assignment operation in C.
|
# the assignment operation in C.
|
||||||
if src.t != nil and src.t.kind == tyPtr:
|
if src.t != nil and src.t.kind == tyPtr:
|
||||||
# little HACK to support the new 'var T' as return type:
|
# little HACK to support the new 'var T' as return type:
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||||
return
|
return
|
||||||
var ty = skipTypes(dest.t, abstractVarRange)
|
var ty = skipTypes(dest.t, abstractVarRange)
|
||||||
case ty.kind
|
case ty.kind
|
||||||
|
|
@ -226,24 +226,24 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if needToCopy notin flags:
|
if needToCopy notin flags:
|
||||||
genRefAssign(p, dest, src, flags)
|
genRefAssign(p, dest, src, flags)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#genericSeqAssign($1, $2, $3);$n",
|
lineCg(p, cpsStmts, "#genericSeqAssign($1, $2, $3);$n",
|
||||||
[addrLoc(dest), rdLoc(src), genTypeInfo(p.module, dest.t)])
|
[addrLoc(dest), rdLoc(src), genTypeInfo(p.module, dest.t)])
|
||||||
of tyString:
|
of tyString:
|
||||||
if needToCopy notin flags:
|
if needToCopy notin flags:
|
||||||
genRefAssign(p, dest, src, flags)
|
genRefAssign(p, dest, src, flags)
|
||||||
else:
|
else:
|
||||||
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
if dest.s == OnStack or optRefcGC notin gGlobalOptions:
|
||||||
appcg(p, cpsStmts, "$1 = #copyString($2);$n", [dest.rdLoc, src.rdLoc])
|
lineCg(p, cpsStmts, "$1 = #copyString($2);$n", [dest.rdLoc, src.rdLoc])
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
if needToKeepAlive in flags: keepAlive(p, dest)
|
||||||
elif dest.s == OnHeap:
|
elif dest.s == OnHeap:
|
||||||
# we use a temporary to care for the dreaded self assignment:
|
# we use a temporary to care for the dreaded self assignment:
|
||||||
var tmp: TLoc
|
var tmp: TLoc
|
||||||
getTemp(p, ty, tmp)
|
getTemp(p, ty, tmp)
|
||||||
appcg(p, cpsStmts, "$3 = $1; $1 = #copyStringRC1($2);$n",
|
lineCg(p, cpsStmts, "$3 = $1; $1 = #copyStringRC1($2);$n",
|
||||||
[dest.rdLoc, src.rdLoc, tmp.rdLoc])
|
[dest.rdLoc, src.rdLoc, tmp.rdLoc])
|
||||||
appcg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", tmp.rdLoc)
|
lineCg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", tmp.rdLoc)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#unsureAsgnRef((void**) $1, #copyString($2));$n",
|
lineCg(p, cpsStmts, "#unsureAsgnRef((void**) $1, #copyString($2));$n",
|
||||||
[addrLoc(dest), rdLoc(src)])
|
[addrLoc(dest), rdLoc(src)])
|
||||||
if needToKeepAlive in flags: keepAlive(p, dest)
|
if needToKeepAlive in flags: keepAlive(p, dest)
|
||||||
of tyTuple, tyObject, tyProc:
|
of tyTuple, tyObject, tyProc:
|
||||||
|
|
@ -251,34 +251,34 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
if needsComplexAssignment(dest.t):
|
if needsComplexAssignment(dest.t):
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||||
of tyArray, tyArrayConstr:
|
of tyArray, tyArrayConstr:
|
||||||
if needsComplexAssignment(dest.t):
|
if needsComplexAssignment(dest.t):
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n",
|
||||||
[rdLoc(dest), rdLoc(src)])
|
[rdLoc(dest), rdLoc(src)])
|
||||||
of tyOpenArray:
|
of tyOpenArray:
|
||||||
# open arrays are always on the stack - really? What if a sequence is
|
# open arrays are always on the stack - really? What if a sequence is
|
||||||
# passed to an open array?
|
# passed to an open array?
|
||||||
if needsComplexAssignment(dest.t):
|
if needsComplexAssignment(dest.t):
|
||||||
appcg(p, cpsStmts, # XXX: is this correct for arrays?
|
lineCg(p, cpsStmts, # XXX: is this correct for arrays?
|
||||||
"#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n",
|
"#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n",
|
||||||
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
[addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n",
|
||||||
[rdLoc(dest), rdLoc(src)])
|
[rdLoc(dest), rdLoc(src)])
|
||||||
of tySet:
|
of tySet:
|
||||||
if mapType(ty) == ctArray:
|
if mapType(ty) == ctArray:
|
||||||
appcg(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n",
|
lineCg(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n",
|
||||||
[rdLoc(dest), rdLoc(src), toRope(getSize(dest.t))])
|
[rdLoc(dest), rdLoc(src), toRope(getSize(dest.t))])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||||
of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString,
|
of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString,
|
||||||
tyInt..tyUInt64, tyRange:
|
tyInt..tyUInt64, tyRange:
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
|
||||||
else: InternalError("genAssignment(" & $ty.kind & ')')
|
else: InternalError("genAssignment(" & $ty.kind & ')')
|
||||||
|
|
||||||
proc expr(p: BProc, e: PNode, d: var TLoc)
|
proc expr(p: BProc, e: PNode, d: var TLoc)
|
||||||
|
|
@ -317,20 +317,20 @@ proc binaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
if d.k != locNone: InternalError(e.info, "binaryStmt")
|
if d.k != locNone: InternalError(e.info, "binaryStmt")
|
||||||
InitLocExpr(p, e.sons[1], d)
|
InitLocExpr(p, e.sons[1], d)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
appcg(p, cpsStmts, frmt, [rdLoc(d), rdLoc(b)])
|
lineCg(p, cpsStmts, frmt, [rdLoc(d), rdLoc(b)])
|
||||||
|
|
||||||
proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
proc unaryStmt(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
if (d.k != locNone): InternalError(e.info, "unaryStmt")
|
if (d.k != locNone): InternalError(e.info, "unaryStmt")
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
appcg(p, cpsStmts, frmt, [rdLoc(a)])
|
lineCg(p, cpsStmts, frmt, [rdLoc(a)])
|
||||||
|
|
||||||
proc binaryStmtChar(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
proc binaryStmtChar(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
if (d.k != locNone): InternalError(e.info, "binaryStmtChar")
|
if (d.k != locNone): InternalError(e.info, "binaryStmtChar")
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
appcg(p, cpsStmts, frmt, [rdCharLoc(a), rdCharLoc(b)])
|
lineCg(p, cpsStmts, frmt, [rdCharLoc(a), rdCharLoc(b)])
|
||||||
|
|
||||||
proc binaryExpr(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
proc binaryExpr(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
|
|
@ -382,11 +382,11 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
else:
|
else:
|
||||||
storage = getTypeDesc(p.module, t)
|
storage = getTypeDesc(p.module, t)
|
||||||
var tmp = getTempName()
|
var tmp = getTempName()
|
||||||
appcg(p, cpsLocals, "$1 $2;$n", [storage, tmp])
|
lineCg(p, cpsLocals, "$1 $2;$n", [storage, tmp])
|
||||||
appcg(p, cpsStmts, "$1 = #$2($3, $4);$n", [tmp, toRope(prc[m]),
|
lineCg(p, cpsStmts, "$1 = #$2($3, $4);$n", [tmp, toRope(prc[m]),
|
||||||
rdLoc(a), rdLoc(b)])
|
rdLoc(a), rdLoc(b)])
|
||||||
if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}:
|
if size < platform.IntSize or t.kind in {tyRange, tyEnum, tySet}:
|
||||||
appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n",
|
lineCg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n",
|
||||||
[tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))])
|
[tmp, intLiteral(firstOrd(t)), intLiteral(lastOrd(t))])
|
||||||
putIntoDest(p, d, e.typ, ropef("(NI$1)($2)", [toRope(getSize(t)*8), tmp]))
|
putIntoDest(p, d, e.typ, ropef("(NI$1)($2)", [toRope(getSize(t)*8), tmp]))
|
||||||
|
|
||||||
|
|
@ -404,7 +404,7 @@ proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
t = skipTypes(e.typ, abstractRange)
|
t = skipTypes(e.typ, abstractRange)
|
||||||
if optOverflowCheck in p.options:
|
if optOverflowCheck in p.options:
|
||||||
appcg(p, cpsStmts, "if ($1 == $2) #raiseOverflow();$n",
|
lineCg(p, cpsStmts, "if ($1 == $2) #raiseOverflow();$n",
|
||||||
[rdLoc(a), intLiteral(firstOrd(t))])
|
[rdLoc(a), intLiteral(firstOrd(t))])
|
||||||
putIntoDest(p, d, e.typ, ropef(opr[m], [rdLoc(a), toRope(getSize(t) * 8)]))
|
putIntoDest(p, d, e.typ, ropef(opr[m], [rdLoc(a), toRope(getSize(t) * 8)]))
|
||||||
|
|
||||||
|
|
@ -634,11 +634,11 @@ proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if id == gBackendId: strLit = getStrLit(p.module, field.name.s)
|
if id == gBackendId: strLit = getStrLit(p.module, field.name.s)
|
||||||
else: strLit = con("TMP", toRope(id))
|
else: strLit = con("TMP", toRope(id))
|
||||||
if op.magic == mNot:
|
if op.magic == mNot:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"if ($1) #raiseFieldError(((#NimStringDesc*) &$2));$n",
|
"if ($1) #raiseFieldError(((#NimStringDesc*) &$2));$n",
|
||||||
[rdLoc(test), strLit])
|
[rdLoc(test), strLit])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"if (!($1)) #raiseFieldError(((#NimStringDesc*) &$2));$n",
|
"if (!($1)) #raiseFieldError(((#NimStringDesc*) &$2));$n",
|
||||||
[rdLoc(test), strLit])
|
[rdLoc(test), strLit])
|
||||||
appf(r, ".$1", [field.loc.r])
|
appf(r, ".$1", [field.loc.r])
|
||||||
|
|
@ -658,10 +658,10 @@ proc genArrayElem(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# semantic pass has already checked for const index expressions
|
# semantic pass has already checked for const index expressions
|
||||||
if firstOrd(ty) == 0:
|
if firstOrd(ty) == 0:
|
||||||
if (firstOrd(b.t) < firstOrd(ty)) or (lastOrd(b.t) > lastOrd(ty)):
|
if (firstOrd(b.t) < firstOrd(ty)) or (lastOrd(b.t) > lastOrd(ty)):
|
||||||
appcg(p, cpsStmts, "if ((NU)($1) > (NU)($2)) #raiseIndexError();$n",
|
lineCg(p, cpsStmts, "if ((NU)($1) > (NU)($2)) #raiseIndexError();$n",
|
||||||
[rdCharLoc(b), intLiteral(lastOrd(ty))])
|
[rdCharLoc(b), intLiteral(lastOrd(ty))])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n",
|
lineCg(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n",
|
||||||
[rdCharLoc(b), first, intLiteral(lastOrd(ty))])
|
[rdCharLoc(b), first, intLiteral(lastOrd(ty))])
|
||||||
if d.k == locNone: d.s = a.s
|
if d.k == locNone: d.s = a.s
|
||||||
putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)),
|
putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)),
|
||||||
|
|
@ -681,7 +681,7 @@ proc genOpenArrayElem(p: BProc, e: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, e.sons[0], a)
|
initLocExpr(p, e.sons[0], a)
|
||||||
initLocExpr(p, e.sons[1], b) # emit range check:
|
initLocExpr(p, e.sons[1], b) # emit range check:
|
||||||
if optBoundsCheck in p.options:
|
if optBoundsCheck in p.options:
|
||||||
appcg(p, cpsStmts, "if ((NU)($1) >= (NU)($2Len0)) #raiseIndexError();$n",
|
lineCg(p, cpsStmts, "if ((NU)($1) >= (NU)($2Len0)) #raiseIndexError();$n",
|
||||||
[rdLoc(b), rdLoc(a)]) # BUGFIX: ``>=`` and not ``>``!
|
[rdLoc(b), rdLoc(a)]) # BUGFIX: ``>=`` and not ``>``!
|
||||||
if d.k == locNone: d.s = a.s
|
if d.k == locNone: d.s = a.s
|
||||||
putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)),
|
putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)),
|
||||||
|
|
@ -696,11 +696,11 @@ proc genSeqElem(p: BPRoc, e: PNode, d: var TLoc) =
|
||||||
ty = skipTypes(ty.sons[0], abstractVarRange) # emit range check:
|
ty = skipTypes(ty.sons[0], abstractVarRange) # emit range check:
|
||||||
if optBoundsCheck in p.options:
|
if optBoundsCheck in p.options:
|
||||||
if ty.kind == tyString:
|
if ty.kind == tyString:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"if ((NU)($1) > (NU)($2->$3)) #raiseIndexError();$n",
|
"if ((NU)($1) > (NU)($2->$3)) #raiseIndexError();$n",
|
||||||
[rdLoc(b), rdLoc(a), lenField()])
|
[rdLoc(b), rdLoc(a), lenField()])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"if ((NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n",
|
"if ((NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n",
|
||||||
[rdLoc(b), rdLoc(a), lenField()])
|
[rdLoc(b), rdLoc(a), lenField()])
|
||||||
if d.k == locNone: d.s = OnHeap
|
if d.k == locNone: d.s = OnHeap
|
||||||
|
|
@ -737,9 +737,9 @@ proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
expr(p, e.sons[1], tmp)
|
expr(p, e.sons[1], tmp)
|
||||||
L = getLabel(p)
|
L = getLabel(p)
|
||||||
if m == mOr:
|
if m == mOr:
|
||||||
appf(p.s(cpsStmts), "if ($1) goto $2;$n", [rdLoc(tmp), L])
|
lineF(p, cpsStmts, "if ($1) goto $2;$n", [rdLoc(tmp), L])
|
||||||
else:
|
else:
|
||||||
appf(p.s(cpsStmts), "if (!($1)) goto $2;$n", [rdLoc(tmp), L])
|
lineF(p, cpsStmts, "if (!($1)) goto $2;$n", [rdLoc(tmp), L])
|
||||||
expr(p, e.sons[2], tmp)
|
expr(p, e.sons[2], tmp)
|
||||||
fixLabel(p, L)
|
fixLabel(p, L)
|
||||||
if d.k == locNone:
|
if d.k == locNone:
|
||||||
|
|
@ -772,9 +772,9 @@ proc genIfExpr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
of nkElifExpr:
|
of nkElifExpr:
|
||||||
initLocExpr(p, it.sons[0], a)
|
initLocExpr(p, it.sons[0], a)
|
||||||
Lelse = getLabel(p)
|
Lelse = getLabel(p)
|
||||||
appf(p.s(cpsStmts), "if (!$1) goto $2;$n", [rdLoc(a), Lelse])
|
lineF(p, cpsStmts, "if (!$1) goto $2;$n", [rdLoc(a), Lelse])
|
||||||
expr(p, it.sons[1], tmp)
|
expr(p, it.sons[1], tmp)
|
||||||
appf(p.s(cpsStmts), "goto $1;$n", [Lend])
|
lineF(p, cpsStmts, "goto $1;$n", [Lend])
|
||||||
fixLabel(p, Lelse)
|
fixLabel(p, Lelse)
|
||||||
of nkElseExpr:
|
of nkElseExpr:
|
||||||
expr(p, it.sons[0], tmp)
|
expr(p, it.sons[0], tmp)
|
||||||
|
|
@ -793,7 +793,7 @@ proc genEcho(p: BProc, n: PNode) =
|
||||||
for i in countup(1, n.len-1):
|
for i in countup(1, n.len-1):
|
||||||
initLocExpr(p, n.sons[i], a)
|
initLocExpr(p, n.sons[i], a)
|
||||||
appf(args, ", ($1)->data", [rdLoc(a)])
|
appf(args, ", ($1)->data", [rdLoc(a)])
|
||||||
appcg(p, cpsStmts, "printf($1$2);$n", [
|
lineCg(p, cpsStmts, "printf($1$2);$n", [
|
||||||
makeCString(repeatStr(n.len-1, "%s") & tnl), args])
|
makeCString(repeatStr(n.len-1, "%s") & tnl), args])
|
||||||
|
|
||||||
include ccgcalls
|
include ccgcalls
|
||||||
|
|
@ -825,14 +825,14 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, e.sons[i + 1], a)
|
initLocExpr(p, e.sons[i + 1], a)
|
||||||
if skipTypes(e.sons[i + 1].Typ, abstractVarRange).kind == tyChar:
|
if skipTypes(e.sons[i + 1].Typ, abstractVarRange).kind == tyChar:
|
||||||
Inc(L)
|
Inc(L)
|
||||||
appcg(p.module, appends, "#appendChar($1, $2);$n", [tmp.r, rdLoc(a)])
|
appLineCg(p, appends, "#appendChar($1, $2);$n", [tmp.r, rdLoc(a)])
|
||||||
else:
|
else:
|
||||||
if e.sons[i + 1].kind in {nkStrLit..nkTripleStrLit}:
|
if e.sons[i + 1].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
Inc(L, len(e.sons[i + 1].strVal))
|
Inc(L, len(e.sons[i + 1].strVal))
|
||||||
else:
|
else:
|
||||||
appf(lens, "$1->$2 + ", [rdLoc(a), lenField()])
|
appf(lens, "$1->$2 + ", [rdLoc(a), lenField()])
|
||||||
appcg(p.module, appends, "#appendString($1, $2);$n", [tmp.r, rdLoc(a)])
|
appLineCg(p, appends, "#appendString($1, $2);$n", [tmp.r, rdLoc(a)])
|
||||||
appcg(p, cpsStmts, "$1 = #rawNewString($2$3);$n", [tmp.r, lens, toRope(L)])
|
lineCg(p, cpsStmts, "$1 = #rawNewString($2$3);$n", [tmp.r, lens, toRope(L)])
|
||||||
app(p.s(cpsStmts), appends)
|
app(p.s(cpsStmts), appends)
|
||||||
if d.k == locNone:
|
if d.k == locNone:
|
||||||
d = tmp
|
d = tmp
|
||||||
|
|
@ -863,16 +863,16 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, e.sons[i + 2], a)
|
initLocExpr(p, e.sons[i + 2], a)
|
||||||
if skipTypes(e.sons[i + 2].Typ, abstractVarRange).kind == tyChar:
|
if skipTypes(e.sons[i + 2].Typ, abstractVarRange).kind == tyChar:
|
||||||
Inc(L)
|
Inc(L)
|
||||||
appcg(p.module, appends, "#appendChar($1, $2);$n",
|
appLineCg(p, appends, "#appendChar($1, $2);$n",
|
||||||
[rdLoc(dest), rdLoc(a)])
|
[rdLoc(dest), rdLoc(a)])
|
||||||
else:
|
else:
|
||||||
if e.sons[i + 2].kind in {nkStrLit..nkTripleStrLit}:
|
if e.sons[i + 2].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
Inc(L, len(e.sons[i + 2].strVal))
|
Inc(L, len(e.sons[i + 2].strVal))
|
||||||
else:
|
else:
|
||||||
appf(lens, "$1->$2 + ", [rdLoc(a), lenField()])
|
appf(lens, "$1->$2 + ", [rdLoc(a), lenField()])
|
||||||
appcg(p.module, appends, "#appendString($1, $2);$n",
|
appLineCg(p, appends, "#appendString($1, $2);$n",
|
||||||
[rdLoc(dest), rdLoc(a)])
|
[rdLoc(dest), rdLoc(a)])
|
||||||
appcg(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n",
|
lineCg(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n",
|
||||||
[rdLoc(dest), lens, toRope(L)])
|
[rdLoc(dest), lens, toRope(L)])
|
||||||
keepAlive(p, dest)
|
keepAlive(p, dest)
|
||||||
app(p.s(cpsStmts), appends)
|
app(p.s(cpsStmts), appends)
|
||||||
|
|
@ -889,7 +889,7 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
var a, b, dest: TLoc
|
var a, b, dest: TLoc
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
appcg(p, cpsStmts, seqAppendPattern, [
|
lineCg(p, cpsStmts, seqAppendPattern, [
|
||||||
rdLoc(a),
|
rdLoc(a),
|
||||||
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
|
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
|
||||||
getTypeDesc(p.module, skipTypes(e.sons[2].Typ, abstractVar))])
|
getTypeDesc(p.module, skipTypes(e.sons[2].Typ, abstractVar))])
|
||||||
|
|
@ -901,7 +901,7 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
proc genReset(p: BProc, n: PNode) =
|
proc genReset(p: BProc, n: PNode) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
InitLocExpr(p, n.sons[1], a)
|
InitLocExpr(p, n.sons[1], a)
|
||||||
appcg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
lineCg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
||||||
[addrLoc(a), genTypeInfo(p.module, skipTypes(a.t, abstractVarRange))])
|
[addrLoc(a), genTypeInfo(p.module, skipTypes(a.t, abstractVarRange))])
|
||||||
|
|
||||||
proc genNew(p: BProc, e: PNode) =
|
proc genNew(p: BProc, e: PNode) =
|
||||||
|
|
@ -917,11 +917,11 @@ proc genNew(p: BProc, e: PNode) =
|
||||||
if a.s == OnHeap and optRefcGc in gGlobalOptions:
|
if a.s == OnHeap and optRefcGc in gGlobalOptions:
|
||||||
# use newObjRC1 as an optimization; and we don't need 'keepAlive' either
|
# use newObjRC1 as an optimization; and we don't need 'keepAlive' either
|
||||||
if canFormAcycle(a.t):
|
if canFormAcycle(a.t):
|
||||||
appcg(p, cpsStmts, "if ($1) #nimGCunref($1);$n", a.rdLoc)
|
lineCg(p, cpsStmts, "if ($1) #nimGCunref($1);$n", a.rdLoc)
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", a.rdLoc)
|
lineCg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", a.rdLoc)
|
||||||
b.r = ropecg(p.module, "($1) #newObjRC1($2, sizeof($3))", args)
|
b.r = ropecg(p.module, "($1) #newObjRC1($2, sizeof($3))", args)
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", a.rdLoc, b.rdLoc)
|
lineCg(p, cpsStmts, "$1 = $2;$n", a.rdLoc, b.rdLoc)
|
||||||
else:
|
else:
|
||||||
b.r = ropecg(p.module, "($1) #newObj($2, sizeof($3))", args)
|
b.r = ropecg(p.module, "($1) #newObj($2, sizeof($3))", args)
|
||||||
genAssignment(p, a, b, {needToKeepAlive}) # set the object type:
|
genAssignment(p, a, b, {needToKeepAlive}) # set the object type:
|
||||||
|
|
@ -935,9 +935,9 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: PRope) =
|
||||||
var call: TLoc
|
var call: TLoc
|
||||||
initLoc(call, locExpr, dest.t, OnHeap)
|
initLoc(call, locExpr, dest.t, OnHeap)
|
||||||
if dest.s == OnHeap and optRefcGc in gGlobalOptions:
|
if dest.s == OnHeap and optRefcGc in gGlobalOptions:
|
||||||
appcg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", dest.rdLoc)
|
lineCg(p, cpsStmts, "if ($1) #nimGCunrefNoCycle($1);$n", dest.rdLoc)
|
||||||
call.r = ropecg(p.module, "($1) #newSeqRC1($2, $3)", args)
|
call.r = ropecg(p.module, "($1) #newSeqRC1($2, $3)", args)
|
||||||
appcg(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc)
|
lineCg(p, cpsStmts, "$1 = $2;$n", dest.rdLoc, call.rdLoc)
|
||||||
else:
|
else:
|
||||||
call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args)
|
call.r = ropecg(p.module, "($1) #newSeq($2, $3)", args)
|
||||||
genAssignment(p, dest, call, {needToKeepAlive})
|
genAssignment(p, dest, call, {needToKeepAlive})
|
||||||
|
|
@ -1124,7 +1124,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
"$1 = ($3) #setLengthSeq($1, sizeof($4), $2);$n"
|
"$1 = ($3) #setLengthSeq($1, sizeof($4), $2);$n"
|
||||||
|
|
||||||
appcg(p, cpsStmts, setLenPattern, [
|
lineCg(p, cpsStmts, setLenPattern, [
|
||||||
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
||||||
getTypeDesc(p.module, t.sons[0])])
|
getTypeDesc(p.module, t.sons[0])])
|
||||||
keepAlive(p, a)
|
keepAlive(p, a)
|
||||||
|
|
@ -1181,7 +1181,7 @@ proc binaryStmtInExcl(p: BProc, e: PNode, d: var TLoc, frmt: string) =
|
||||||
assert(d.k == locNone)
|
assert(d.k == locNone)
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
appf(p.s(cpsStmts), frmt, [rdLoc(a), rdSetElemLoc(b, a.t)])
|
lineF(p, cpsStmts, frmt, [rdLoc(a), rdSetElemLoc(b, a.t)])
|
||||||
|
|
||||||
proc genInOp(p: BProc, e: PNode, d: var TLoc) =
|
proc genInOp(p: BProc, e: PNode, d: var TLoc) =
|
||||||
var a, b, x, y: TLoc
|
var a, b, x, y: TLoc
|
||||||
|
|
@ -1257,7 +1257,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
initLocExpr(p, e.sons[2], b)
|
initLocExpr(p, e.sons[2], b)
|
||||||
if d.k == locNone: getTemp(p, a.t, d)
|
if d.k == locNone: getTemp(p, a.t, d)
|
||||||
appf(p.s(cpsStmts), lookupOpr[op],
|
lineF(p, cpsStmts, lookupOpr[op],
|
||||||
[rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b)])
|
[rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b)])
|
||||||
of mEqSet:
|
of mEqSet:
|
||||||
binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)")
|
binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)")
|
||||||
|
|
@ -1267,7 +1267,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
initLocExpr(p, e.sons[2], b)
|
initLocExpr(p, e.sons[2], b)
|
||||||
if d.k == locNone: getTemp(p, a.t, d)
|
if d.k == locNone: getTemp(p, a.t, d)
|
||||||
appf(p.s(cpsStmts),
|
lineF(p, cpsStmts,
|
||||||
"for ($1 = 0; $1 < $2; $1++) $n" &
|
"for ($1 = 0; $1 < $2; $1++) $n" &
|
||||||
" $3[$1] = $4[$1] $6 $5[$1];$n", [
|
" $3[$1] = $4[$1] $6 $5[$1];$n", [
|
||||||
rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b),
|
rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b),
|
||||||
|
|
@ -1356,9 +1356,9 @@ proc binaryFloatArith(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||||
putIntoDest(p, d, e.typ, ropef("($2 $1 $3)", [
|
putIntoDest(p, d, e.typ, ropef("($2 $1 $3)", [
|
||||||
toRope(opr[m]), rdLoc(a), rdLoc(b)]))
|
toRope(opr[m]), rdLoc(a), rdLoc(b)]))
|
||||||
if optNanCheck in p.options:
|
if optNanCheck in p.options:
|
||||||
appcg(p, cpsStmts, "#nanCheck($1);$n", [rdLoc(d)])
|
lineCg(p, cpsStmts, "#nanCheck($1);$n", [rdLoc(d)])
|
||||||
if optInfCheck in p.options:
|
if optInfCheck in p.options:
|
||||||
appcg(p, cpsStmts, "#infCheck($1);$n", [rdLoc(d)])
|
lineCg(p, cpsStmts, "#infCheck($1);$n", [rdLoc(d)])
|
||||||
else:
|
else:
|
||||||
binaryArith(p, e, d, m)
|
binaryArith(p, e, d, m)
|
||||||
|
|
||||||
|
|
@ -1479,35 +1479,35 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if d.k == locNone: getTemp(p, e.typ, d)
|
if d.k == locNone: getTemp(p, e.typ, d)
|
||||||
if getSize(e.typ) > 8:
|
if getSize(e.typ) > 8:
|
||||||
# big set:
|
# big set:
|
||||||
appf(p.s(cpsStmts), "memset($1, 0, sizeof($1));$n", [rdLoc(d)])
|
lineF(p, cpsStmts, "memset($1, 0, sizeof($1));$n", [rdLoc(d)])
|
||||||
for i in countup(0, sonsLen(e) - 1):
|
for i in countup(0, sonsLen(e) - 1):
|
||||||
if e.sons[i].kind == nkRange:
|
if e.sons[i].kind == nkRange:
|
||||||
getTemp(p, getSysType(tyInt), idx) # our counter
|
getTemp(p, getSysType(tyInt), idx) # our counter
|
||||||
initLocExpr(p, e.sons[i].sons[0], a)
|
initLocExpr(p, e.sons[i].sons[0], a)
|
||||||
initLocExpr(p, e.sons[i].sons[1], b)
|
initLocExpr(p, e.sons[i].sons[1], b)
|
||||||
appf(p.s(cpsStmts), "for ($1 = $3; $1 <= $4; $1++) $n" &
|
lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" &
|
||||||
"$2[$1/8] |=(1<<($1%8));$n", [rdLoc(idx), rdLoc(d),
|
"$2[$1/8] |=(1<<($1%8));$n", [rdLoc(idx), rdLoc(d),
|
||||||
rdSetElemLoc(a, e.typ), rdSetElemLoc(b, e.typ)])
|
rdSetElemLoc(a, e.typ), rdSetElemLoc(b, e.typ)])
|
||||||
else:
|
else:
|
||||||
initLocExpr(p, e.sons[i], a)
|
initLocExpr(p, e.sons[i], a)
|
||||||
appf(p.s(cpsStmts), "$1[$2/8] |=(1<<($2%8));$n",
|
lineF(p, cpsStmts, "$1[$2/8] |=(1<<($2%8));$n",
|
||||||
[rdLoc(d), rdSetElemLoc(a, e.typ)])
|
[rdLoc(d), rdSetElemLoc(a, e.typ)])
|
||||||
else:
|
else:
|
||||||
# small set
|
# small set
|
||||||
var ts = "NI" & $(getSize(e.typ) * 8)
|
var ts = "NI" & $(getSize(e.typ) * 8)
|
||||||
appf(p.s(cpsStmts), "$1 = 0;$n", [rdLoc(d)])
|
lineF(p, cpsStmts, "$1 = 0;$n", [rdLoc(d)])
|
||||||
for i in countup(0, sonsLen(e) - 1):
|
for i in countup(0, sonsLen(e) - 1):
|
||||||
if e.sons[i].kind == nkRange:
|
if e.sons[i].kind == nkRange:
|
||||||
getTemp(p, getSysType(tyInt), idx) # our counter
|
getTemp(p, getSysType(tyInt), idx) # our counter
|
||||||
initLocExpr(p, e.sons[i].sons[0], a)
|
initLocExpr(p, e.sons[i].sons[0], a)
|
||||||
initLocExpr(p, e.sons[i].sons[1], b)
|
initLocExpr(p, e.sons[i].sons[1], b)
|
||||||
appf(p.s(cpsStmts), "for ($1 = $3; $1 <= $4; $1++) $n" &
|
lineF(p, cpsStmts, "for ($1 = $3; $1 <= $4; $1++) $n" &
|
||||||
"$2 |=(1<<((" & ts & ")($1)%(sizeof(" & ts & ")*8)));$n", [
|
"$2 |=(1<<((" & ts & ")($1)%(sizeof(" & ts & ")*8)));$n", [
|
||||||
rdLoc(idx), rdLoc(d), rdSetElemLoc(a, e.typ),
|
rdLoc(idx), rdLoc(d), rdSetElemLoc(a, e.typ),
|
||||||
rdSetElemLoc(b, e.typ)])
|
rdSetElemLoc(b, e.typ)])
|
||||||
else:
|
else:
|
||||||
initLocExpr(p, e.sons[i], a)
|
initLocExpr(p, e.sons[i], a)
|
||||||
appf(p.s(cpsStmts),
|
lineF(p, cpsStmts,
|
||||||
"$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n",
|
"$1 |=(1<<((" & ts & ")($2)%(sizeof(" & ts & ")*8)));$n",
|
||||||
[rdLoc(d), rdSetElemLoc(a, e.typ)])
|
[rdLoc(d), rdSetElemLoc(a, e.typ)])
|
||||||
|
|
||||||
|
|
@ -1548,7 +1548,7 @@ proc genClosure(p: BProc, n: PNode, d: var TLoc) =
|
||||||
initLocExpr(p, n.sons[0], a)
|
initLocExpr(p, n.sons[0], a)
|
||||||
initLocExpr(p, n.sons[1], b)
|
initLocExpr(p, n.sons[1], b)
|
||||||
getTemp(p, n.typ, tmp)
|
getTemp(p, n.typ, tmp)
|
||||||
appcg(p, cpsStmts, "$1.ClPrc = $2; $1.ClEnv = $3;$n",
|
lineCg(p, cpsStmts, "$1.ClPrc = $2; $1.ClEnv = $3;$n",
|
||||||
tmp.rdLoc, a.rdLoc, b.rdLoc)
|
tmp.rdLoc, a.rdLoc, b.rdLoc)
|
||||||
putLocIntoDest(p, d, tmp)
|
putLocIntoDest(p, d, tmp)
|
||||||
|
|
||||||
|
|
@ -1588,10 +1588,10 @@ proc upConv(p: BProc, n: PNode, d: var TLoc) =
|
||||||
app(r, ".Sup")
|
app(r, ".Sup")
|
||||||
t = skipTypes(t.sons[0], abstractInst)
|
t = skipTypes(t.sons[0], abstractInst)
|
||||||
if nilCheck != nil:
|
if nilCheck != nil:
|
||||||
appcg(p, cpsStmts, "if ($1) #chckObj($2.m_type, $3);$n",
|
lineCg(p, cpsStmts, "if ($1) #chckObj($2.m_type, $3);$n",
|
||||||
[nilCheck, r, genTypeInfo(p.module, dest)])
|
[nilCheck, r, genTypeInfo(p.module, dest)])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#chckObj($1.m_type, $2);$n",
|
lineCg(p, cpsStmts, "#chckObj($1.m_type, $2);$n",
|
||||||
[r, genTypeInfo(p.module, dest)])
|
[r, genTypeInfo(p.module, dest)])
|
||||||
if n.sons[0].typ.kind != tyObject:
|
if n.sons[0].typ.kind != tyObject:
|
||||||
putIntoDest(p, d, n.typ,
|
putIntoDest(p, d, n.typ,
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,12 @@ proc loadInto(p: BProc, le, ri: PNode, a: var TLoc) {.inline.} =
|
||||||
|
|
||||||
proc startBlock(p: BProc, start: TFormatStr = "{$n",
|
proc startBlock(p: BProc, start: TFormatStr = "{$n",
|
||||||
args: openarray[PRope]): int {.discardable.} =
|
args: openarray[PRope]): int {.discardable.} =
|
||||||
|
lineCg(p, cpsStmts, start, args)
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
result = len(p.blocks)
|
result = len(p.blocks)
|
||||||
setlen(p.blocks, result + 1)
|
setlen(p.blocks, result + 1)
|
||||||
p.blocks[result].id = p.labels
|
p.blocks[result].id = p.labels
|
||||||
p.blocks[result].nestedTryStmts = p.nestedTryStmts.len
|
p.blocks[result].nestedTryStmts = p.nestedTryStmts.len
|
||||||
appcg(p, cpsLocals, start, args)
|
|
||||||
|
|
||||||
proc assignLabel(b: var TBlock): PRope {.inline.} =
|
proc assignLabel(b: var TBlock): PRope {.inline.} =
|
||||||
b.label = con("LA", b.id.toRope)
|
b.label = con("LA", b.id.toRope)
|
||||||
|
|
@ -70,7 +70,7 @@ proc endBlock(p: BProc, blockEnd: PRope) =
|
||||||
setlen(p.blocks, topBlock)
|
setlen(p.blocks, topBlock)
|
||||||
# this is done after the block is popped so $n is
|
# this is done after the block is popped so $n is
|
||||||
# properly indented when pretty printing is enabled
|
# properly indented when pretty printing is enabled
|
||||||
app(p.s(cpsStmts), blockEnd)
|
line(p, cpsStmts, blockEnd)
|
||||||
|
|
||||||
var gBlockEndBracket = ropef("}$n")
|
var gBlockEndBracket = ropef("}$n")
|
||||||
|
|
||||||
|
|
@ -184,12 +184,12 @@ proc genIfStmt(p: BProc, n: PNode) =
|
||||||
initLocExpr(p, it.sons[0], a)
|
initLocExpr(p, it.sons[0], a)
|
||||||
Lelse = getLabel(p)
|
Lelse = getLabel(p)
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
appff(p.s(cpsStmts), "if (!$1) goto $2;$n",
|
lineFF(p, cpsStmts, "if (!$1) goto $2;$n",
|
||||||
"br i1 $1, label %LOC$3, label %$2$n" & "LOC$3: $n",
|
"br i1 $1, label %LOC$3, label %$2$n" & "LOC$3: $n",
|
||||||
[rdLoc(a), Lelse, toRope(p.labels)])
|
[rdLoc(a), Lelse, toRope(p.labels)])
|
||||||
genSimpleBlock(p, it.sons[1])
|
genSimpleBlock(p, it.sons[1])
|
||||||
if sonsLen(n) > 1:
|
if sonsLen(n) > 1:
|
||||||
appff(p.s(cpsStmts), "goto $1;$n", "br label %$1$n", [Lend])
|
lineFF(p, cpsStmts, "goto $1;$n", "br label %$1$n", [Lend])
|
||||||
fixLabel(p, Lelse)
|
fixLabel(p, Lelse)
|
||||||
of nkElse:
|
of nkElse:
|
||||||
genSimpleBlock(p, it.sons[0])
|
genSimpleBlock(p, it.sons[0])
|
||||||
|
|
@ -211,7 +211,7 @@ proc blockLeaveActions(p: BProc, howMany: int) =
|
||||||
if alreadyPoppedCnt > 0:
|
if alreadyPoppedCnt > 0:
|
||||||
dec alreadyPoppedCnt
|
dec alreadyPoppedCnt
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#popSafePoint();$n", [])
|
lineCg(p, cpsStmts, "#popSafePoint();$n", [])
|
||||||
var finallyStmt = lastSon(tryStmt)
|
var finallyStmt = lastSon(tryStmt)
|
||||||
if finallyStmt.kind == nkFinally:
|
if finallyStmt.kind == nkFinally:
|
||||||
genStmts(p, finallyStmt.sons[0])
|
genStmts(p, finallyStmt.sons[0])
|
||||||
|
|
@ -220,14 +220,14 @@ proc blockLeaveActions(p: BProc, howMany: int) =
|
||||||
p.nestedTryStmts.add(stack[i])
|
p.nestedTryStmts.add(stack[i])
|
||||||
if gCmd != cmdCompileToCpp:
|
if gCmd != cmdCompileToCpp:
|
||||||
for i in countdown(p.inExceptBlock-1, 0):
|
for i in countdown(p.inExceptBlock-1, 0):
|
||||||
appcg(p, cpsStmts, "#popCurrentException();$n", [])
|
lineCg(p, cpsStmts, "#popCurrentException();$n", [])
|
||||||
|
|
||||||
proc genReturnStmt(p: BProc, t: PNode) =
|
proc genReturnStmt(p: BProc, t: PNode) =
|
||||||
p.beforeRetNeeded = true
|
p.beforeRetNeeded = true
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
if (t.sons[0].kind != nkEmpty): genStmts(p, t.sons[0])
|
if (t.sons[0].kind != nkEmpty): genStmts(p, t.sons[0])
|
||||||
blockLeaveActions(p, min(1, p.nestedTryStmts.len))
|
blockLeaveActions(p, min(1, p.nestedTryStmts.len))
|
||||||
appff(p.s(cpsStmts), "goto BeforeRet;$n", "br label %BeforeRet$n", [])
|
lineFF(p, cpsStmts, "goto BeforeRet;$n", "br label %BeforeRet$n", [])
|
||||||
|
|
||||||
proc genWhileStmt(p: BProc, t: PNode) =
|
proc genWhileStmt(p: BProc, t: PNode) =
|
||||||
# we don't generate labels here as for example GCC would produce
|
# we don't generate labels here as for example GCC would produce
|
||||||
|
|
@ -245,7 +245,7 @@ proc genWhileStmt(p: BProc, t: PNode) =
|
||||||
initLocExpr(p, t.sons[0], a)
|
initLocExpr(p, t.sons[0], a)
|
||||||
if (t.sons[0].kind != nkIntLit) or (t.sons[0].intVal == 0):
|
if (t.sons[0].kind != nkIntLit) or (t.sons[0].intVal == 0):
|
||||||
let label = assignLabel(p.blocks[p.breakIdx])
|
let label = assignLabel(p.blocks[p.breakIdx])
|
||||||
appf(p.s(cpsStmts), "if (!$1) goto $2;$n", [rdLoc(a), label])
|
lineF(p, cpsStmts, "if (!$1) goto $2;$n", [rdLoc(a), label])
|
||||||
genStmts(p, t.sons[1])
|
genStmts(p, t.sons[1])
|
||||||
endBlock(p)
|
endBlock(p)
|
||||||
|
|
||||||
|
|
@ -279,7 +279,7 @@ proc genParForStmt(p: BProc, t: PNode) =
|
||||||
initLocExpr(p, call.sons[1], rangeA)
|
initLocExpr(p, call.sons[1], rangeA)
|
||||||
initLocExpr(p, call.sons[2], rangeB)
|
initLocExpr(p, call.sons[2], rangeB)
|
||||||
|
|
||||||
appf(p.s(cpsStmts), "#pragma omp parallel for $4$n" &
|
lineF(p, cpsStmts, "#pragma omp parallel for $4$n" &
|
||||||
"for ($1 = $2; $1 <= $3; ++$1)",
|
"for ($1 = $2; $1 <= $3; ++$1)",
|
||||||
forLoopVar.loc.rdLoc,
|
forLoopVar.loc.rdLoc,
|
||||||
rangeA.rdLoc, rangeB.rdLoc,
|
rangeA.rdLoc, rangeB.rdLoc,
|
||||||
|
|
@ -308,7 +308,7 @@ proc genBreakStmt(p: BProc, t: PNode) =
|
||||||
let label = assignLabel(p.blocks[idx])
|
let label = assignLabel(p.blocks[idx])
|
||||||
blockLeaveActions(p, p.nestedTryStmts.len - p.blocks[idx].nestedTryStmts)
|
blockLeaveActions(p, p.nestedTryStmts.len - p.blocks[idx].nestedTryStmts)
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
appf(p.s(cpsStmts), "goto $1;$n", [label])
|
lineF(p, cpsStmts, "goto $1;$n", [label])
|
||||||
|
|
||||||
proc getRaiseFrmt(p: BProc): string =
|
proc getRaiseFrmt(p: BProc): string =
|
||||||
if gCmd == cmdCompileToCpp:
|
if gCmd == cmdCompileToCpp:
|
||||||
|
|
@ -329,14 +329,14 @@ proc genRaiseStmt(p: BProc, t: PNode) =
|
||||||
var e = rdLoc(a)
|
var e = rdLoc(a)
|
||||||
var typ = skipTypes(t.sons[0].typ, abstractPtrs)
|
var typ = skipTypes(t.sons[0].typ, abstractPtrs)
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
appcg(p, cpsStmts, getRaiseFrmt(p), [e, makeCString(typ.sym.name.s)])
|
lineCg(p, cpsStmts, getRaiseFrmt(p), [e, makeCString(typ.sym.name.s)])
|
||||||
else:
|
else:
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
# reraise the last exception:
|
# reraise the last exception:
|
||||||
if gCmd == cmdCompileToCpp:
|
if gCmd == cmdCompileToCpp:
|
||||||
appcg(p, cpsStmts, "throw;$n")
|
lineCg(p, cpsStmts, "throw;$n")
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts, "#reraiseException();$n")
|
lineCg(p, cpsStmts, "#reraiseException();$n")
|
||||||
|
|
||||||
proc genCaseGenericBranch(p: BProc, b: PNode, e: TLoc,
|
proc genCaseGenericBranch(p: BProc, b: PNode, e: TLoc,
|
||||||
rangeFormat, eqFormat: TFormatStr, labl: TLabel) =
|
rangeFormat, eqFormat: TFormatStr, labl: TLabel) =
|
||||||
|
|
@ -347,20 +347,20 @@ proc genCaseGenericBranch(p: BProc, b: PNode, e: TLoc,
|
||||||
if b.sons[i].kind == nkRange:
|
if b.sons[i].kind == nkRange:
|
||||||
initLocExpr(p, b.sons[i].sons[0], x)
|
initLocExpr(p, b.sons[i].sons[0], x)
|
||||||
initLocExpr(p, b.sons[i].sons[1], y)
|
initLocExpr(p, b.sons[i].sons[1], y)
|
||||||
appcg(p, cpsStmts, rangeFormat,
|
lineCg(p, cpsStmts, rangeFormat,
|
||||||
[rdCharLoc(e), rdCharLoc(x), rdCharLoc(y), labl])
|
[rdCharLoc(e), rdCharLoc(x), rdCharLoc(y), labl])
|
||||||
else:
|
else:
|
||||||
initLocExpr(p, b.sons[i], x)
|
initLocExpr(p, b.sons[i], x)
|
||||||
appcg(p, cpsStmts, eqFormat, [rdCharLoc(e), rdCharLoc(x), labl])
|
lineCg(p, cpsStmts, eqFormat, [rdCharLoc(e), rdCharLoc(x), labl])
|
||||||
|
|
||||||
proc genCaseSecondPass(p: BProc, t: PNode, labId, until: int): TLabel =
|
proc genCaseSecondPass(p: BProc, t: PNode, labId, until: int): TLabel =
|
||||||
var Lend = getLabel(p)
|
var Lend = getLabel(p)
|
||||||
for i in 1..until:
|
for i in 1..until:
|
||||||
appf(p.s(cpsStmts), "LA$1: ;$n", [toRope(labId + i)])
|
lineF(p, cpsStmts, "LA$1: ;$n", [toRope(labId + i)])
|
||||||
if t.sons[i].kind == nkOfBranch:
|
if t.sons[i].kind == nkOfBranch:
|
||||||
var length = sonsLen(t.sons[i])
|
var length = sonsLen(t.sons[i])
|
||||||
genSimpleBlock(p, t.sons[i].sons[length - 1])
|
genSimpleBlock(p, t.sons[i].sons[length - 1])
|
||||||
appf(p.s(cpsStmts), "goto $1;$n", [Lend])
|
lineF(p, cpsStmts, "goto $1;$n", [Lend])
|
||||||
else:
|
else:
|
||||||
genSimpleBlock(p, t.sons[i].sons[0])
|
genSimpleBlock(p, t.sons[i].sons[0])
|
||||||
result = Lend
|
result = Lend
|
||||||
|
|
@ -375,13 +375,13 @@ proc genIfForCaseUntil(p: BProc, t: PNode, rangeFormat, eqFormat: TFormatStr,
|
||||||
genCaseGenericBranch(p, t.sons[i], a, rangeFormat, eqFormat,
|
genCaseGenericBranch(p, t.sons[i], a, rangeFormat, eqFormat,
|
||||||
con("LA", toRope(p.labels)))
|
con("LA", toRope(p.labels)))
|
||||||
else:
|
else:
|
||||||
appf(p.s(cpsStmts), "goto LA$1;$n", [toRope(p.labels)])
|
lineF(p, cpsStmts, "goto LA$1;$n", [toRope(p.labels)])
|
||||||
if until < t.len-1:
|
if until < t.len-1:
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
var gotoTarget = p.labels
|
var gotoTarget = p.labels
|
||||||
appf(p.s(cpsStmts), "goto LA$1;$n", [toRope(gotoTarget)])
|
lineF(p, cpsStmts, "goto LA$1;$n", [toRope(gotoTarget)])
|
||||||
result = genCaseSecondPass(p, t, labId, until)
|
result = genCaseSecondPass(p, t, labId, until)
|
||||||
appf(p.s(cpsStmts), "LA$1: ;$n", [toRope(gotoTarget)])
|
lineF(p, cpsStmts, "LA$1: ;$n", [toRope(gotoTarget)])
|
||||||
else:
|
else:
|
||||||
result = genCaseSecondPass(p, t, labId, until)
|
result = genCaseSecondPass(p, t, labId, until)
|
||||||
|
|
||||||
|
|
@ -423,7 +423,7 @@ proc genStringCase(p: BProc, t: PNode) =
|
||||||
else:
|
else:
|
||||||
# else statement: nothing to do yet
|
# else statement: nothing to do yet
|
||||||
# but we reserved a label, which we use later
|
# but we reserved a label, which we use later
|
||||||
appcg(p, cpsStmts, "switch (#hashString($1) & $2) {$n",
|
lineCg(p, cpsStmts, "switch (#hashString($1) & $2) {$n",
|
||||||
[rdLoc(a), toRope(bitMask)])
|
[rdLoc(a), toRope(bitMask)])
|
||||||
for j in countup(0, high(branches)):
|
for j in countup(0, high(branches)):
|
||||||
when false:
|
when false:
|
||||||
|
|
@ -433,11 +433,11 @@ proc genStringCase(p: BProc, t: PNode) =
|
||||||
if interior != brn:
|
if interior != brn:
|
||||||
echo "BUG! ", interior, "-", brn
|
echo "BUG! ", interior, "-", brn
|
||||||
if branches[j] != nil:
|
if branches[j] != nil:
|
||||||
appf(p.s(cpsStmts), "case $1: $n$2break;$n",
|
lineF(p, cpsStmts, "case $1: $n$2break;$n",
|
||||||
[intLiteral(j), branches[j]])
|
[intLiteral(j), branches[j]])
|
||||||
appf(p.s(cpsStmts), "}$n") # else statement:
|
lineF(p, cpsStmts, "}$n") # else statement:
|
||||||
if t.sons[sonsLen(t) - 1].kind != nkOfBranch:
|
if t.sons[sonsLen(t) - 1].kind != nkOfBranch:
|
||||||
appf(p.s(cpsStmts), "goto LA$1;$n", [toRope(p.labels)])
|
lineF(p, cpsStmts, "goto LA$1;$n", [toRope(p.labels)])
|
||||||
# third pass: generate statements
|
# third pass: generate statements
|
||||||
var Lend = genCaseSecondPass(p, t, labId, sonsLen(t)-1)
|
var Lend = genCaseSecondPass(p, t, labId, sonsLen(t)-1)
|
||||||
fixLabel(p, Lend)
|
fixLabel(p, Lend)
|
||||||
|
|
@ -466,16 +466,16 @@ proc genCaseRange(p: BProc, branch: PNode) =
|
||||||
for j in 0 .. length-2:
|
for j in 0 .. length-2:
|
||||||
if branch[j].kind == nkRange:
|
if branch[j].kind == nkRange:
|
||||||
if hasSwitchRange in CC[ccompiler].props:
|
if hasSwitchRange in CC[ccompiler].props:
|
||||||
appf(p.s(cpsStmts), "case $1 ... $2:$n", [
|
lineF(p, cpsStmts, "case $1 ... $2:$n", [
|
||||||
genLiteral(p, branch[j][0]),
|
genLiteral(p, branch[j][0]),
|
||||||
genLiteral(p, branch[j][1])])
|
genLiteral(p, branch[j][1])])
|
||||||
else:
|
else:
|
||||||
var v = copyNode(branch[j][0])
|
var v = copyNode(branch[j][0])
|
||||||
while v.intVal <= branch[j][1].intVal:
|
while v.intVal <= branch[j][1].intVal:
|
||||||
appf(p.s(cpsStmts), "case $1:$n", [genLiteral(p, v)])
|
lineF(p, cpsStmts, "case $1:$n", [genLiteral(p, v)])
|
||||||
Inc(v.intVal)
|
Inc(v.intVal)
|
||||||
else:
|
else:
|
||||||
appf(p.s(cpsStmts), "case $1:$n", [genLiteral(p, branch[j])])
|
lineF(p, cpsStmts, "case $1:$n", [genLiteral(p, branch[j])])
|
||||||
|
|
||||||
proc genOrdinalCase(p: BProc, n: PNode) =
|
proc genOrdinalCase(p: BProc, n: PNode) =
|
||||||
# analyse 'case' statement:
|
# analyse 'case' statement:
|
||||||
|
|
@ -491,7 +491,7 @@ proc genOrdinalCase(p: BProc, n: PNode) =
|
||||||
|
|
||||||
# generate switch part (might be empty):
|
# generate switch part (might be empty):
|
||||||
if splitPoint+1 < n.len:
|
if splitPoint+1 < n.len:
|
||||||
appf(p.s(cpsStmts), "switch ($1) {$n", [rdCharLoc(a)])
|
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
|
||||||
var hasDefault = false
|
var hasDefault = false
|
||||||
for i in splitPoint+1 .. < n.len:
|
for i in splitPoint+1 .. < n.len:
|
||||||
var branch = n[i]
|
var branch = n[i]
|
||||||
|
|
@ -500,13 +500,13 @@ proc genOrdinalCase(p: BProc, n: PNode) =
|
||||||
genSimpleBlock(p, branch.lastSon)
|
genSimpleBlock(p, branch.lastSon)
|
||||||
else:
|
else:
|
||||||
# else part of case statement:
|
# else part of case statement:
|
||||||
appf(p.s(cpsStmts), "default:$n")
|
lineF(p, cpsStmts, "default:$n")
|
||||||
genSimpleBlock(p, branch[0])
|
genSimpleBlock(p, branch[0])
|
||||||
hasDefault = true
|
hasDefault = true
|
||||||
appf(p.s(cpsStmts), "break;$n")
|
lineF(p, cpsStmts, "break;$n")
|
||||||
if (hasAssume in CC[ccompiler].props) and not hasDefault:
|
if (hasAssume in CC[ccompiler].props) and not hasDefault:
|
||||||
appf(p.s(cpsStmts), "default: __assume(0);$n")
|
lineF(p, cpsStmts, "default: __assume(0);$n")
|
||||||
appf(p.s(cpsStmts), "}$n")
|
lineF(p, cpsStmts, "}$n")
|
||||||
if Lend != nil: fixLabel(p, Lend)
|
if Lend != nil: fixLabel(p, Lend)
|
||||||
|
|
||||||
proc genCaseStmt(p: BProc, t: PNode) =
|
proc genCaseStmt(p: BProc, t: PNode) =
|
||||||
|
|
@ -563,7 +563,7 @@ proc genTryStmtCpp(p: BProc, t: PNode) =
|
||||||
length = sonsLen(t)
|
length = sonsLen(t)
|
||||||
endBlock(p, ropecg(p.module, "} catch (NimException& $1) {$n", [exc]))
|
endBlock(p, ropecg(p.module, "} catch (NimException& $1) {$n", [exc]))
|
||||||
if optStackTrace in p.Options:
|
if optStackTrace in p.Options:
|
||||||
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
lineCg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
||||||
inc p.inExceptBlock
|
inc p.inExceptBlock
|
||||||
i = 1
|
i = 1
|
||||||
var catchAllPresent = false
|
var catchAllPresent = false
|
||||||
|
|
@ -582,22 +582,22 @@ proc genTryStmtCpp(p: BProc, t: PNode) =
|
||||||
appcg(p.module, orExpr,
|
appcg(p.module, orExpr,
|
||||||
"#isObj($1.exp->m_type, $2)",
|
"#isObj($1.exp->m_type, $2)",
|
||||||
[exc, genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
[exc, genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
||||||
appf(p.s(cpsStmts), "if ($1) ", [orExpr])
|
lineF(p, cpsStmts, "if ($1) ", [orExpr])
|
||||||
genSimpleBlock(p, t.sons[i].sons[blen-1])
|
genSimpleBlock(p, t.sons[i].sons[blen-1])
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
# reraise the exception if there was no catch all
|
# reraise the exception if there was no catch all
|
||||||
# and none of the handlers matched
|
# and none of the handlers matched
|
||||||
if not catchAllPresent:
|
if not catchAllPresent:
|
||||||
if i > 1: appf(p.s(cpsStmts), "else ")
|
if i > 1: lineF(p, cpsStmts, "else ")
|
||||||
startBlock(p)
|
startBlock(p)
|
||||||
var finallyBlock = t.lastSon
|
var finallyBlock = t.lastSon
|
||||||
if finallyBlock.kind == nkFinally:
|
if finallyBlock.kind == nkFinally:
|
||||||
genStmts(p, finallyBlock.sons[0])
|
genStmts(p, finallyBlock.sons[0])
|
||||||
appcg(p, cpsStmts, "throw;$n")
|
lineCg(p, cpsStmts, "throw;$n")
|
||||||
endBlock(p)
|
endBlock(p)
|
||||||
|
|
||||||
appf(p.s(cpsStmts), "}$n") # end of catch block
|
lineF(p, cpsStmts, "}$n") # end of catch block
|
||||||
dec p.inExceptBlock
|
dec p.inExceptBlock
|
||||||
|
|
||||||
discard pop(p.nestedTryStmts)
|
discard pop(p.nestedTryStmts)
|
||||||
|
|
@ -636,27 +636,30 @@ proc genTryStmt(p: BProc, t: PNode) =
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
var safePoint = getTempName()
|
var safePoint = getTempName()
|
||||||
discard cgsym(p.module, "E_Base")
|
discard cgsym(p.module, "E_Base")
|
||||||
appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
|
lineCg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
|
||||||
appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" &
|
lineCg(p, cpsStmts, "#pushSafePoint(&$1);$n", [safePoint])
|
||||||
"$1.status = setjmp($1.context);$n", [safePoint])
|
lineF(p, cpsStmts, "$1.status = setjmp($1.context);$n", [safePoint])
|
||||||
startBlock(p, "if ($1.status == 0) {$n", [safePoint])
|
startBlock(p, "if ($1.status == 0) {$n", [safePoint])
|
||||||
var length = sonsLen(t)
|
var length = sonsLen(t)
|
||||||
add(p.nestedTryStmts, t)
|
add(p.nestedTryStmts, t)
|
||||||
genStmts(p, t.sons[0])
|
genStmts(p, t.sons[0])
|
||||||
endBlock(p, ropecg(p.module, "#popSafePoint();$n } else {$n#popSafePoint();$n"))
|
linecg(p, cpsStmts, "#popSafePoint();$n")
|
||||||
|
endBlock(p)
|
||||||
|
startBlock(p, "else {$n")
|
||||||
|
lineCg(p, cpsStmts, "#popSafePoint();$n")
|
||||||
if optStackTrace in p.Options:
|
if optStackTrace in p.Options:
|
||||||
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
lineCg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
|
||||||
inc p.inExceptBlock
|
inc p.inExceptBlock
|
||||||
var i = 1
|
var i = 1
|
||||||
while (i < length) and (t.sons[i].kind == nkExceptBranch):
|
while (i < length) and (t.sons[i].kind == nkExceptBranch):
|
||||||
var blen = sonsLen(t.sons[i])
|
var blen = sonsLen(t.sons[i])
|
||||||
if blen == 1:
|
if blen == 1:
|
||||||
# general except section:
|
# general except section:
|
||||||
if i > 1: appf(p.s(cpsStmts), "else")
|
if i > 1: lineF(p, cpsStmts, "else")
|
||||||
startBlock(p)
|
startBlock(p)
|
||||||
appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
lineCg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
||||||
genStmts(p, t.sons[i].sons[0])
|
genStmts(p, t.sons[i].sons[0])
|
||||||
appcg(p, cpsStmts, "#popCurrentException();$n", [])
|
lineCg(p, cpsStmts, "#popCurrentException();$n")
|
||||||
endBlock(p)
|
endBlock(p)
|
||||||
else:
|
else:
|
||||||
var orExpr: PRope = nil
|
var orExpr: PRope = nil
|
||||||
|
|
@ -666,18 +669,19 @@ proc genTryStmt(p: BProc, t: PNode) =
|
||||||
appcg(p.module, orExpr,
|
appcg(p.module, orExpr,
|
||||||
"#isObj(#getCurrentException()->Sup.m_type, $1)",
|
"#isObj(#getCurrentException()->Sup.m_type, $1)",
|
||||||
[genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
[genTypeInfo(p.module, t.sons[i].sons[j].typ)])
|
||||||
if i > 1: app(p.s(cpsStmts), "else ")
|
if i > 1: line(p, cpsStmts, "else ")
|
||||||
startBlock(p, "if ($1) {$n", [orExpr])
|
startBlock(p, "if ($1) {$n", [orExpr])
|
||||||
appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
lineCg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
|
||||||
genStmts(p, t.sons[i].sons[blen-1])
|
genStmts(p, t.sons[i].sons[blen-1])
|
||||||
endBlock(p, ropecg(p.module, "#popCurrentException();}$n"))
|
lineCg(p, cpsStmts, "#popCurrentException();$n")
|
||||||
|
endBlock(p)
|
||||||
inc(i)
|
inc(i)
|
||||||
dec p.inExceptBlock
|
dec p.inExceptBlock
|
||||||
discard pop(p.nestedTryStmts)
|
discard pop(p.nestedTryStmts)
|
||||||
appf(p.s(cpsStmts), "}$n") # end of else block
|
endBlock(p) # end of else block
|
||||||
if i < length and t.sons[i].kind == nkFinally:
|
if i < length and t.sons[i].kind == nkFinally:
|
||||||
genSimpleBlock(p, t.sons[i].sons[0])
|
genSimpleBlock(p, t.sons[i].sons[0])
|
||||||
appcg(p, cpsStmts, "if ($1.status != 0) #reraiseException();$n", [safePoint])
|
lineCg(p, cpsStmts, "if ($1.status != 0) #reraiseException();$n", [safePoint])
|
||||||
|
|
||||||
proc genAsmOrEmitStmt(p: BProc, t: PNode): PRope =
|
proc genAsmOrEmitStmt(p: BProc, t: PNode): PRope =
|
||||||
for i in countup(0, sonsLen(t) - 1):
|
for i in countup(0, sonsLen(t) - 1):
|
||||||
|
|
@ -704,7 +708,7 @@ proc genAsmStmt(p: BProc, t: PNode) =
|
||||||
assert(t.kind == nkAsmStmt)
|
assert(t.kind == nkAsmStmt)
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
var s = genAsmOrEmitStmt(p, t)
|
var s = genAsmOrEmitStmt(p, t)
|
||||||
appf(p.s(cpsStmts), CC[ccompiler].asmStmtFrmt, [s])
|
lineF(p, cpsStmts, CC[ccompiler].asmStmtFrmt, [s])
|
||||||
|
|
||||||
proc genEmit(p: BProc, t: PNode) =
|
proc genEmit(p: BProc, t: PNode) =
|
||||||
genLineDir(p, t)
|
genLineDir(p, t)
|
||||||
|
|
@ -713,7 +717,7 @@ proc genEmit(p: BProc, t: PNode) =
|
||||||
# top level emit pragma?
|
# top level emit pragma?
|
||||||
app(p.module.s[cfsProcHeaders], s)
|
app(p.module.s[cfsProcHeaders], s)
|
||||||
else:
|
else:
|
||||||
app(p.s(cpsStmts), s)
|
line(p, cpsStmts, s)
|
||||||
|
|
||||||
var
|
var
|
||||||
breakPointId: int = 0
|
breakPointId: int = 0
|
||||||
|
|
@ -739,7 +743,7 @@ proc genWatchpoint(p: BProc, n: PNode) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, n.sons[1], a)
|
initLocExpr(p, n.sons[1], a)
|
||||||
let typ = skipTypes(n.sons[1].typ, abstractVarRange)
|
let typ = skipTypes(n.sons[1].typ, abstractVarRange)
|
||||||
appcg(p, cpsStmts, "#dbgRegisterWatchpoint($1, (NCSTRING)$2, $3);$n",
|
lineCg(p, cpsStmts, "#dbgRegisterWatchpoint($1, (NCSTRING)$2, $3);$n",
|
||||||
[a.addrLoc, makeCString(renderTree(n.sons[1])),
|
[a.addrLoc, makeCString(renderTree(n.sons[1])),
|
||||||
genTypeInfo(p.module, typ)])
|
genTypeInfo(p.module, typ)])
|
||||||
|
|
||||||
|
|
@ -779,7 +783,7 @@ proc genDiscriminantCheck(p: BProc, a, tmp: TLoc, objtype: PType,
|
||||||
if not ContainsOrIncl(p.module.declaredThings, field.id):
|
if not ContainsOrIncl(p.module.declaredThings, field.id):
|
||||||
appcg(p.module, cfsVars, "extern $1",
|
appcg(p.module, cfsVars, "extern $1",
|
||||||
discriminatorTableDecl(p.module, t, field))
|
discriminatorTableDecl(p.module, t, field))
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"#FieldDiscriminantCheck((NI)(NU)($1), (NI)(NU)($2), $3, $4);$n",
|
"#FieldDiscriminantCheck((NI)(NU)($1), (NI)(NU)($2), $3, $4);$n",
|
||||||
[rdLoc(a), rdLoc(tmp), discriminatorTableName(p.module, t, field),
|
[rdLoc(a), rdLoc(tmp), discriminatorTableName(p.module, t, field),
|
||||||
intLiteral(L+1)])
|
intLiteral(L+1)])
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,8 @@ proc AccessThreadLocalVar(p: BProc, s: PSym) =
|
||||||
if emulatedThreadVars() and not p.ThreadVarAccessed:
|
if emulatedThreadVars() and not p.ThreadVarAccessed:
|
||||||
p.ThreadVarAccessed = true
|
p.ThreadVarAccessed = true
|
||||||
p.module.usesThreadVars = true
|
p.module.usesThreadVars = true
|
||||||
appf(p.procSec(cpsLocals), "NimThreadVars* NimTV;$n")
|
lineF(p, cpsLocals, "NimThreadVars* NimTV;$n")
|
||||||
app(p.procSec(cpsInit),
|
lineCg(p, cpsInit, "NimTV = (NimThreadVars*) #GetThreadLocalVars();$n")
|
||||||
ropecg(p.module, "NimTV=(NimThreadVars*)#GetThreadLocalVars();$n"))
|
|
||||||
|
|
||||||
var
|
var
|
||||||
nimtv: PRope # nimrod thread vars; the struct body
|
nimtv: PRope # nimrod thread vars; the struct body
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,17 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: PRope, n: PNode) =
|
||||||
if (n.sons[0].kind != nkSym): InternalError(n.info, "genTraverseProc")
|
if (n.sons[0].kind != nkSym): InternalError(n.info, "genTraverseProc")
|
||||||
var p = c.p
|
var p = c.p
|
||||||
let disc = n.sons[0].sym
|
let disc = n.sons[0].sym
|
||||||
p.s(cpsStmts).appf("switch ($1.$2) {$n", accessor, disc.loc.r)
|
lineF(p, cpsStmts, "switch ($1.$2) {$n", accessor, disc.loc.r)
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
let branch = n.sons[i]
|
let branch = n.sons[i]
|
||||||
assert branch.kind in {nkOfBranch, nkElse}
|
assert branch.kind in {nkOfBranch, nkElse}
|
||||||
if branch.kind == nkOfBranch:
|
if branch.kind == nkOfBranch:
|
||||||
genCaseRange(c.p, branch)
|
genCaseRange(c.p, branch)
|
||||||
else:
|
else:
|
||||||
p.s(cpsStmts).appf("default:$n")
|
lineF(p, cpsStmts, "default:$n")
|
||||||
genTraverseProc(c, accessor, lastSon(branch))
|
genTraverseProc(c, accessor, lastSon(branch))
|
||||||
p.s(cpsStmts).appf("break;$n")
|
lineF(p, cpsStmts, "break;$n")
|
||||||
p.s(cpsStmts).appf("} $n")
|
lineF(p, cpsStmts, "} $n")
|
||||||
of nkSym:
|
of nkSym:
|
||||||
let field = n.sym
|
let field = n.sym
|
||||||
genTraverseProc(c, ropef("$1.$2", accessor, field.loc.r), field.loc.t)
|
genTraverseProc(c, ropef("$1.$2", accessor, field.loc.r), field.loc.t)
|
||||||
|
|
@ -63,10 +63,10 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: PRope, typ: PType) =
|
||||||
let arraySize = lengthOrd(typ.sons[0])
|
let arraySize = lengthOrd(typ.sons[0])
|
||||||
var i: TLoc
|
var i: TLoc
|
||||||
getTemp(p, getSysType(tyInt), i)
|
getTemp(p, getSysType(tyInt), i)
|
||||||
appf(p.s(cpsStmts), "for ($1 = 0; $1 < $2; $1++) {$n",
|
lineF(p, cpsStmts, "for ($1 = 0; $1 < $2; $1++) {$n",
|
||||||
i.r, arraySize.toRope)
|
i.r, arraySize.toRope)
|
||||||
genTraverseProc(c, ropef("$1[$2]", accessor, i.r), typ.sons[1])
|
genTraverseProc(c, ropef("$1[$2]", accessor, i.r), typ.sons[1])
|
||||||
appf(p.s(cpsStmts), "}$n")
|
lineF(p, cpsStmts, "}$n")
|
||||||
of tyObject:
|
of tyObject:
|
||||||
for i in countup(0, sonsLen(typ) - 1):
|
for i in countup(0, sonsLen(typ) - 1):
|
||||||
genTraverseProc(c, accessor.parentObj, typ.sons[i])
|
genTraverseProc(c, accessor.parentObj, typ.sons[i])
|
||||||
|
|
@ -79,7 +79,7 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: PRope, typ: PType) =
|
||||||
for i in countup(0, sonsLen(typ) - 1):
|
for i in countup(0, sonsLen(typ) - 1):
|
||||||
genTraverseProc(c, ropef("$1.Field$2", accessor, i.toRope), typ.sons[i])
|
genTraverseProc(c, ropef("$1.Field$2", accessor, i.toRope), typ.sons[i])
|
||||||
of tyRef, tyString, tySequence:
|
of tyRef, tyString, tySequence:
|
||||||
appcg(p, cpsStmts, c.visitorFrmt, accessor)
|
lineCg(p, cpsStmts, c.visitorFrmt, accessor)
|
||||||
else:
|
else:
|
||||||
# no marker procs for closures yet
|
# no marker procs for closures yet
|
||||||
nil
|
nil
|
||||||
|
|
@ -89,10 +89,10 @@ proc genTraverseProcSeq(c: var TTraversalClosure, accessor: PRope, typ: PType) =
|
||||||
assert typ.kind == tySequence
|
assert typ.kind == tySequence
|
||||||
var i: TLoc
|
var i: TLoc
|
||||||
getTemp(p, getSysType(tyInt), i)
|
getTemp(p, getSysType(tyInt), i)
|
||||||
appf(p.s(cpsStmts), "for ($1 = 0; $1 < $2->$3; $1++) {$n",
|
lineF(p, cpsStmts, "for ($1 = 0; $1 < $2->$3; $1++) {$n",
|
||||||
i.r, accessor, toRope(if gCmd != cmdCompileToCpp: "Sup.len" else: "len"))
|
i.r, accessor, toRope(if gCmd != cmdCompileToCpp: "Sup.len" else: "len"))
|
||||||
genTraverseProc(c, ropef("$1->data[$2]", accessor, i.r), typ.sons[0])
|
genTraverseProc(c, ropef("$1->data[$2]", accessor, i.r), typ.sons[0])
|
||||||
appf(p.s(cpsStmts), "}$n")
|
lineF(p, cpsStmts, "}$n")
|
||||||
|
|
||||||
proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): PRope =
|
proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): PRope =
|
||||||
var c: TTraversalClosure
|
var c: TTraversalClosure
|
||||||
|
|
@ -106,8 +106,8 @@ proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): PRope =
|
||||||
let header = ropef("N_NIMCALL(void, $1)(void* p, NI op)", result)
|
let header = ropef("N_NIMCALL(void, $1)(void* p, NI op)", result)
|
||||||
|
|
||||||
let t = getTypeDesc(m, typ)
|
let t = getTypeDesc(m, typ)
|
||||||
p.s(cpsLocals).appf("$1 a;$n", t)
|
lineF(p, cpsLocals, "$1 a;$n", t)
|
||||||
p.s(cpsInit).appf("a = ($1)p;$n", t)
|
lineF(p, cpsInit, "a = ($1)p;$n", t)
|
||||||
|
|
||||||
c.p = p
|
c.p = p
|
||||||
if typ.kind == tySequence:
|
if typ.kind == tySequence:
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,34 @@ proc appcg(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||||
args: openarray[PRope]) =
|
args: openarray[PRope]) =
|
||||||
app(p.s(s), ropecg(p.module, frmt, args))
|
app(p.s(s), ropecg(p.module, frmt, args))
|
||||||
|
|
||||||
|
var indent = "\t".toRope
|
||||||
|
proc indentLine(p: BProc, r: PRope): PRope =
|
||||||
|
result = r
|
||||||
|
for i in countup(0, p.blocks.len-1): prepend(result, indent)
|
||||||
|
|
||||||
|
proc line(p: BProc, s: TCProcSection, r: PRope) =
|
||||||
|
app(p.s(s), indentLine(p, r))
|
||||||
|
|
||||||
|
proc line(p: BProc, s: TCProcSection, r: string) =
|
||||||
|
app(p.s(s), indentLine(p, r.toRope))
|
||||||
|
|
||||||
|
proc lineF(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||||
|
args: openarray[PRope]) =
|
||||||
|
app(p.s(s), indentLine(p, ropef(frmt, args)))
|
||||||
|
|
||||||
|
proc lineCg(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||||
|
args: openarray[PRope]) =
|
||||||
|
app(p.s(s), indentLine(p, ropecg(p.module, frmt, args)))
|
||||||
|
|
||||||
|
proc appLineCg(p: BProc, r: var PRope, frmt: TFormatStr,
|
||||||
|
args: openarray[PRope]) =
|
||||||
|
app(r, indentLine(p, ropecg(p.module, frmt, args)))
|
||||||
|
|
||||||
|
proc lineFF(p: BProc, s: TCProcSection, cformat, llvmformat: string,
|
||||||
|
args: openarray[PRope]) =
|
||||||
|
if gCmd == cmdCompileToLLVM: lineF(p, s, llvmformat, args)
|
||||||
|
else: lineF(p, s, cformat, args)
|
||||||
|
|
||||||
proc safeLineNm(info: TLineInfo): int =
|
proc safeLineNm(info: TLineInfo): int =
|
||||||
result = toLinenumber(info)
|
result = toLinenumber(info)
|
||||||
if result < 0: result = 0 # negative numbers are not allowed in #line
|
if result < 0: result = 0 # negative numbers are not allowed in #line
|
||||||
|
|
@ -171,11 +199,11 @@ proc genLineDir(p: BProc, t: PNode) =
|
||||||
genCLineDir(p.s(cpsStmts), t.info.toFullPath, line)
|
genCLineDir(p.s(cpsStmts), t.info.toFullPath, line)
|
||||||
if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and
|
if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags):
|
(p.prc == nil or sfPure notin p.prc.flags):
|
||||||
appcg(p, cpsStmts, "#endb($1);$n", [toRope(line)])
|
lineCg(p, cpsStmts, "#endb($1);$n", [toRope(line)])
|
||||||
elif ({optLineTrace, optStackTrace} * p.Options ==
|
elif ({optLineTrace, optStackTrace} * p.Options ==
|
||||||
{optLineTrace, optStackTrace}) and
|
{optLineTrace, optStackTrace}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags):
|
(p.prc == nil or sfPure notin p.prc.flags):
|
||||||
appf(p.s(cpsStmts), "F.line = $1;F.filename = $2;$n",
|
lineF(p, cpsStmts, "F.line = $1;F.filename = $2;$n",
|
||||||
[toRope(line), makeCString(toFilename(t.info).extractFilename)])
|
[toRope(line), makeCString(toFilename(t.info).extractFilename)])
|
||||||
|
|
||||||
include "ccgtypes.nim"
|
include "ccgtypes.nim"
|
||||||
|
|
@ -211,11 +239,11 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
|
||||||
while (s.kind == tyObject) and (s.sons[0] != nil):
|
while (s.kind == tyObject) and (s.sons[0] != nil):
|
||||||
app(r, ".Sup")
|
app(r, ".Sup")
|
||||||
s = skipTypes(s.sons[0], abstractInst)
|
s = skipTypes(s.sons[0], abstractInst)
|
||||||
appcg(p, section, "$1.m_type = $2;$n", [r, genTypeInfo(p.module, t)])
|
lineCg(p, section, "$1.m_type = $2;$n", [r, genTypeInfo(p.module, t)])
|
||||||
of frEmbedded:
|
of frEmbedded:
|
||||||
# worst case for performance:
|
# worst case for performance:
|
||||||
var r = if takeAddr: addrLoc(a) else: rdLoc(a)
|
var r = if takeAddr: addrLoc(a) else: rdLoc(a)
|
||||||
appcg(p, section, "#objectInit($1, $2);$n", [r, genTypeInfo(p.module, t)])
|
lineCg(p, section, "#objectInit($1, $2);$n", [r, genTypeInfo(p.module, t)])
|
||||||
|
|
||||||
type
|
type
|
||||||
TAssignmentFlag = enum
|
TAssignmentFlag = enum
|
||||||
|
|
@ -238,16 +266,16 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
nilLoc.r = toRope("NIM_NIL")
|
nilLoc.r = toRope("NIM_NIL")
|
||||||
genRefAssign(p, loc, nilLoc, {afSrcIsNil})
|
genRefAssign(p, loc, nilLoc, {afSrcIsNil})
|
||||||
else:
|
else:
|
||||||
appf(p.s(cpsStmts), "$1 = 0;$n", [rdLoc(loc)])
|
lineF(p, cpsStmts, "$1 = 0;$n", [rdLoc(loc)])
|
||||||
else:
|
else:
|
||||||
if loc.s != OnStack:
|
if loc.s != OnStack:
|
||||||
appcg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
lineCg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
||||||
[addrLoc(loc), genTypeInfo(p.module, loc.t)])
|
[addrLoc(loc), genTypeInfo(p.module, loc.t)])
|
||||||
# XXX: generated reset procs should not touch the m_type
|
# XXX: generated reset procs should not touch the m_type
|
||||||
# field, so disabling this should be safe:
|
# field, so disabling this should be safe:
|
||||||
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
genObjectInit(p, cpsStmts, loc.t, loc, true)
|
||||||
else:
|
else:
|
||||||
appf(p.s(cpsStmts), "memset((void*)$1, 0, sizeof($2));$n",
|
lineF(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n",
|
||||||
[addrLoc(loc), rdLoc(loc)])
|
[addrLoc(loc), rdLoc(loc)])
|
||||||
# XXX: We can be extra clever here and call memset only
|
# XXX: We can be extra clever here and call memset only
|
||||||
# on the bytes following the m_type field?
|
# on the bytes following the m_type field?
|
||||||
|
|
@ -255,9 +283,9 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
|
|
||||||
proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) =
|
proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) =
|
||||||
if not isComplexValueType(skipTypes(loc.t, abstractVarRange)):
|
if not isComplexValueType(skipTypes(loc.t, abstractVarRange)):
|
||||||
appf(p.s(section), "$1 = 0;$n", [rdLoc(loc)])
|
lineF(p, section, "$1 = 0;$n", [rdLoc(loc)])
|
||||||
else:
|
else:
|
||||||
appf(p.s(section), "memset((void*)$1, 0, sizeof($2));$n",
|
lineF(p, section, "memset((void*)$1, 0, sizeof($2));$n",
|
||||||
[addrLoc(loc), rdLoc(loc)])
|
[addrLoc(loc), rdLoc(loc)])
|
||||||
genObjectInit(p, section, loc.t, loc, true)
|
genObjectInit(p, section, loc.t, loc, true)
|
||||||
|
|
||||||
|
|
@ -285,7 +313,7 @@ proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
||||||
result.r = con("%LOC", toRope(p.labels))
|
result.r = con("%LOC", toRope(p.labels))
|
||||||
else:
|
else:
|
||||||
result.r = con("LOC", toRope(p.labels))
|
result.r = con("LOC", toRope(p.labels))
|
||||||
appf(p.s(cpsLocals), "$1 $2;$n", [getTypeDesc(p.module, t), result.r])
|
lineF(p, cpsLocals, "$1 $2;$n", [getTypeDesc(p.module, t), result.r])
|
||||||
result.k = locTemp
|
result.k = locTemp
|
||||||
result.a = - 1
|
result.a = - 1
|
||||||
result.t = getUniqueType(t)
|
result.t = getUniqueType(t)
|
||||||
|
|
@ -311,9 +339,9 @@ proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
|
|
||||||
if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)):
|
if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)):
|
||||||
appf(p.s[cpsStmts], "$1 = $2;$n", [rdLoc(result), rdLoc(toKeepAlive)])
|
lineF(p, cpsStmts, "$1 = $2;$n", [rdLoc(result), rdLoc(toKeepAlive)])
|
||||||
else:
|
else:
|
||||||
appcg(p, cpsStmts,
|
lineCg(p, cpsStmts,
|
||||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||||
[addrLoc(result), addrLoc(toKeepAlive), rdLoc(result)])
|
[addrLoc(result), addrLoc(toKeepAlive), rdLoc(result)])
|
||||||
|
|
||||||
|
|
@ -355,7 +383,7 @@ proc allocParam(p: BProc, s: PSym) =
|
||||||
var tmp = con("%LOC", toRope(p.labels))
|
var tmp = con("%LOC", toRope(p.labels))
|
||||||
incl(s.loc.flags, lfParamCopy)
|
incl(s.loc.flags, lfParamCopy)
|
||||||
incl(s.loc.flags, lfIndirect)
|
incl(s.loc.flags, lfIndirect)
|
||||||
appf(p.s(cpsInit), "$1 = alloca $3$n" & "store $3 $2, $3* $1$n",
|
lineF(p, cpsInit, "$1 = alloca $3$n" & "store $3 $2, $3* $1$n",
|
||||||
[tmp, s.loc.r, getTypeDesc(p.module, s.loc.t)])
|
[tmp, s.loc.r, getTypeDesc(p.module, s.loc.t)])
|
||||||
s.loc.r = tmp
|
s.loc.r = tmp
|
||||||
|
|
||||||
|
|
@ -365,7 +393,7 @@ proc localDebugInfo(p: BProc, s: PSym) =
|
||||||
if skipTypes(s.typ, abstractVar).kind == tyOpenArray: return
|
if skipTypes(s.typ, abstractVar).kind == tyOpenArray: return
|
||||||
var a = con("&", s.loc.r)
|
var a = con("&", s.loc.r)
|
||||||
if (s.kind == skParam) and ccgIntroducedPtr(s): a = s.loc.r
|
if (s.kind == skParam) and ccgIntroducedPtr(s): a = s.loc.r
|
||||||
appf(p.s(cpsInit),
|
lineF(p, cpsInit,
|
||||||
"F.s[$1].address = (void*)$3; F.s[$1].typ = $4; F.s[$1].name = $2;$n",
|
"F.s[$1].address = (void*)$3; F.s[$1].typ = $4; F.s[$1].name = $2;$n",
|
||||||
[toRope(p.frameLen), makeCString(normalize(s.name.s)), a,
|
[toRope(p.frameLen), makeCString(normalize(s.name.s)), a,
|
||||||
genTypeInfo(p.module, s.loc.t)])
|
genTypeInfo(p.module, s.loc.t)])
|
||||||
|
|
@ -378,13 +406,14 @@ proc assignLocalVar(p: BProc, s: PSym) =
|
||||||
if s.loc.k == locNone:
|
if s.loc.k == locNone:
|
||||||
fillLoc(s.loc, locLocalVar, s.typ, mangleName(s), OnStack)
|
fillLoc(s.loc, locLocalVar, s.typ, mangleName(s), OnStack)
|
||||||
if s.kind == skLet: incl(s.loc.flags, lfNoDeepCopy)
|
if s.kind == skLet: incl(s.loc.flags, lfNoDeepCopy)
|
||||||
app(p.s(cpsLocals), getTypeDesc(p.module, s.loc.t))
|
var decl = getTypeDesc(p.module, s.loc.t)
|
||||||
if sfRegister in s.flags: app(p.s(cpsLocals), " register")
|
if sfRegister in s.flags: app(decl, " register")
|
||||||
#elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds:
|
#elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds:
|
||||||
# app(p.s[cpsLocals], " GC_GUARD")
|
# app(decl, " GC_GUARD")
|
||||||
if (sfVolatile in s.flags) or (p.nestedTryStmts.len > 0):
|
if (sfVolatile in s.flags) or (p.nestedTryStmts.len > 0):
|
||||||
app(p.s(cpsLocals), " volatile")
|
app(decl, " volatile")
|
||||||
appf(p.s(cpsLocals), " $1;$n", [s.loc.r])
|
appf(decl, " $1;$n", [s.loc.r])
|
||||||
|
line(p, cpsLocals, decl)
|
||||||
localDebugInfo(p, s)
|
localDebugInfo(p, s)
|
||||||
|
|
||||||
include ccgthreadvars
|
include ccgthreadvars
|
||||||
|
|
@ -427,7 +456,7 @@ proc getLabel(p: BProc): TLabel =
|
||||||
result = con("LA", toRope(p.labels))
|
result = con("LA", toRope(p.labels))
|
||||||
|
|
||||||
proc fixLabel(p: BProc, labl: TLabel) =
|
proc fixLabel(p: BProc, labl: TLabel) =
|
||||||
appf(p.s(cpsStmts), "$1: ;$n", [labl])
|
lineF(p, cpsStmts, "$1: ;$n", [labl])
|
||||||
|
|
||||||
proc genVarPrototype(m: BModule, sym: PSym)
|
proc genVarPrototype(m: BModule, sym: PSym)
|
||||||
proc requestConstImpl(p: BProc, sym: PSym)
|
proc requestConstImpl(p: BProc, sym: PSym)
|
||||||
|
|
@ -545,28 +574,28 @@ proc getFrameDecl(p: BProc) =
|
||||||
[toRope(p.frameLen)])
|
[toRope(p.frameLen)])
|
||||||
else:
|
else:
|
||||||
slots = nil
|
slots = nil
|
||||||
appff(p.s(cpsLocals), "volatile struct {TFrame* prev;" &
|
lineFF(p, cpsLocals, "volatile struct {TFrame* prev;" &
|
||||||
"NCSTRING procname;NI line;NCSTRING filename;" &
|
"NCSTRING procname;NI line;NCSTRING filename;" &
|
||||||
"NI len;$n$1} F;$n",
|
"NI len;$1} F;$n",
|
||||||
"%TF = type {%TFrame*, i8*, %NI, %NI$1}$n" &
|
"%TF = type {%TFrame*, i8*, %NI, %NI$1}$n" &
|
||||||
"%F = alloca %TF$n", [slots])
|
"%F = alloca %TF$n", [slots])
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
prepend(p.s(cpsInit), ropeff("F.len = $1;$n",
|
prepend(p.s(cpsInit), indentLine(p, ropeff("F.len = $1;$n",
|
||||||
"%LOC$2 = getelementptr %TF %F, %NI 4$n" &
|
"%LOC$2 = getelementptr %TF %F, %NI 4$n" &
|
||||||
"store %NI $1, %NI* %LOC$2$n", [toRope(p.frameLen), toRope(p.labels)]))
|
"store %NI $1, %NI* %LOC$2$n", [toRope(p.frameLen), toRope(p.labels)])))
|
||||||
|
|
||||||
proc retIsNotVoid(s: PSym): bool =
|
proc retIsNotVoid(s: PSym): bool =
|
||||||
result = (s.typ.sons[0] != nil) and not isInvalidReturnType(s.typ.sons[0])
|
result = (s.typ.sons[0] != nil) and not isInvalidReturnType(s.typ.sons[0])
|
||||||
|
|
||||||
proc initFrame(p: BProc, procname, filename: PRope): PRope =
|
proc initFrame(p: BProc, procname, filename: PRope): PRope =
|
||||||
result = ropecg(p.module,
|
result = ropecg(p.module,
|
||||||
"F.procname = $1;$n" &
|
"\tF.procname = $1;$n" &
|
||||||
"F.filename = $2;$n" &
|
"\tF.filename = $2;$n" &
|
||||||
"F.line = 0;$n" &
|
"\tF.line = 0;$n" &
|
||||||
"#pushFrame((TFrame*)&F);$n", [procname, filename])
|
"\t#pushFrame((TFrame*)&F);$n", [procname, filename])
|
||||||
|
|
||||||
proc deinitFrame(p: BProc): PRope =
|
proc deinitFrame(p: BProc): PRope =
|
||||||
result = ropecg(p.module, "#popFrame();$n")
|
result = ropecg(p.module, "\t#popFrame();$n")
|
||||||
|
|
||||||
proc closureSetup(p: BProc, prc: PSym) =
|
proc closureSetup(p: BProc, prc: PSym) =
|
||||||
if prc.typ.callConv != ccClosure: return
|
if prc.typ.callConv != ccClosure: return
|
||||||
|
|
@ -575,7 +604,7 @@ proc closureSetup(p: BProc, prc: PSym) =
|
||||||
#echo "created environment: ", env.id, " for ", prc.name.s
|
#echo "created environment: ", env.id, " for ", prc.name.s
|
||||||
assignLocalVar(p, env)
|
assignLocalVar(p, env)
|
||||||
# generate cast assignment:
|
# generate cast assignment:
|
||||||
appcg(p, cpsStmts, "$1 = ($2) ClEnv;$n", rdLoc(env.loc),
|
lineCg(p, cpsStmts, "$1 = ($2) ClEnv;$n", rdLoc(env.loc),
|
||||||
getTypeDesc(p.module, env.typ))
|
getTypeDesc(p.module, env.typ))
|
||||||
|
|
||||||
proc genProcAux(m: BModule, prc: PSym) =
|
proc genProcAux(m: BModule, prc: PSym) =
|
||||||
|
|
@ -590,7 +619,7 @@ proc genProcAux(m: BModule, prc: PSym) =
|
||||||
# declare the result symbol:
|
# declare the result symbol:
|
||||||
assignLocalVar(p, res)
|
assignLocalVar(p, res)
|
||||||
assert(res.loc.r != nil)
|
assert(res.loc.r != nil)
|
||||||
returnStmt = ropeff("return $1;$n", "ret $1$n", [rdLoc(res.loc)])
|
returnStmt = ropeff("\treturn $1;$n", "ret $1$n", [rdLoc(res.loc)])
|
||||||
initLocalVar(p, res, immediateAsgn=false)
|
initLocalVar(p, res, immediateAsgn=false)
|
||||||
else:
|
else:
|
||||||
fillResult(res)
|
fillResult(res)
|
||||||
|
|
@ -606,10 +635,10 @@ proc genProcAux(m: BModule, prc: PSym) =
|
||||||
genStmts(p, prc.getBody) # modifies p.locals, p.init, etc.
|
genStmts(p, prc.getBody) # modifies p.locals, p.init, etc.
|
||||||
var generatedProc: PRope
|
var generatedProc: PRope
|
||||||
if sfPure in prc.flags:
|
if sfPure in prc.flags:
|
||||||
generatedProc = ropeff("$1 {$n$2$3$4}$n", "define $1 {$n$2$3$4}$n",
|
generatedProc = ropeff("$N$1 {$n$2$3$4}$N$N", "define $1 {$n$2$3$4}$N",
|
||||||
[header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
|
[header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
|
||||||
else:
|
else:
|
||||||
generatedProc = ropeff("$1 {$n", "define $1 {$n", [header])
|
generatedProc = ropeff("$N$1 {$N", "$Ndefine $1 {$N", [header])
|
||||||
app(generatedProc, initGCFrame(p))
|
app(generatedProc, initGCFrame(p))
|
||||||
if optStackTrace in prc.options:
|
if optStackTrace in prc.options:
|
||||||
getFrameDecl(p)
|
getFrameDecl(p)
|
||||||
|
|
@ -623,25 +652,25 @@ proc genProcAux(m: BModule, prc: PSym) =
|
||||||
if gProcProfile >= 64 * 1024:
|
if gProcProfile >= 64 * 1024:
|
||||||
InternalError(prc.info, "too many procedures for profiling")
|
InternalError(prc.info, "too many procedures for profiling")
|
||||||
discard cgsym(m, "profileData")
|
discard cgsym(m, "profileData")
|
||||||
appf(p.s(cpsLocals), "ticks NIM_profilingStart;$n")
|
appf(p.s(cpsLocals), "\tticks NIM_profilingStart;$n")
|
||||||
if prc.loc.a < 0:
|
if prc.loc.a < 0:
|
||||||
appf(m.s[cfsDebugInit], "profileData[$1].procname = $2;$n", [
|
appf(m.s[cfsDebugInit], "\tprofileData[$1].procname = $2;$n", [
|
||||||
toRope(gProcProfile),
|
toRope(gProcProfile),
|
||||||
makeCString(prc.name.s)])
|
makeCString(prc.name.s)])
|
||||||
prc.loc.a = gProcProfile
|
prc.loc.a = gProcProfile
|
||||||
inc(gProcProfile)
|
inc(gProcProfile)
|
||||||
prepend(p.s(cpsInit), ropef("NIM_profilingStart = getticks();$n"))
|
prepend(p.s(cpsInit), ropef("\tNIM_profilingStart = getticks();$n"))
|
||||||
app(generatedProc, p.s(cpsInit))
|
app(generatedProc, p.s(cpsInit))
|
||||||
app(generatedProc, p.s(cpsStmts))
|
app(generatedProc, p.s(cpsStmts))
|
||||||
if p.beforeRetNeeded: appf(generatedProc, "BeforeRet: $n;")
|
if p.beforeRetNeeded: appf(generatedProc, "\tBeforeRet: ;$n")
|
||||||
app(generatedProc, deinitGCFrame(p))
|
app(generatedProc, deinitGCFrame(p))
|
||||||
if optStackTrace in prc.options: app(generatedProc, deinitFrame(p))
|
if optStackTrace in prc.options: app(generatedProc, deinitFrame(p))
|
||||||
if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM):
|
if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM):
|
||||||
appf(generatedProc,
|
appf(generatedProc,
|
||||||
"profileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n",
|
"\tprofileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n",
|
||||||
[toRope(prc.loc.a)])
|
[toRope(prc.loc.a)])
|
||||||
app(generatedProc, returnStmt)
|
app(generatedProc, returnStmt)
|
||||||
appf(generatedProc, "}$n")
|
appf(generatedProc, "}$N")
|
||||||
app(m.s[cfsProcs], generatedProc)
|
app(m.s[cfsProcs], generatedProc)
|
||||||
|
|
||||||
proc genProcPrototype(m: BModule, sym: PSym) =
|
proc genProcPrototype(m: BModule, sym: PSym) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue