[llvm] [TableGen] Implement a preprocessor (PR #120113)
Ivan Kosarev via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 22 07:07:04 PST 2025
================
@@ -77,12 +77,65 @@ static cl::opt<bool> NoWarnOnUnusedTemplateArgs(
"no-warn-on-unused-template-args",
cl::desc("Disable unused template argument warnings."));
+static cl::opt<bool> Preprocess("E", cl::desc("Write preprocessed output"));
+
static int reportError(const char *ProgName, Twine Msg) {
errs() << ProgName << ": " << Msg;
errs().flush();
return 1;
}
+/// Encapsulate file, line and column numbers from SourceMgr.
+struct SMCoords {
+ unsigned Buf = 0;
+ unsigned Line = 0;
+ unsigned Col = 0;
+ SMCoords() = default;
+ SMCoords(const SourceMgr &Mgr, SMLoc Loc) {
+ Buf = Mgr.FindBufferContainingLoc(Loc);
+ // TODO: SourceMgr::getLineAndColumn is not a fast method. Find a better way
+ // to do this. For example we don't need the column number for every token,
+ // only the first token on each output line.
+ std::tie(Line, Col) = Mgr.getLineAndColumn(Loc, Buf);
+ }
+};
+
+/// Create preprocessed output for `-E` option.
+static int preprocessInput(raw_ostream &OS) {
+ TGLexer Lex(SrcMgr, MacroNames);
+ SMCoords Last;
+ bool Any = false;
----------------
kosarev wrote:
```suggestion
bool EmptyOutput = true;
```
https://github.com/llvm/llvm-project/pull/120113
More information about the llvm-commits
mailing list