Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Add integer addition parser support. #6701

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLExpressions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,18 @@ class IntegerBinaryPrimOp<string mnemonic, list<Trait> traits = []> :
[Pure, SameOperandsAndResultType] # traits> {
// We use the standard inferReturnTypes from SameOperandsAndResultType.
let inferReturnTypesDecl = "";

// We use a static inferType that always returns FIntegerType.
let inferType = "getFIntegerType";

// Define the getFIntegerType inline in ODS.
let firrtlExtraClassDeclaration = [{
static FIntegerType getFIntegerType(FIRRTLType lhs,
FIRRTLType rhs,
std::optional<Location> loc) {
return FIntegerType::get(lhs.getContext());
}
}];
}

def IntegerAddOp : IntegerBinaryPrimOp<"integer.add", [Commutative]> {
Expand Down
4 changes: 4 additions & 0 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,10 @@ ParseResult FIRStmtParser::parsePrimExp(Value &result) {
case FIRToken::lp_tail:
attrNames.push_back(getConstants().amountIdentifier);
break;
case FIRToken::lp_integer_add:
if (requireFeature({4, 0, 0}, "Integer arithmetic expressions", loc))
return failure();
break;
}

if (operands.size() != numOperandsExpected) {
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/FIRRTL/Import/FIRTokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ TOK_LPKEYWORD_PRIM(sub, SubPrimOp, 2)
TOK_LPKEYWORD_PRIM(tail, TailPrimOp, 1)
TOK_LPKEYWORD_PRIM(xor, XorPrimOp, 2)
TOK_LPKEYWORD_PRIM(xorr, XorRPrimOp, 1)
TOK_LPKEYWORD_PRIM(integer_add, IntegerAddOp, 2)

#undef TOK_MARKER
#undef TOK_IDENTIFIER
Expand Down
14 changes: 14 additions & 0 deletions test/Dialect/FIRRTL/parse-basic.fir
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,20 @@ circuit BasicProps :
; CHECK-NEXT: firrtl.propassign %nested, %[[NESTED]]
propassign nested, List<List<String>>(List<String>(), List<String>(String("test")), List<String>())

;// -----
FIRRTL version 4.0.0

; CHECK-LABEL: firrtl.circuit "IntegerArithmetic"
circuit IntegerArithmetic :
module IntegerArithmetic :
input a : Integer
input b : Integer
output c : Integer

; CHECK: [[C:%.+]] = firrtl.integer.add %a, %b
; CHECK: firrtl.propassign %c, [[C]]
propassign c, integer_add(a, b)

;// -----
FIRRTL version 3.1.0

Expand Down
11 changes: 11 additions & 0 deletions test/Dialect/FIRRTL/parse-errors.fir
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,17 @@ circuit Top:
output out : Integer
propassign out, in

;// -----
FIRRTL version 3.1.0

circuit Top:
module Top:
input a : Integer
input b : Integer
output c : Integer
; expected-error @below {{Integer arithmetic expressions are a FIRRTL 4.0.0+ feature, but the specified FIRRTL version was 3.1.0}}
propassign c, integer_add(a, b)

;// -----
FIRRTL version 3.3.0

Expand Down
Loading