Skip to content

Commit

Permalink
caching coreir context with debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Durst committed Jun 11, 2019
1 parent 7655fb6 commit a63a4ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions magma/frontend/coreir_.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from magma.backend.coreir_ import CoreIRBackend
from magma import cache_definition
from magma.backend.coreir_ import CoreIRBackend, magma_coreir_context
from magma.circuit import DefineCircuitKind, Circuit
from magma import cache_definition
from coreir.generator import Generator
import coreir

@cache_definition
def GetCoreIRBackend():
return CoreIRBackend()

@cache_definition
def GetMagmaContext():
return magma_coreir_context

def DefineModuleWrapper(cirb: CoreIRBackend, coreirModule, uniqueName, deps):
class ModuleWrapper(Circuit):
Expand All @@ -18,8 +28,15 @@ def definition(cls):

def DefineCircuitFromGeneratorWrapper(cirb: CoreIRBackend, namespace: str, generator: str,
uniqueName: str, dependentNamespaces: list = [],
genargs: dict = {}, runGenerators = True):
genargs: dict = {}, runGenerators = True, print_error=False):
moduleToWrap = cirb.context.import_generator(namespace,generator)(**genargs)

if print_error:
print(f"Cached cirb IO: {moduleToWrap.type.items()}")
fresh_context = coreir.Context()
fresh_moduleToWrap = fresh_context.import_generator(namespace,generator)(**genargs)
print(f"Fresh cirb IO: {fresh_moduleToWrap.type.items()}")

deps = [namespace] + dependentNamespaces
if runGenerators:
cirb.context.run_passes(["rungenerators"], deps)
Expand Down
3 changes: 2 additions & 1 deletion magma/simulator/coreir_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .simulator import CircuitSimulator, ExecutionState
from ..backend import coreir_
from ..frontend.coreir_ import GetMagmaContext
from ..scope import Scope
from ..ref import DefnRef, ArrayRef, TupleRef
from ..array import ArrayType
Expand Down Expand Up @@ -134,7 +135,7 @@ def __init__(self, circuit, clock, coreir_filename=None, context=None,
setup_clocks(circuit)

if context is None:
self.ctx = coreir.Context()
self.ctx = GetMagmaContext()
else:
self.ctx = context
coreir_.compile(circuit, coreir_filename, context=self.ctx)
Expand Down

0 comments on commit a63a4ca

Please sign in to comment.