Skip to content

Commit

Permalink
initial setup for pdl extensions + interpreter extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-luecke committed Nov 27, 2023
1 parent 7d69937 commit 1b50f01
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_pdl_interpreter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from xdsl.dialects import arith
from xdsl.dialects.builtin import (
ModuleOp,
i32,
)
from xdsl.interpreter import Interpreter
from xdsl.ir import MLContext
from xdsl.utils.test_value import TestSSAValue

from xdsl_pdl.dialects import pdl_extension as pdl
from xdsl_pdl.interpreters.pdl_interpreter_extension import PDLRewriteFunctionsExt


def test_pdl_result_op():
interpreter = Interpreter(ModuleOp([]))
interpreter.register_implementations(PDLRewriteFunctionsExt(MLContext()))

c0 = TestSSAValue(i32)
c1 = TestSSAValue(i32)
add = arith.Addi(c0, c1)
add_res = add.result

assert interpreter.run_op(
pdl.ResultOp(0, TestSSAValue(pdl.OperationType())), (add,)
) == (add_res,)
52 changes: 52 additions & 0 deletions xdsl_pdl/dialects/pdl_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from xdsl.dialects.pdl import (
ApplyNativeConstraintOp, # Operations; Types
ApplyNativeRewriteOp,
AttributeOp,
AttributeType,
EraseOp,
OperandOp,
OperandsOp,
OperationOp,
OperationType,
PatternOp,
RangeOp,
RangeType,
ReplaceOp,
ResultOp,
ResultsOp,
RewriteOp,
TypeOp,
TypesOp,
TypeType,
ValueType,
)
from xdsl.interpreter import Interpreter
from xdsl.ir import Dialect

PDL_EXT = Dialect(
"pdl",
[
ApplyNativeConstraintOp,
ApplyNativeRewriteOp,
AttributeOp,
OperandOp,
EraseOp,
OperandsOp,
OperationOp,
PatternOp,
RangeOp,
ReplaceOp,
ResultOp,
ResultsOp,
RewriteOp,
TypeOp,
TypesOp,
],
[
AttributeType,
OperationType,
TypeType,
ValueType,
RangeType,
],
)
10 changes: 10 additions & 0 deletions xdsl_pdl/interpreters/pdl_interpreter_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass

from xdsl.interpreter import register_impls
from xdsl.interpreters.experimental import pdl


@register_impls
@dataclass
class PDLRewriteFunctionsExt(pdl.PDLRewriteFunctions):
pass

0 comments on commit 1b50f01

Please sign in to comment.