LLVM 20.0.0git
COFFDirectiveParser.cpp
Go to the documentation of this file.
1//===-- COFFDirectiveParser.cpp - JITLink coff directive parser --*- C++ -*===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// MSVC COFF directive parser
10//
11//===----------------------------------------------------------------------===//
12
13#include "COFFDirectiveParser.h"
14
15#include <array>
16
17using namespace llvm;
18using namespace jitlink;
19
20#define DEBUG_TYPE "jitlink"
21
22// Create prefix string literals used in Options.td
23#define PREFIX(NAME, VALUE) \
24 static constexpr StringLiteral NAME##_init[] = VALUE; \
25 static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \
26 std::size(NAME##_init) - 1);
27#include "COFFOptions.inc"
28#undef PREFIX
29
30static constexpr const StringLiteral PrefixTable_init[] =
31#define PREFIX_UNION(VALUES) VALUES
32#include "COFFOptions.inc"
33#undef PREFIX_UNION
34 ;
35static constexpr const ArrayRef<StringLiteral>
37
38// Create table mapping all options defined in COFFOptions.td
39using namespace llvm::opt;
40static constexpr opt::OptTable::Info infoTable[] = {
41#define OPTION(...) \
42 LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX(COFF_OPT_, __VA_ARGS__),
43#include "COFFOptions.inc"
44#undef OPTION
45};
46
48public:
50};
51
53
57 cl::TokenizeWindowsCommandLineNoCopy(Str, saver, Tokens);
58 for (StringRef Tok : Tokens) {
59 bool HasNul = Tok.end() != Str.end() && Tok.data()[Tok.size()] == '\0';
60 Buffer.push_back(HasNul ? Tok.data() : saver.save(Tok).data());
61 }
62
63 unsigned missingIndex;
64 unsigned missingCount;
65
66 auto Result = optTable.ParseArgs(Buffer, missingIndex, missingCount);
67
68 if (missingCount)
69 return make_error<JITLinkError>(Twine("COFF directive parsing failed: ") +
70 Result.getArgString(missingIndex) +
71 " missing argument");
73 for (auto *arg : Result.filtered(COFF_OPT_UNKNOWN))
74 dbgs() << "Unknown coff option argument: " << arg->getAsString(Result)
75 << "\n";
76 });
77 return std::move(Result);
78}
basic Basic Alias true
static constexpr const ArrayRef< StringLiteral > PrefixTable(PrefixTable_init, std::size(PrefixTable_init) - 1)
static COFFOptTable optTable
static constexpr const StringLiteral PrefixTable_init[]
static constexpr opt::OptTable::Info infoTable[]
#define LLVM_DEBUG(X)
Definition: Debug.h:101
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Tagged union holding either a T or a Error.
Definition: Error.h:481
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:838
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
StringRef save(const char *S)
Definition: StringSaver.h:30
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
InputArgList ParseArgs(ArrayRef< const char * > Args, unsigned &MissingArgIndex, unsigned &MissingArgCount, Visibility VisibilityMask=Visibility()) const
Parse an list of arguments into an InputArgList.
Definition: OptTable.cpp:490
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
Definition: Arg.h:26
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Entry for a single option instance in the option data table.
Definition: OptTable.h:55