Skip to content

Commit

Permalink
printer: suppression of types nice comment printing
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgrosser committed Mar 16, 2022
1 parent 63c41c4 commit 1ff745b
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/xdsl/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

class Printer:

def __init__(self, stream=sys.stdout):
def __init__(self,
stream=sys.stdout,
print_operand_types=True,
print_result_types=True):
self._indent: int = 0
self._ssaValues: Dict[SSAValue, int] = dict()
self._blockNames: Dict[Block, int] = dict()
self._nextValidNameId: int = 0
self._nextValidBlockId: int = 0
self.stream = stream
self.print_operand_types = print_operand_types
self.print_result_types = print_result_types
self.recognize_comments = recognize_comments

def _print(self, *args, **kwargs):
print(*args, **kwargs, file=self.stream)
Expand Down Expand Up @@ -48,10 +54,15 @@ def _get_new_valid_block_id(self) -> int:
def _print_result_value(self, op: Operation, idx: int) -> None:
val = op.results[idx]
self._print("%", end='')
name = self._get_new_valid_name_id()
self._ssaValues[val] = name
self._print("%s : " % name, end='')
self.print_attribute(val.typ)
if val in self._ssaValues.keys():
name = self._ssaValues[val]
else:
name = self._get_new_valid_name_id()
self._ssaValues[val] = name
self._print("%s" % name, end='')
if self.print_result_types:
self._print(" : ", end='')
self.print_attribute(val.typ)

def _print_results(self, op: Operation) -> None:
results = op.results
Expand Down Expand Up @@ -79,8 +90,12 @@ def _print_operand(self, operand: SSAValue) -> None:
"SSAValue is not part of the IR, are you sure all operations are added before their uses?"
)
self._print("%", end='')
self._print("%s : " % self._ssaValues[operand], end='')
self.print_attribute(operand.typ)

self._print("%s" % self._ssaValues[operand], end='')

if self.print_operand_types:
self._print(" : ", end='')
self.print_attribute(operand.typ)

def _print_ops(self, ops: List[Operation]) -> None:
self._indent += 1
Expand Down Expand Up @@ -206,6 +221,9 @@ def _print_op_attributes(self, attributes: Dict[str, Attribute]) -> None:

self._print(" ", end='')
self._print("[", end='')

attributes = attributes.copy()

attribute_list = [p for p in attributes.items()]
self._print("\"%s\" = " % attribute_list[0][0], end='')
self.print_attribute(attribute_list[0][1])
Expand Down

0 comments on commit 1ff745b

Please sign in to comment.