pyGHDL.dom.formatting.prettyprint

This module offers a formatter to render a design, document or design unit as an indented plain-text tree.

Exceptions

  • PrettyPrintException: The exception is raised when a model item cannot be rendered back to VHDL source code.

Classes


Exceptions

exception pyGHDL.dom.formatting.prettyprint.PrettyPrintException(message='')[source]

The exception is raised when a model item cannot be rendered back to VHDL source code.

It reports an item the pretty-printer has no formatting rule for.

Inheritance

Inheritance diagram of PrettyPrintException

Parameters:

message (str)

Return type:

None


Classes

class pyGHDL.dom.formatting.prettyprint.PrettyPrint[source]

Renders a pyGHDL.dom design, document or design unit as an indented plain-text tree.

Each Format* method returns a list of lines and is given an indentation level, so the methods compose from a whole design down to the smallest model item.

Inheritance

Inheritance diagram of PrettyPrint

CleanupDocumentationBlocks(documentationContent, level=0)[source]

Renders a documentation comment as its first line, indented to the given level.

Parameters:
  • documentationContent (str) – The documentation comment, or None if the item has none.

  • level (int) – The indentation level, two spaces each.

Returns:

The indented first line of the comment, or just the indentation.

formatDesign(design, level=0)[source]

Renders a design’s libraries and documents.

Parameters:
  • design (Design) – The design to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatLibrary(library, level=0)[source]

Renders a library’s design units.

Parameters:
  • library (Library) – The library to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatDocument(document, level=0)[source]

Renders a document’s design units.

Parameters:
  • document (Document) – The document to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatEntity(entity, level=0)[source]

Renders an entity’s generics, ports, declarations and statements.

Parameters:
  • entity (Entity) – The entity to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatArchitecture(architecture, level=0)[source]

Renders an architecture’s declarations and statements.

Parameters:
  • architecture (Architecture) – The architecture to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatComponent(component, level=0)[source]

Renders a component’s generics and ports.

Parameters:
  • component (Component) – The component to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatPackage(package, level=0)[source]

Renders a package’s generics and declarations.

Parameters:
  • package (Package) – The package to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatPackageInstance(package, level=0)[source]

Renders a package instantiation’s generic map.

Parameters:
  • package (PackageInstantiation) – The package instantiation to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatPackageBody(packageBody, level=0)[source]

Renders a package body’s declarations.

Parameters:
  • packageBody (PackageBody) – The package body to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatConfiguration(configuration, level=0)[source]

Renders a configuration.

Parameters:
  • configuration (Configuration) – The configuration to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatContext(context, level=0)[source]

Renders a context’s clauses.

Parameters:
  • context (Context) – The context to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatGeneric(generic, level=0)[source]

Renders a generic, dispatching on its kind.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatPort(port, level=0)[source]

Renders a port, dispatching on its kind.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatGenericConstant(generic, level=0)[source]

Renders a generic constant.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatGenericType(generic, level=0)[source]

Renders a generic type.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatPortSignal(port, level=0)[source]

Renders a port signal.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatPortView(port, level=0)[source]

Renders a port declared with a mode view.

Parameters:
Return type:

List[str]

Returns:

The rendered lines.

formatDeclaredItems(item, level=0)[source]

Renders the declared items of a declarative region.

Parameters:
  • item – The declarative region to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.

formatModeViewElement(element)[source]

Renders a mode view element.

Parameters:

element (ModeViewElement) – The mode view element to render.

Return type:

str

Returns:

The rendered line.

formatType(item)[source]

Renders an object’s subtype indication.

Parameters:

item (BaseType) – The object to render.

Return type:

str

Returns:

The rendered line.

formatSubtypeIndication(subtypeIndication, entity, name)[source]

Renders a subtype indication.

Parameters:
  • subtypeIndication – The subtype indication to render.

  • entity (str) – The kind of item the subtype indication belongs to. Used in exception messages.

  • name (str) – The name of that item. Used in exception messages.

Return type:

str

Returns:

The rendered subtype indication.

Raises:

PrettyPrintException – If the subtype indication’s kind is not handled.

formatInitialValue(item)[source]

Renders an object’s default value, if it has one.

Parameters:

item (WithDefaultExpressionMixin) – The object to render.

Return type:

str

Returns:

The rendered line.

formatHierarchy(statement, level=0)[source]

Renders a statement and the statements nested in it.

Parameters:
  • statement (ConcurrentStatement) – The statement to render.

  • level (int) – The indentation level, two spaces each.

Return type:

List[str]

Returns:

The rendered lines.