Exemple #1
0
class hdlTool():
    def __init__(self):
        self.collection_list = []
        self.organized_list = []
        self.testbench_list = []
        self.project_path = self._get_caller_filepath()
        self.compiler = Compiler(self.project_path)
        self.args = self._parse_arguments()

    def _parse_arguments(self):
        ap = argparse.ArgumentParser(
            description="hdlTool command line arguments")
        ap.add_argument('-lt',
                        '--list_tc',
                        help="list testcases",
                        action='store_true')
        ap.add_argument('-nc',
                        '--no_compile',
                        help='no compilation',
                        action='store_true')
        ap.add_argument('-lc',
                        '--list_compile',
                        help='list compile order',
                        action='store_true')
        ap.add_argument('-v', '--verbose', help="terminal output")
        return ap.parse_args()

    def _get_caller_filepath(self):
        abs_path = os.path.abspath((inspect.stack()[2])[3])
        return os.path.dirname(abs_path)

    def add_collection(self, collection):
        if not (collection in self.collection_list):
            self.collection_list.append(collection)

    def get_collections(self):
        if self.organized_list:
            return self.organized_list
        else:
            return self.collection_list

    def organize_collection(self):
        """
        Organize collections based on library dependencies
        """
        collection_list_copy = self.collection_list.copy()
        self.organized_list = self.collection_list.copy()

        for run_idx in range(0, len(self.collection_list)):
            for check_collection in collection_list_copy:
                for dep_collection in self.organized_list:
                    if dep_collection.get_library(
                    ) in check_collection.get_external_dependency():
                        check_idx = self.organized_list.index(check_collection)
                        dep_idx = self.organized_list.index(dep_collection)

                        # Swap items in list
                        if check_idx < dep_idx:
                            self.organized_list[check_idx], self.organized_list[
                                dep_idx] = self.organized_list[
                                    dep_idx], self.organized_list[check_idx]

    def list_compile_order(self):
        print(
            "\n================================ HDL Tool ================================"
        )
        for idx, item in enumerate(self.organized_list):
            print("[%i] Lib: %s" % (idx + 1, item.get_library()))

    def collection(self):
        return Collection()

    def compile_collection(self):
        """
        Create the compile.do file
        """
        for collection in self.organized_list:
            lib = collection.get_library()
            self.compiler.set_library(lib)
            for vhd_obj in collection.get_compile_order():
                filename = vhd_obj.get_filename()
                self.compiler.compile_file(filename)
        self.compiler.run_compilation()
        self.compiler.clean_up()

    def compile(self):
        self.compile_collection()

    def add_testbench(self,
                      testbench_name,
                      simulator="modelsim",
                      verbose=False):
        return Testbench(testbench_name, project_path=self.project_path)
Exemple #2
0
class Testbench:
    def __init__(self,
                 testbench_name,
                 project_path=".",
                 simulator="modelsim",
                 verbose=False):
        self.generics_list = []
        self.filename = None
        self.testbench_name = testbench_name
        self.entity = None
        self.library = None
        self.simulator = simulator
        self.verbose = verbose
        self.compiler = Compiler(project_path, filename="tb_compiler.do")

    def get_testbench_name(self):
        return self.testbench_name

    def set_testbench_name(self, name):
        self.testbench_name = name

    def set_entity(self, name):
        self.entity = name

    def set_name(self, name):
        self.entity(name)

    def get_entity(self):
        return self.entity

    def get_name(self):
        return self.get_entity()

    def set_library(self, library):
        self.library = library.lower()

    def get_library(self):
        return self.library

    def set_filename(self, filename):
        self.filename = filename

    def get_filename(self):
        return self.filename

    def set_harness(self, harness):
        self.harness = harness

    def get_harness(self):
        return self.harness

    def add_generic(self, name, value):
        self.generics_list.append([name, value.lower()])

    def add_generics(self, generics_list):
        for name, value in generics_list:
            self.add_generic(name, value)

    def get_generics(self):
        return self._get_generics()

    def _get_generics(self):
        generic_list = []
        num_generics = len(self.generics_list)
        for idx, generic in enumerate(self.generics_list):
            generic_string = "-g" + generic[0].upper(
            ) + "=" + generic[1].lower()
            if (idx + 1) < num_generics:
                generic_string += " "
            generic_list.append(generic_string)
        return generic_list

    def _run_cmd(self, cmd, path="."):
        print("Running: %s" % (cmd))
        if self.verbose:
            run = subprocess.run(cmd,
                                 cwd=path,
                                 stdout=FNULL,
                                 stderr=subprocess.PIPE,
                                 shell=True,
                                 env={'PATH': os.getenv('PATH')})
        else:
            run = subprocess.run(cmd,
                                 cwd=path,
                                 stderr=subprocess.PIPE,
                                 shell=True,
                                 env={'PATH': os.getenv('PATH')})

    def set_compile_directives(self, directives, simulator="modelsim"):
        self.compile_directives = directives

    def _set_compile_directices(self, simulator="modelsim"):
        if simulator.lower() == "aldec" or simulator.lower() == "rivierapro":
            self.compile_directives = "-2008 -nowarn COMP96_0564 -nowarn COMP96_0048 -dbg -work " + self.get_library(
            )
        else:
            self.compile_directives = "-suppress 1346,1236 -2008 -work " + self.get_library(
            )

    def get_compile_directives(self, simulator="modelsim"):
        if simulator.lower() == "aldec" or simulator.lower() == "rivierapro":
            return "-2008 -nowarn COMP96_0564 -nowarn COMP96_0048 -dbg -work " + self.get_library(
            )
        else:
            return "-suppress 1346,1236 -2008 -work " + self.get_library()

    def run_simulation(self, generics):
        path = os.getcwd().replace("\\", "/") + "/sim"
        env_var = os.environ.copy()
        env_var["SIMULATOR"] = "MODELSIM"
        for generic in generics:
            with open("sim/run.do", 'w') as file:
                file.write("vsim " + generic + " " + self.get_library() + "." +
                           self.get_entity() + "\n")
                file.write("run -all\n")
                file.write("exit -f\n")
            process = subprocess.Popen(["vsim", "-c", "-do", "run.do"],
                                       env=env_var,
                                       stderr=subprocess.PIPE,
                                       cwd=path)
            process.wait()

    def run_testbench(self, simulator="modelsim"):
        if self.compiler:
            self.compiler.set_library(self.get_library())
            self.compiler.compile_file(self.get_harness())
            self.compiler.add_to_compile_file(self.get_testbench_name())
            self.compiler.run_compilation()

            self.run_simulation(self._get_generics())
        else:
            print("ERROR! No compiler found.")
        return
