示例#1
0
文件: core.py 项目: jjts/fusesoc
    def __init__(self, core_file=None, name=None, core_root=None):
        logger.debug('__init__() *Entered*' +
                     '\n    core_file=' + str(core_file) +
                     '\n    name=' + str(name) + 
                     '\n    core_root=' + str(core_root)
                    )
        if core_file:
            basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.system   = None
        self.verilog  = None
        self.vpi = None
        if core_file:
            config = FusesocConfigParser(core_file)

            if config.has_option('main', 'name'):
                self.name = config.get('main','name')
            else:
                self.name = basename.split('.core')[0]

            self.depend     = config.get_list('main', 'depend')
            self.simulators = config.get_list('main', 'simulators')

            #FIXME : Make simulators part of the core object
            self.simulator        = config.get_section('simulator')
            self.icarus    = IcarusSection(config.get_section('icarus'))
            self.modelsim  = ModelsimSection(config.get_section('modelsim'))
            self.verilator = VerilatorSection(config.get_section('verilator'))
            self.pre_run_scripts  = config.get_list('scripts','pre_run_scripts')
            self.post_run_scripts = config.get_list('scripts','post_run_scripts')

            logger.debug('name=' + str(self.name))
            self.core_root = os.path.dirname(core_file)

            if config.has_section('plusargs'):
                self.plusargs = Plusargs(dict(config.items('plusargs')))
            if config.has_section('provider'):
                self.cache_dir = os.path.join(Config().cache_root, self.name)
                self.files_root = self.cache_dir
                items    = config.items('provider')
                self.provider = ProviderFactory(dict(items))
            else:
                self.files_root = self.core_root

            if config.has_section('verilog'):
                self.verilog = Verilog()
                items = config.items('verilog')
                self.verilog.load_items((dict(items)))
                logger.debug('verilog.src_files=' + str(self.verilog.src_files))
                logger.debug('verilog.include_files=' + str(self.verilog.include_files))
                logger.debug('verilog.include_dirs=' + str(self.verilog.include_dirs))
            if config.has_section('vpi'):
                items = config.items('vpi')
                self.vpi = VPI(dict(items))
            system_file = os.path.join(self.core_root, self.name+'.system')
            if os.path.exists(system_file):
                self.system = System(system_file)
        else:
            self.name = name

            self.core_root = core_root
            self.cache_root = core_root
            self.files_root = core_root

            self.provider = None
        logger.debug('__init__() -Done-')
示例#2
0
文件: core.py 项目: jjts/fusesoc
class Core:
    def __init__(self, core_file=None, name=None, core_root=None):
        logger.debug('__init__() *Entered*' +
                     '\n    core_file=' + str(core_file) +
                     '\n    name=' + str(name) + 
                     '\n    core_root=' + str(core_root)
                    )
        if core_file:
            basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.system   = None
        self.verilog  = None
        self.vpi = None
        if core_file:
            config = FusesocConfigParser(core_file)

            if config.has_option('main', 'name'):
                self.name = config.get('main','name')
            else:
                self.name = basename.split('.core')[0]

            self.depend     = config.get_list('main', 'depend')
            self.simulators = config.get_list('main', 'simulators')

            #FIXME : Make simulators part of the core object
            self.simulator        = config.get_section('simulator')
            self.icarus    = IcarusSection(config.get_section('icarus'))
            self.modelsim  = ModelsimSection(config.get_section('modelsim'))
            self.verilator = VerilatorSection(config.get_section('verilator'))
            self.pre_run_scripts  = config.get_list('scripts','pre_run_scripts')
            self.post_run_scripts = config.get_list('scripts','post_run_scripts')

            logger.debug('name=' + str(self.name))
            self.core_root = os.path.dirname(core_file)

            if config.has_section('plusargs'):
                self.plusargs = Plusargs(dict(config.items('plusargs')))
            if config.has_section('provider'):
                self.cache_dir = os.path.join(Config().cache_root, self.name)
                self.files_root = self.cache_dir
                items    = config.items('provider')
                self.provider = ProviderFactory(dict(items))
            else:
                self.files_root = self.core_root

            if config.has_section('verilog'):
                self.verilog = Verilog()
                items = config.items('verilog')
                self.verilog.load_items((dict(items)))
                logger.debug('verilog.src_files=' + str(self.verilog.src_files))
                logger.debug('verilog.include_files=' + str(self.verilog.include_files))
                logger.debug('verilog.include_dirs=' + str(self.verilog.include_dirs))
            if config.has_section('vpi'):
                items = config.items('vpi')
                self.vpi = VPI(dict(items))
            system_file = os.path.join(self.core_root, self.name+'.system')
            if os.path.exists(system_file):
                self.system = System(system_file)
        else:
            self.name = name

            self.core_root = core_root
            self.cache_root = core_root
            self.files_root = core_root

            self.provider = None
        logger.debug('__init__() -Done-')


    def cache_status(self):
        logger.debug('cache_status() *Entered*')
        if self.provider:
            return self.provider.status(self.cache_dir)
        else:
            return 'local'

    def setup(self):
        logger.debug('setup() *Entered*')
        logger.debug("  name="+self.name)
        if self.provider:
            if self.provider.fetch(self.cache_dir, self.name):
                self.patch(self.cache_dir)
        logger.debug('setup() -Done-')

    def export(self, dst_dir):
        logger.debug('export() *Entered*')
        logger.debug("  name="+self.name)
        if os.path.exists(dst_dir):
            shutil.rmtree(dst_dir)

        src_dir = self.files_root

        #FIXME: Separate tb_files to an own directory tree (src/tb/core_name ?)
        src_files = []
        if self.verilog:
            src_files += self.verilog.export()
        if self.vpi:
            src_files += self.vpi.export()

        dirs = list(set(map(os.path.dirname,src_files)))
        logger.debug("export src_files=" + str(src_files))
        logger.debug("export dirs=" + str(dirs))
        for d in dirs:
            if not os.path.exists(os.path.join(dst_dir, d)):
                os.makedirs(os.path.join(dst_dir, d))

        for f in src_files:
            if(os.path.exists(os.path.join(src_dir, f))):
                shutil.copyfile(os.path.join(src_dir, f), 
                                os.path.join(dst_dir, f))
            else:
                print("File " + os.path.join(src_dir, f) + " doesn't exist")
        logger.debug('export() -Done-')
        
    def patch(self, dst_dir):
        logger.debug('patch() *Entered*')
        logger.debug("  name=" + self.name)
        #FIXME: Use native python patch instead
        patch_root = os.path.join(self.core_root, 'patches')
        if os.path.exists(patch_root):
            for f in sorted(os.listdir(patch_root)):
                patch_file = os.path.abspath(os.path.join(patch_root, f))
                if os.path.isfile(patch_file):
                    logger.debug("  applying patch file: " + patch_file + "\n" +
                                 "                   to: " + os.path.join(dst_dir))
                    try:
                        subprocess.call(['patch','-p1', '-s',
                                         '-d', os.path.join(dst_dir),
                                         '-i', patch_file])
                    except OSError:
                        print("Error: Failed to call external command 'patch'")
                        return False
        logger.debug('patch() -Done-')
        return True

    def info(self):
        logger.debug('info() *Entered*')

        show_list = lambda l: "\n                        ".join(l)
        show_dict = lambda d: show_list(["%s: %s" % (k, d[k]) for k in d.keys()])

        print("CORE INFO")
        print("Name:                   " + self.name)
        print("Core root:              " + self.core_root)
        if self.simulators:
            print("Simulators:             " + show_list(self.simulators))
        if self.plusargs: 
            print("\nPlusargs:               " + show_dict(self.plusargs.items))
        if self.depend:
            print("\nCores:                  " + show_list(self.depend))
        if self.verilog.include_dirs:
            print("\nInclude dirs:           " + show_list(self.verilog.include_dirs))
        if self.verilog.include_files:
            print("\nInclude files:          " + show_list(self.verilog.include_files))
        if self.verilog.src_files:
            print("\nSrc files:              " + show_list(self.verilog.src_files))
        if self.verilog.tb_src_files:
            print("\nTestbench files:        " + show_list(self.verilog.tb_src_files))
        if self.verilog.tb_private_src_files:
            print("\nPrivate Testbench files:" + show_list(self.verilog.tb_private_src_files))
        if self.verilog.tb_include_files:
            print("\nTestbench include files:" + show_list(self.verilog.tb_include_files))
        if self.verilog.tb_include_dirs:
            print("\nTestbench include dirs: " + show_list(self.verilog.tb_include_dirs))
        logger.debug('info() -Done-')
示例#3
0
    def __init__(self, core_file=None, name=None, core_root=None):
        logger.debug('__init__() *Entered*' + '\n    core_file=' +
                     str(core_file) + '\n    name=' + str(name) +
                     '\n    core_root=' + str(core_root))
        if core_file:
            basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.system = None
        self.verilog = None
        self.vpi = None
        if core_file:
            config = FusesocConfigParser(core_file)

            if config.has_option('main', 'name'):
                self.name = config.get('main', 'name')
            else:
                self.name = basename.split('.core')[0]

            self.depend = config.get_list('main', 'depend')
            self.simulators = config.get_list('main', 'simulators')

            #FIXME : Make simulators part of the core object
            self.simulator = config.get_section('simulator')
            self.icarus = IcarusSection(config.get_section('icarus'))
            self.modelsim = ModelsimSection(config.get_section('modelsim'))
            self.verilator = VerilatorSection(config.get_section('verilator'))
            self.pre_run_scripts = config.get_list('scripts',
                                                   'pre_run_scripts')
            self.post_run_scripts = config.get_list('scripts',
                                                    'post_run_scripts')

            logger.debug('name=' + str(self.name))
            self.core_root = os.path.dirname(core_file)

            if config.has_section('plusargs'):
                self.plusargs = Plusargs(dict(config.items('plusargs')))
            if config.has_section('provider'):
                self.cache_dir = os.path.join(Config().cache_root, self.name)
                self.files_root = self.cache_dir
                items = config.items('provider')
                self.provider = ProviderFactory(dict(items))
            else:
                self.files_root = self.core_root

            if config.has_section('verilog'):
                self.verilog = Verilog()
                items = config.items('verilog')
                self.verilog.load_items((dict(items)))
                logger.debug('verilog.src_files=' +
                             str(self.verilog.src_files))
                logger.debug('verilog.include_files=' +
                             str(self.verilog.include_files))
                logger.debug('verilog.include_dirs=' +
                             str(self.verilog.include_dirs))
            if config.has_section('vpi'):
                items = config.items('vpi')
                self.vpi = VPI(dict(items))
            system_file = os.path.join(self.core_root, self.name + '.system')
            if os.path.exists(system_file):
                self.system = System(system_file)
        else:
            self.name = name

            self.core_root = core_root
            self.cache_root = core_root
            self.files_root = core_root

            self.provider = None
        logger.debug('__init__() -Done-')
示例#4
0
文件: simulator.py 项目: jjts/fusesoc
    def __init__(self, system):
        logger.debug('__init__() *Entered*')
        config = Config()
        self.system = system
        self.build_root = os.path.join(config.build_root, self.system.name)

        self.src_root = os.path.join(self.build_root, 'src')

        if 'toplevel' in self.system.simulator:
            self.toplevel = self.system.simulator['toplevel']
        else:
            self.toplevel = 'orpsoc_tb'

        self.vpi_modules = []

        self.cm = CoreManager()
        self.cores = self.cm.get_depends(self.system.name)
        logger.debug("depend -->  " + str(self.cores))

        self.env = os.environ.copy()
        self.env['CORE_ROOT'] = os.path.abspath(self.system.core_root)
        self.env['BUILD_ROOT'] = os.path.abspath(self.build_root)
        self.env['SIMULATOR'] = self.TOOL_NAME

        self.verilog = Verilog()
        for core_name in self.cores:
            logger.debug('core_name=' + core_name)
            core = self.cm.get_core(core_name)

            if core.verilog:
                if core.verilog.include_dirs:
                    logger.debug('core.include_dirs=' +
                                 str(core.verilog.include_dirs))
                else:
                    logger.debug('core.include_dirs=None')
                self.verilog.include_dirs += [
                    os.path.join(self.src_root, core_name, d)
                    for d in core.verilog.include_dirs
                ]
                self.verilog.tb_include_dirs += [
                    os.path.join(self.src_root, core_name, d)
                    for d in core.verilog.tb_include_dirs
                ]
                self.verilog.src_files += [
                    os.path.join(self.src_root, core_name, f)
                    for f in core.verilog.src_files
                ]
                self.verilog.tb_src_files += [
                    os.path.join(self.src_root, core_name, f)
                    for f in core.verilog.tb_src_files
                ]
                if core_name == self.system.name:
                    self.verilog.tb_src_files += [
                        os.path.join(self.src_root, core_name, f)
                        for f in core.verilog.tb_private_src_files
                    ]

            if core.vpi:
                vpi_module = {}
                core_root = os.path.join(self.src_root, core_name)
                vpi_module['include_dirs'] = [
                    os.path.abspath(os.path.join(core_root, d))
                    for d in core.vpi.include_dirs
                ]
                vpi_module['src_files'] = [
                    os.path.abspath(os.path.join(core_root, f))
                    for f in core.vpi.src_files
                ]
                vpi_module['name'] = core.vpi.name
                vpi_module['libs'] = [l for l in core.vpi.libs]
                self.vpi_modules += [vpi_module]

        logger.debug('__init__() -Done-')
示例#5
0
class Core:
    def __init__(self, core_file=None, name=None, core_root=None):
        logger.debug('__init__() *Entered*' + '\n    core_file=' +
                     str(core_file) + '\n    name=' + str(name) +
                     '\n    core_root=' + str(core_root))
        if core_file:
            basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.system = None
        self.verilog = None
        self.vpi = None
        if core_file:
            config = FusesocConfigParser(core_file)

            if config.has_option('main', 'name'):
                self.name = config.get('main', 'name')
            else:
                self.name = basename.split('.core')[0]

            self.depend = config.get_list('main', 'depend')
            self.simulators = config.get_list('main', 'simulators')

            #FIXME : Make simulators part of the core object
            self.simulator = config.get_section('simulator')
            self.icarus = IcarusSection(config.get_section('icarus'))
            self.modelsim = ModelsimSection(config.get_section('modelsim'))
            self.verilator = VerilatorSection(config.get_section('verilator'))
            self.pre_run_scripts = config.get_list('scripts',
                                                   'pre_run_scripts')
            self.post_run_scripts = config.get_list('scripts',
                                                    'post_run_scripts')

            logger.debug('name=' + str(self.name))
            self.core_root = os.path.dirname(core_file)

            if config.has_section('plusargs'):
                self.plusargs = Plusargs(dict(config.items('plusargs')))
            if config.has_section('provider'):
                self.cache_dir = os.path.join(Config().cache_root, self.name)
                self.files_root = self.cache_dir
                items = config.items('provider')
                self.provider = ProviderFactory(dict(items))
            else:
                self.files_root = self.core_root

            if config.has_section('verilog'):
                self.verilog = Verilog()
                items = config.items('verilog')
                self.verilog.load_items((dict(items)))
                logger.debug('verilog.src_files=' +
                             str(self.verilog.src_files))
                logger.debug('verilog.include_files=' +
                             str(self.verilog.include_files))
                logger.debug('verilog.include_dirs=' +
                             str(self.verilog.include_dirs))
            if config.has_section('vpi'):
                items = config.items('vpi')
                self.vpi = VPI(dict(items))
            system_file = os.path.join(self.core_root, self.name + '.system')
            if os.path.exists(system_file):
                self.system = System(system_file)
        else:
            self.name = name

            self.core_root = core_root
            self.cache_root = core_root
            self.files_root = core_root

            self.provider = None
        logger.debug('__init__() -Done-')

    def cache_status(self):
        logger.debug('cache_status() *Entered*')
        if self.provider:
            return self.provider.status(self.cache_dir)
        else:
            return 'local'

    def setup(self):
        logger.debug('setup() *Entered*')
        logger.debug("  name=" + self.name)
        if self.provider:
            if self.provider.fetch(self.cache_dir, self.name):
                self.patch(self.cache_dir)
        logger.debug('setup() -Done-')

    def export(self, dst_dir):
        logger.debug('export() *Entered*')
        logger.debug("  name=" + self.name)
        if os.path.exists(dst_dir):
            shutil.rmtree(dst_dir)

        src_dir = self.files_root

        #FIXME: Separate tb_files to an own directory tree (src/tb/core_name ?)
        src_files = []
        if self.verilog:
            src_files += self.verilog.export()
        if self.vpi:
            src_files += self.vpi.export()

        dirs = list(set(map(os.path.dirname, src_files)))
        logger.debug("export src_files=" + str(src_files))
        logger.debug("export dirs=" + str(dirs))
        for d in dirs:
            if not os.path.exists(os.path.join(dst_dir, d)):
                os.makedirs(os.path.join(dst_dir, d))

        for f in src_files:
            if (os.path.exists(os.path.join(src_dir, f))):
                shutil.copyfile(os.path.join(src_dir, f),
                                os.path.join(dst_dir, f))
            else:
                print("File " + os.path.join(src_dir, f) + " doesn't exist")
        logger.debug('export() -Done-')

    def patch(self, dst_dir):
        logger.debug('patch() *Entered*')
        logger.debug("  name=" + self.name)
        #FIXME: Use native python patch instead
        patch_root = os.path.join(self.core_root, 'patches')
        if os.path.exists(patch_root):
            for f in sorted(os.listdir(patch_root)):
                patch_file = os.path.abspath(os.path.join(patch_root, f))
                if os.path.isfile(patch_file):
                    logger.debug("  applying patch file: " + patch_file +
                                 "\n" + "                   to: " +
                                 os.path.join(dst_dir))
                    try:
                        subprocess.call([
                            'patch', '-p1', '-s', '-d',
                            os.path.join(dst_dir), '-i', patch_file
                        ])
                    except OSError:
                        print("Error: Failed to call external command 'patch'")
                        return False
        logger.debug('patch() -Done-')
        return True

    def info(self):
        logger.debug('info() *Entered*')

        show_list = lambda l: "\n                        ".join(l)
        show_dict = lambda d: show_list(
            ["%s: %s" % (k, d[k]) for k in d.keys()])

        print("CORE INFO")
        print("Name:                   " + self.name)
        print("Core root:              " + self.core_root)
        if self.simulators:
            print("Simulators:             " + show_list(self.simulators))
        if self.plusargs:
            print("\nPlusargs:               " +
                  show_dict(self.plusargs.items))
        if self.depend:
            print("\nCores:                  " + show_list(self.depend))
        if self.verilog.include_dirs:
            print("\nInclude dirs:           " +
                  show_list(self.verilog.include_dirs))
        if self.verilog.include_files:
            print("\nInclude files:          " +
                  show_list(self.verilog.include_files))
        if self.verilog.src_files:
            print("\nSrc files:              " +
                  show_list(self.verilog.src_files))
        if self.verilog.tb_src_files:
            print("\nTestbench files:        " +
                  show_list(self.verilog.tb_src_files))
        if self.verilog.tb_private_src_files:
            print("\nPrivate Testbench files:" +
                  show_list(self.verilog.tb_private_src_files))
        if self.verilog.tb_include_files:
            print("\nTestbench include files:" +
                  show_list(self.verilog.tb_include_files))
        if self.verilog.tb_include_dirs:
            print("\nTestbench include dirs: " +
                  show_list(self.verilog.tb_include_dirs))
        logger.debug('info() -Done-')