123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #
- #
- # The Nim Compiler
- # (c) Copyright 2023 Andreas Rumpf
- #
- # See the file "copying.txt", included in this
- # distribution, for details about the copyright.
- #
- import ".." / ic / [bitabs, rodfiles]
- import nirinsts, nirtypes, nirlineinfos
- type
- NirModule* = object
- code*: Tree
- man*: LineInfoManager
- types*: TypeGraph
- lit*: Literals
- namespace*: LitId
- intbits*: uint32
- symnames*: SymNames
- proc load*(filename: string): NirModule =
- let lit = Literals()
- result = NirModule(lit: lit, types: initTypeGraph(lit))
- var r = rodfiles.open(filename)
- try:
- r.loadHeader(nirCookie)
- r.loadSection stringsSection
- r.load result.lit.strings
- r.loadSection numbersSection
- r.load result.lit.numbers
- r.loadSection bodiesSection
- r.load result.code
- r.loadSection typesSection
- r.load result.types
- r.loadSection sideChannelSection
- r.load result.man
- r.loadSection namespaceSection
- r.loadPrim result.namespace
- r.loadPrim result.intbits
- r.loadSection symnamesSection
- r.load result.symnames
- finally:
- r.close()
- proc store*(m: NirModule; outp: string) =
- var r = rodfiles.create(outp)
- try:
- r.storeHeader(nirCookie)
- r.storeSection stringsSection
- r.store m.lit.strings
- r.storeSection numbersSection
- r.store m.lit.numbers
- r.storeSection bodiesSection
- r.store m.code
- r.storeSection typesSection
- r.store m.types
- r.storeSection sideChannelSection
- r.store m.man
- r.storeSection namespaceSection
- r.storePrim m.namespace
- r.storePrim m.intbits
- r.storeSection symnamesSection
- r.store m.symnames
- finally:
- r.close()
- if r.err != ok:
- raise newException(IOError, "could store into: " & outp)
|