Improve template path handling. Add synthesis tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from ..base import CpuifBase
|
||||
|
||||
class APB3_Cpuif(CpuifBase):
|
||||
template_path = "cpuif/apb3/apb3_tmpl.sv"
|
||||
template_path = "apb3_tmpl.sv"
|
||||
|
||||
@property
|
||||
def port_declaration(self) -> str:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from ..base import CpuifBase
|
||||
|
||||
class AXI4Lite_Cpuif(CpuifBase):
|
||||
template_path = "cpuif/axi4lite/axi4lite_tmpl.sv"
|
||||
template_path = "axi4lite_tmpl.sv"
|
||||
|
||||
@property
|
||||
def port_declaration(self) -> str:
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
import inspect
|
||||
import os
|
||||
|
||||
import jinja2 as jj
|
||||
|
||||
from ..utils import get_always_ff_event, clog2, is_pow2
|
||||
|
||||
@@ -7,6 +11,8 @@ if TYPE_CHECKING:
|
||||
from systemrdl import SignalNode
|
||||
|
||||
class CpuifBase:
|
||||
|
||||
# Path is relative to class that defines it
|
||||
template_path = ""
|
||||
|
||||
def __init__(self, exp:'RegblockExporter', cpuif_reset:Optional['SignalNode'], data_width:int=32, addr_width:int=32):
|
||||
@@ -20,6 +26,13 @@ class CpuifBase:
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_implementation(self) -> str:
|
||||
class_dir = os.path.dirname(inspect.getfile(self.__class__))
|
||||
loader = jj.FileSystemLoader(class_dir)
|
||||
jj_env = jj.Environment(
|
||||
loader=loader,
|
||||
undefined=jj.StrictUndefined,
|
||||
)
|
||||
|
||||
context = {
|
||||
"cpuif": self,
|
||||
"get_always_ff_event": lambda resetsignal : get_always_ff_event(self.exp.dereferencer, resetsignal),
|
||||
@@ -28,5 +41,5 @@ class CpuifBase:
|
||||
"is_pow2": is_pow2,
|
||||
}
|
||||
|
||||
template = self.exp.jj_env.get_template(self.template_path)
|
||||
template = jj_env.get_template(self.template_path)
|
||||
return template.render(context)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from ..base import CpuifBase
|
||||
|
||||
class PassthroughCpuif(CpuifBase):
|
||||
template_path = "cpuif/passthrough/passthrough_tmpl.sv"
|
||||
template_path = "passthrough_tmpl.sv"
|
||||
|
||||
@property
|
||||
def port_declaration(self) -> str:
|
||||
|
||||
@@ -17,8 +17,6 @@ from .scan_design import DesignScanner
|
||||
|
||||
class RegblockExporter:
|
||||
def __init__(self, **kwargs) -> None:
|
||||
user_template_dir = kwargs.pop("user_template_dir", None)
|
||||
|
||||
# Check for stray kwargs
|
||||
if kwargs:
|
||||
raise TypeError("got an unexpected keyword argument '%s'" % list(kwargs.keys())[0])
|
||||
@@ -34,22 +32,12 @@ class RegblockExporter:
|
||||
self.min_read_latency = 0
|
||||
self.min_write_latency = 0
|
||||
|
||||
if user_template_dir:
|
||||
loader = jj.ChoiceLoader([
|
||||
jj.FileSystemLoader(user_template_dir),
|
||||
jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
jj.PrefixLoader({
|
||||
'user': jj.FileSystemLoader(user_template_dir),
|
||||
'base': jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
}, delimiter=":")
|
||||
])
|
||||
else:
|
||||
loader = jj.ChoiceLoader([
|
||||
jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
jj.PrefixLoader({
|
||||
'base': jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
}, delimiter=":")
|
||||
])
|
||||
loader = jj.ChoiceLoader([
|
||||
jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
jj.PrefixLoader({
|
||||
'base': jj.FileSystemLoader(os.path.dirname(__file__)),
|
||||
}, delimiter=":")
|
||||
])
|
||||
|
||||
self.jj_env = jj.Environment(
|
||||
loader=loader,
|
||||
|
||||
Reference in New Issue
Block a user