LLVM: lib/TableGen/Main.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
36#include
37#include
38#include <system_error>
39#include
40using namespace llvm;
41
45
48 cl::desc("Dependency filename"),
51
54
58
62
65
68
70 "long-string-literals",
71 cl::desc("when emitting large string tables, prefer string literals over "
72 "comma-separated char literals. This can be a readability and "
73 "compile-time performance win, but upsets some compilers"),
75
77 "no-warn-on-unused-template-args",
78 cl::desc("Disable unused template argument warnings."));
79
81 errs() << ProgName << ": " << Msg;
83 return 1;
84}
85
86
87
88
89
92 return reportError(argv0, "the option -d must be used together with -o\n");
93
94 std::error_code EC;
96 if (EC)
98 EC.message() + "\n");
101 DepOut.os() << ' ' << Dep;
102 }
103 DepOut.os() << "\n";
104 DepOut.keep();
105 return 0;
106}
107
111
112
113
115 if (std::move(ExistingOrErr.get())->getBuffer() == Content)
116 return 0;
117 }
118 std::error_code EC;
120 if (EC)
121 return reportError(argv0, "error opening " + Filename + ": " +
122 EC.message() + "\n");
123 OutFile.os() << Content;
125 OutFile.keep();
126
127 return 0;
128}
129
133
135 Timer.startPhaseTiming();
136
137
138
142 if (std::error_code EC = FileOrErr.getError())
144 "': " + EC.message() + "\n");
145
147
148
149 SrcMgr.AddNewSourceBuffer(std::move(*FileOrErr), SMLoc());
150
151
152
155
157
159 return 1;
161
162
163
166
167
168 Timer.startBackendTimer("Backend overall");
170 unsigned status = 0;
171
172
175 status = MainFn ? MainFn(OutFiles, Records) : 1;
176 Timer.stopBackendTimer();
177 if (status)
178 return 1;
179
180
181
182
183
186 return Ret;
187 }
188
191 return Ret;
192 for (auto [Suffix, Content] : OutFiles.AdditionalFiles) {
194
195 if (Filename != "-") {
197 Filename.append(Suffix);
198 }
199 if (int Ret = WriteOutput(Parser, argv0, Filename, Content))
200 return Ret;
201 }
202
204 Timer.stopPhaseTiming();
205
208 return 0;
209}
210
214 std::string S;
216 int Res = MainFn(OS, Records);
217 OutFiles = {S, {}};
218 return Res;
219 });
220}
Provides ErrorOr smart pointer.
static cl::opt< bool > NoWarnOnUnusedTemplateArgs("no-warn-on-unused-template-args", cl::desc("Disable unused template argument warnings."))
static cl::list< std::string > IncludeDirs("I", cl::desc("Directory of include files"), cl::value_desc("directory"), cl::Prefix)
static int createDependencyFile(const TGParser &Parser, const char *argv0)
Create a dependency file for -d option.
Definition Main.cpp:90
static cl::opt< bool > WriteIfChanged("write-if-changed", cl::desc("Only write output if it changed"))
static cl::opt< std::string > DependFilename("d", cl::desc("Dependency filename"), cl::value_desc("filename"), cl::init(""))
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
static cl::opt< bool > TimePhases("time-phases", cl::desc("Time phases of parser and backend"))
static int WriteOutput(const TGParser &Parser, const char *argv0, StringRef Filename, StringRef Content)
Definition Main.cpp:108
static cl::opt< std::string > InputFilename(cl::Positional, cl::desc(""), cl::init("-"))
static cl::list< std::string > MacroNames("D", cl::desc("Name of the macro to be defined"), cl::value_desc("macro name"), cl::Prefix)
static int reportError(const char *ProgName, Twine Msg)
Definition Main.cpp:80
Defines the virtual file system interface vfs::FileSystem.
Represents either an error or a value T.
std::error_code getError() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
const TGLexer::DependenciesSetTy & getDependencies() const
bool ParseFile()
ParseFile - Main entrypoint for parsing a tblgen file.
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
LLVM_ABI void stopTimer()
Stop the timer.
LLVM_ABI void startTimer()
Start the timer running.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A raw_ostream that writes to an std::string.
bool ApplyCallback(const RecordKeeper &Records, TableGenOutputFiles &OutFiles, StringRef FilenamePrefix)
Apply callback for any command line option registered above.
initializer< Ty > init(const Ty &Val)
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
LLVM_ABI StringRef stem(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get stem.
LLVM_ABI void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
LLVM_ABI IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This is an optimization pass for GlobalISel generic memory operations.
function_ref< bool(TableGenOutputFiles &OutFiles, const RecordKeeper &Records)> MultiFileTableGenMainFn
Perform the action using Records, and store output in OutFiles.
function_ref< bool(raw_ostream &OS, const RecordKeeper &Records)> TableGenMainFn
Returns true on error, false otherwise.
cl::opt< bool > EmitLongStrLiterals
Controls emitting large character arrays as strings or character arrays.
int TableGenMain(const char *argv0, TableGenMainFn MainFn=nullptr)
Definition Main.cpp:211
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::map< StringRef, std::string > AdditionalFiles