34#define OPTTABLE_STR_TABLE_CODE
36#undef OPTTABLE_STR_TABLE_CODE
40#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
45#define OPTTABLE_PREFIXES_TABLE_CODE
47#undef OPTTABLE_PREFIXES_TABLE_CODE
51#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
67 if (std::error_code EC = MB.
getError()) {
72 return std::move(*MB);
86 switch (
T.getArch()) {
105std::optional<std::string> getPrefix(
StringRef Argv0) {
110 ProgName = ProgName.
rtrim(
"0123456789.-");
115 return ProgName.
str();
120 std::vector<COFFShortExport> &Exports,
121 std::string &OutputFile) {
122 std::unique_ptr<MemoryBuffer> MB =
openFile(DefFileName);
126 if (!MB->getBufferSize()) {
132 *MB,
Machine,
true, AddUnderscores);
139 if (OutputFile.empty())
140 OutputFile = std::move(
Def->OutputFile);
154 Exports = std::move(
Def->Exports);
162 unsigned MissingIndex;
163 unsigned MissingCount;
165 Table.ParseArgs(ArgsArr.
slice(1), MissingIndex, MissingCount);
167 llvm::errs() << Args.getArgString(MissingIndex) <<
": missing argument\n";
172 if (Args.hasArgNoClaim(OPT_INPUT) ||
173 (!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
174 Table.printHelp(
outs(),
"llvm-dlltool [options] file...",
"llvm-dlltool",
176 llvm::outs() <<
"\nTARGETS: i386, i386:x86-64, arm, arm64, arm64ec\n";
180 for (
auto *
Arg : Args.filtered(OPT_UNKNOWN))
184 if (!Args.hasArg(OPT_d)) {
185 llvm::errs() <<
"no definition file specified\n";
190 if (std::optional<std::string> Prefix = getPrefix(ArgsArr[0])) {
195 if (
auto *
Arg = Args.getLastArg(OPT_m))
203 bool AddUnderscores = !Args.hasArg(OPT_no_leading_underscore);
205 std::string OutputFile;
206 if (
auto *
Arg = Args.getLastArg(OPT_D))
209 std::vector<COFFShortExport> Exports, NativeExports;
211 if (Args.hasArg(OPT_N)) {
213 llvm::errs() <<
"native .def file is supported only on arm64ec target\n";
216 if (!parseModuleDefinition(Args.getLastArg(OPT_N)->getValue(),
218 NativeExports, OutputFile))
222 if (!parseModuleDefinition(Args.getLastArg(OPT_d)->getValue(),
Machine,
223 AddUnderscores, Exports, OutputFile))
226 if (OutputFile.empty()) {
248 std::string Path = std::string(Args.getLastArgValue(OPT_l));
251 true, NativeExports)) {
Defines the llvm::Arg class for parsed arguments.
COFF::MachineTypes Machine
std::unique_ptr< MemoryBuffer > openFile(const Twine &Path)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
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,...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
bool consume_back_insensitive(StringRef Suffix)
Returns true if this StringRef has the given suffix, ignoring case, and removes that suffix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A concrete instance of a particular driver option.
std::string getAsString(const ArgList &Args) const
Return a formatted version of the argument and its values, for diagnostics.
const char * getValue(unsigned N=0) const
Specialization of OptTable.
@ IMAGE_FILE_MACHINE_ARM64
@ IMAGE_FILE_MACHINE_UNKNOWN
@ IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_ARM64EC
@ IMAGE_FILE_MACHINE_I386
@ IMAGE_FILE_MACHINE_ARMNT
bool isArm64EC(T Machine)
Expected< COFFModuleDefinition > parseCOFFModuleDefinition(MemoryBufferRef MB, COFF::MachineTypes Machine, bool MingwDef=false, bool AddUnderscores=true)
Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef< COFFShortExport > Exports, COFF::MachineTypes Machine, bool MinGW, ArrayRef< COFFShortExport > NativeExports={})
Writes a COFF import library containing entries described by the Exports array.
NodeAddr< DefNode * > Def
StringRef stem(StringRef path, Style style=Style::native)
Get stem.
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
This is an optimization pass for GlobalISel generic memory operations.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
int dlltoolDriverMain(ArrayRef< const char * > ArgsArr)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
std::string Name
The name of the export as specified in the .def file or on the command line, i.e.
std::string SymbolName
The real, mangled symbol name from the object file.
std::string ImportName
Creates an import library entry that imports from a DLL export with a different name.
std::string ExtName
The external, exported name.
Entry for a single option instance in the option data table.