[FIRRTL] Make "intrinsic" name of intmodule mandatory. (#6858)

It's mandatory in the FIRRTL spec and only an error if it's missing,
so directly require this.

Add test for this and invalid intrinsic name.
This commit is contained in:
Will Dietz 2024-03-20 16:35:34 -05:00 committed by GitHub
parent e4b78d771a
commit d5327de174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 30 deletions

View File

@ -225,7 +225,7 @@ def FIntModuleOp : FIRRTLModuleLike<"intmodule"> {
The "firrtl.intmodule" operation represents a compiler intrinsic.
}];
let arguments = (ins
OptionalAttr<StrAttr>:$intrinsic,
StrAttr:$intrinsic,
ArrayRefAttr:$portLocations,
ParamDeclArrayAttr:$parameters,
DefaultValuedAttr<AnnotationArrayAttr,
@ -240,7 +240,7 @@ def FIntModuleOp : FIRRTLModuleLike<"intmodule"> {
let builders = [
OpBuilder<(ins "StringAttr":$name,
"ArrayRef<PortInfo>":$ports,
CArg<"StringRef", "StringRef()">:$intrinsicNameAttr,
"StringRef":$intrinsicNameStr,
CArg<"ArrayAttr", "ArrayAttr()">:$annotations,
CArg<"ArrayAttr", "ArrayAttr()">:$parameters,
CArg<"ArrayAttr", "ArrayAttr()">:$internalPaths,

View File

@ -490,18 +490,9 @@ void Emitter::emitModule(FIntModuleOp op) {
auto ports = op.getPorts();
emitModulePorts(ports);
// Emit the optional intrinsic.
//
// TODO: This really shouldn't be optional, but it is currently encoded like
// this.
if (op.getIntrinsic().has_value()) {
auto intrinsic = *op.getIntrinsic();
if (!intrinsic.empty()) {
startStatement();
ps << "intrinsic = " << PPExtString(*op.getIntrinsic());
ps << "intrinsic = " << PPExtString(op.getIntrinsic());
setPendingNewline();
}
}
// Emit the parameters.
emitModuleParameters(op, op.getParameters());

View File

@ -137,11 +137,6 @@ LogicalResult IntrinsicLowerings::lower(CircuitOp circuit,
continue;
auto intname = intMod.getIntrinsicAttr();
if (!intname) {
op.emitError("intrinsic module with no intrinsic name");
++numFailures;
continue;
}
// Find the converter and apply it.
auto it = intmods.find(intname);

View File

@ -1028,11 +1028,11 @@ void FExtModuleOp::build(OpBuilder &builder, OperationState &result,
void FIntModuleOp::build(OpBuilder &builder, OperationState &result,
StringAttr name, ArrayRef<PortInfo> ports,
StringRef intrinsicNameAttr, ArrayAttr annotations,
StringRef intrinsicNameStr, ArrayAttr annotations,
ArrayAttr parameters, ArrayAttr internalPaths,
ArrayAttr layers) {
buildModule(builder, result, name, ports, annotations, layers);
result.addAttribute("intrinsic", builder.getStringAttr(intrinsicNameAttr));
result.addAttribute("intrinsic", builder.getStringAttr(intrinsicNameStr));
if (!parameters)
parameters = builder.getArrayAttr({});
result.addAttribute(getParametersAttrName(result.name), parameters);

View File

@ -5005,6 +5005,7 @@ ParseResult FIRCircuitParser::parseExtModule(CircuitOp circuit,
ParseResult FIRCircuitParser::parseIntModule(CircuitOp circuit,
unsigned indent) {
StringAttr name;
StringRef intName;
ArrayAttr layers;
SmallVector<PortInfo, 8> portList;
SmallVector<SMLoc> portLocs;
@ -5013,15 +5014,11 @@ ParseResult FIRCircuitParser::parseIntModule(CircuitOp circuit,
if (parseId(name, "expected intmodule name") ||
parseOptionalEnabledLayers(layers) ||
parseToken(FIRToken::colon, "expected ':' in intmodule definition") ||
info.parseOptionalInfo() || parsePortList(portList, portLocs, indent))
return failure();
StringRef intName;
if (consumeIf(FIRToken::kw_intrinsic)) {
if (parseToken(FIRToken::equal, "expected '=' in intrinsic") ||
info.parseOptionalInfo() || parsePortList(portList, portLocs, indent) ||
parseToken(FIRToken::kw_intrinsic, "expected 'intrinsic'") ||
parseToken(FIRToken::equal, "expected '=' in intrinsic") ||
parseId(intName, "expected intrinsic name"))
return failure();
}
ArrayAttr parameters;
ArrayAttr internalPaths;

View File

@ -785,7 +785,8 @@ firrtl.circuit "Foo" {
layers = [
@GroupA,
@GroupA::@GroupB
]
],
intrinsic = "test"
}
// CHECK: module ModuleWithLargeEnabledLayers

View File

@ -1382,3 +1382,16 @@ FIRRTL version 4.0.0
circuit PrivateMainModule:
; expected-error @below {{private main modules were removed in FIRRTL 4.0.0}}
module PrivateMainModule:
;// -----
circuit IntModuleNoIntrinsic:
intmodule test:
; expected-error @below {{expected 'intrinsic'}}
module IntModule:
;// -----
circuit IntModuleBadIntrinsic:
intmodule test:
; expected-error @below {{expected intrinsic name}}
intrinsic = 0
module IntModule: