Example #1
0
    def __call__(self, T):
        global _import_info_l, _export_info_l
        type_info = BfmTypeInfo(T, self.hdl, self.has_init,
                                _import_info_l.copy(), _export_info_l.copy())
        BfmMgr.inst().add_type_info(T, type_info)
        _import_info_l.clear()
        _export_info_l.clear()

        return T
Example #2
0
def main():
    parser = get_parser()

    args = parser.parse_args()

    # Ensure the BfmMgr is created
    BfmMgr.inst()

    if hasattr(args, 'm') and args.m is not None:
        bfm_load_modules(args.m)

    args.func(args)
Example #3
0
def bfm_generate_sv(args):
    inst = BfmMgr.inst()

    filename_c = args.o
    if filename_c.find('.') != -1:
        filename_c = os.path.splitext(filename_c)[0]
    filename_c += ".c"

    with open(args.o, "w") as out_sv:
        with open(filename_c, "w") as out_c:
            out_sv.write(
                "//***************************************************************************\n"
            )
            out_sv.write("//* BFMs file for pybfms. \n")
            out_sv.write("//* Note: This file is generated. Do Not Edit\n")
            out_sv.write(
                "//***************************************************************************\n"
            )
            out_sv.write("`define PYBFMS_GEN\n")

            out_c.write(
                "//***************************************************************************\n"
            )
            out_c.write("//* BFMs DPI interface file for pybfms. \n")
            out_c.write("//* Note: This file is generated. Do Not Edit\n")
            out_c.write(
                "//***************************************************************************\n"
            )
            out_c.write("#include <stdio.h>\n")
            out_c.write("#ifdef __cplusplus\n")
            out_c.write("extern \"C\" {\n")
            out_c.write("#endif\n")
            out_c.write("\n")
            out_c.write("#include \"svdpi.h\"\n")
            out_c.write("#define _GNU_SOURCE\n")
            out_c.write("#define __USE_GNU\n")
            out_c.write("#include <dlfcn.h>\n")
            out_c.write("typedef void (*pybfms_notify_f)(void *);\n")
            out_c.write("\n")

            for t, info in inst.bfm_type_info_m.items():
                if BfmType.Verilog not in info.hdl.keys():
                    raise Exception("BFM \"" + t.__name__ +
                                    "\" does not support Verilog")

                with open(info.hdl[BfmType.SystemVerilog], "r") as template_f:
                    template = template_f.read()

                bfm_name = os.path.basename(info.hdl[BfmType.SystemVerilog])

                if bfm_name.find('.') != -1:
                    bfm_name = os.path.splitext(bfm_name)[0]

                out_sv.write(process_template_sv(template, bfm_name, info))
                out_c.write(generate_dpi_c(bfm_name, info))

            out_c.write("#ifdef __cplusplus\n")
            out_c.write("}\n")
            out_c.write("#endif\n")
            out_sv.write("`undef PYBFMS_GEN\n")
Example #4
0
def bfm_generate_vl(args):
    inst = BfmMgr.inst()

    with open(args.o, "w") as out:
        out.write(
            "//***************************************************************************\n"
        )
        out.write("//* BFMs file for pybfms. \n")
        out.write(
            "//* Note: This file is generated by pybfms.bfmgen. Do Not Edit\n")
        out.write(
            "//***************************************************************************\n"
        )
        out.write("\n")
        out.write("`define PYBFMS_GEN\n")

        for t, info in inst.bfm_type_info_m.items():

            if BfmType.Verilog not in info.hdl.keys():
                raise Exception("BFM {!r} does not support Verilog".format(
                    t.__name__))

            with open(info.hdl[BfmType.Verilog], "r") as template_f:
                template = template_f.read()

            out.write(process_template_vl(template, info))

        out.write("`undef PYBFMS_GEN\n")
Example #5
0
 def import_taskw(self, *args):
     arg_l = []
     for a in args:
         arg_l.append(a)
     BfmMgr.inst().send_msg(self.bfm_info.id, info.id, arg_l,
                            info.type_info)