Skip to content

Commit

Permalink
[ExportVerilog] Add verilog debug locations to output MLIR (#6092)
Browse files Browse the repository at this point in the history
Use the PrettyPrinter CallbackToken API, to record print events and store the
 verilog output locations for each operation. Record the print begin and end
 location of each op. This has a side-effect of updating the IR, location
 attribute of the op is updated to include the verilog location range. `FusedLoc`
 is used to record the location ranges and each op can correspond to multiple
verilog locations.
This feature is disabled by default under an emission flag `emitVerilogLocations`.
  • Loading branch information
prithayan committed Sep 20, 2023
1 parent 03eb57d commit 7556e97
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 22 deletions.
3 changes: 3 additions & 0 deletions include/circt/Support/LoweringOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ struct LoweringOptions {
/// This is used to avoid stricter lint warnings which, e.g., treat "REG" as a
/// Verilog keyword.
bool caseInsensitiveKeywords = false;

/// If true, then update the the mlir to include output verilog locations.
bool emitVerilogLocations = false;
};
} // namespace circt

Expand Down
24 changes: 24 additions & 0 deletions include/circt/Support/PrettyPrinterHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ struct PPSaveString {
template <typename PPTy = PrettyPrinter>
class TokenStream : public TokenBuilder<PPTy> {
using Base = TokenBuilder<PPTy>;

protected:
TokenStringSaver &saver;

public:
Expand Down Expand Up @@ -369,6 +371,28 @@ class TokenStream : public TokenBuilder<PPTy> {
}
};

/// Wrap the TokenStream with a helper for CallbackTokens, to record the print
/// events on the stream.
template <typename CallableType, typename DataType,
typename PPTy = PrettyPrinter>
class TokenStreamWithCallback : public TokenStream<PPTy> {
using Base = TokenStream<PPTy>;
PrintEventAndStorageListener<CallableType, DataType> &saver;

const bool enableCallback;

public:
TokenStreamWithCallback(
PPTy &pp, PrintEventAndStorageListener<CallableType, DataType> &saver,
bool enableCallback)
: TokenStream<PPTy>(pp, saver), saver(saver),
enableCallback(enableCallback) {}
/// Add a Callback token.
void addCallback(DataType d) {
if (enableCallback)
Base::addToken(saver.getToken(d));
}
};
} // end namespace pretty
} // end namespace circt

Expand Down
Loading

0 comments on commit 7556e97

Please sign in to comment.