-
-// FIXME: Eliminate globals from tblgen.
-RecordKeeper llvm::Records;
-
-static SourceMgr SrcMgr;
-
-void llvm::PrintError(SMLoc ErrorLoc, const std::string &Msg) {
- SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
-}
-
-
-
-/// ParseFile - this function begins the parsing of the specified tablegen
-/// file.
-static bool ParseFile(const std::string &Filename,
- const std::vector<std::string> &IncludeDirs,
- SourceMgr &SrcMgr) {
- std::string ErrorStr;
- MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
- if (F == 0) {
- errs() << "Could not open input file '" << Filename << "': "
- << ErrorStr <<"\n";
- return true;
- }
-
- // Tell SrcMgr about this buffer, which is what TGParser will pick up.
- SrcMgr.AddNewSourceBuffer(F, SMLoc());
-
- // Record the location of the include directory so that the lexer can find
- // it later.
- SrcMgr.setIncludeDirs(IncludeDirs);
-
- TGParser Parser(SrcMgr);
-
- return Parser.ParseFile();
-}
-
-int main(int argc, char **argv) {
- sys::PrintStackTraceOnErrorSignal();
- PrettyStackTraceProgram X(argc, argv);
- cl::ParseCommandLineOptions(argc, argv);
-
-
- // Parse the input file.
- if (ParseFile(InputFilename, IncludeDirs, SrcMgr))
- return 1;
-
- raw_ostream *Out = &outs();
- if (OutputFilename != "-") {
- std::string Error;
- Out = new raw_fd_ostream(OutputFilename.c_str(), Error);
-
- if (!Error.empty()) {
- errs() << argv[0] << ": error opening " << OutputFilename
- << ":" << Error << "\n";
- return 1;
- }
-
- // Make sure the file gets removed if *gasp* tablegen crashes...
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- }
-
- try {