initial commit for open source NoC IP
This commit is contained in:
1
rtl/util/commoncell/tools/pico/.gitignore
vendored
Normal file
1
rtl/util/commoncell/tools/pico/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__
|
||||
132
rtl/util/commoncell/tools/pico/PackageParser.py
Executable file
132
rtl/util/commoncell/tools/pico/PackageParser.py
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from distutils.log import error, fatal
|
||||
from pathlib import Path
|
||||
from sys import argv
|
||||
import yaml
|
||||
|
||||
|
||||
class Module:
|
||||
def __init__(self, root: Path, moduleMeta: dict) -> None:
|
||||
self.rtlPathList = []
|
||||
self.simPathList = []
|
||||
self.dependModuleList = []
|
||||
if moduleMeta.get("dependency"):
|
||||
for m in moduleMeta["dependency"]:
|
||||
self.dependModuleList.append(m)
|
||||
if moduleMeta.get("rtl"):
|
||||
for m in moduleMeta["rtl"]:
|
||||
self.rtlPathList.append(Path(root) / m)
|
||||
if moduleMeta.get("sim"):
|
||||
for m in moduleMeta["sim"]:
|
||||
self.simPathList.append(Path(root) / m)
|
||||
try:
|
||||
self.name = moduleMeta["name"]
|
||||
self.description = moduleMeta["description"]
|
||||
self.language = moduleMeta["language"]
|
||||
except yaml.YAMLError as e:
|
||||
error(e)
|
||||
|
||||
|
||||
class PackageParser:
|
||||
def __init__(self, manifestPath: str):
|
||||
with open(manifestPath) as f:
|
||||
self.packageLocation = Path(manifestPath)
|
||||
ROOT = self.packageLocation.parent
|
||||
manifest = yaml.load(f, yaml.CLoader)
|
||||
self.dependPackageDict = {}
|
||||
self.ModuleDict = {}
|
||||
if manifest.get("Dependency"):
|
||||
for packagePath in manifest["Dependency"]:
|
||||
filePath = Path(ROOT / packagePath)
|
||||
package = PackageParser(filePath)
|
||||
if not self.dependPackageDict.get(package.Name):
|
||||
self.dependPackageDict[package.Name] = package
|
||||
for (key, value) in package.ModuleDict.items():
|
||||
if not self.ModuleDict.get(key):
|
||||
self.ModuleDict[key] = value
|
||||
if manifest.get("Module"):
|
||||
for module in manifest["Module"]:
|
||||
self.addModule(ROOT, module)
|
||||
try:
|
||||
self.Name = manifest["Name"]
|
||||
self.addModule(ROOT, self.packModule())
|
||||
except yaml.YAMLError as e:
|
||||
error(e)
|
||||
|
||||
def packModule(self):
|
||||
packedModule = {}
|
||||
packedModule['name'] = self.Name
|
||||
packedModule['language'] = None
|
||||
packedModule['description'] = "package {}".format(self.Name)
|
||||
packedModule['dependency'] = []
|
||||
for module in self.ModuleDict:
|
||||
packedModule['dependency'].append(module)
|
||||
return packedModule
|
||||
|
||||
|
||||
def addModule(self, root: Path, moduleMeta: dict) -> None:
|
||||
self.ModuleDict[moduleMeta["name"]] = Module(root, moduleMeta)
|
||||
if moduleMeta.get("sim"):
|
||||
self.ModuleDict[moduleMeta["name"]+'_tb'] = Module(root, moduleMeta)
|
||||
|
||||
def genModuleFileList(self, top: str, sim: bool):
|
||||
if self.ModuleDict.get(top):
|
||||
module = self.ModuleDict[top]
|
||||
filelist = []
|
||||
for dependModule in module.dependModuleList:
|
||||
for file in self.genModuleFileList(dependModule, False):
|
||||
if file not in filelist:
|
||||
filelist.append(file)
|
||||
for file in module.rtlPathList:
|
||||
absPath = str(file.absolute())
|
||||
if absPath not in filelist:
|
||||
filelist.append((absPath,module.language))
|
||||
if sim:
|
||||
for file in module.simPathList:
|
||||
absPath = str(file.absolute())
|
||||
if absPath not in filelist:
|
||||
filelist.append((absPath,module.language))
|
||||
return filelist
|
||||
else:
|
||||
fatal("Module {} doesn't exist".format(top))
|
||||
|
||||
def genPackageFileList(self, sim: bool):
|
||||
filelist = []
|
||||
for module in self.ModuleDict:
|
||||
for file in self.genModuleFileList(module, sim):
|
||||
if file not in filelist :
|
||||
filelist.append(file)
|
||||
return filelist
|
||||
|
||||
def genVcsFileList(self, sim: bool):
|
||||
filelist = self.genPackageFileList(sim)
|
||||
vcsfilelist = []
|
||||
for file in filelist:
|
||||
vcsfilelist.append(file[0])
|
||||
return vcsfilelist
|
||||
|
||||
def genEDAlizeFile(self,top: str, sim: bool):
|
||||
edalizeFileList = []
|
||||
filelist = self.genModuleFileList(top,sim)
|
||||
for (filePath,language) in filelist:
|
||||
if language == "SystemVerilog" :
|
||||
edalizeFileList.append(
|
||||
{'name' : filePath, 'file_type' : 'systemVerilogSource'}
|
||||
)
|
||||
elif language == "Verilog" :
|
||||
edalizeFileList.append(
|
||||
{'name' : filePath, 'file_type' : 'verilogSource'}
|
||||
)
|
||||
elif language == "Vhdl":
|
||||
edalizeFileList.append(
|
||||
{'name' : filePath, 'file_type' : 'vhdlSource'}
|
||||
)
|
||||
return edalizeFileList
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = PackageParser(argv[1])
|
||||
for file in t.genVcsFileList(False):
|
||||
print(file)
|
||||
2
rtl/util/commoncell/tools/pico/README.md
Normal file
2
rtl/util/commoncell/tools/pico/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# pico
|
||||
Pico is a hardware dependency manangement tool which integrate Edalize to support different cad flow
|
||||
8
rtl/util/commoncell/tools/pico/defaultToolOption.yaml
Normal file
8
rtl/util/commoncell/tools/pico/defaultToolOption.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
vcs :
|
||||
vcs_options : [-full64,-sverilog,+v2k,-debug_access+all,-kdb]
|
||||
run_options : []
|
||||
spyglass:
|
||||
methodology : GuideWare/latest/block/rtl_handoff
|
||||
goals : [ 'lint/lint_rtl' ]
|
||||
spyglass_parameters : []
|
||||
rule_parameters : []
|
||||
127
rtl/util/commoncell/tools/pico/pico
Executable file
127
rtl/util/commoncell/tools/pico/pico
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
from distutils.log import fatal
|
||||
from genericpath import getmtime
|
||||
import os
|
||||
from pathlib import Path
|
||||
from sys import argv
|
||||
import yaml
|
||||
from time import ctime, gmtime, strftime, time
|
||||
from edalize import *
|
||||
import edalize
|
||||
from PackageParser import PackageParser
|
||||
|
||||
SIM_TOOL = [
|
||||
'vcs', 'verilator'
|
||||
]
|
||||
|
||||
TOOLS = [tool for tool in edalize.walk_tool_packages()]
|
||||
|
||||
def getTime():
|
||||
return strftime("%m%d_%H_%M", gmtime())
|
||||
|
||||
|
||||
class PicoArgsParser:
|
||||
def __init__(self, argv) -> None:
|
||||
argParser = argparse.ArgumentParser(usage='Pico.py [manifest] -top [topmodule] -tool [vcs/verilator/veriblelint .etc] -configure -build -run',prefix_chars="-+")
|
||||
argParser.add_argument('manifest', type=str, help="Project manifest")
|
||||
argParser.add_argument(
|
||||
'+args', nargs='?', action='append', help="Compile arguments")
|
||||
argParser.add_argument(
|
||||
'-tool', type=str, choices=TOOLS, required=True, help="EDA tool")
|
||||
argParser.add_argument(
|
||||
'-top', type=str, required=True, help="Top module")
|
||||
argParser.add_argument('-trace', action='store_true',
|
||||
default=False, help="Enable Waveform")
|
||||
argParser.add_argument(
|
||||
'+define', nargs='?', action='append', type=str, help="Verilog defination")
|
||||
argParser.add_argument('-workdir', type=str, help="Work space")
|
||||
argParser.add_argument('-build', action='store_true',
|
||||
default=False, help="Build Project")
|
||||
argParser.add_argument('-run', action='store_true',
|
||||
default=False, help="Run Project")
|
||||
argParser.add_argument('+runtime', action='append', help="runtime args")
|
||||
argParser.add_argument('-cov','-coverage', dest='coverage', action='store_true',help='Enable coverage')
|
||||
self.config = argParser.parse_args(argv)
|
||||
|
||||
self.tool = self.config.tool
|
||||
self.toplevel = self.config.top
|
||||
self.build = self.config.build
|
||||
self.run = self.config.run
|
||||
self.tool_options = self.buildToolOptions()
|
||||
self.parameters = self.buildDefination()
|
||||
self.file = self.buildFlist()
|
||||
self.edam = {
|
||||
'files': self.file,
|
||||
'name': self.toplevel,
|
||||
'parameters': self.parameters,
|
||||
'tool_options': self.tool_options,
|
||||
'toplevel': self.toplevel
|
||||
}
|
||||
self.workSpace = self.getWorkSpace()
|
||||
|
||||
def getWorkSpace(self):
|
||||
if self.config.workdir:
|
||||
work_root = self.config.workdir
|
||||
else:
|
||||
work_root = self.tool + '_' + self.toplevel + '_' + getTime()
|
||||
return work_root
|
||||
|
||||
def buildFlist(self):
|
||||
manifestParser = PackageParser(self.config.manifest)
|
||||
simulationEnable = self.tool in SIM_TOOL
|
||||
return manifestParser.genEDAlizeFile(self.toplevel, simulationEnable)
|
||||
|
||||
def buildToolOptions(self):
|
||||
config = self.config
|
||||
tool_options = yaml.load(
|
||||
open(Path(__file__).parent / "defaultToolOption.yaml"), yaml.CLoader)
|
||||
if config.args:
|
||||
if config.tool == 'vcs':
|
||||
tool_options['vcs']['vcs_options'] += config.args
|
||||
if config.runtime:
|
||||
if config.tool == 'vcs':
|
||||
tool_options['vcs']['run_options'] += config.runtime
|
||||
if config.coverage:
|
||||
if config.tool == 'vcs':
|
||||
tool_options['vcs']['vcs_options'] += ['-cm line+cond+tgl+fsm+branch+assert']
|
||||
tool_options['vcs']['run_options'] += ['-cm line+cond+tgl+fsm+branch+assert']
|
||||
return tool_options
|
||||
|
||||
def buildDefination(self):
|
||||
parameters = {}
|
||||
config = self.config
|
||||
if config.trace:
|
||||
parameters["DUMPON"] = {
|
||||
'datatype': 'bool',
|
||||
'default': 1,
|
||||
'paramtype': 'vlogdefine'
|
||||
}
|
||||
if config.define:
|
||||
for define in config.define:
|
||||
for item in define.split(','):
|
||||
parameters[item] = {
|
||||
'datatype': 'bool',
|
||||
'default': 1,
|
||||
'paramtype': 'vlogdefine'
|
||||
}
|
||||
return parameters
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
config = PicoArgsParser(argv[1:])
|
||||
|
||||
work_root = config.workSpace
|
||||
|
||||
backend = get_edatool(config.tool)(edam=config.edam, work_root=work_root)
|
||||
|
||||
if not os.path.exists(work_root):
|
||||
os.makedirs(work_root)
|
||||
|
||||
if config.build:
|
||||
backend.configure()
|
||||
backend.build()
|
||||
|
||||
if config.run:
|
||||
backend.run()
|
||||
Reference in New Issue
Block a user