diff options
-rw-r--r-- | pyGHDL/dom/Attribute.py | 4 | ||||
-rw-r--r-- | pyGHDL/dom/Concurrent.py | 6 | ||||
-rw-r--r-- | pyGHDL/dom/Expression.py | 2 | ||||
-rw-r--r-- | pyGHDL/dom/NonStandard.py | 9 | ||||
-rw-r--r-- | pyGHDL/dom/Sequential.py | 2 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 40 | ||||
-rw-r--r-- | pyGHDL/dom/_Utils.py | 2 | ||||
-rw-r--r-- | pyGHDL/dom/formatting/prettyprint.py | 98 | ||||
-rw-r--r-- | pyGHDL/libghdl/__init__.py | 8 | ||||
-rw-r--r-- | pyGHDL/libghdl/errorout_memory.py | 3 | ||||
-rw-r--r-- | pyGHDL/libghdl/files_map_editor.py | 4 | ||||
-rw-r--r-- | pyGHDL/libghdl/name_table.py | 7 | ||||
-rw-r--r-- | pyGHDL/libghdl/str_table.py | 3 |
13 files changed, 73 insertions, 115 deletions
diff --git a/pyGHDL/dom/Attribute.py b/pyGHDL/dom/Attribute.py index ccd3ecf47..e43ea173e 100644 --- a/pyGHDL/dom/Attribute.py +++ b/pyGHDL/dom/Attribute.py @@ -125,7 +125,7 @@ class AttributeSpecification(VHDLModel_AttributeSpecification, DOMMixin): else: position = Position.parse(name) raise DOMException( - f"Unknown name kind '{nameKind.name}' in attribute specification '{attributeNode}' at {position.Filename}:{position.Line}:{position.Column}." + f"Unknown name kind '{nameKind.name}' in attribute specification '{attributeNode}' at {position}." ) entityClassToken = nodes.Get_Entity_Class(attributeNode) @@ -134,7 +134,7 @@ class AttributeSpecification(VHDLModel_AttributeSpecification, DOMMixin): except KeyError: position = Position.parse(attributeNode) raise DOMException( - f"Unknown token '{entityClassToken.name}' in attribute specification for entity class '{attributeNode}' at {position.Filename}:{position.Line}:{position.Column}." + f"Unknown token '{entityClassToken.name}' in attribute specification for entity class '{attributeNode}' at {position}." ) expression = GetExpressionFromNode(nodes.Get_Expression(attributeNode)) diff --git a/pyGHDL/dom/Concurrent.py b/pyGHDL/dom/Concurrent.py index 693feba27..df3e97a2a 100644 --- a/pyGHDL/dom/Concurrent.py +++ b/pyGHDL/dom/Concurrent.py @@ -579,9 +579,7 @@ class CaseGenerateStatement(VHDLModel_CaseGenerateStatement, DOMMixin): cases.append(GenerateCase.parse(caseNode, choices)) caseNode = alternative - choices = [ - choice, - ] + choices = [choice] alternative = nodes.Get_Chain(alternative) @@ -630,7 +628,7 @@ class ForGenerateStatement(VHDLModel_ForGenerateStatement, DOMMixin): else: pos = Position.parse(generateNode) raise DOMException( - f"Unknown discete range kind '{rangeKind.name}' in for...generate statement at line {pos.Line}." + f"Unknown discrete range kind '{rangeKind.name}' in for...generate statement at line {pos.Line}." ) body = nodes.Get_Generate_Statement_Body(generateNode) diff --git a/pyGHDL/dom/Expression.py b/pyGHDL/dom/Expression.py index 51b73c57e..4a61597e2 100644 --- a/pyGHDL/dom/Expression.py +++ b/pyGHDL/dom/Expression.py @@ -520,7 +520,7 @@ class Aggregate(VHDLModel_Aggregate, DOMMixin): else: pos = Position.parse(item) raise DOMException( - f"Unknown discete range kind '{rangeKind.name}' in for...generate statement at line {pos.Line}." + f"Unknown discrete range kind '{rangeKind.name}' in for...generate statement at line {pos.Line}." ) choices.append(RangedAggregateElement(item, rng, value)) diff --git a/pyGHDL/dom/NonStandard.py b/pyGHDL/dom/NonStandard.py index 14f5e1eac..db160faaf 100644 --- a/pyGHDL/dom/NonStandard.py +++ b/pyGHDL/dom/NonStandard.py @@ -60,6 +60,7 @@ from pyGHDL.libghdl import ( LibGHDLException, utils, files_map_editor, + ENCODING, ) from pyGHDL.libghdl.flags import Flag_Gather_Comments from pyGHDL.libghdl.vhdl import nodes, sem_lib @@ -142,24 +143,24 @@ class Document(VHDLModel_Document): else: self.__loadFromString(sourceCode) - if dontParse == False: + if not dontParse: # Parse input file t1 = time.perf_counter() self.__ghdlFile = sem_lib.Load_File(self.__ghdlSourceFileEntry) CheckForErrors() self.__ghdlProcessingTime = time.perf_counter() - t1 - if dontTranslate == False: + if not dontTranslate: t1 = time.perf_counter() self.translate() self.__domTranslateTime = time.perf_counter() - t1 def __loadFromPath(self): - with self._filename.open("r", encoding="utf-8") as file: + with self._filename.open("r", encoding=ENCODING) as file: self.__loadFromString(file.read()) def __loadFromString(self, sourceCode: str): - sourcesBytes = sourceCode.encode("utf-8") + sourcesBytes = sourceCode.encode(ENCODING) sourceLength = len(sourcesBytes) bufferLength = sourceLength + 128 self.__ghdlFileID = name_table.Get_Identifier(str(self._filename)) diff --git a/pyGHDL/dom/Sequential.py b/pyGHDL/dom/Sequential.py index 0258d3a14..296f57f52 100644 --- a/pyGHDL/dom/Sequential.py +++ b/pyGHDL/dom/Sequential.py @@ -365,7 +365,7 @@ class ForLoopStatement(VHDLModel_ForLoopStatement, DOMMixin): else: pos = Position.parse(loopNode) raise DOMException( - f"Unknown discete range kind '{rangeKind.name}' in for...loop statement at line {pos.Line}." + f"Unknown discrete range kind '{rangeKind.name}' in for...loop statement at line {pos.Line}." ) statementChain = nodes.Get_Sequential_Statement_Chain(loopNode) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index b3a48769b..20d173710 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -242,7 +242,7 @@ def GetArrayConstraintsFromSubtypeIndication( else: position = Position.parse(constraint) raise DOMException( - f"Unknown constraint kind '{constraintKind.name}' for constraint '{constraint}' in subtype indication '{subtypeIndication}' at {position.Filename}:{position.Line}:{position.Column}." + f"Unknown constraint kind '{constraintKind.name}' for constraint '{constraint}' in subtype indication '{subtypeIndication}' at {position}." ) return constraints @@ -271,7 +271,7 @@ def GetTypeFromNode(node: Iir) -> BaseType: else: position = Position.parse(typeDefinition) raise DOMException( - f"GetTypeFromNode: Unknown type definition kind '{kind.name}' for type '{typeName}' at {position.Filename}:{position.Line}:{position.Column}." + f"GetTypeFromNode: Unknown type definition kind '{kind.name}' for type '{typeName}' at {position}." ) @@ -301,7 +301,7 @@ def GetAnonymousTypeFromNode(node: Iir) -> BaseType: else: position = Position.parse(typeDefinition) raise DOMException( - f"GetAnonymousTypeFromNode: Unknown type definition kind '{kind.name}' for type '{typeName}' at {position.Filename}:{position.Line}:{position.Column}." + f"GetAnonymousTypeFromNode: Unknown type definition kind '{kind.name}' for type '{typeName}' at {position}." ) @@ -446,9 +446,7 @@ def GetExpressionFromNode(node: Iir) -> ExpressionUnion: cls = __EXPRESSION_TRANSLATION[kind] except KeyError: position = Position.parse(node) - raise DOMException( - f"Unknown expression kind '{kind.name}' in expression '{node}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown expression kind '{kind.name}' in expression '{node}' at {position}.") return cls.parse(node) @@ -507,9 +505,7 @@ def GetGenericsFromChainedNodes( yield GenericFunctionInterfaceItem.parse(generic) else: position = Position.parse(generic) - raise DOMException( - f"Unknown generic kind '{kind.name}' in generic '{generic}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown generic kind '{kind.name}' in generic '{generic}' at {position}.") generic = nodes.Get_Chain(generic) @@ -553,9 +549,7 @@ def GetPortsFromChainedNodes( continue else: position = Position.parse(port) - raise DOMException( - f"Unknown port kind '{kind.name}' in port '{port}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown port kind '{kind.name}' in port '{port}' at {position}.") @export @@ -589,9 +583,7 @@ def GetParameterFromChainedNodes( parseNode = parameter else: position = Position.parse(parameter) - raise DOMException( - f"Unknown parameter kind '{kind.name}' in parameter '{parameter}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown parameter kind '{kind.name}' in parameter '{parameter}' at {position}.") # Lookahead for parameters with multiple identifiers at once if nodes.Get_Has_Identifier_List(parameter): @@ -713,7 +705,7 @@ def GetDeclaredItemsFromChainedNodes(nodeChain: Iir, entity: str, name: str) -> else: position = Position.parse(item) raise DOMException( - f"Found unexpected function body '{GetNameOfNode(item)}' in {entity} '{name}' at {position.Filename}:{position.Line}:{position.Column}." + f"Found unexpected function body '{GetNameOfNode(item)}' in {entity} '{name}' at {position}." ) elif kind == nodes.Iir_Kind.Procedure_Declaration: if nodes.Get_Has_Body(item): @@ -730,7 +722,7 @@ def GetDeclaredItemsFromChainedNodes(nodeChain: Iir, entity: str, name: str) -> else: position = Position.parse(item) raise DOMException( - f"Found unexpected procedure body '{GetNameOfNode(item)}' in {entity} '{name}' at {position.Filename}:{position.Line}:{position.Column}." + f"Found unexpected procedure body '{GetNameOfNode(item)}' in {entity} '{name}' at {position}." ) elif kind == nodes.Iir_Kind.Protected_Type_Body: yield ProtectedTypeBody.parse(item) @@ -782,9 +774,7 @@ def GetDeclaredItemsFromChainedNodes(nodeChain: Iir, entity: str, name: str) -> print(f"[NOT IMPLEMENTED] Terminal declaration in {name}") else: position = Position.parse(item) - raise DOMException( - f"Unknown declared item kind '{kind.name}' in {entity} '{name}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown declared item kind '{kind.name}' in {entity} '{name}' at {position}.") lastKind = None item = nodes.Get_Chain(item) @@ -853,7 +843,7 @@ def GetConcurrentStatementsFromChainedNodes( yield ComponentInstantiation.parse(statement, instantiatedUnit, label) else: raise DOMException( - f"Unknown instantiation kind '{instantiatedUnitKind.name}' in instantiation of label {label} at {position.Filename}:{position.Line}:{position.Column}." + f"Unknown instantiation kind '{instantiatedUnitKind.name}' in instantiation of label {label} at {position}." ) elif kind == nodes.Iir_Kind.Block_Statement: yield ConcurrentBlockStatement.parse(statement, label) @@ -868,9 +858,7 @@ def GetConcurrentStatementsFromChainedNodes( elif kind == nodes.Iir_Kind.Simple_Simultaneous_Statement: print(f"[NOT IMPLEMENTED] Simple simultaneous statement (label: '{label}') at line {position.Line}") else: - raise DOMException( - f"Unknown statement of kind '{kind.name}' in {entity} '{name}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown statement of kind '{kind.name}' in {entity} '{name}' at {position}.") def GetSequentialStatementsFromChainedNodes( @@ -906,9 +894,7 @@ def GetSequentialStatementsFromChainedNodes( elif kind == nodes.Iir_Kind.Null_Statement: yield NullStatement(statement, label) else: - raise DOMException( - f"Unknown statement of kind '{kind.name}' in {entity} '{name}' at {position.Filename}:{position.Line}:{position.Column}." - ) + raise DOMException(f"Unknown statement of kind '{kind.name}' in {entity} '{name}' at {position}.") def GetAliasFromNode(aliasNode: Iir): diff --git a/pyGHDL/dom/_Utils.py b/pyGHDL/dom/_Utils.py index 10053db6e..3b647013b 100644 --- a/pyGHDL/dom/_Utils.py +++ b/pyGHDL/dom/_Utils.py @@ -64,6 +64,8 @@ def CheckForErrors() -> None: errors.append(f"{fileName}:{rec.line}:{rec.offset}: {message}") + errorout_memory.Clear_Errors() + raise DOMException("Error raised in libghdl.") from LibGHDLException("libghdl: Internal error.", errors) diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index b5397610a..0f548210b 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -124,7 +124,7 @@ class PrettyPrint: buffer.append(line) buffer.append(f"{prefix}Documents:") for document in design.Documents: - buffer.append(f"{prefix} - Path: '{document.Path!s}':") + buffer.append(f"{prefix} - Path: '{document.Path}':") for line in self.formatDocument(document, level + 2): buffer.append(line) @@ -190,7 +190,9 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - f"{prefix}- Name: {entity.Identifier}\n{prefix} File: {entity.Position.Filename.name}\n{prefix} Position: {entity.Position.Line}:{entity.Position.Column}" + f"{prefix}- Name: {entity.Identifier}\n" + f"{prefix} File: {entity.Position.Filename.name}\n" + f"{prefix} Position: {entity.Position.Line}:{entity.Position.Column}" ) buffer.append(f"{prefix} Generics:") for generic in entity.GenericItems: @@ -217,7 +219,9 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - f"{prefix}- Name: {architecture.Identifier}\n{prefix} File: {architecture.Position.Filename.name}\n{prefix} Position: {architecture.Position.Line}:{architecture.Position.Column}" + f"{prefix}- Name: {architecture.Identifier}\n" + f"{prefix} File: {architecture.Position.Filename.name}\n" + f"{prefix} Position: {architecture.Position.Line}:{architecture.Position.Column}" ) buffer.append(f"{prefix} Entity: {architecture.Entity.SymbolName}") buffer.append(f"{prefix} Declared:") @@ -255,7 +259,9 @@ class PrettyPrint: buffer = [] prefix = " " * level buffer.append( - f"{prefix}- Name: {package.Identifier}\n{prefix} File: {package.Position.Filename.name}\n{prefix} Position: {package.Position.Line}:{package.Position.Column}" + f"{prefix}- Name: {package.Identifier}\n" + f"{prefix} File: {package.Position.Filename.name}\n" + f"{prefix} Position: {package.Position.Line}:{package.Position.Column}" ) buffer.append(f"{prefix} Declared:") for item in package.DeclaredItems: @@ -323,14 +329,9 @@ class PrettyPrint: buffer = [] prefix = " " * level + subTypeIndication = self.formatSubtypeIndication(generic.Subtype, "generic", generic.Identifiers[0]) buffer.append( - "{prefix} - {name} : {mode!s} {subtypeindication}{initialValue}".format( - prefix=prefix, - name=", ".join(generic.Identifiers), - mode=generic.Mode, - subtypeindication=self.formatSubtypeIndication(generic.Subtype, "generic", generic.Identifiers[0]), - initialValue=self.formatInitialValue(generic), - ) + f"{prefix} - {', '.join(generic.Identifiers)} : {generic.Mode!s} {subTypeIndication}{self.formatInitialValue(generic)}" ) return buffer @@ -347,14 +348,9 @@ class PrettyPrint: buffer = [] prefix = " " * level + subTypeIndication = self.formatSubtypeIndication(port.Subtype, "port", port.Identifiers[0]) buffer.append( - "{prefix} - {name} : {mode!s} {subtypeindication}{initialValue}".format( - prefix=prefix, - name=", ".join(port.Identifiers), - mode=port.Mode, - subtypeindication=self.formatSubtypeIndication(port.Subtype, "port", port.Identifiers[0]), - initialValue=self.formatInitialValue(port), - ) + f"{prefix} - {', '.join(port.Identifiers)} : {port.Mode} {subTypeIndication}{self.formatInitialValue(port)}" ) return buffer @@ -364,44 +360,19 @@ class PrettyPrint: prefix = " " * level if isinstance(item, BaseConstant): - if isinstance(item, Constant): - default = f" := {item.DefaultExpression!s}" - else: - default = "" - - buffer.append( - "{prefix}- constant {name} : {subtype}{default}".format( - prefix=prefix, - name=", ".join(item.Identifiers), - subtype=self.formatSubtypeIndication(item.Subtype, "constant", item.Identifiers[0]), - default=default, - ) - ) + subTypeIndication = self.formatSubtypeIndication(item.Subtype, "constant", item.Identifiers[0]) + initValue = f" := {item.DefaultExpression}" if isinstance(item, Constant) else "" + buffer.append(f"{prefix}- constant {', '.join(item.Identifiers)} : {subTypeIndication}{initValue}") elif isinstance(item, SharedVariable): - buffer.append( - "{prefix}- shared variable {name} : {subtype}".format( - prefix=prefix, - name=", ".join(item.Identifiers), - subtype=self.formatSubtypeIndication(item.Subtype, "shared variable", item.Identifiers[0]), - ) - ) + subTypeIndication = self.formatSubtypeIndication(item.Subtype, "shared variable", item.Identifiers[0]) + buffer.append(f"{prefix}- shared variable {', '.join(item.Identifiers)} : {subTypeIndication}") elif isinstance(item, Signal): - buffer.append( - "{prefix}- signal {name} : {subtype}{initValue}".format( - prefix=prefix, - name=", ".join(item.Identifiers), - subtype=self.formatSubtypeIndication(item.Subtype, "signal", item.Identifiers[0]), - initValue=f" := {item.DefaultExpression!s}" if item.DefaultExpression is not None else "", - ) - ) + subTypeIndication = self.formatSubtypeIndication(item.Subtype, "signal", item.Identifiers[0]) + initValue = f" := {item.DefaultExpression}" if item.DefaultExpression is not None else "" + buffer.append(f"{prefix}- signal {', '.join(item.Identifiers)} : {subTypeIndication}{initValue}") elif isinstance(item, File): - buffer.append( - "{prefix}- File {name} : {subtype}".format( - prefix=prefix, - name=", ".join(item.Identifiers), - subtype=self.formatSubtypeIndication(item.Subtype, "file", item.Identifiers[0]), - ) - ) + subTypeIndication = self.formatSubtypeIndication(item.Subtype, "file", item.Identifiers[0]) + buffer.append(f"{prefix}- File {', '.join(item.Identifiers)} : {subTypeIndication}") elif isinstance(item, (FullType, IncompleteType)): buffer.append(f"{prefix}- {self.formatType(item)}") elif isinstance(item, Subtype): @@ -409,26 +380,24 @@ class PrettyPrint: elif isinstance(item, Alias): buffer.append(f"{prefix}- alias {item.Identifier} is ?????") elif isinstance(item, Function): - buffer.append(f"{prefix}- function {item.Identifier} return {item.ReturnType!s}") + buffer.append(f"{prefix}- function {item.Identifier} return {item.ReturnType}") elif isinstance(item, Procedure): buffer.append(f"{prefix}- procedure {item.Identifier}") elif isinstance(item, Component): for line in self.formatComponent(item, level): buffer.append(line) elif isinstance(item, Attribute): - buffer.append(f"{prefix}- attribute {item.Identifier} : {item.Subtype!s}") + buffer.append(f"{prefix}- attribute {item.Identifier} : {item.Subtype}") elif isinstance(item, AttributeSpecification): - buffer.append(f"{prefix}- attribute {item.Attribute!s} of {'????'} : {'????'} is {'????'}") + buffer.append(f"{prefix}- attribute {item.Attribute} of {'????'} : {'????'} is {'????'}") elif isinstance(item, UseClause): - buffer.append("{prefix}- use {names}".format(prefix=prefix, names=", ".join([str(n) for n in item.Names]))) + buffer.append(f"{prefix}- use {', '.join([str(n) for n in item.Names])}") elif isinstance(item, Package): buffer.append(f"{prefix}- package {item.Identifier} is ..... end package") elif isinstance(item, PackageInstantiation): - buffer.append(f"{prefix}- package {item.Identifier} is new {item.PackageReference!s} generic map (.....)") + buffer.append(f"{prefix}- package {item.Identifier} is new {item.PackageReference} generic map (.....)") elif isinstance(item, DefaultClock): - buffer.append( - f"{prefix}- default {item.Identifier} is {'...'}", - ) + buffer.append(f"{prefix}- default {item.Identifier} is {'...'}") else: raise PrettyPrintException(f"Unhandled declared item kind '{item.__class__.__name__}'.") @@ -469,17 +438,14 @@ class PrettyPrint: for constraint in subtypeIndication.Constraints: constraints.append(str(constraint)) - return "{type}({constraints})".format(type=subtypeIndication.SymbolName, constraints=", ".join(constraints)) + return f"{subtypeIndication.SymbolName}({', '.join(constraints)})" else: raise PrettyPrintException( f"Unhandled subtype kind '{subtypeIndication.__class__.__name__}' for {entity} '{name}'." ) def formatInitialValue(self, item: WithDefaultExpressionMixin) -> str: - if item.DefaultExpression is None: - return "" - - return f" := {item.DefaultExpression!s}" + return f" := {item.DefaultExpression}" if item.DefaultExpression is not None else "" def formatHierarchy(self, statement: ConcurrentStatement, level: int = 0) -> StringBuffer: buffer = [] diff --git a/pyGHDL/libghdl/__init__.py b/pyGHDL/libghdl/__init__.py index 372f5968b..2cf9cff70 100644 --- a/pyGHDL/libghdl/__init__.py +++ b/pyGHDL/libghdl/__init__.py @@ -48,6 +48,8 @@ from pyGHDL import __version__ as ghdlVersion Nullable = Optional +ENCODING = "latin-1" + class LibGHDLException(GHDLBaseException): _internalErrors: Nullable[List[str]] @@ -164,7 +166,7 @@ def _initialize(): libghdl.libghdl__set_hooks_for_analysis() # Set the prefix in order to locate the VHDL libraries. - prefix = str(_libghdl_path.parent.parent).encode("utf-8") + prefix = str(_libghdl_path.parent.parent).encode(ENCODING) libghdl.libghdl__set_exec_prefix(c_char_p(prefix), len(prefix)) return libghdl @@ -197,7 +199,7 @@ def set_option(Opt: str) -> bool: :param Opt: Option to set. :return: Return ``True``, if the option is known and handled. """ - Opt = Opt.encode("utf-8") + Opt = Opt.encode(ENCODING) return libghdl.libghdl__set_option(c_char_p(Opt), len(Opt)) == 0 @@ -233,7 +235,7 @@ def analyze_file(fname: str) -> Iir: :param fname: File name :return: Internal Intermediate Representation (IIR) """ - fname = fname.encode("utf-8") + fname = fname.encode(ENCODING) return libghdl.libghdl__analyze_file(c_char_p(fname), len(fname)) diff --git a/pyGHDL/libghdl/errorout_memory.py b/pyGHDL/libghdl/errorout_memory.py index 9f75d0331..d0847417e 100644 --- a/pyGHDL/libghdl/errorout_memory.py +++ b/pyGHDL/libghdl/errorout_memory.py @@ -36,6 +36,7 @@ from ctypes import c_int8, c_int32, c_char_p, Structure from pyTooling.Decorators import export +from pyGHDL.libghdl import ENCODING from pyGHDL.libghdl._types import ErrorIndex from pyGHDL.libghdl._decorator import BindToLibGHDL @@ -122,7 +123,7 @@ def Get_Error_Message(Idx: ErrorIndex) -> str: :param Idx: Index from 1 to ``Nbr_Messages`` See :func:`Get_Nbr_Messages`. :return: Error message. """ - return _Get_Error_Message(Idx).decode("iso-8859-1") + return _Get_Error_Message(Idx).decode(ENCODING) @export diff --git a/pyGHDL/libghdl/files_map_editor.py b/pyGHDL/libghdl/files_map_editor.py index a67766c44..c7cfad4c2 100644 --- a/pyGHDL/libghdl/files_map_editor.py +++ b/pyGHDL/libghdl/files_map_editor.py @@ -36,7 +36,7 @@ from ctypes import c_int32, c_char_p, c_bool, c_uint32 from pyTooling.Decorators import export -from pyGHDL.libghdl import libghdl +from pyGHDL.libghdl import libghdl, ENCODING from pyGHDL.libghdl._decorator import BindToLibGHDL from pyGHDL.libghdl._types import SourceFileEntry @@ -85,7 +85,7 @@ def Replace_Text( :param Text: undocumented :return: Return True in case of success, False in case of failure (the gap is too small). """ - buffer = Text.encode("utf-8") + buffer = Text.encode(ENCODING) return _Replace_Text( File, Start_Line, diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py index b29775213..e40bd635b 100644 --- a/pyGHDL/libghdl/name_table.py +++ b/pyGHDL/libghdl/name_table.py @@ -36,6 +36,7 @@ from ctypes import c_char, c_char_p from pyTooling.Decorators import export +from pyGHDL.libghdl import ENCODING from pyGHDL.libghdl._types import NameId from pyGHDL.libghdl._decorator import BindToLibGHDL @@ -73,7 +74,7 @@ def Get_Name_Ptr(Id: NameId) -> str: :param Id: NameId for the identifier to query. :return: Identifier as string. """ - return _Get_Name_Ptr(Id).decode("utf-8") + return _Get_Name_Ptr(Id).decode(ENCODING) # @export @@ -95,7 +96,7 @@ def Get_Character(Id: NameId) -> str: :param Id: NameId for the identifier to query. :return: Get the character of the identifier. """ - return _Get_Character(Id).decode("utf-8") + return _Get_Character(Id).decode(ENCODING) # @export @@ -119,5 +120,5 @@ def Get_Identifier(string: str) -> NameId: :param string: String to create or lookup. :return: Id in name table. """ - string = string.encode("utf-8") + string = string.encode(ENCODING) return _Get_Identifier(c_char_p(string), len(string)) diff --git a/pyGHDL/libghdl/str_table.py b/pyGHDL/libghdl/str_table.py index a91268bb4..3f55d1eb3 100644 --- a/pyGHDL/libghdl/str_table.py +++ b/pyGHDL/libghdl/str_table.py @@ -36,6 +36,7 @@ from ctypes import c_char_p from pyTooling.Decorators import export +from pyGHDL.libghdl import ENCODING from pyGHDL.libghdl._types import String8Id from pyGHDL.libghdl._decorator import BindToLibGHDL @@ -57,4 +58,4 @@ def Get_String8_Ptr(Id: String8Id, Length: int) -> str: :param Id: String8Id for the string to query. :return: String8 as string. """ - return _String8_Address(Id)[:Length].decode("utf-8") + return _String8_Address(Id)[:Length].decode(ENCODING) |