30 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
31 void addDirectiveHandler(StringRef Directive) {
33 this, HandleDirective<COFFAsmParser, HandlerMethod>);
34 getParser().addDirectiveHandler(Directive, Handler);
37 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics);
39 bool parseSectionSwitch(StringRef Section,
unsigned Characteristics,
43 bool parseSectionName(StringRef &SectionName);
46 void Initialize(MCAsmParser &Parser)
override {
50 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveText>(
".text");
51 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveData>(
".data");
52 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveBSS>(
".bss");
53 addDirectiveHandler<&COFFAsmParser::parseDirectiveSection>(
".section");
54 addDirectiveHandler<&COFFAsmParser::parseDirectivePushSection>(
56 addDirectiveHandler<&COFFAsmParser::parseDirectivePopSection>(
58 addDirectiveHandler<&COFFAsmParser::parseDirectiveDef>(
".def");
59 addDirectiveHandler<&COFFAsmParser::parseDirectiveScl>(
".scl");
60 addDirectiveHandler<&COFFAsmParser::parseDirectiveType>(
".type");
61 addDirectiveHandler<&COFFAsmParser::parseDirectiveEndef>(
".endef");
62 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecRel32>(
".secrel32");
63 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymIdx>(
".symidx");
64 addDirectiveHandler<&COFFAsmParser::parseDirectiveSafeSEH>(
".safeseh");
65 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecIdx>(
".secidx");
66 addDirectiveHandler<&COFFAsmParser::parseDirectiveLinkOnce>(
".linkonce");
67 addDirectiveHandler<&COFFAsmParser::parseDirectiveRVA>(
".rva");
68 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
".weak");
69 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
71 addDirectiveHandler<&COFFAsmParser::parseDirectiveCGProfile>(
".cg_profile");
72 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecNum>(
".secnum");
73 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecOffset>(
".secoffset");
76 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartProc>(
78 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProc>(
80 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc>(
82 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartChained>(
84 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndChained>(
86 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandler>(
88 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandlerData>(
90 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveAllocStack>(
92 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProlog>(
94 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveBeginEpilog>(
95 ".seh_startepilogue");
96 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndEpilog>(
98 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindV2Start>(
99 ".seh_unwindv2start");
100 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindVersion>(
101 ".seh_unwindversion");
104 bool parseSectionDirectiveText(StringRef, SMLoc) {
110 bool parseSectionDirectiveData(StringRef, SMLoc) {
116 bool parseSectionDirectiveBSS(StringRef, SMLoc) {
122 bool parseDirectiveSection(StringRef, SMLoc);
123 bool parseSectionArguments(StringRef, SMLoc);
124 bool parseDirectivePushSection(StringRef, SMLoc);
125 bool parseDirectivePopSection(StringRef, SMLoc);
126 bool parseDirectiveDef(StringRef, SMLoc);
127 bool parseDirectiveScl(StringRef, SMLoc);
128 bool parseDirectiveType(StringRef, SMLoc);
129 bool parseDirectiveEndef(StringRef, SMLoc);
130 bool parseDirectiveSecRel32(StringRef, SMLoc);
131 bool parseDirectiveSecIdx(StringRef, SMLoc);
132 bool parseDirectiveSafeSEH(StringRef, SMLoc);
133 bool parseDirectiveSymIdx(StringRef, SMLoc);
135 bool parseDirectiveLinkOnce(StringRef, SMLoc);
136 bool parseDirectiveRVA(StringRef, SMLoc);
137 bool parseDirectiveCGProfile(StringRef, SMLoc);
138 bool parseDirectiveSecNum(StringRef, SMLoc);
139 bool parseDirectiveSecOffset(StringRef, SMLoc);
142 bool parseSEHDirectiveStartProc(StringRef, SMLoc);
143 bool parseSEHDirectiveEndProc(StringRef, SMLoc);
144 bool parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc);
145 bool parseSEHDirectiveStartChained(StringRef, SMLoc);
146 bool parseSEHDirectiveEndChained(StringRef, SMLoc);
147 bool parseSEHDirectiveHandler(StringRef, SMLoc);
148 bool parseSEHDirectiveHandlerData(StringRef, SMLoc);
149 bool parseSEHDirectiveAllocStack(StringRef, SMLoc);
150 bool parseSEHDirectiveEndProlog(StringRef, SMLoc);
151 bool ParseSEHDirectiveBeginEpilog(StringRef, SMLoc);
152 bool ParseSEHDirectiveEndEpilog(StringRef, SMLoc);
153 bool ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc);
154 bool ParseSEHDirectiveUnwindVersion(StringRef, SMLoc);
156 bool parseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
157 bool parseDirectiveSymbolAttribute(StringRef Directive, SMLoc);
160 COFFAsmParser() =
default;
166 StringRef FlagsString,
unsigned *Flags) {
177 Discardable = 1 << 8,
181 bool ReadOnlyRemoved =
false;
182 unsigned SecFlags =
None;
184 for (
char FlagChar : FlagsString) {
192 if (SecFlags & InitData)
193 return TokError(
"conflicting section flags 'b' and 'd'.");
198 SecFlags |= InitData;
199 if (SecFlags &
Alloc)
200 return TokError(
"conflicting section flags 'b' and 'd'.");
201 SecFlags &= ~NoWrite;
202 if ((SecFlags & NoLoad) == 0)
212 SecFlags |= Discardable;
216 ReadOnlyRemoved =
false;
218 if ((SecFlags & Code) == 0)
219 SecFlags |= InitData;
220 if ((SecFlags & NoLoad) == 0)
225 SecFlags |=
Shared | InitData;
226 SecFlags &= ~NoWrite;
227 if ((SecFlags & NoLoad) == 0)
232 SecFlags &= ~NoWrite;
233 ReadOnlyRemoved =
true;
238 if ((SecFlags & NoLoad) == 0)
240 if (!ReadOnlyRemoved)
245 SecFlags |= NoRead | NoWrite;
253 return TokError(
"unknown flag");
259 if (SecFlags ==
None)
264 if (SecFlags & InitData)
266 if ((SecFlags &
Alloc) && (SecFlags & Load) == 0)
268 if (SecFlags & NoLoad)
270 if ((SecFlags & Discardable) ||
273 if ((SecFlags & NoRead) == 0)
275 if ((SecFlags & NoWrite) == 0)
277 if (SecFlags & Shared)
287bool COFFAsmParser::parseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
288 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
298 return TokError(
"expected identifier in directive");
300 getStreamer().emitSymbolAttribute(Sym, Attr);
306 return TokError(
"unexpected token in directive");
315bool COFFAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
319bool COFFAsmParser::parseSectionSwitch(StringRef Section,
320 unsigned Characteristics) {
321 return parseSectionSwitch(Section, Characteristics,
"", (
COFF::COMDATType)0,
325bool COFFAsmParser::parseSectionSwitch(StringRef Section,
326 unsigned Characteristics,
327 StringRef COMDATSymName,
331 return TokError(
"unexpected token in section switching directive");
334 getStreamer().switchSection(
getContext().getCOFFSection(
335 Section, Characteristics, COMDATSymName,
Type, UniqueID));
340bool COFFAsmParser::parseSectionName(StringRef &SectionName) {
349bool COFFAsmParser::parseDirectiveSection(StringRef directive, SMLoc loc) {
350 return parseSectionArguments(directive, loc);
369bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
372 if (parseSectionName(SectionName))
373 return TokError(
"expected identifier in directive");
383 return TokError(
"expected string in directive");
385 StringRef FlagsStr = getTok().getStringContents();
393 StringRef COMDATSymName;
395 getLexer().peekTok().getString() !=
"unique") {
402 return TokError(
"expected comdat type such as 'discard' or 'largest' "
403 "after protection bits");
405 if (parseCOMDATType(
Type))
409 return TokError(
"expected comma in directive");
412 if (getParser().parseIdentifier(COMDATSymName))
413 return TokError(
"expected identifier in directive");
417 if (maybeParseUniqueID(UniqueID))
421 return TokError(
"unexpected token in directive");
428 parseSectionSwitch(SectionName, Flags, COMDATSymName,
Type, UniqueID);
432bool COFFAsmParser::parseDirectivePushSection(StringRef directive, SMLoc loc) {
433 getStreamer().pushSection();
435 if (parseSectionArguments(directive, loc)) {
436 getStreamer().popSection();
443bool COFFAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
444 if (!getStreamer().popSection())
445 return TokError(
".popsection without corresponding .pushsection");
449bool COFFAsmParser::parseDirectiveDef(StringRef, SMLoc) {
453 return TokError(
"expected identifier in directive");
455 getStreamer().beginCOFFSymbolDef(Sym);
461bool COFFAsmParser::parseDirectiveScl(StringRef, SMLoc) {
463 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
467 return TokError(
"unexpected token in directive");
470 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
474bool COFFAsmParser::parseDirectiveType(StringRef, SMLoc) {
476 if (getParser().parseAbsoluteExpression(
Type))
480 return TokError(
"unexpected token in directive");
483 getStreamer().emitCOFFSymbolType(
Type);
487bool COFFAsmParser::parseDirectiveEndef(StringRef, SMLoc) {
489 getStreamer().endCOFFSymbolDef();
493bool COFFAsmParser::parseDirectiveSecRel32(StringRef, SMLoc) {
496 return TokError(
"expected identifier in directive");
501 OffsetLoc = getLexer().getLoc();
502 if (getParser().parseAbsoluteExpression(
Offset))
507 return TokError(
"unexpected token in directive");
512 "invalid '.secrel32' directive offset, can't be less "
513 "than zero or greater than std::numeric_limits<uint32_t>::max()");
516 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
520bool COFFAsmParser::parseDirectiveRVA(StringRef, SMLoc) {
521 auto parseOp = [&]() ->
bool {
524 return TokError(
"expected identifier in directive");
529 OffsetLoc = getLexer().getLoc();
530 if (getParser().parseAbsoluteExpression(
Offset))
534 if (
Offset < std::numeric_limits<int32_t>::min() ||
535 Offset > std::numeric_limits<int32_t>::max())
536 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
537 "than -2147483648 or greater than "
540 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
544 if (getParser().parseMany(parseOp))
545 return addErrorSuffix(
" in directive");
549bool COFFAsmParser::parseDirectiveSafeSEH(StringRef, SMLoc) {
552 return TokError(
"expected identifier in directive");
555 return TokError(
"unexpected token in directive");
558 getStreamer().emitCOFFSafeSEH(Symbol);
562bool COFFAsmParser::parseDirectiveSecIdx(StringRef, SMLoc) {
565 return TokError(
"expected identifier in directive");
568 return TokError(
"unexpected token in directive");
571 getStreamer().emitCOFFSectionIndex(Symbol);
575bool COFFAsmParser::parseDirectiveSymIdx(StringRef, SMLoc) {
578 return TokError(
"expected identifier in directive");
581 return TokError(
"unexpected token in directive");
584 getStreamer().emitCOFFSymbolIndex(Symbol);
588bool COFFAsmParser::parseDirectiveSecNum(StringRef, SMLoc) {
591 return TokError(
"expected identifier in directive");
594 return TokError(
"unexpected token in directive");
597 getStreamer().emitCOFFSecNumber(Symbol);
601bool COFFAsmParser::parseDirectiveSecOffset(StringRef, SMLoc) {
604 return TokError(
"expected identifier in directive");
607 return TokError(
"unexpected token in directive");
610 getStreamer().emitCOFFSecOffset(Symbol);
616 StringRef TypeId = getTok().getIdentifier();
618 Type = StringSwitch<COFF::COMDATType>(TypeId)
629 return TokError(Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
638bool COFFAsmParser::parseDirectiveLinkOnce(StringRef, SMLoc Loc) {
641 if (parseCOMDATType(
Type))
644 const MCSectionCOFF *Current =
645 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
648 return Error(Loc,
"cannot make section associative with .linkonce");
651 return Error(Loc, Twine(
"section '") + Current->
getName() +
652 "' is already linkonce");
657 return TokError(
"unexpected token in directive");
662bool COFFAsmParser::parseSEHDirectiveStartProc(StringRef, SMLoc Loc) {
668 return TokError(
"unexpected token in directive");
671 getStreamer().emitWinCFIStartProc(Symbol, Loc);
675bool COFFAsmParser::parseSEHDirectiveEndProc(StringRef, SMLoc Loc) {
677 getStreamer().emitWinCFIEndProc(Loc);
681bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc Loc) {
683 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
687bool COFFAsmParser::parseSEHDirectiveStartChained(StringRef, SMLoc Loc) {
689 getStreamer().emitWinCFIStartChained(Loc);
693bool COFFAsmParser::parseSEHDirectiveEndChained(StringRef, SMLoc Loc) {
695 getStreamer().emitWinCFIEndChained(Loc);
699bool COFFAsmParser::parseSEHDirectiveHandler(StringRef, SMLoc Loc) {
705 return TokError(
"you must specify one or both of @unwind or @except");
707 bool unwind =
false, except =
false;
708 if (parseAtUnwindOrAtExcept(unwind, except))
712 if (parseAtUnwindOrAtExcept(unwind, except))
716 return TokError(
"unexpected token in directive");
719 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
723bool COFFAsmParser::parseSEHDirectiveHandlerData(StringRef, SMLoc Loc) {
725 getStreamer().emitWinEHHandlerData();
729bool COFFAsmParser::parseSEHDirectiveAllocStack(StringRef, SMLoc Loc) {
731 if (getParser().parseAbsoluteExpression(
Size))
735 return TokError(
"unexpected token in directive");
738 getStreamer().emitWinCFIAllocStack(
Size, Loc);
742bool COFFAsmParser::parseSEHDirectiveEndProlog(StringRef, SMLoc Loc) {
744 getStreamer().emitWinCFIEndProlog(Loc);
748bool COFFAsmParser::ParseSEHDirectiveBeginEpilog(StringRef, SMLoc Loc) {
750 getStreamer().emitWinCFIBeginEpilogue(Loc);
754bool COFFAsmParser::ParseSEHDirectiveEndEpilog(StringRef, SMLoc Loc) {
756 getStreamer().emitWinCFIEndEpilogue(Loc);
760bool COFFAsmParser::ParseSEHDirectiveUnwindV2Start(StringRef, SMLoc Loc) {
762 getStreamer().emitWinCFIUnwindV2Start(Loc);
766bool COFFAsmParser::ParseSEHDirectiveUnwindVersion(StringRef, SMLoc Loc) {
768 if (getParser().parseIntToken(
Version,
"expected unwind version number"))
772 return Error(Loc,
"invalid unwind version");
775 return TokError(
"unexpected token in directive");
778 getStreamer().emitWinCFIUnwindVersion(
Version, Loc);
782bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
783 StringRef identifier;
785 return TokError(
"a handler attribute must begin with '@' or '%'");
786 SMLoc startLoc = getLexer().getLoc();
788 if (getParser().parseIdentifier(identifier))
789 return Error(startLoc,
"expected @unwind or @except");
790 if (identifier ==
"unwind")
792 else if (identifier ==
"except")
795 return Error(startLoc,
"expected @unwind or @except");
802 return new COFFAsmParser;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
AMDGPU Prepare AGPR Alloc
Analysis containing CSE Info
static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr, bool *UseLastGroup)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool parseDirectiveCGProfile(StringRef, SMLoc)
parseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
static bool isImplicitlyDiscardable(StringRef Name)
unsigned getCharacteristics() const
void setSelection(int Selection) const
static constexpr unsigned NonUniqueID
StringRef getName() const
StringRef - Represent a constant reference to a string, i.e.
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_CNT_INITIALIZED_DATA
SymbolStorageClass
Storage class tells where and what the symbol represents.
@ IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_NEWEST
@ IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_ANY
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
NodeAddr< CodeNode * > Code
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
MCAsmParserExtension * createCOFFAsmParser()
FunctionAddr VTableAddr uintptr_t uintptr_t Version
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_Invalid
Not a valid directive.