[ImportVerilog] Support Generate constructs (#7243)

This commit is contained in:
Anqi Yu 2024-06-28 10:10:51 +08:00 committed by GitHub
parent 765cec6bb8
commit ce121a0a15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 1 deletions

View File

@ -98,6 +98,11 @@ struct MemberVisitor {
LogicalResult visit(const slang::ast::PortSymbol &) { return success(); }
LogicalResult visit(const slang::ast::MultiPortSymbol &) { return success(); }
// Skip genvars.
LogicalResult visit(const slang::ast::GenvarSymbol &genvarNode) {
return success();
}
// Handle instances.
LogicalResult visit(const slang::ast::InstanceSymbol &instNode) {
using slang::ast::ArgumentDirection;
@ -368,6 +373,26 @@ struct MemberVisitor {
return success();
}
// Handle generate block.
LogicalResult visit(const slang::ast::GenerateBlockSymbol &genNode) {
if (!genNode.isUninstantiated) {
for (auto &member : genNode.members()) {
if (failed(member.visit(MemberVisitor(context, loc))))
return failure();
}
}
return success();
}
// Handle generate block array.
LogicalResult visit(const slang::ast::GenerateBlockArraySymbol &genArrNode) {
for (const auto *member : genArrNode.entries) {
if (failed(member->asSymbol().visit(MemberVisitor(context, loc))))
return failure();
}
return success();
}
// Ignore statement block symbols. These get generated by Slang for blocks
// with variables and other declarations. For example, having an initial
// procedure with a variable declaration, such as `initial begin int x;

View File

@ -1258,3 +1258,43 @@ module EventControl(input clk);
// CHECK: moore.assign %clk_0, %clk : l1
// CHECK: moore.output
endmodule
// CHECK-LABEL: moore.module @GenerateConstructs()
module GenerateConstructs;
genvar i;
parameter p=2;
generate
// CHECK: [[TMP1:%.+]] = moore.constant 0 : l32
// CHECK: %i = moore.named_constant localparam [[TMP1]] : l32
// CHECK: [[TMP2:%.+]] = moore.conversion %i : !moore.l32 -> !moore.i32
// CHECK: %g1 = moore.variable [[TMP2]] : <i32>
// CHECK: [[TMP3:%.+]] = moore.constant 1 : l32
// CHECK: %i_0 = moore.named_constant localparam name "i" [[TMP3]] : l32
// CHECK: [[TMP4:%.+]] = moore.conversion %i_0 : !moore.l32 -> !moore.i32
// CHECK: %g1_1 = moore.variable name "g1" [[TMP4]] : <i32>
for(i=0; i<2; i=i+1) begin
int g1 = i;
end
// CHECK: [[TMP:%.+]] = moore.constant 2 : i32
// CHECK: %g2 = moore.variable [[TMP]] : <i32>
if(p == 2) begin
int g2 = 2;
end
else begin
int g2 = 3;
end
// CHECK: [[TMP:%.+]] = moore.constant 2 : i32
// CHECK: %g3 = moore.variable [[TMP]] : <i32>
case (p)
2: begin
int g3 = 2;
end
default: begin
int g3 = 3;
end
endcase
endgenerate
endmodule

View File

@ -27,8 +27,9 @@ endmodule
// -----
module Foo;
parameter a = 1;
// expected-error @below {{unsupported construct}}
genvar a;
defparam a = 2;
endmodule
// -----