Skip to content

Commit

Permalink
feat: Define whole program assembly representation
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Oct 14, 2024
1 parent 6613689 commit 906da93
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/qibolab/_core/instruments/qblox/ast_.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,26 @@ def from_elements(cls, elements: list[Element]):
elements_.append(el)

return cls(elements=elements_)

def asm(self, width: Optional[int] = None, comments: bool = True) -> str:
max_label_len = max(
len(line.label)
for line in self.elements
if isinstance(line, Line) and line.label is not None
)
max_instr_len = max(
len(line.instruction.asm)
for line in self.elements
if isinstance(line, Line)
)
code = "\n".join(
(
(el if comments else el.model_copy(update={"comment": None})).asm(
width, label_width=max_label_len, instr_width=max_instr_len
)
if isinstance(el, Line)
else (el.asm(width) if comments else "")
)
for el in self.elements
)
return code if comments else re.sub("^\n*", "", re.sub("\n+", "\n", code))

0 comments on commit 906da93

Please sign in to comment.