TableGen.cpp (194612) | TableGen.cpp (195340) |
---|---|
1//===- TableGen.cpp - Top-Level TableGen implementation -------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13// code generators to automate generation of a code generator through a 14// high-level description of the target. 15// 16//===----------------------------------------------------------------------===// 17 18#include "Record.h" 19#include "TGParser.h" 20#include "llvm/Support/CommandLine.h" | 1//===- TableGen.cpp - Top-Level TableGen implementation -------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13// code generators to automate generation of a code generator through a 14// high-level description of the target. 15// 16//===----------------------------------------------------------------------===// 17 18#include "Record.h" 19#include "TGParser.h" 20#include "llvm/Support/CommandLine.h" |
21#include "llvm/Support/Streams.h" | |
22#include "llvm/System/Signals.h" 23#include "llvm/Support/FileUtilities.h" 24#include "llvm/Support/MemoryBuffer.h" 25#include "llvm/Support/PrettyStackTrace.h" | 21#include "llvm/System/Signals.h" 22#include "llvm/Support/FileUtilities.h" 23#include "llvm/Support/MemoryBuffer.h" 24#include "llvm/Support/PrettyStackTrace.h" |
25#include "llvm/Support/raw_ostream.h" |
|
26#include "CallingConvEmitter.h" 27#include "CodeEmitterGen.h" 28#include "RegisterInfoEmitter.h" 29#include "InstrInfoEmitter.h" 30#include "InstrEnumEmitter.h" 31#include "AsmWriterEmitter.h" 32#include "DAGISelEmitter.h" 33#include "FastISelEmitter.h" 34#include "SubtargetEmitter.h" 35#include "IntrinsicEmitter.h" 36#include "LLVMCConfigurationEmitter.h" 37#include "ClangDiagnosticsEmitter.h" 38#include <algorithm> 39#include <cstdio> | 26#include "CallingConvEmitter.h" 27#include "CodeEmitterGen.h" 28#include "RegisterInfoEmitter.h" 29#include "InstrInfoEmitter.h" 30#include "InstrEnumEmitter.h" 31#include "AsmWriterEmitter.h" 32#include "DAGISelEmitter.h" 33#include "FastISelEmitter.h" 34#include "SubtargetEmitter.h" 35#include "IntrinsicEmitter.h" 36#include "LLVMCConfigurationEmitter.h" 37#include "ClangDiagnosticsEmitter.h" 38#include <algorithm> 39#include <cstdio> |
40#include <fstream> 41#include <ios> | |
42using namespace llvm; 43 44enum ActionType { 45 PrintRecords, 46 GenEmitter, 47 GenRegisterEnums, GenRegister, GenRegisterHeader, 48 GenInstrEnums, GenInstrs, GenAsmWriter, 49 GenCallingConv, --- 72 unchanged lines hidden (view full) --- 122 123 124// FIXME: Eliminate globals from tblgen. 125RecordKeeper llvm::Records; 126 127static SourceMgr SrcMgr; 128 129void llvm::PrintError(SMLoc ErrorLoc, const std::string &Msg) { | 40using namespace llvm; 41 42enum ActionType { 43 PrintRecords, 44 GenEmitter, 45 GenRegisterEnums, GenRegister, GenRegisterHeader, 46 GenInstrEnums, GenInstrs, GenAsmWriter, 47 GenCallingConv, --- 72 unchanged lines hidden (view full) --- 120 121 122// FIXME: Eliminate globals from tblgen. 123RecordKeeper llvm::Records; 124 125static SourceMgr SrcMgr; 126 127void llvm::PrintError(SMLoc ErrorLoc, const std::string &Msg) { |
130 SrcMgr.PrintMessage(ErrorLoc, Msg); | 128 SrcMgr.PrintMessage(ErrorLoc, Msg, "error"); |
131} 132 133 134 135/// ParseFile - this function begins the parsing of the specified tablegen 136/// file. 137static bool ParseFile(const std::string &Filename, 138 const std::vector<std::string> &IncludeDirs, 139 SourceMgr &SrcMgr) { 140 std::string ErrorStr; 141 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr); 142 if (F == 0) { | 129} 130 131 132 133/// ParseFile - this function begins the parsing of the specified tablegen 134/// file. 135static bool ParseFile(const std::string &Filename, 136 const std::vector<std::string> &IncludeDirs, 137 SourceMgr &SrcMgr) { 138 std::string ErrorStr; 139 MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr); 140 if (F == 0) { |
143 cerr << "Could not open input file '" + Filename + "': " << ErrorStr <<"\n"; | 141 errs() << "Could not open input file '" + Filename + "': " 142 << ErrorStr <<"\n"; |
144 return true; 145 } 146 147 // Tell SrcMgr about this buffer, which is what TGParser will pick up. 148 SrcMgr.AddNewSourceBuffer(F, SMLoc()); 149 150 // Record the location of the include directory so that the lexer can find 151 // it later. --- 9 unchanged lines hidden (view full) --- 161 PrettyStackTraceProgram X(argc, argv); 162 cl::ParseCommandLineOptions(argc, argv); 163 164 165 // Parse the input file. 166 if (ParseFile(InputFilename, IncludeDirs, SrcMgr)) 167 return 1; 168 | 143 return true; 144 } 145 146 // Tell SrcMgr about this buffer, which is what TGParser will pick up. 147 SrcMgr.AddNewSourceBuffer(F, SMLoc()); 148 149 // Record the location of the include directory so that the lexer can find 150 // it later. --- 9 unchanged lines hidden (view full) --- 160 PrettyStackTraceProgram X(argc, argv); 161 cl::ParseCommandLineOptions(argc, argv); 162 163 164 // Parse the input file. 165 if (ParseFile(InputFilename, IncludeDirs, SrcMgr)) 166 return 1; 167 |
169 std::ostream *Out = cout.stream(); | 168 raw_ostream *Out = &outs(); |
170 if (OutputFilename != "-") { | 169 if (OutputFilename != "-") { |
171 Out = new std::ofstream(OutputFilename.c_str()); | 170 std::string Error; 171 Out = new raw_fd_ostream(OutputFilename.c_str(), false, Error); |
172 | 172 |
173 if (!Out->good()) { 174 cerr << argv[0] << ": error opening " << OutputFilename << "!\n"; | 173 if (!Error.empty()) { 174 errs() << argv[0] << ": error opening " << OutputFilename 175 << ":" << Error << "\n"; |
175 return 1; 176 } 177 178 // Make sure the file gets removed if *gasp* tablegen crashes... 179 sys::RemoveFileOnSignal(sys::Path(OutputFilename)); 180 } 181 182 try { --- 58 unchanged lines hidden (view full) --- 241 *Out << "\n"; 242 break; 243 } 244 default: 245 assert(1 && "Invalid Action"); 246 return 1; 247 } 248 | 176 return 1; 177 } 178 179 // Make sure the file gets removed if *gasp* tablegen crashes... 180 sys::RemoveFileOnSignal(sys::Path(OutputFilename)); 181 } 182 183 try { --- 58 unchanged lines hidden (view full) --- 242 *Out << "\n"; 243 break; 244 } 245 default: 246 assert(1 && "Invalid Action"); 247 return 1; 248 } 249 |
249 if (Out != cout.stream()) | 250 if (Out != &outs()) |
250 delete Out; // Close the file 251 return 0; 252 253 } catch (const TGError &Error) { | 251 delete Out; // Close the file 252 return 0; 253 254 } catch (const TGError &Error) { |
254 cerr << argv[0] << ": error:\n"; | 255 errs() << argv[0] << ": error:\n"; |
255 PrintError(Error.getLoc(), Error.getMessage()); 256 257 } catch (const std::string &Error) { | 256 PrintError(Error.getLoc(), Error.getMessage()); 257 258 } catch (const std::string &Error) { |
258 cerr << argv[0] << ": " << Error << "\n"; | 259 errs() << argv[0] << ": " << Error << "\n"; |
259 } catch (const char *Error) { | 260 } catch (const char *Error) { |
260 cerr << argv[0] << ": " << Error << "\n"; | 261 errs() << argv[0] << ": " << Error << "\n"; |
261 } catch (...) { | 262 } catch (...) { |
262 cerr << argv[0] << ": Unknown unexpected exception occurred.\n"; | 263 errs() << argv[0] << ": Unknown unexpected exception occurred.\n"; |
263 } 264 | 264 } 265 |
265 if (Out != cout.stream()) { | 266 if (Out != &outs()) { |
266 delete Out; // Close the file 267 std::remove(OutputFilename.c_str()); // Remove the file, it's broken 268 } 269 return 1; 270} | 267 delete Out; // Close the file 268 std::remove(OutputFilename.c_str()); // Remove the file, it's broken 269 } 270 return 1; 271} |