diff options
author | Araq <rumpf_a@web.de> | 2011-10-18 17:21:51 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-10-18 17:21:51 +0200 |
commit | 4de84024e5e1b91fcd66d4f093cec4d1a985194a (patch) | |
tree | 6b8941742c59c21c729e6d8ecd868bb0c29e4a36 /compiler/idgen.nim | |
parent | 0914ba8980976ed5204f953aa5548e33ac103686 (diff) | |
download | Nim-4de84024e5e1b91fcd66d4f093cec4d1a985194a.tar.gz |
much more efficient rod file generation
Diffstat (limited to 'compiler/idgen.nim')
-rw-r--r-- | compiler/idgen.nim | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/compiler/idgen.nim b/compiler/idgen.nim new file mode 100644 index 000000000..f5ae8a1f8 --- /dev/null +++ b/compiler/idgen.nim @@ -0,0 +1,57 @@ +# +# +# The Nimrod Compiler +# (c) Copyright 2011 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module contains a simple persistent id generator. + +import idents, strutils, os + +var gFrontEndId, gBackendId*: int + +const + debugIds* = false + +when debugIds: + import intsets + + var usedIds = InitIntSet() + +proc registerID*(id: PIdObj) = + when debugIDs: + if (id.id == - 1) or ContainsOrIncl(usedIds, id.id): + InternalError("ID already used: " & $id.id) + +proc getID*(): int {.inline.} = + result = gFrontEndId + inc(gFrontEndId) + +proc backendId*(): int {.inline.} = + result = gBackendId + inc(gBackendId) + +proc setId*(id: int) {.inline.} = + gFrontEndId = max(gFrontEndId, id + 1) + +proc IDsynchronizationPoint*(idRange: int) = + gFrontEndId = (gFrontEndId div IdRange + 1) * IdRange + 1 + +proc saveMaxIds*(project: string) = + var f = open(project.addFileExt("gid"), fmWrite) + f.writeln($gFrontEndId) + f.writeln($gBackEndId) + f.close() + +proc loadMaxIds*(project: string) = + var f: TFile + if open(f, project.addFileExt("gid"), fmRead): + var frontEndId = parseInt(f.readLine) + var backEndId = parseInt(f.readLine) + gFrontEndId = max(gFrontEndId, frontEndId) + gBackEndId = max(gBackEndId, backEndId) + f.close() + |