CIRCT 24.0.0git
Loading...
Searching...
No Matches
esiaccel.codegen.indented_writer.IndentedWriter Class Reference

Public Member Functions

None __init__ (self, TextIO out, int level=0)
None line (self, str text="")
None lines (self, *str texts)
None write (self, str text)
None access (self, str label)
Iterator[None] indented (self)
Iterator[None] block (self, str header, *, str tail="")

Protected Attributes

 _out = out
 _level = level

Detailed Description

Stream indented source text to an output sink.

Wraps a `TextIO`-like `out` and tracks indentation as a stack of two-space
levels, so emit code never has to thread an `indent` string or hand-write
trailing newlines and doubled `{{` / `}}` braces. Every call writes through
to `out` immediately. The primitives are:

  * `line(text)` -- write one line at the current indent (blank if empty).
  * `block(header)` -- a context manager that writes `header {`, indents its
    body, then closes with `}` (plus an optional `tail`, e.g. `;`).
  * `access(label)` -- write an access specifier (`public:` / `private:`)
    one level out from the members it introduces.

`write(text)` streams `text` verbatim (no indentation); it mirrors
`TextIO.write` so an `IndentedWriter` can itself stand in for a sink.
`indented()` opens a bare indent (e.g. a single-statement loop body)
without braces.

Definition at line 16 of file indented_writer.py.

Constructor & Destructor Documentation

◆ __init__()

None esiaccel.codegen.indented_writer.IndentedWriter.__init__ ( self,
TextIO out,
int level = 0 )

Definition at line 36 of file indented_writer.py.

Member Function Documentation

◆ access()

None esiaccel.codegen.indented_writer.IndentedWriter.access ( self,
str label )

Definition at line 52 of file indented_writer.py.

References _level, _out, and write().

◆ block()

Iterator[None] esiaccel.codegen.indented_writer.IndentedWriter.block ( self,
str header,
* ,
str tail = "" )

◆ indented()

Iterator[None] esiaccel.codegen.indented_writer.IndentedWriter.indented ( self)

Definition at line 59 of file indented_writer.py.

References _level.

◆ line()

None esiaccel.codegen.indented_writer.IndentedWriter.line ( self,
str text = "" )

Definition at line 40 of file indented_writer.py.

References _out, and write().

Referenced by block(), and lines().

◆ lines()

None esiaccel.codegen.indented_writer.IndentedWriter.lines ( self,
*str texts )

Definition at line 43 of file indented_writer.py.

References circt::ExportVerilog::OpLocMap::LineColPair.line, and line().

◆ write()

None esiaccel.codegen.indented_writer.IndentedWriter.write ( self,
str text )
Write `text` verbatim (no indentation). Mirrors `TextIO.write` so the
writer can be passed to emitters that build pre-indented strings.

Definition at line 47 of file indented_writer.py.

References _out, and write().

Referenced by access(), line(), and write().

Member Data Documentation

◆ _level

esiaccel.codegen.indented_writer.IndentedWriter._level = level
protected

Definition at line 38 of file indented_writer.py.

Referenced by access(), block(), and indented().

◆ _out

esiaccel.codegen.indented_writer.IndentedWriter._out = out
protected

Definition at line 37 of file indented_writer.py.

Referenced by access(), line(), and write().


The documentation for this class was generated from the following file: