-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial setup for pdl extensions + interpreter extensions
- Loading branch information
1 parent
7d69937
commit 1b50f01
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |