diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2023-10-29 14:47:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-29 14:47:22 +0100 |
commit | 0c26d19e228e831393cb5d2c1f43660362d349c9 (patch) | |
tree | 6b989d3175a5332dcd61489e22350f3748b89b09 /compiler/nir/nirc.nim | |
parent | 94ffc183323c859fc5a395404ac6035ae29cbc5a (diff) | |
download | Nim-0c26d19e228e831393cb5d2c1f43660362d349c9.tar.gz |
NIR: VM + refactorings (#22835)
Diffstat (limited to 'compiler/nir/nirc.nim')
-rw-r--r-- | compiler/nir/nirc.nim | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/compiler/nir/nirc.nim b/compiler/nir/nirc.nim index 3d8c8e6ff..363507ca6 100644 --- a/compiler/nir/nirc.nim +++ b/compiler/nir/nirc.nim @@ -10,41 +10,46 @@ ## Nir Compiler. Currently only supports a "view" command. import ".." / ic / [bitabs, rodfiles] -import nirinsts, nirtypes, nirlineinfos +import nirinsts, nirtypes, nirlineinfos, nirfiles #, nir2gcc proc view(filename: string) = - var lit = Literals() - - var r = rodfiles.open(filename) - var code = default Tree - var man = default LineInfoManager - var types = initTypeGraph(lit) - try: - r.loadHeader(nirCookie) - r.loadSection stringsSection - r.load lit.strings - - r.loadSection numbersSection - r.load lit.numbers - - r.loadSection bodiesSection - r.load code - - r.loadSection typesSection - r.load types - - r.loadSection sideChannelSection - r.load man - - finally: - r.close() - + let m = load(filename) var res = "" - allTreesToString code, lit.strings, lit.numbers, res + allTreesToString m.code, m.lit.strings, m.lit.numbers, m.symnames, res res.add "\n# TYPES\n" - nirtypes.toString res, types + nirtypes.toString res, m.types echo res -import std / os - -view paramStr(1) +proc libgcc(filename: string) = + let m = load(filename) + #gcc m, filename + +import std / [syncio, parseopt] + +proc writeHelp = + echo """Usage: nirc view|gcc <file.nir>""" + quit 0 + +proc main = + var inp = "" + var cmd = "" + for kind, key, val in getopt(): + case kind + of cmdArgument: + if cmd.len == 0: cmd = key + elif inp.len == 0: inp = key + else: quit "Error: too many arguments" + of cmdLongOption, cmdShortOption: + case key + of "help", "h": writeHelp() + of "version", "v": stdout.write "1.0\n" + of cmdEnd: discard + if inp.len == 0: + quit "Error: no input file specified" + case cmd + of "", "view": + view inp + of "gcc": + libgcc inp + +main() |