31 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
34 this, HandleDirective<COFFAsmParser, HandlerMethod>);
51 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveText>(
".text");
52 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveData>(
".data");
53 addDirectiveHandler<&COFFAsmParser::parseSectionDirectiveBSS>(
".bss");
54 addDirectiveHandler<&COFFAsmParser::parseDirectiveSection>(
".section");
55 addDirectiveHandler<&COFFAsmParser::parseDirectivePushSection>(
57 addDirectiveHandler<&COFFAsmParser::parseDirectivePopSection>(
59 addDirectiveHandler<&COFFAsmParser::parseDirectiveDef>(
".def");
60 addDirectiveHandler<&COFFAsmParser::parseDirectiveScl>(
".scl");
61 addDirectiveHandler<&COFFAsmParser::parseDirectiveType>(
".type");
62 addDirectiveHandler<&COFFAsmParser::parseDirectiveEndef>(
".endef");
63 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecRel32>(
".secrel32");
64 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymIdx>(
".symidx");
65 addDirectiveHandler<&COFFAsmParser::parseDirectiveSafeSEH>(
".safeseh");
66 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecIdx>(
".secidx");
67 addDirectiveHandler<&COFFAsmParser::parseDirectiveLinkOnce>(
".linkonce");
68 addDirectiveHandler<&COFFAsmParser::parseDirectiveRVA>(
".rva");
69 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
".weak");
70 addDirectiveHandler<&COFFAsmParser::parseDirectiveSymbolAttribute>(
72 addDirectiveHandler<&COFFAsmParser::parseDirectiveCGProfile>(
".cg_profile");
73 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecNum>(
".secnum");
74 addDirectiveHandler<&COFFAsmParser::parseDirectiveSecOffset>(
".secoffset");
77 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartProc>(
79 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProc>(
81 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc>(
83 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveStartChained>(
85 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndChained>(
87 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandler>(
89 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveHandlerData>(
91 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveAllocStack>(
93 addDirectiveHandler<&COFFAsmParser::parseSEHDirectiveEndProlog>(
145 bool parseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
149 COFFAsmParser() =
default;
155 StringRef FlagsString,
unsigned *Flags) {
166 Discardable = 1 << 8,
170 bool ReadOnlyRemoved =
false;
171 unsigned SecFlags =
None;
173 for (
char FlagChar : FlagsString) {
181 if (SecFlags & InitData)
182 return TokError(
"conflicting section flags 'b' and 'd'.");
187 SecFlags |= InitData;
188 if (SecFlags & Alloc)
189 return TokError(
"conflicting section flags 'b' and 'd'.");
190 SecFlags &= ~NoWrite;
191 if ((SecFlags & NoLoad) == 0)
201 SecFlags |= Discardable;
205 ReadOnlyRemoved =
false;
207 if ((SecFlags & Code) == 0)
208 SecFlags |= InitData;
209 if ((SecFlags & NoLoad) == 0)
214 SecFlags |= Shared | InitData;
215 SecFlags &= ~NoWrite;
216 if ((SecFlags & NoLoad) == 0)
221 SecFlags &= ~NoWrite;
222 ReadOnlyRemoved =
true;
227 if ((SecFlags & NoLoad) == 0)
229 if (!ReadOnlyRemoved)
234 SecFlags |= NoRead | NoWrite;
242 return TokError(
"unknown flag");
248 if (SecFlags ==
None)
253 if (SecFlags & InitData)
255 if ((SecFlags & Alloc) && (SecFlags & Load) == 0)
257 if (SecFlags & NoLoad)
259 if ((SecFlags & Discardable) ||
262 if ((SecFlags & NoRead) == 0)
264 if ((SecFlags & NoWrite) == 0)
266 if (SecFlags & Shared)
286 if (getParser().parseIdentifier(
Name))
287 return TokError(
"expected identifier in directive");
291 getStreamer().emitSymbolAttribute(
Sym, Attr);
297 return TokError(
"unexpected token in directive");
306bool COFFAsmParser::parseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
310bool COFFAsmParser::parseSectionSwitch(
StringRef Section,
315bool COFFAsmParser::parseSectionSwitch(
StringRef Section,
320 return TokError(
"unexpected token in section switching directive");
323 getStreamer().switchSection(getContext().getCOFFSection(
338bool COFFAsmParser::parseDirectiveSection(
StringRef directive,
SMLoc loc) {
339 return parseSectionArguments(directive, loc);
362 return TokError(
"expected identifier in directive");
372 return TokError(
"expected string in directive");
374 StringRef FlagsStr = getTok().getStringContents();
390 return TokError(
"expected comdat type such as 'discard' or 'largest' "
391 "after protection bits");
393 if (parseCOMDATType(
Type))
397 return TokError(
"expected comma in directive");
400 if (getParser().parseIdentifier(COMDATSymName))
401 return TokError(
"expected identifier in directive");
405 return TokError(
"unexpected token in directive");
408 const Triple &
T = getContext().getTargetTriple();
416bool COFFAsmParser::parseDirectivePushSection(
StringRef directive,
SMLoc loc) {
417 getStreamer().pushSection();
419 if (parseSectionArguments(directive, loc)) {
420 getStreamer().popSection();
428 if (!getStreamer().popSection())
429 return TokError(
".popsection without corresponding .pushsection");
436 if (getParser().parseIdentifier(SymbolName))
437 return TokError(
"expected identifier in directive");
439 MCSymbol *
Sym = getContext().getOrCreateSymbol(SymbolName);
441 getStreamer().beginCOFFSymbolDef(
Sym);
449 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
453 return TokError(
"unexpected token in directive");
456 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
462 if (getParser().parseAbsoluteExpression(
Type))
466 return TokError(
"unexpected token in directive");
469 getStreamer().emitCOFFSymbolType(
Type);
475 getStreamer().endCOFFSymbolDef();
481 if (getParser().parseIdentifier(SymbolID))
482 return TokError(
"expected identifier in directive");
487 OffsetLoc = getLexer().getLoc();
488 if (getParser().parseAbsoluteExpression(
Offset))
493 return TokError(
"unexpected token in directive");
495 if (Offset < 0 || Offset > std::numeric_limits<uint32_t>::max())
498 "invalid '.secrel32' directive offset, can't be less "
499 "than zero or greater than std::numeric_limits<uint32_t>::max()");
504 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
509 auto parseOp = [&]() ->
bool {
511 if (getParser().parseIdentifier(SymbolID))
512 return TokError(
"expected identifier in directive");
517 OffsetLoc = getLexer().getLoc();
518 if (getParser().parseAbsoluteExpression(
Offset))
522 if (
Offset < std::numeric_limits<int32_t>::min() ||
523 Offset > std::numeric_limits<int32_t>::max())
524 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
525 "than -2147483648 or greater than "
530 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
534 if (getParser().parseMany(parseOp))
535 return addErrorSuffix(
" in directive");
541 if (getParser().parseIdentifier(SymbolID))
542 return TokError(
"expected identifier in directive");
545 return TokError(
"unexpected token in directive");
550 getStreamer().emitCOFFSafeSEH(Symbol);
556 if (getParser().parseIdentifier(SymbolID))
557 return TokError(
"expected identifier in directive");
560 return TokError(
"unexpected token in directive");
565 getStreamer().emitCOFFSectionIndex(Symbol);
571 if (getParser().parseIdentifier(SymbolID))
572 return TokError(
"expected identifier in directive");
575 return TokError(
"unexpected token in directive");
580 getStreamer().emitCOFFSymbolIndex(Symbol);
586 if (getParser().parseIdentifier(SymbolID))
587 return TokError(
"expected identifier in directive");
590 return TokError(
"unexpected token in directive");
595 getStreamer().emitCOFFSecNumber(Symbol);
601 if (getParser().parseIdentifier(SymbolID))
602 return TokError(
"expected identifier in directive");
605 return TokError(
"unexpected token in directive");
610 getStreamer().emitCOFFSecOffset(Symbol);
616 StringRef TypeId = getTok().getIdentifier();
629 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
641 if (parseCOMDATType(
Type))
645 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
648 return Error(Loc,
"cannot make section associative with .linkonce");
652 "' is already linkonce");
657 return TokError(
"unexpected token in directive");
662bool COFFAsmParser::parseSEHDirectiveStartProc(
StringRef,
SMLoc Loc) {
664 if (getParser().parseIdentifier(SymbolID))
668 return TokError(
"unexpected token in directive");
673 getStreamer().emitWinCFIStartProc(Symbol, Loc);
677bool COFFAsmParser::parseSEHDirectiveEndProc(
StringRef,
SMLoc Loc) {
679 getStreamer().emitWinCFIEndProc(Loc);
683bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(
StringRef,
SMLoc Loc) {
685 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
689bool COFFAsmParser::parseSEHDirectiveStartChained(
StringRef,
SMLoc Loc) {
691 getStreamer().emitWinCFIStartChained(Loc);
695bool COFFAsmParser::parseSEHDirectiveEndChained(
StringRef,
SMLoc Loc) {
697 getStreamer().emitWinCFIEndChained(Loc);
701bool COFFAsmParser::parseSEHDirectiveHandler(
StringRef,
SMLoc Loc) {
703 if (getParser().parseIdentifier(SymbolID))
707 return TokError(
"you must specify one or both of @unwind or @except");
709 bool unwind =
false, except =
false;
710 if (parseAtUnwindOrAtExcept(unwind, except))
714 if (parseAtUnwindOrAtExcept(unwind, except))
718 return TokError(
"unexpected token in directive");
720 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
723 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
727bool COFFAsmParser::parseSEHDirectiveHandlerData(
StringRef,
SMLoc Loc) {
729 getStreamer().emitWinEHHandlerData();
733bool COFFAsmParser::parseSEHDirectiveAllocStack(
StringRef,
SMLoc Loc) {
735 if (getParser().parseAbsoluteExpression(
Size))
739 return TokError(
"unexpected token in directive");
742 getStreamer().emitWinCFIAllocStack(
Size, Loc);
746bool COFFAsmParser::parseSEHDirectiveEndProlog(
StringRef,
SMLoc Loc) {
748 getStreamer().emitWinCFIEndProlog(Loc);
752bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
755 return TokError(
"a handler attribute must begin with '@' or '%'");
756 SMLoc startLoc = getLexer().getLoc();
758 if (getParser().parseIdentifier(identifier))
759 return Error(startLoc,
"expected @unwind or @except");
760 if (identifier ==
"unwind")
762 else if (identifier ==
"except")
765 return Error(startLoc,
"expected @unwind or @except");
772 return new COFFAsmParser;
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
COFFYAML::WeakExternalCharacteristics Characteristics
Analysis containing CSE Info
static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr, bool *UseLastGroup)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Lightweight error class with error context and mandatory checking.
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>
MCAsmParser & getParser()
Generic assembler parser interface, for use by target specific assembly parsers.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
This represents a section on Windows.
static bool isImplicitlyDiscardable(StringRef Name)
unsigned getCharacteristics() const
void setSelection(int Selection) const
StringRef getName() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Represents a location in source code.
StringRef - Represent a constant reference to a string, i.e.
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...
The instances of the Type class are immutable: once they are created, they are never changed.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ 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
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
MCAsmParserExtension * createCOFFAsmParser()
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_Invalid
Not a valid directive.