Skip to content

Commit c661d9a

Browse files
committed
Add debug prints
1 parent 83fb49d commit c661d9a

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

lib/Conversion/ImportVerilog/Expressions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,10 @@ struct RvalueExprVisitor : public ExprVisitor {
994994

995995
case (1):
996996
value = context.convertRvalueExpression(*args[0]);
997-
if (!value)
997+
if (!value){
998+
dbgs(loc) << "Failed to convert RValue Expression of call " << subroutine.name;
998999
return {};
1000+
}
9991001
result = context.convertSystemCallArity1(subroutine, loc, value);
10001002
break;
10011003

lib/Conversion/ImportVerilog/HierarchicalNames.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ LogicalResult Context::traverseInstanceBody(const slang::ast::Symbol &symbol) {
184184
if (auto *instBodySymbol = symbol.as_if<slang::ast::InstanceBodySymbol>())
185185
for (auto &member : instBodySymbol->members()) {
186186
auto loc = convertLocation(member.location);
187-
if (failed(member.visit(InstBodyVisitor(*this, loc))))
187+
if (failed(member.visit(InstBodyVisitor(*this, loc)))) {
188+
dbgs(member.location) << ": Failed to convert symbol " << member.name;
188189
return failure();
190+
}
189191
}
190192
return success();
191193
}

lib/Conversion/ImportVerilog/ImportVerilog.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "slang/parsing/Preprocessor.h"
2424
#include "slang/syntax/SyntaxPrinter.h"
2525
#include "slang/util/VersionInfo.h"
26-
#include "ImportVerilogDebugStream.h"
2726

2827
using namespace mlir;
2928
using namespace circt;
@@ -263,8 +262,10 @@ LogicalResult ImportDriver::importVerilog(ModuleOp module) {
263262
auto compilation = driver.createCompilation();
264263
for (auto &diag : compilation->getAllDiagnostics())
265264
driver.diagEngine.issue(diag);
266-
if (!parseSuccess || driver.diagEngine.getNumErrors() > 0)
265+
if (!parseSuccess || driver.diagEngine.getNumErrors() > 0) {
266+
dbgs() << "Failed to parse and elaborate inputs!";
267267
return failure();
268+
}
268269
compileTimer.stop();
269270

270271
// If we were only supposed to lint the input, return here. This leaves the
@@ -279,8 +280,10 @@ LogicalResult ImportDriver::importVerilog(ModuleOp module) {
279280
debug::DebugDialect>();
280281
auto conversionTimer = ts.nest("Verilog to dialect mapping");
281282
Context context(options, *compilation, module, driver.sourceManager);
282-
if (failed(context.convertCompilation()))
283+
if (failed(context.convertCompilation())) {
284+
dbgs() << "Failed to convert Slang compilation!";
283285
return failure();
286+
}
284287
conversionTimer.stop();
285288

286289
// Run the verifier on the constructed module to ensure it is clean.

lib/Conversion/ImportVerilog/ImportVerilogDebugStream.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
// If includer defined DEBUG_TYPE, use that; else fall back to our default.
2323
#ifndef IMPORTVERILOG_DEBUG_TYPE
24-
#ifdef DEBUG_TYPE
25-
#define IMPORTVERILOG_DEBUG_TYPE DEBUG_TYPE
26-
#else
27-
#define IMPORTVERILOG_DEBUG_TYPE "import-verilog"
28-
#endif
24+
#ifdef DEBUG_TYPE
25+
#define IMPORTVERILOG_DEBUG_TYPE DEBUG_TYPE
26+
#else
27+
#define IMPORTVERILOG_DEBUG_TYPE "import-verilog"
28+
#endif
2929
#endif
3030

3131
struct ImportVerilogDebugStream {
@@ -40,7 +40,7 @@ struct ImportVerilogDebugStream {
4040

4141
inline ~ImportVerilogDebugStream() {
4242
DEBUG_WITH_TYPE(IMPORTVERILOG_DEBUG_TYPE, {
43-
if(compLoc)
43+
if (compLoc)
4444
llvm::dbgs() << compLoc->file_name() << ":" << compLoc->line() << " ("
4545
<< compLoc->function_name() << ") ";
4646
if (srcLoc) {
@@ -86,8 +86,8 @@ operator<<(ImportVerilogDebugStream &&s,
8686
}
8787

8888
/// Helper function to set up a debug stream with reasonable defaults
89-
ImportVerilogDebugStream dbgs(
90-
std::optional<mlir::Location> sourceLocation = {},
91-
std::optional<std::source_location> cl = std::source_location::current());
89+
ImportVerilogDebugStream
90+
dbgs(std::optional<mlir::Location> sourceLocation = {},
91+
std::optional<std::source_location> cl = std::source_location::current());
9292

9393
#endif // IMPORT_VERILOG_DEBUG_H

lib/Conversion/ImportVerilog/ImportVerilogInternals.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ struct Context {
9595
/// Convert a slang `SourceRange` into an MLIR `Location`.
9696
Location convertLocation(slang::SourceRange range);
9797

98-
/// A convenient debug stream wrapper which attaches information about input source location and compiler source location; also accepts slang::SourceLocation and tries to unwrap it.
98+
/// A convenient debug stream wrapper which attaches information about input
99+
/// source location and compiler source location; also accepts
100+
/// slang::SourceLocation and tries to unwrap it.
99101
ImportVerilogDebugStream dbgs(
100102
std::optional<std::variant<mlir::Location, slang::SourceLocation>>
101-
sourceLocation = {},
103+
sourceLocation = {},
102104
std::optional<std::source_location> cl = std::source_location::current());
103105

104106
/// Convert a slang type into an MLIR type. Returns null on failure. Uses the

lib/Conversion/ImportVerilog/Statements.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include "ImportVerilogInternals.h"
1010
#include "slang/ast/Compilation.h"
1111
#include "slang/ast/SystemSubroutine.h"
12+
#include "slang/syntax/AllSyntax.h"
1213
#include "llvm/ADT/ScopeExit.h"
14+
#include <slang/ast/SFormat.h>
1315

1416
using namespace mlir;
1517
using namespace circt;
@@ -138,8 +140,11 @@ struct StmtVisitor {
138140
mlir::emitWarning(loc, "unreachable code");
139141
break;
140142
}
141-
if (failed(context.convertStatement(*stmt)))
143+
if (failed(context.convertStatement(*stmt))) {
144+
context.dbgs(stmt->syntax->sourceRange().start())
145+
<< "Failed to convert statement " << stmt->syntax->toString();
142146
return failure();
147+
}
143148
}
144149
return success();
145150
}
@@ -157,17 +162,26 @@ struct StmtVisitor {
157162
std::get_if<slang::ast::CallExpression::SystemCallInfo>(
158163
&call->subroutine)) {
159164
auto handled = visitSystemCall(stmt, *call, *info);
160-
if (failed(handled))
165+
if (failed(handled)) {
166+
context.dbgs(stmt.sourceRange.start())
167+
<< "Failed to convert system call " << stmt.syntax->toString();
161168
return failure();
169+
}
162170
if (handled == true)
163171
return success();
164172
}
173+
context.dbgs(stmt.sourceRange.start())
174+
<< "Assuming statement " << stmt.syntax->toString()
175+
<< " is not a system task";
165176
}
166177

167178
auto value = context.convertRvalueExpression(stmt.expr);
168-
if (!value)
179+
if (!value) {
180+
context.dbgs(stmt.sourceRange.start())
181+
<< "Failed to convert expression statement as RValue "
182+
<< stmt.expr.syntax->toString();
169183
return failure();
170-
184+
}
171185
// Expressions like calls to void functions return a dummy value that has no
172186
// uses. If the returned value is trivially dead, remove it.
173187
if (auto *defOp = value.getDefiningOp())

lib/Conversion/ImportVerilog/Structure.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,23 +669,30 @@ LogicalResult Context::convertCompilation() {
669669
for (auto *unit : root.compilationUnits) {
670670
for (const auto &member : unit->members()) {
671671
auto loc = convertLocation(member.location);
672-
if (failed(member.visit(RootVisitor(*this, loc))))
672+
if (failed(member.visit(RootVisitor(*this, loc)))) {
673+
dbgs(loc) << "Failed to convert top-level object " << member.name;
673674
return failure();
675+
}
674676
}
675677
}
676678

677679
// Prime the root definition worklist by adding all the top-level modules.
678680
SmallVector<const slang::ast::InstanceSymbol *> topInstances;
679681
for (auto *inst : root.topInstances)
680-
if (!convertModuleHeader(&inst->body))
682+
if (!convertModuleHeader(&inst->body)) {
683+
dbgs(inst->location) << ": Failed to convert module header of module "
684+
<< inst->name;
681685
return failure();
682-
686+
}
683687
// Convert all the root module definitions.
684688
while (!moduleWorklist.empty()) {
685689
auto *module = moduleWorklist.front();
686690
moduleWorklist.pop();
687-
if (failed(convertModuleBody(module)))
691+
if (failed(convertModuleBody(module))) {
692+
dbgs(module->location)
693+
<< ": Failed to convert module body of module " << module->name;
688694
return failure();
695+
}
689696
}
690697

691698
return success();
@@ -1057,8 +1064,10 @@ Context::convertFunction(const slang::ast::SubroutineSymbol &subroutine) {
10571064

10581065
// First get or create the function declaration.
10591066
auto *lowering = declareFunction(subroutine);
1060-
if (!lowering)
1067+
if (!lowering) {
1068+
dbgs(subroutine.location) << "Failed to lower function " << subroutine.name;
10611069
return failure();
1070+
}
10621071
ValueSymbolScope scope(valueSymbols);
10631072

10641073
// Create a function body block and populate it with block arguments.
@@ -1101,9 +1110,11 @@ Context::convertFunction(const slang::ast::SubroutineSymbol &subroutine) {
11011110
valueSymbols.insert(subroutine.returnValVar, returnVar);
11021111
}
11031112

1104-
if (failed(convertStatement(subroutine.getBody())))
1113+
if (failed(convertStatement(subroutine.getBody()))) {
1114+
dbgs(subroutine.location)
1115+
<< "Failed to convert body of function " << subroutine.name;
11051116
return failure();
1106-
1117+
}
11071118
// If there was no explicit return statement provided by the user, insert a
11081119
// default one.
11091120
if (builder.getBlock()) {

0 commit comments

Comments
 (0)