-
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.
- Loading branch information
1 parent
4258fb5
commit 2f526c1
Showing
3 changed files
with
75 additions
and
1 deletion.
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,40 @@ | ||
from typing import Any | ||
|
||
from xdsl.interpreter import ( | ||
Interpreter, | ||
InterpreterFunctions, | ||
PythonValues, | ||
ReturnedValues, | ||
TerminatorValue, | ||
impl, | ||
impl_callable, | ||
impl_terminator, | ||
register_impls, | ||
) | ||
|
||
from asl_xdsl.dialects import asl | ||
|
||
|
||
@register_impls | ||
class ASLFunctions(InterpreterFunctions): | ||
@impl_terminator(asl.ReturnOp) | ||
def run_return( | ||
self, interpreter: Interpreter, op: asl.ReturnOp, args: tuple[Any, ...] | ||
) -> tuple[TerminatorValue, PythonValues]: | ||
return ReturnedValues(args), () | ||
|
||
@impl_callable(asl.FuncOp) | ||
def call_func( | ||
self, interpreter: Interpreter, op: asl.FuncOp, args: tuple[Any, ...] | ||
): | ||
if (first_block := op.body.blocks.first) is None or not first_block.ops: | ||
return interpreter.call_external(op.sym_name.data, op, args) | ||
else: | ||
return interpreter.run_ssacfg_region(op.body, args, op.sym_name.data) | ||
|
||
@impl(asl.ConstantIntOp) | ||
def run_constant( | ||
self, interpreter: Interpreter, op: asl.ConstantIntOp, args: PythonValues | ||
) -> PythonValues: | ||
value = op.value | ||
return (value.data,) |
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
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,8 @@ | ||
// RUN: asl-opt --t exec %s | filecheck %s | ||
|
||
func main() => integer | ||
begin | ||
return 42; | ||
end; | ||
|
||
// CHECK: result: 42 |