Skip to content

Convert print format to riscv debug

convert_print_format_to_riscv_debug

LowerPrintFormatOp

Bases: RewritePattern

Rewrites printf.PrintFormatOp to riscv_debug.printf.

Source code in xdsl/backend/riscv/lowering/convert_print_format_to_riscv_debug.py
14
15
16
17
18
19
20
21
22
23
class LowerPrintFormatOp(RewritePattern):
    """
    Rewrites printf.PrintFormatOp to riscv_debug.printf.
    """

    @op_type_rewrite_pattern
    def match_and_rewrite(self, op: printf.PrintFormatOp, rewriter: PatternRewriter):
        rewriter.replace_op(
            op, riscv_debug.PrintfOp(op.format_str, cast_operands_to_regs(rewriter, op))
        )

match_and_rewrite(op: printf.PrintFormatOp, rewriter: PatternRewriter)

Source code in xdsl/backend/riscv/lowering/convert_print_format_to_riscv_debug.py
19
20
21
22
23
@op_type_rewrite_pattern
def match_and_rewrite(self, op: printf.PrintFormatOp, rewriter: PatternRewriter):
    rewriter.replace_op(
        op, riscv_debug.PrintfOp(op.format_str, cast_operands_to_regs(rewriter, op))
    )

ConvertPrintFormatToRiscvDebugPass dataclass

Bases: ModulePass

Source code in xdsl/backend/riscv/lowering/convert_print_format_to_riscv_debug.py
26
27
28
29
30
class ConvertPrintFormatToRiscvDebugPass(ModulePass):
    name = "convert-print-format-to-riscv-debug"

    def apply(self, ctx: Context, op: ModuleOp) -> None:
        PatternRewriteWalker(LowerPrintFormatOp()).rewrite_module(op)

name = 'convert-print-format-to-riscv-debug' class-attribute instance-attribute

apply(ctx: Context, op: ModuleOp) -> None

Source code in xdsl/backend/riscv/lowering/convert_print_format_to_riscv_debug.py
29
30
def apply(self, ctx: Context, op: ModuleOp) -> None:
    PatternRewriteWalker(LowerPrintFormatOp()).rewrite_module(op)