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

[ImportVerilog] Fix unknown name caused by local variables. #6995

Merged
merged 1 commit into from
May 8, 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
7 changes: 5 additions & 2 deletions lib/Conversion/ImportVerilog/Statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ struct StmtVisitor {
return failure();
}

builder.create<moore::VariableOp>(loc, type,
builder.getStringAttr(var.name), initial);
// Collect local temporary variables.
auto varOp = builder.create<moore::VariableOp>(
loc, type, builder.getStringAttr(var.name), initial);
context.valueSymbols.insertIntoScope(context.valueSymbols.getCurScope(),
&var, varOp);
return success();
}

Expand Down
6 changes: 6 additions & 0 deletions test/Conversion/ImportVerilog/basic.sv
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ module Statements;
bit x, y, z;
int i;
initial begin
//===------------------------------------------------------------------===//
// local variables

// CHECK: %a = moore.variable : !moore.int
automatic int a;

//===------------------------------------------------------------------===//
// Conditional statements

Expand Down
14 changes: 14 additions & 0 deletions test/Conversion/ImportVerilog/errors.sv
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,17 @@ module Foo;
b = a[1-:-1];
end
endmodule

// -----

module Foo;
int x;
initial begin
// expected-remark @below {{declared here}}
automatic int a;
// expected-error @below {{nonblocking assignment to automatic variable 'a' is not allowed}}
a <= x;
// expected-error @below {{declaration must come before all statements in the block}}
automatic int b;
end
endmodule
2 changes: 2 additions & 0 deletions test/Dialect/Moore/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ moore.module @Foo {
moore.blocking_assign %v1, %v2 : !moore.bit
// CHECK: moore.nonblocking_assign %v1, %v2 : !moore.bit
moore.nonblocking_assign %v1, %v2 : !moore.bit
// CHECK: %a = moore.variable : !moore.int
%a = moore.variable : !moore.int
}
}

Expand Down
Loading