summary refs log tree commit diff stats
path: root/compiler/nir/nirc.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2023-10-16 00:01:33 +0200
committerGitHub <noreply@github.com>2023-10-16 00:01:33 +0200
commit10c3ab626941d9c1ec69a2921696f4b7d0c2a6ac (patch)
treec1b8b2117bbb86101f54269ff2e66816ce4b8296 /compiler/nir/nirc.nim
parent5f400983d588ec91a688453ce69cec94d310cc70 (diff)
downloadNim-10c3ab626941d9c1ec69a2921696f4b7d0c2a6ac.tar.gz
NIR: store sizes, alignments and offsets in the type graph; beginning… (#22822)
…s of a patent-pending new VM
Diffstat (limited to 'compiler/nir/nirc.nim')
-rw-r--r--compiler/nir/nirc.nim48
1 files changed, 48 insertions, 0 deletions
diff --git a/compiler/nir/nirc.nim b/compiler/nir/nirc.nim
new file mode 100644
index 000000000..da8d7d778
--- /dev/null
+++ b/compiler/nir/nirc.nim
@@ -0,0 +1,48 @@
+#
+#
+#           The Nim Compiler
+#        (c) Copyright 2023 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## Nir Compiler. Currently only supports a "view" command.
+
+import ".." / ic / [bitabs, rodfiles]
+import nirinsts, nirtypes, nirlineinfos
+
+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()
+
+  var res = ""
+  allTreesToString code, lit.strings, lit.numbers, res
+  echo res
+
+import std / os
+
+view paramStr(1)