summary refs log tree commit diff stats
path: root/compiler/nir/nirc.nim
blob: da8d7d7786b3287efa5b9e598cbd1116d76427c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)