distinguish between 'reorder' and 'noforward'
This commit is contained in:
parent
e00953cbc0
commit
50f62ff44a
5 changed files with 53 additions and 8 deletions
|
|
@ -292,6 +292,8 @@ const
|
||||||
|
|
||||||
sfNoForward* = sfRegister
|
sfNoForward* = sfRegister
|
||||||
# forward declarations are not required (per module)
|
# forward declarations are not required (per module)
|
||||||
|
sfReorder* = sfForward
|
||||||
|
# reordering pass is enabled
|
||||||
|
|
||||||
sfCompileToCpp* = sfInfixCall # compile the module as C++ code
|
sfCompileToCpp* = sfInfixCall # compile the module as C++ code
|
||||||
sfCompileToObjc* = sfNamedParamCall # compile the module as Objective-C code
|
sfCompileToObjc* = sfNamedParamCall # compile the module as Objective-C code
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream,
|
||||||
if graph.stopCompile(): break
|
if graph.stopCompile(): break
|
||||||
var n = parseTopLevelStmt(p)
|
var n = parseTopLevelStmt(p)
|
||||||
if n.kind == nkEmpty: break
|
if n.kind == nkEmpty: break
|
||||||
if sfNoForward in module.flags:
|
if {sfNoForward, sfReorder} * module.flags != {}:
|
||||||
# read everything, no streaming possible
|
# read everything, no streaming possible
|
||||||
var sl = newNodeI(nkStmtList, n.info)
|
var sl = newNodeI(nkStmtList, n.info)
|
||||||
sl.add n
|
sl.add n
|
||||||
|
|
@ -210,7 +210,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream,
|
||||||
var n = parseTopLevelStmt(p)
|
var n = parseTopLevelStmt(p)
|
||||||
if n.kind == nkEmpty: break
|
if n.kind == nkEmpty: break
|
||||||
sl.add n
|
sl.add n
|
||||||
if isDefined"nimreorder":
|
if sfReorder in module.flags:
|
||||||
sl = reorder sl
|
sl = reorder sl
|
||||||
discard processTopLevelStmt(sl, a)
|
discard processTopLevelStmt(sl, a)
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ const
|
||||||
wFatal, wDefine, wUndef, wCompile, wLink, wLinksys, wPure, wPush, wPop,
|
wFatal, wDefine, wUndef, wCompile, wLink, wLinksys, wPure, wPush, wPop,
|
||||||
wBreakpoint, wWatchPoint, wPassl, wPassc, wDeadCodeElim, wDeprecated,
|
wBreakpoint, wWatchPoint, wPassl, wPassc, wDeadCodeElim, wDeprecated,
|
||||||
wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
||||||
wLinearScanEnd, wPatterns, wEffects, wNoForward, wComputedGoto,
|
wLinearScanEnd, wPatterns, wEffects, wNoForward, wReorder, wComputedGoto,
|
||||||
wInjectStmt, wDeprecated, wExperimental, wThis}
|
wInjectStmt, wDeprecated, wExperimental, wThis}
|
||||||
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
||||||
wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader,
|
wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader,
|
||||||
|
|
@ -210,9 +210,9 @@ proc pragmaDeadCodeElim(c: PContext, n: PNode) =
|
||||||
if isTurnedOn(c, n): incl(c.module.flags, sfDeadCodeElim)
|
if isTurnedOn(c, n): incl(c.module.flags, sfDeadCodeElim)
|
||||||
else: excl(c.module.flags, sfDeadCodeElim)
|
else: excl(c.module.flags, sfDeadCodeElim)
|
||||||
|
|
||||||
proc pragmaNoForward(c: PContext, n: PNode) =
|
proc pragmaNoForward(c: PContext, n: PNode; flag=sfNoForward) =
|
||||||
if isTurnedOn(c, n): incl(c.module.flags, sfNoForward)
|
if isTurnedOn(c, n): incl(c.module.flags, flag)
|
||||||
else: excl(c.module.flags, sfNoForward)
|
else: excl(c.module.flags, flag)
|
||||||
|
|
||||||
proc processCallConv(c: PContext, n: PNode) =
|
proc processCallConv(c: PContext, n: PNode) =
|
||||||
if (n.kind == nkExprColonExpr) and (n.sons[1].kind == nkIdent):
|
if (n.kind == nkExprColonExpr) and (n.sons[1].kind == nkIdent):
|
||||||
|
|
@ -726,6 +726,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
incl(sym.flags, sfThread)
|
incl(sym.flags, sfThread)
|
||||||
of wDeadCodeElim: pragmaDeadCodeElim(c, it)
|
of wDeadCodeElim: pragmaDeadCodeElim(c, it)
|
||||||
of wNoForward: pragmaNoForward(c, it)
|
of wNoForward: pragmaNoForward(c, it)
|
||||||
|
of wReorder: pragmaNoForward(c, it, sfReorder)
|
||||||
of wMagic: processMagic(c, it, sym)
|
of wMagic: processMagic(c, it, sym)
|
||||||
of wCompileTime:
|
of wCompileTime:
|
||||||
noVal(it)
|
noVal(it)
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ type
|
||||||
wFloatchecks, wNanChecks, wInfChecks,
|
wFloatchecks, wNanChecks, wInfChecks,
|
||||||
wAssertions, wPatterns, wWarnings,
|
wAssertions, wPatterns, wWarnings,
|
||||||
wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags,
|
wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags,
|
||||||
wDeadCodeElim, wSafecode, wNoForward, wNoRewrite,
|
wDeadCodeElim, wSafecode, wNoForward, wReorder, wNoRewrite,
|
||||||
wPragma,
|
wPragma,
|
||||||
wCompileTime, wNoInit,
|
wCompileTime, wNoInit,
|
||||||
wPassc, wPassl, wBorrow, wDiscardable,
|
wPassc, wPassl, wBorrow, wDiscardable,
|
||||||
|
|
@ -143,7 +143,7 @@ const
|
||||||
|
|
||||||
"assertions", "patterns", "warnings", "hints",
|
"assertions", "patterns", "warnings", "hints",
|
||||||
"optimization", "raises", "writes", "reads", "size", "effects", "tags",
|
"optimization", "raises", "writes", "reads", "size", "effects", "tags",
|
||||||
"deadcodeelim", "safecode", "noforward", "norewrite",
|
"deadcodeelim", "safecode", "noforward", "reorder", "norewrite",
|
||||||
"pragma",
|
"pragma",
|
||||||
"compiletime", "noinit",
|
"compiletime", "noinit",
|
||||||
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
||||||
|
|
|
||||||
42
tests/modules/treorder.nim
Normal file
42
tests/modules/treorder.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim -d:testdef $target $file"
|
||||||
|
output: '''works 34
|
||||||
|
34
|
||||||
|
defined
|
||||||
|
first impl'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
{.reorder: on.}
|
||||||
|
|
||||||
|
{.push callconv: stdcall.}
|
||||||
|
proc bar(x: T)
|
||||||
|
|
||||||
|
proc foo() =
|
||||||
|
bar(34)
|
||||||
|
whendep()
|
||||||
|
|
||||||
|
proc foo(dummy: int) = echo dummy
|
||||||
|
|
||||||
|
proc bar(x: T) =
|
||||||
|
echo "works ", x
|
||||||
|
foo(x)
|
||||||
|
|
||||||
|
foo()
|
||||||
|
|
||||||
|
type
|
||||||
|
T = int
|
||||||
|
|
||||||
|
when defined(testdef):
|
||||||
|
proc whendep() = echo "defined"
|
||||||
|
else:
|
||||||
|
proc whendep() = echo "undefined"
|
||||||
|
|
||||||
|
when not declared(goo):
|
||||||
|
proc goo() = echo "first impl"
|
||||||
|
|
||||||
|
when not declared(goo):
|
||||||
|
proc goo() = echo "second impl"
|
||||||
|
|
||||||
|
goo()
|
||||||
|
|
||||||
|
{.pop.}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue