Example #1
0
    def _merge_system_file(self, system_file, config):
        def _replace(sec, src=None, dst=None):
            if not system.has_section(sec):
                return

            if not config.has_section(sec):
                config.add_section(sec)

            if src:
                if system.has_option(sec, src):
                    items = [src]
                else:
                    items = []
            else:
                items = system.options(sec)

            for item in items:
                if dst:
                    _dst = dst
                else:
                    _dst = item
                if not config.has_option(sec, _dst):
                    config.set(sec, _dst, system.get(sec, item))

        system = FusesocConfigParser(system_file)
        for section in ['icestorm', 'ise', 'quartus', 'vivado']:
            _replace(section)

        _replace('main', 'backend')
        _replace('scripts', 'pre_build_scripts', 'pre_synth_scripts')
        _replace('scripts', 'post_build_scripts', 'post_impl_scripts')
Example #2
0
    def _merge_system_file(self, system_file, config):
        def _replace(sec, src=None, dst=None):
            if not system.has_section(sec):
                return

            if not config.has_section(sec):
                config.add_section(sec)

            if src:
                if system.has_option(sec, src):
                    items = [src]
                else:
                    items = []
            else:
                items = system.options(sec)

            for item in items:
                if dst:
                    _dst = dst
                else:
                    _dst = item
                if not config.has_option(sec, _dst):
                    config.set(sec, _dst, system.get(sec, item))

        system = FusesocConfigParser(system_file)
        for section in ["icestorm", "ise", "quartus", "vivado", "trellis"]:
            _replace(section)

        _replace("main", "backend")
        _replace("scripts", "pre_build_scripts", "pre_synth_scripts")
        _replace("scripts", "post_build_scripts", "post_impl_scripts")
Example #3
0
    def __init__(self, core_file, cache_root=""):
        basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.backend = None

        for s in section.SECTION_MAP:
            assert not hasattr(self, s)
            if section.SECTION_MAP[s].named:
                setattr(self, s, OrderedDict())
            else:
                setattr(self, s, None)

        self.core_root = os.path.dirname(core_file)
        self.files_root = self.core_root

        self.export_files = []

        config = FusesocConfigParser(core_file)

        # Add .system options to .core file
        system_file = os.path.join(self.core_root,
                                   basename.split(".core")[0] + ".system")
        if os.path.exists(system_file):
            self._merge_system_file(system_file, config)

        # FIXME : Make simulators part of the core object
        self.simulator = config.get_section("simulator")
        if not "toplevel" in self.simulator:
            self.simulator["toplevel"] = "orpsoc_tb"

        for s in section.load_all(config, core_file):
            if type(s) == tuple:
                _l = getattr(self, s[0].TAG)
                _l[s[1]] = s[0]
                setattr(self, s[0].TAG, _l)
            else:
                setattr(self, s.TAG, s)

        if not self.main:
            self.main = section.MainSection()
        if self.main.name:
            self.name = Vlnv(self.main.name)
        else:
            self.name = Vlnv(basename.split(".core")[0])

        self.sanitized_name = self.name.sanitized_name

        self.depend = self.main.depend[:]

        self.simulators = self.main.simulators

        if self.main.backend:
            try:
                self.backend = getattr(self, self.main.backend)
            except AttributeError:
                raise SyntaxError('Invalid backend "{}"'.format(
                    self.main.backend))

        self._collect_filesets()

        cache_root = os.path.join(cache_root, self.sanitized_name)
        if config.has_section("plusargs"):
            self._warning(
                "plusargs section is deprecated and will not be parsed by FuseSoC. Please migrate to parameters"
            )
            self.plusargs = Plusargs(dict(config.items("plusargs")))
        if config.has_section("verilator") and config.has_option(
                "verilator", "define_files"):
            self._warning("verilator define_files are deprecated")
        if config.has_section("provider"):
            items = dict(config.items("provider"))
            patch_root = os.path.join(self.core_root, "patches")
            patches = self.main.patches
            if os.path.exists(patch_root):
                for p in sorted(os.listdir(patch_root)):
                    patches.append(os.path.join("patches", p))
            items["patches"] = patches
            provider_name = items.get("name")
            if provider_name is None:
                raise RuntimeError('Missing "name" in section [provider]')
            self.provider = get_provider(provider_name)(items, self.core_root,
                                                        cache_root)
        if self.provider:
            self.files_root = self.provider.files_root

        # We need the component file here, but it might not be
        # available until the core is fetched. Try to fetch first if any
        # of the component files are missing
        if False in [os.path.exists(f) for f in self.main.component]:
            self.setup()

        for f in self.main.component:
            self._parse_component(f)
Example #4
0
    def __init__(self, core_file, cache_root=''):
        basename = os.path.basename(core_file)
        self.depend = []
        self.simulators = []

        self.plusargs = None
        self.provider = None
        self.backend  = None

        for s in section.SECTION_MAP:
            assert(not hasattr(self, s))
            if(section.SECTION_MAP[s].named):
                setattr(self, s, OrderedDict())
            else:
                setattr(self, s, None)

        self.core_root = os.path.dirname(core_file)
        self.files_root = self.core_root

        self.export_files = []

        config = FusesocConfigParser(core_file)

        #Add .system options to .core file
        system_file = os.path.join(self.core_root, basename.split('.core')[0]+'.system')
        if os.path.exists(system_file):
            self._merge_system_file(system_file, config)

        #FIXME : Make simulators part of the core object
        self.simulator        = config.get_section('simulator')
        if not 'toplevel' in self.simulator:
            self.simulator['toplevel'] = 'orpsoc_tb'

        for s in section.load_all(config, core_file):
            if type(s) == tuple:
                _l = getattr(self, s[0].TAG)
                _l[s[1]] = s[0]
                setattr(self, s[0].TAG, _l)
            else:
                setattr(self, s.TAG, s)

        if not self.main:
            self.main = section.MainSection()
        if self.main.name:
            self.name = Vlnv(self.main.name)
        else:
            self.name = Vlnv(basename.split('.core')[0])

        self.sanitized_name = self.name.sanitized_name

        self.depend     = self.main.depend[:]

        self.simulators = self.main.simulators

        if self.main.backend:
            try:
                self.backend = getattr(self, self.main.backend)
            except AttributeError:
                raise SyntaxError('Invalid backend "{}"'.format(self.main.backend))

        self._collect_filesets()

        cache_root = os.path.join(cache_root, self.sanitized_name)
        if config.has_section('plusargs'):
            self._warning("plusargs section is deprecated and will not be parsed by FuseSoC. Please migrate to parameters")
            self.plusargs = Plusargs(dict(config.items('plusargs')))
        if config.has_section('verilator') and config.has_option('verilator', 'define_files'):
            self._warning("verilator define_files are deprecated")
        if config.has_section('provider'):
            items    = dict(config.items('provider'))
            patch_root = os.path.join(self.core_root, 'patches')
            patches = self.main.patches
            if os.path.exists(patch_root):
                for p in sorted(os.listdir(patch_root)):
                    patches.append(os.path.join('patches', p))
            items['patches'] = patches
            provider_name = items.get('name')
            if provider_name is None:
                raise RuntimeError('Missing "name" in section [provider]')
            self.provider = get_provider(provider_name)(
                items, self.core_root, cache_root)
        if self.provider:
            self.files_root = self.provider.files_root

        # We need the component file here, but it might not be
        # available until the core is fetched. Try to fetch first if any
        # of the component files are missing
        if False in [os.path.exists(f) for f in self.main.component]:
            self.setup()

        for f in self.main.component:
            self._parse_component(f)