Skip to content

Commit

Permalink
Move verilator templates to templates/verilator directory
Browse files Browse the repository at this point in the history
Add EDALIZE_LAUNCHER to verilator template
  • Loading branch information
mtdudek committed May 19, 2021
1 parent c693144 commit 5e3e584
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
6 changes: 6 additions & 0 deletions edalize/templates/verilator/verilator-config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Auto generated by Edalize

TOP_MODULE := {{ top_module }}
VC_FILE := {{ vc_file }}
VERILATOR_OPTIONS := {{ verilator_options }}
MAKE_OPTIONS := {{ make_options }}
17 changes: 17 additions & 0 deletions edalize/templates/verilator/verilator-makefile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Auto generated by Edalize

include config.mk

#Assume a local installation if VERILATOR_ROOT is set

ifeq ($(VERILATOR_ROOT),)
VERILATOR ?= verilator
else
VERILATOR ?= $(VERILATOR_ROOT)/bin/verilator
endif

V$(TOP_MODULE): V$(TOP_MODULE).mk
$(MAKE) $(MAKE_OPTIONS) -f $<

V$(TOP_MODULE).mk:
$(EDALIZE_LAUNCHER) $(VERILATOR) -f $(VC_FILE) $(VERILATOR_OPTIONS)
44 changes: 10 additions & 34 deletions edalize/verilator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,6 @@

logger = logging.getLogger(__name__)

CONFIG_MK_TEMPLATE = """#Auto generated by Edalize
TOP_MODULE := {top_module}
VC_FILE := {vc_file}
VERILATOR_OPTIONS := {verilator_options}
MAKE_OPTIONS := {make_options}
"""

MAKEFILE_TEMPLATE = """#Auto generated by Edalize
include config.mk
#Assume a local installation if VERILATOR_ROOT is set
ifeq ($(VERILATOR_ROOT),)
VERILATOR ?= verilator
else
VERILATOR ?= $(VERILATOR_ROOT)/bin/verilator
endif
V$(TOP_MODULE): V$(TOP_MODULE).mk
$(MAKE) $(MAKE_OPTIONS) -f $<
V$(TOP_MODULE).mk:
$(VERILATOR) -f $(VC_FILE) $(VERILATOR_OPTIONS)
"""

class Verilator(Edatool):

argtypes = ['cmdlinearg', 'plusarg', 'vlogdefine', 'vlogparam']
Expand Down Expand Up @@ -131,8 +105,8 @@ def _write_config_files(self):
f.write(''.join(['-G{}={}\n'.format(key, self._param_value_str(value, str_quote_style='\\"')) for key, value in self.vlogparam.items()]))
f.write(''.join(['-D{}={}\n'.format(key, self._param_value_str(value)) for key, value in self.vlogdefine.items()]))

with open(os.path.join(self.work_root, 'Makefile'), 'w') as makefile:
makefile.write(MAKEFILE_TEMPLATE)
self.render_template('verilator-makefile.j2',
'Makefile')

if 'verilator_options' in self.tool_options:
verilator_options = ' '.join(self.tool_options['verilator_options'])
Expand All @@ -144,12 +118,14 @@ def _write_config_files(self):
else:
make_options = ''

with open(os.path.join(self.work_root, 'config.mk'), 'w') as config_mk:
config_mk.write(CONFIG_MK_TEMPLATE.format(
top_module = self.toplevel,
vc_file = self.verilator_file,
verilator_options = verilator_options,
make_options = make_options))
self.render_template('verilator-config.j2',
'config.mk',
{
'top_module' : self.toplevel,
'vc_file' : self.verilator_file,
'verilator_options' : verilator_options,
'make_options' : make_options
})

def build_main(self):
logger.info("Building simulation model")
Expand Down

0 comments on commit 5e3e584

Please sign in to comment.