def gen_vhdl_axi(in_filename, out_filename): if out_filename[-4:] != ".vhd": raise ValueError("output filename is expected to have .vhd extension") rdlc = RDLCompiler() rdlc.compile_file(in_filename) root = rdlc.elaborate() walker = RDLWalker(unroll=True) listener = HectareListener() walker.walk(root, listener) print("Parsing finished.") vhdl_gen = HectareVhdlGen(listener.addrmaps[0], input_filename=in_filename) s_pkg = vhdl_gen.generate_package() s_vhdl = vhdl_gen.generate_string() print("Generating {0} ...".format(out_filename)) out_file = open(out_filename, "w") out_file.write(s_vhdl) out_file.close() if s_pkg is not None: pkg_filename = out_filename.replace(".vhd", "_pkg.vhd") print("Generating {0} ...".format(pkg_filename)) out_file = open(pkg_filename, "w") out_file.write(s_pkg) out_file.close()
def compile(self, files, top_name, inst_name=None, parameters=None): this_dir = os.path.dirname(os.path.realpath(__file__)) rdlc = RDLCompiler(message_printer=TestPrinter(), warning_flags=self.compiler_warning_flags, error_flags=self.compiler_error_flags) for file in files: rdlc.compile_file(os.path.join(this_dir, file)) return rdlc.elaborate(top_name, inst_name, parameters)
def compile(self, files, top_name=None): rdlc = RDLCompiler(message_printer=TestPrinter()) ipxact = IPXACTImporter(rdlc) for file in files: if file.endswith(".rdl"): rdlc.compile_file(file) elif file.endswith(".xml"): ipxact.import_file(file) return rdlc.elaborate(top_name)
def test_list_udps(self): this_dir = os.path.dirname(os.path.realpath(__file__)) rdlc = RDLCompiler() rdlc.define_udp("int_udp", int, default=123) rdlc.compile_file(os.path.join(this_dir, "rdl_src/udp_15.2.2_ex1.rdl")) rdlc.elaborate("foo") self.assertEqual(sorted(rdlc.list_udps()), [ 'a_map_p', 'int_udp', 'some_bool_p', 'some_num_p', 'some_ref_p', ])
def test_builtin_udp(self): this_dir = os.path.dirname(os.path.realpath(__file__)) rdlc = RDLCompiler() rdlc.define_udp("int_udp", int, default=123) rdlc.compile_file(os.path.join(this_dir, "rdl_src/udp_builtin.rdl")) root = rdlc.elaborate("top") top = root.find_by_path("top") reg1 = root.find_by_path("top.reg1") field1 = root.find_by_path("top.reg1.field1") self.assertIs(top.get_property('int_udp'), 43) self.assertIs(reg1.get_property('int_udp'), 42) self.assertIs(field1.get_property('int_udp'), 123)
def compile(self): # Create an instance of the compiler rdlc = RDLCompiler() # Compile all the files provided for input_file in self.input_files: rdlc.compile_file(input_file) # Elaborate the design root = rdlc.elaborate() # Traverse the register model! walker = RDLWalker(unroll=True) listener = MyModelPrintingListener() walker.walk(root, listener)
def gen_rdl_header(top_name, rdl_file, output_folder): # Generate HTML and addressmap header rdlc = RDLCompiler() try: rdlc.compile_file(rdl_file) # Elaborate the design root = rdlc.elaborate() except RDLCompileError: # A compilation error occurred. Exit with error code sys.exit(1) root = rdlc.elaborate() exporter = HTMLExporter() exporter.export(root, os.path.join(output_folder, f"{top_name}_html")) rdl_json = convert_addrmap(rdlc, root.top) convert_to_json(rdl_json, os.path.join(output_folder, f"{top_name}.json")) convert_to_header(rdl_json, os.path.join(output_folder, top_name))
class RDL(object): def __init__(self): self.files = [] #the RDL File self.rdlc = RDLCompiler() #for compiler the file self.root = "" #the file has been elaborate self.listener = GetRegListener() #using self listener #read rdl file @DEBUG() def read_rdl(self, files=[]): INFO("read_rdl: " + "Reading SystemRDL Files") try: #compile all the files provided for input_file in files: self.rdlc.compile_file(input_file) self.root = self.rdlc.elaborate( ) #get the root of Tree in the RDL except RDLCompileError: sys.exit(1) self.files = files walker = RDLWalker(unroll=True) walker.walk(self.root, self.listener) self.listener.do_stats() #to process the information of SystemRDL file #gen the uvm file according the SystemRDL file has been elaborate @DEBUG() def gen_uvmral(self, outdir="", outfile=""): INFO("gen_uvmral: " + "Generate UVM-RAL File") exporter = uvmGenExporter() exporter.export(self.root, outdir, outfile) #gen the ip-xact file according the SystemRDL file has been elaborate @DEBUG() def gen_ipxact(self, outdir="", outfile=""): INFO("gen_ipxact: " + "Generate IP-XACT File") exporter = IPXACTExporter() exporter.export(self.root, outdir, outfile) def display_rdl(self): print(self.files) print(self.listener.reg_name) print(self.listener.reg_width) print(self.listener.reg_type) print(self.listener.reg_addr)
def process_input(rdlc: RDLCompiler, importers: 'List[Importer]', input_files: List[str], options: 'argparse.Namespace') -> None: for file in input_files: if not os.path.exists(file): rdlc.msg.fatal(f"Input file does not exist: {file}") ext = os.path.splitext(file)[1].strip(".") if ext == "rdl": # Is SystemRDL file rdlc.compile_file( file, incl_search_paths=options.incdirs, ) else: # Is foreign input file. # Search which importer to use by extension first importer_candidates = [] # type: List[Importer] for importer in importers: if ext in importer.file_extensions: importer_candidates.append(importer) # Do 2nd pass if needed importer = None if len(importer_candidates) == 1: importer = importer_candidates[0] elif len(importer_candidates) > 1: # ambiguous which importer to use # Do 2nd pass compatibility check for importer_candidate in importer_candidates: if importer_candidate.is_compatible(file): importer = importer_candidate break if not importer: rdlc.msg.fatal( "Unknown file type. Could not find any importers capable of reading this file.", FileSourceRef(file) ) importer.do_import(rdlc, options, file)
def gen_c_header(in_filename, out_filename): if out_filename[-2:] != ".h": raise ValueError("output filename is expected to have .h extension") rdlc = RDLCompiler() rdlc.compile_file(in_filename) root = rdlc.elaborate() walker = RDLWalker(unroll=True) listener = HectareListener() walker.walk(root, listener) print("Parsing finished.") c_header_gen = HectareCHeaderGen(listener.addrmaps[0], input_filename=in_filename) s_header = c_header_gen.generate_string() print("Generating {0} ...".format(out_filename)) out_file = open(out_filename, "w") out_file.write(s_header) out_file.close()
def main(): if len(sys.argv) < 3: raise Exception('Usage: generate_test_case.py <tc_name> <rdl_file>') testcase_name = sys.argv[1] rdl_file = sys.argv[2] output_dir = os.path.dirname(rdl_file) rdlc = RDLCompiler() rdlc.compile_file(rdl_file) root = rdlc.elaborate().top UVMGenerator(output_dir, False, True).export_reg_models(root, testcase_name) UVMGenerator(output_dir, True, True).export_reg_models(root, testcase_name) UVMGenerator(output_dir, True, False).export_reg_models(root, testcase_name) # Generate test logic UVMGenerator(output_dir, True, True).generate_test_logic(root, testcase_name)
def compile_rdl(infile, incl_search_paths=None, top=None): '''compile the rdl''' rdlc = RDLCompiler() rdlc.compile_file(infile, incl_search_paths=incl_search_paths) return rdlc.elaborate(top_def_name=top).top
#parser.add_argument('infile', nargs='?', type=argparse.FileType('r') ) parser.add_argument('rdl', type=str, help='SystemRDL source file') parser.add_argument('chip', type=str, help='Chip model name') #parser.add_argument('--', type=int, help='Full (default) or Half duplex mode', required=False) #parser.add_argument('--mc21', type=int, help='To remove', required=False) #parser.add_argument('--servercamera', type=int, help='Camera number', required=False) args = parser.parse_args() #print(args) rdlc = RDLCompiler() try: rdlc.compile_file(args.rdl) root = rdlc.elaborate(args.chip) except RDLCompileError: sys.exit(1) #sys.exit(10) walker = RDLWalker(unroll=True) golistener = RdlToGoCodeListener() walker.walk(root, golistener) print("//THIS FILE WAS AUTO GENERATED. PLEASE DO NOT EDIT") print("package main") print('func init() { addAddrMap("%s", %sRegisters[:]) }' %
this_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, os.path.join(this_dir, "../")) from systemrdl import RDLCompiler, RDLListener, RDLWalker, RDLCompileError from systemrdl.node import FieldNode, RegNode, AddrmapNode, SignalNode from ralbot.uvmgen import uvmGenExporter # Collect input files from the command line arguments input_files = sys.argv[1:] # Create an instance of the compiler rdlc = RDLCompiler() try: # Compile all the files provided for input_file in input_files: rdlc.compile_file(input_file) # Elaborate the design root = rdlc.elaborate() except RDLCompileError: # A compilation error occurred. Exit with error code sys.exit(1) file = "test.svh" exporter = uvmGenExporter() exporter.export(root, file) exporter.export(root, "output/test_uvmgen")
#!/usr/bin/env python3 import sys import os from systemrdl import RDLCompiler from peakrdl.uvm import UVMExporter rdl_file = sys.argv[1] sv_file = sys.argv[2] rdlc = RDLCompiler() rdlc.compile_file(rdl_file) root = rdlc.elaborate().top UVMExporter().export( root, sv_file, use_uvm_factory=False, reuse_class_definitions=True, export_as_package=True, )
def compile(self, files, top_name): this_dir = os.path.dirname(os.path.realpath(__file__)) rdlc = RDLCompiler(message_printer=TestPrinter()) for file in files: rdlc.compile_file(os.path.join(this_dir, file)) return rdlc.elaborate(top_name)
from ralbot.html import HTMLExporter #=============================================================================== #input_file = sys.argv[1] #output_dir = sys.argv[1] output_dir = "./output" #print(output_dir) top = ['hi3516av200', 'hi3519v101'] #top = ['hi3519v101'] # top level address maps roots = [] rdlc = RDLCompiler() rdlc.compile_file('hi3516av200.rdl') #rdlc.compile_file('hi3516cv300_family.rdl') for addrspace in top: root = rdlc.elaborate(addrspace) roots.append(root.top) htmlexporter = HTMLExporter() htmlexporter.export(roots, output_dir) #rdlc = RDLCompiler() #try: #for input_file in input_files: # rdlc.compile_file(input_file) # root = rdlc.elaborate() #except RDLCompileError: