Exemplo n.º 1
0
    def run_passes(self):
        Logger.log("Running CoreIR passes...", 1)
        print_level = 3
        if not Logger.level(print_level):
            saved_stdout = suppress_output()

        self.context.run_passes(PASSES)

        if not Logger.level(print_level):
            restore_output(saved_stdout)
Exemplo n.º 2
0
    def parse_file(self, strfile, config, flags=None):
        if flags is None:
            Logger.error("Top module not provided")

        topmodule = flags[0]
        absstrfile = os.path.abspath(strfile)
        directory = "/".join(absstrfile.split("/")[:-1])
        filename = absstrfile.split("/")[-1]

        if self.single_file:
            files = [absstrfile]
        else:
            if self.files_from_dir:
                files = [
                    "%s/%s" % (directory, f) for f in os.listdir(directory)
                    if self._get_extension(f) in self.extensions
                ]
            else:
                files = [
                    "%s/%s" % (directory, f) for f in list(
                        set(self._collect_dependencies(directory, filename)))
                ]
                files.append(absstrfile)

        command = "%s -p \"%s\"" % (CMD, "; ".join(COMMANDS))
        command = command.format(FILES=" ".join(files), \
                                 TARGET=topmodule, \
                                 PASSES="; ".join(PASSES), \
                                 BTORFILE=TMPFILE)

        Logger.log("Command: %s" % command, 2)

        print_level = 3
        if not Logger.level(print_level):
            saved_stdout = suppress_output()

        retval = os.system(command)

        if not Logger.level(print_level):
            restore_output(saved_stdout)

        if retval != 0:
            Logger.error("Error in Verilog conversion")

        parser = BTOR2Parser()
        ret = parser.parse_file(TMPFILE, config)

        if not Logger.level(1):
            os.remove(TMPFILE)

        return ret
Exemplo n.º 3
0
    def parse_file(self, strfile, config, flags=None):
        if flags is None:
            Logger.error("Top module not provided")

        topmodule = flags[0]
        absstrfile = os.path.abspath(strfile)
        directory = "/".join(absstrfile.split("/")[:-1])
        filename = absstrfile.split("/")[-1]

        files = [absstrfile]

        with open(strfile, "r") as f:
            if topmodule not in f.read():
                Logger.error("Module \"%s\" not found"%topmodule)
            
        commands = "\n".join(COMMANDS)
        commands = commands.format(FILES=" ".join(files), \
                                   TARGET=topmodule, \
                                   FILE=TMPFILE)

        command = "%s -script_file %s"%(CMD, TMPCMDFILE)
        
        with open(TMPCMDFILE, "w") as f:
            f.write(commands)
        
        Logger.log("Commands: %s"%commands, 2)

        print_level = 3
        if not Logger.level(print_level):
            saved_stdout = suppress_output()
        
        retval = os.system(command)

        if not Logger.level(print_level):
            restore_output(saved_stdout)

        if retval != 0:
            Logger.error("Error in SystemVerilog conversion")
            
        parser = VerilogHTSParser()
        ret = parser.parse_file(TMPFILE, config, flags=flags)
        self.model_info = parser.get_model_info()

        if (not Logger.level(1)) and (not config.devel):
            os.remove(TMPFILE)
            os.remove(TMPCMDFILE)
        
        return ret
Exemplo n.º 4
0
    def is_available(self):
        if shutil.which(CMD) is None:
            return False

        print_level = 3
        if not Logger.level(print_level):
            saved_stdout = suppress_output()
        
        retval = os.system("%s -h"%CMD)

        if not Logger.level(print_level):
            restore_output(saved_stdout)

        if retval != 0:
            return False
        
        return True
Exemplo n.º 5
0
def available(toolname, optiongrep=None):
    if shutil.which(toolname) is None:
        return False

    print_level = 3
    if not Logger.level(print_level):
        saved_status = suppress_output()

    # assuming there's a -h for the program
    # yosys and verific have it
    retval = os.system("{} -h".format(toolname))

    if not Logger.level(print_level):
        restore_output(saved_status)

    if optiongrep is not None:
        with open(saved_status[0].name, 'r') as f:
            output = f.read()
            if optiongrep not in output:
                return False

    return (retval == 0)
Exemplo n.º 6
0
    def parse_file(self,
                   filepath: Path,
                   config: NamedTuple,
                   flags: str = None) -> Tuple[HTS, List[FNode], List[FNode]]:

        # create copy of yosys commands (will be modified below)
        # Note: This class is only instantiated once per python environment
        #       but we don't want subsequent calls to parse_file to be coupled
        COPY_PASSES = PASSES.copy()
        COPY_OPT_PASSES = OPT_PASSES.copy()
        COPY_COMMANDS = COMMANDS.copy()

        if flags is None:
            Logger.error("Top module not provided")

        if config.verific:
            COPY_COMMANDS[
                0] = "verific -sv2009 {FILES}; verific -import -extnets {TARGET};"

        topmodule = flags[0]
        abspath = filepath.absolute()
        directory = filepath.parent
        filename = filepath.name
        if abspath.is_dir():
            # TODO: Test this feature
            self.files_from_dir = True
        else:
            self.single_file = filename.split(".")[-1] != MULTI_FILE_EXT

        if config.no_arrays:
            COPY_PASSES.append("memory")
        else:
            COPY_PASSES.append("memory -nomap")

        if config.synchronize:
            COPY_PASSES.append("async2sync")

        if config.opt_circuit:
            for op in COPY_OPT_PASSES:
                COPY_PASSES.append(op)
        else:
            COPY_PASSES.append("flatten;")

        if not config.abstract_clock:
            COPY_PASSES.append("clk2fflogic;")
            if config.opt_circuit:
                COPY_PASSES.append("opt;;")

        if self.single_file:
            files = [str(abspath)]
        else:
            if self.files_from_dir:
                files = [
                    str(f) for f in directory.iterdir()
                    if f.suffix[1:] in self.extensions
                ]
            else:
                files = []
                with abspath.open("r") as source_list:
                    Logger.msg(
                        "Reading source files from \"%s\"... " % (filename), 0)
                    for source in source_list.read().split("\n"):
                        source = source.strip()
                        if source:
                            files.append(source)

        command = "%s -p \"%s\"" % (CMD, "; ".join(COPY_COMMANDS))
        command = command.format(FILES=" ".join(files), \
                                 TARGET=topmodule, \
                                 PASSES="; ".join(COPY_PASSES), \
                                 BTORFILE=TMPFILE)

        Logger.log("Command: %s" % command, 2)

        print_level = 3
        if not Logger.level(print_level):
            saved_status = suppress_output(redirect_error=True)

        retval = os.system(command)

        if not Logger.level(print_level):
            restore_output(saved_status)

        if retval != 0:
            os.system("mv %s %s" % (saved_status[0].name, YOSYSERRLOG))
            Logger.error(
                "Error in Verilog conversion.\nSee %s for more info." %
                YOSYSERRLOG)

        parser = BTOR2Parser()
        ret = parser.parse_file(Path(TMPFILE), config)

        if not Logger.level(1):
            os.remove(TMPFILE)

        return ret