def __WriteGHDLSection(self, binPath): if (self._host.Platform == "Windows"): ghdlPath = binPath / "ghdl.exe" else: ghdlPath = binPath / "ghdl" if not ghdlPath.exists(): raise ConfigurationException("Executable '{0!s}' not found.".format(ghdlPath)) from FileNotFoundError( str(ghdlPath)) # get version and backend output = check_output([str(ghdlPath), "-v"], universal_newlines=True) version = None backend = None versionRegExpStr = r"^GHDL (.+?) " versionRegExp = RegExpCompile(versionRegExpStr) backendRegExpStr = r"(?i).*(mcode|gcc|llvm).* code generator" backendRegExp = RegExpCompile(backendRegExpStr) for line in output.split('\n'): if version is None: match = versionRegExp.match(line) if match is not None: version = match.group(1) if backend is None: match = backendRegExp.match(line) if match is not None: backend = match.group(1).lower() self._host.PoCConfig[self._section]['Version'] = '<unknown>' if version is None else version self._host.PoCConfig[self._section]['Backend'] = '<unknown>' if backend is None else backend
def GHDLRunFilter(gen): # Pattern Classification # ------------------------------------------------------------------------------------------------------ # <path>:<line>:<column>: <message> -> Severity.Error (by (*)) # <path>:<line>:<column>:<severity>: <message> -> According to <severity> # <path>:<line>:<column>:@<time>:(report <severity>): <message> -> According to <severity> # others -> Severity.Normal # (*) -> unknown <severity> -> Severity.Error filterPattern = r".+?:\d+:\d+:((?P<report>@\w+:\((?:report|assertion) )?(?P<severity>\w+)(?(report)\)):)? (?P<message>.*)" filterRegExp = RegExpCompile(filterPattern) lineno = 0 for line in gen: if (lineno < 2): lineno += 1 if ("Linking in memory" in line): yield LogEntry(line, Severity.Verbose) continue if ("Starting simulation" in line): yield LogEntry(line, Severity.Verbose) continue filterMatch = filterRegExp.match(line) if filterMatch is not None: yield LogEntry(line, Severity.ParseVHDLSeverityLevel(filterMatch.group('severity'), Severity.Error)) continue yield LogEntry(line, Severity.Normal)
def _DecodeXilinx(self, deviceString): self.__vendor = Vendors.Xilinx self.__generation = int(deviceString[2:3]) familyToken = deviceString[3:4].lower() for fam in XilinxFamilies: if fam.Token == familyToken: self.__family = fam break else: raise ConfigurationException("Unknown Xilinx device family.") deviceRegExpStr = r"(?P<st1>[a-z]{0,2})" # device subtype - part 1 deviceRegExpStr += r"(?P<no>\d{1,4})" # device number deviceRegExpStr += r"(?P<st2>[t]{0,1})" # device subtype - part 2 deviceRegExpStr += r"(?P<sg>[-1-5]{2})" # speed grade deviceRegExpStr += r"(?P<pack>[a-z]{1,3})" # package deviceRegExpStr += r"(?P<pins>\d{1,4})" # pin count deviceRegExp = RegExpCompile(deviceRegExpStr) deviceRegExpMatch = deviceRegExp.match(deviceString[4:].lower()) if (deviceRegExpMatch is not None): subtype = deviceRegExpMatch.group('st1') + deviceRegExpMatch.group('st2') package = deviceRegExpMatch.group('pack') if (subtype != ""): self.__subtype = SubTypes[subtype.upper()] else: self.__subtype = SubTypes.NoSubType self.__number = int(deviceRegExpMatch.group('no')) self.__speedGrade = int(deviceRegExpMatch.group('sg')) self.__package = Packages[package.upper()] self.__pinCount = int(deviceRegExpMatch.group('pins')) else: raise ConfigurationException("RegExp mismatch.")
def _DecodeAltera(self, deviceString): self.__vendor = Vendors.Altera deviceRegExpStr = r"(?P<gen>\d{1,2})" # generation deviceRegExpStr += r"(?P<fam>[acms])" # family deviceRegExpStr += r"(?P<st>(ls|e|g|x|t|gs|gx|gt|gz|sx|st)?)" # subtype deviceRegExp = RegExpCompile(deviceRegExpStr) deviceRegExpMatch = deviceRegExp.match(deviceString[2:].lower()) if (deviceRegExpMatch is not None): self.__generation = int(deviceRegExpMatch.group('gen')) family = deviceRegExpMatch.group('fam') for fam in AlteraFamilies: if fam.Token == family: self.__family = fam break else: raise ConfigurationException("Unknown Altera device family.") subtype = deviceRegExpMatch.group('st') if (subtype != ""): d = {"g": "gx", "x": "sx", "t": "gt"} # re-name for Stratix 10 and Arria 10 if subtype in d: subtype = d[subtype] self.__subtype = SubTypes[subtype.upper()] else: self.__subtype = SubTypes.NoSubType else: raise ConfigurationException("RegExp mismatch.")
def __GetQuestaSimVersion(self, binPath): if (self._host.Platform == "Windows"): vsimPath = binPath / "vsim.exe" else: vsimPath = binPath / "vsim" if not vsimPath.exists(): raise ConfigurationException("Executable '{0!s}' not found.".format(vsimPath)) from FileNotFoundError( str(vsimPath)) # get version and backend try: output = check_output([str(vsimPath), "-version"], universal_newlines=True) except OSError as ex: raise ConfigurationException("Error while accessing '{0!s}'.".format(vsimPath)) from ex version = None versionRegExpStr = r"^.* vsim (.+?) " versionRegExp = RegExpCompile(versionRegExpStr) for line in output.split('\n'): if version is None: match = versionRegExp.match(line) if match is not None: version = match.group(1) self._host.PoCConfig[self._section]['Version'] = version
def GHDLAnalyzeFilter(gen): filterPattern = r".+?:\d+:\d+:(?P<warning>warning:)? (?P<message>.*)" # <Path>:<line>:<column>:[warning:] <message> filterRegExp = RegExpCompile(filterPattern) for line in gen: filterMatch = filterRegExp.match(line) if (filterMatch is not None): if (filterMatch.group('warning') is not None): yield LogEntry(line, Severity.Warning) continue message = filterMatch.group('message') if message.endswith("has changed and must be reanalysed"): raise GHDLReanalyzeException(message) yield LogEntry(line, Severity.Error) continue yield LogEntry(line, Severity.Normal)
def __WriteGtkWaveSection(self, binPath): if (self._host.Platform == "Windows"): gtkwPath = binPath / "gtkwave.exe" else: gtkwPath = binPath / "gtkwave" if not gtkwPath.exists(): raise ConfigurationException("Executable '{0!s}' not found.".format(gtkwPath)) from FileNotFoundError( str(gtkwPath)) # get version and backend output = check_output([str(gtkwPath), "--version"], universal_newlines=True) version = None versionRegExpStr = r"^GTKWave Analyzer v(.+?) " versionRegExp = RegExpCompile(versionRegExpStr) for line in output.split('\n'): if version is None: match = versionRegExp.match(line) if match is not None: version = match.group(1) self._host.PoCConfig[self._section]['Version'] = version
def transform(string, year): """Where possible, replace all runner's with their database ID numbers. May raise a key error.""" result_list = load(string) schools = [(school, Regex("|".join(school.names()))) for school in Schools.select()] for (school, pattern) in schools: for item in result_list: if pattern.match(item["school"]): item["school_id"] = school.id del item["school"] join = INNERJOINOn(Runners, Affiliations, Runners.q.id == Affiliations.q.runner) for runner in Runners.select(Affiliations.q.year == year, join=join): for name in runner.given_names: last_first = r"%s,\s*%s" % (runner.surname, name) first_last = r"%s\s*%s" % (name, runner.surname) pattern = Regex(last_first + "|" + first_last, IGNORECASE) for item in result_list: if pattern.match(item["name"]): item["runner_id"] = runner.id del item["name"] del item["school_id"] return dump(result_list)
def remove_comments(lines): """Remove all lines containing a comment.""" comment_line = Regex("^\s*#.*$") eol_comment = Regex(r"(?<!\\)#.*$") return [eol_comment.sub("", line) for line in lines if not comment_line.match(line)]