# # # The Nim Compiler # (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # ## This module implements the passes functionality. A pass must implement the ## `TPass` interface. import options, ast, llstream, msgs, idents, syntaxes, modulegraphs, reorder, lineinfos, pipelineutils, modules, pathutils, packages, sem, semdata import ic/replayer export skipCodegen, resolveMod, prepareConfigNotes when defined(nimsuggest): import ../dist/checksums/src/checksums/sha1 when defined(nimPreviewSlimSystem): import std/[syncio, assertions] import std/tables type TPassData* = tuple[input: PNode, closeOutput: PNode] # a pass is a tuple of procedure vars ``TPass.close`` may produce additional # nodes. These are passed to the other close procedures. # This mechanism used to be used for the instantiation of generics. proc makePass*(open: TPassOpen = nil, process: TPassProcess = nil, close: TPassClose = nil, isFrontend = false): TPass = result.open = open result.close = close result.process = process result.isFrontend = isFrontend const maxPasses = 10 type TPassContextArray = array[0..maxPasses - 1, PPassContext] proc clearPasses*(g: ModuleGraph) = g.passes.setLen(0) proc registerPass*(g: ModuleGraph; p: TPass) = internalAssert g.config, g.passes.len < maxPasses g.passes.add(p) proc openPasses(g: ModuleGraph; a: var TPassContextArray; module: PSym; idgen: IdGenerator) = for i in 0..