diff options
author | Araq <rumpf_a@web.de> | 2011-04-12 01:13:42 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-04-12 01:13:42 +0200 |
commit | cd292568d775d55d9abb51e962882ecda12c03a9 (patch) | |
tree | 85451f0e1f17dc0463350915f12bdd0a82a73455 /compiler/passaux.nim | |
parent | 46c41e43690cba9bc1caff6a994bb6915df8a1b7 (diff) | |
download | Nim-cd292568d775d55d9abb51e962882ecda12c03a9.tar.gz |
big repo cleanup
Diffstat (limited to 'compiler/passaux.nim')
-rwxr-xr-x | compiler/passaux.nim | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/compiler/passaux.nim b/compiler/passaux.nim new file mode 100755 index 000000000..a57963c06 --- /dev/null +++ b/compiler/passaux.nim @@ -0,0 +1,52 @@ +# +# +# The Nimrod Compiler +# (c) Copyright 2011 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## implements some little helper passes + +import + strutils, ast, astalgo, passes, msgs, options + +proc verboseOpen(s: PSym, filename: string): PPassContext = + #MessageOut('compiling ' + s.name.s); + result = nil # we don't need a context + if gVerbosity > 0: rawMessage(hintProcessing, s.name.s) + +proc verboseProcess(context: PPassContext, n: PNode): PNode = + result = n + if context != nil: InternalError("logpass: context is not nil") + if gVerbosity == 3: + # system.nim deactivates all hints, for verbosity:3 we want the processing + # messages nonetheless, so we activate them again unconditionally: + incl(msgs.gNotes, hintProcessing) + Message(n.info, hintProcessing, $ast.gid) + +proc verbosePass*(): TPass = + initPass(result) + result.open = verboseOpen + result.process = verboseProcess + +proc cleanUp(c: PPassContext, n: PNode): PNode = + result = n + # we cannot clean up if dead code elimination is activated + if optDeadCodeElim in gGlobalOptions: return + case n.kind + of nkStmtList: + for i in countup(0, sonsLen(n) - 1): discard cleanup(c, n.sons[i]) + of nkProcDef, nkMethodDef: + if n.sons[namePos].kind == nkSym: + var s = n.sons[namePos].sym + if sfDeadCodeElim notin getModule(s).flags and not astNeeded(s): + s.ast.sons[codePos] = ast.emptyNode # free the memory + else: + nil + +proc cleanupPass*(): TPass = + initPass(result) + result.process = cleanUp + result.close = cleanUp |