Exemple #3
0
class Goviaji:
    def __init__(self, file_name):
        self.proof_steps_budget = 10000
        self.max_eval_steps = 1000
        self.prover_cache = {}
        self.compiler = Compiler()
        self.compiler.compile_file(file_name)
        self.compiler.finalize()
        self.syntax_predicate_name = self.compiler.rules_db.constants["term"] \
            if "term" in self.compiler.rules_db.constants else None

        self.value_predicate_name = self.compiler.rules_db.constants["value"] \
            if "value" in self.compiler.rules_db.constants else None

        self.eval_predicate_name = self.compiler.rules_db.constants["eval"] \
            if "eval" in self.compiler.rules_db.constants else None

        print("%d rules loaded: %s" %
              (len(self.compiler.rules_db.rules_by_name), ", ".join(
                  rn.name
                  for rn in self.compiler.rules_db.rules_by_name.keys())))

        print("%d defs loaded: %s" %
              (len(self.compiler.rules_db.definitions), ", ".join(
                  rn.name
                  for rn in self.compiler.rules_db.definitions.keys())))

        print("%d outputs loaded: %s" %
              (len(self.compiler.expressions_to_print), ", ".join(
                  rn.name
                  for rn in self.compiler.expressions_to_print.keys())))

    def property_check(self, expr, property_name):
        test_proposition = [expression_from_list([property_name, expr])]
        steps, subs = next(
            prover.prove_dfs(self.compiler.rules_db, test_proposition,
                             self.proof_steps_budget, self.prover_cache))
        return steps, subs is not None

    def syntax_check(self, expr):
        return self.property_check(expr, self.syntax_predicate_name)

    def value_check(self, expr):
        return self.property_check(expr, self.value_predicate_name)

    def eval_step(self, expr):
        target_var = self.compiler.rules_db.introduce_variable()
        eval_proposition = [
            expression_from_list([self.eval_predicate_name, expr, target_var])
        ]
        steps, subs = next(
            prover.prove_dfs(self.compiler.rules_db, eval_proposition,
                             self.proof_steps_budget, self.prover_cache))

        return steps, subs.replacements[
            target_var] if subs is not None else subs

    def steps_report(self, num_steps):
        return "[%d steps%s]" % (num_steps, " - stopped" *
                                 (num_steps >= self.proof_steps_budget))

    def str_to_expression(self, s):
        tokens = tokenize(s)
        parsed_expr = parse_expression(tokens)
        return self.compiler.compile_expression(parsed_expr, tokens)
Exemple #4
0
class Hdl_tool():
    def __init__(self):
        self.collection_list = []
        self.organized_list = []
        self.testbench_list = []
        self.project_path = self._get_caller_filepath()
        self.compiler = Compiler(self.project_path)

    def _get_caller_filepath(self):
        abs_path = os.path.abspath((inspect.stack()[2])[3])
        return os.path.dirname(abs_path)

    def add_collection(self, collection):
        if not (collection in self.collection_list):
            self.collection_list.append(collection)

    def get_collections(self):
        if self.organized_list:
            return self.organized_list
        else:
            return self.collection_list

    def organize_collection(self):
        """
        Organize collections based on library dependencies
        """
        collection_list_copy = self.collection_list.copy()
        self.organized_list = self.collection_list.copy()

        for run in range(1, len(self.collection_list)):
            for check_collection in collection_list_copy:
                for dep_collection in self.organized_list:
                    if dep_collection.get_library(
                    ) in check_collection.get_external_dependency():
                        check_idx = self.organized_list.index(check_collection)
                        dep_idx = self.organized_list.index(dep_collection)

                        # Swap items in list
                        if check_idx < dep_idx:
                            self.organized_list[check_idx], self.organized_list[
                                dep_idx] = self.organized_list[
                                    dep_idx], self.organized_list[check_idx]

    def list_compile_order(self):
        print(
            "\n================================ HDL Tool ================================"
        )
        for idx, item in enumerate(self.organized_list):
            print("[%i] Lib: %s" % (idx + 1, item.get_library()))

    def collection(self):
        return Collection()

    def compile_collection(self):
        """
        Create the compile.do file
        """
        for collection in self.organized_list:
            lib = collection.get_library()
            self.compiler.set_library(lib)
            for vhd_obj in collection.get_compile_order():
                filename = vhd_obj.get_filename()
                self.compiler.compile_file(filename)
        self.compiler.run_compilation()
        self.compiler.clean_up()

    def compile(self):
        self.compile_collection()

    def add_testbench(self,
                      testbench_name,
                      simulator="modelsim",
                      verbose=False):
        return Testbench(testbench_name, project_path=self.project_path)