-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to instantiate subparsers
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
- Loading branch information
Showing
6 changed files
with
235 additions
and
2 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
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
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,65 @@ | ||
// RUN: p4mlir-opt %s | FileCheck %s | ||
|
||
!empty = !p4hir.struct<"empty"> | ||
!i10i = !p4hir.int<10> | ||
#false = #p4hir.bool<false> : !p4hir.bool | ||
#subparser2_ctorArg = #p4hir.ctor_param<@subparser2, "ctorArg"> : !p4hir.bool | ||
#int1_i10i = #p4hir.int<1> : !i10i | ||
#int2_i10i = #p4hir.int<2> : !i10i | ||
// CHECK: module | ||
module { | ||
p4hir.parser @subparser(%arg0: !empty)() { | ||
p4hir.state @start { | ||
p4hir.transition to @subparser::@accept | ||
} | ||
p4hir.state @accept { | ||
p4hir.parser_accept | ||
} | ||
p4hir.state @reject { | ||
p4hir.parser_reject | ||
} | ||
p4hir.transition to @subparser::@start | ||
} | ||
p4hir.parser @subparser2(%arg0: !empty)(ctorArg: !p4hir.bool) { | ||
%ctorArg = p4hir.const ["ctorArg"] #subparser2_ctorArg | ||
p4hir.state @start { | ||
p4hir.transition to @subparser2::@accept | ||
} | ||
p4hir.state @accept { | ||
p4hir.parser_accept | ||
} | ||
p4hir.state @reject { | ||
p4hir.parser_reject | ||
} | ||
p4hir.transition to @subparser2::@start | ||
} | ||
p4hir.parser @p(%arg0: !empty, %arg1: !i10i)() { | ||
%s = p4hir.variable ["s", init] : <!i10i> | ||
p4hir.assign %arg1, %s : <!i10i> | ||
%sp = p4hir.instantiate @subparser() as "sp" : () -> !p4hir.parser<"subparser", (!empty)> | ||
%false = p4hir.const #false | ||
%sp2 = p4hir.instantiate @subparser2(%false) as "sp2" : (!p4hir.bool) -> !p4hir.parser<"subparser2", (!empty)> | ||
p4hir.state @start { | ||
%c1_i10i = p4hir.const #int1_i10i | ||
%cast = p4hir.cast(%c1_i10i : !i10i) : !i10i | ||
p4hir.assign %cast, %s : <!i10i> | ||
p4hir.transition to @p::@next | ||
} | ||
p4hir.state @next { | ||
%c2_i10i = p4hir.const #int2_i10i | ||
%cast = p4hir.cast(%c2_i10i : !i10i) : !i10i | ||
p4hir.assign %cast, %s : <!i10i> | ||
p4hir.transition to @p::@accept | ||
} | ||
p4hir.state @drop { | ||
p4hir.transition to @p::@reject | ||
} | ||
p4hir.state @accept { | ||
p4hir.parser_accept | ||
} | ||
p4hir.state @reject { | ||
p4hir.parser_reject | ||
} | ||
p4hir.transition to @p::@start | ||
} | ||
} |
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,38 @@ | ||
// RUN: p4mlir-translate --typeinference-only %s | FileCheck %s | ||
|
||
struct empty {} | ||
|
||
parser subparser(in empty e) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
parser subparser2(in empty e)(bool ctorArg) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
// CHECK-LABEL: p4hir.parser @p | ||
// CHECK: p4hir.instantiate @subparser() as "sp" : () -> !p4hir.parser<"subparser", (!empty)> | ||
// CHECK: %[[false:.*]] = p4hir.const #false | ||
// CHECK: p4hir.instantiate @subparser2(%[[false]]) as "sp2" : (!p4hir.bool) -> !p4hir.parser<"subparser2", (!empty)> | ||
|
||
parser p(in empty e, in int<10> sinit) { | ||
int<10> s = sinit; | ||
subparser() sp; | ||
subparser2(false) sp2; | ||
|
||
state start { | ||
s = 1; | ||
transition next; | ||
} | ||
|
||
state next { | ||
s = 2; | ||
transition accept; | ||
} | ||
|
||
state drop {} | ||
} |
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