aboutsummaryrefslogtreecommitdiffstats
path: root/lib/TableGen/Main.cpp
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@gmail.com>2011-10-04 15:14:51 +0000
committerChe-Liang Chiou <clchiou@gmail.com>2011-10-04 15:14:51 +0000
commitf98742565765a10558824ea45f0d9a70843ed0d9 (patch)
tree88c769a0ed43e8d86df7354c4826df16f942c113 /lib/TableGen/Main.cpp
parent34804c4f4793abbcb908c79fe9512c03090d8520 (diff)
downloadexternal_llvm-f98742565765a10558824ea45f0d9a70843ed0d9.zip
external_llvm-f98742565765a10558824ea45f0d9a70843ed0d9.tar.gz
external_llvm-f98742565765a10558824ea45f0d9a70843ed0d9.tar.bz2
tblgen: add preprocessor as a separate mode
This patch adds a preprocessor that can expand nested for-loops for saving some copy-n-paste in *.td files. The preprocessor is not yet integrated with TGParser, and so it has no direct effect on *.td inputs. However, you may preprocess an td input (and only preprocess it). To test the proprecessor, type: tblgen -E -o $@ $< git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141079 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen/Main.cpp')
-rw-r--r--lib/TableGen/Main.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp
index 01bc55e..e15c09f 100644
--- a/lib/TableGen/Main.cpp
+++ b/lib/TableGen/Main.cpp
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "TGParser.h"
+#include "TGPreprocessor.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -43,6 +44,12 @@ namespace {
cl::list<std::string>
IncludeDirs("I", cl::desc("Directory of include files"),
cl::value_desc("directory"), cl::Prefix);
+
+ cl::opt<bool>
+ PreprocessOnly("E",
+ cl::desc("Stop after the preprocessing stage; "
+ "This is work in progress and has no effect yet"),
+ cl::init(false));
}
namespace llvm {
@@ -67,6 +74,22 @@ int TableGenMain(char *argv0, TableGenAction &Action) {
// it later.
SrcMgr.setIncludeDirs(IncludeDirs);
+ // TODO(clchiou): Integrate preprocessor into TGParser
+ if (PreprocessOnly) {
+ std::string Error;
+ tool_output_file Out(OutputFilename.c_str(), Error);
+ if (!Error.empty()) {
+ errs() << argv0 << ": error opening " << OutputFilename
+ << ":" << Error << "\n";
+ return 1;
+ }
+ TGPreprocessor Preprocessor(SrcMgr, Out);
+ if (Preprocessor.PreprocessFile())
+ return 1;
+ Out.keep();
+ return 0;
+ }
+
TGParser Parser(SrcMgr, Records);
if (Parser.ParseFile())