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>(
95 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveBeginEpilog>(
96 ".seh_startepilogue");
97 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndEpilog>(
99 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindV2Start>(
100 ".seh_unwindv2start");
101 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveUnwindVersion>(
102 ".seh_unwindversion");
157 bool parseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
161 COFFAsmParser() =
default;
167 StringRef FlagsString,
unsigned *Flags) {
178 Discardable = 1 << 8,
182 bool ReadOnlyRemoved =
false;
183 unsigned SecFlags =
None;
185 for (
char FlagChar : FlagsString) {
193 if (SecFlags & InitData)
194 return TokError(
"conflicting section flags 'b' and 'd'.");
199 SecFlags |= InitData;
200 if (SecFlags & Alloc)
201 return TokError(
"conflicting section flags 'b' and 'd'.");
202 SecFlags &= ~NoWrite;
203 if ((SecFlags & NoLoad) == 0)
213 SecFlags |= Discardable;
217 ReadOnlyRemoved =
false;
219 if ((SecFlags & Code) == 0)
220 SecFlags |= InitData;
221 if ((SecFlags & NoLoad) == 0)
226 SecFlags |= Shared | InitData;
227 SecFlags &= ~NoWrite;
228 if ((SecFlags & NoLoad) == 0)
233 SecFlags &= ~NoWrite;
234 ReadOnlyRemoved =
true;
239 if ((SecFlags & NoLoad) == 0)
241 if (!ReadOnlyRemoved)
246 SecFlags |= NoRead | NoWrite;
254 return TokError(
"unknown flag");
260 if (SecFlags ==
None)
265 if (SecFlags & InitData)
267 if ((SecFlags & Alloc) && (SecFlags & Load) == 0)
269 if (SecFlags & NoLoad)
271 if ((SecFlags & Discardable) ||
274 if ((SecFlags & NoRead) == 0)
276 if ((SecFlags & NoWrite) == 0)
278 if (SecFlags & Shared)
298 if (getParser().parseIdentifier(
Name))
299 return TokError(
"expected identifier in directive");
303 getStreamer().emitSymbolAttribute(
Sym, Attr);
309 return TokError(
"unexpected token in directive");
318bool COFFAsmParser::parseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
322bool COFFAsmParser::parseSectionSwitch(
StringRef Section,
328bool COFFAsmParser::parseSectionSwitch(
StringRef Section,
334 return TokError(
"unexpected token in section switching directive");
337 getStreamer().switchSection(getContext().getCOFFSection(
352bool COFFAsmParser::parseDirectiveSection(
StringRef directive,
SMLoc loc) {
353 return parseSectionArguments(directive, loc);
376 return TokError(
"expected identifier in directive");
386 return TokError(
"expected string in directive");
388 StringRef FlagsStr = getTok().getStringContents();
398 getLexer().peekTok().getString() !=
"unique") {
405 return TokError(
"expected comdat type such as 'discard' or 'largest' "
406 "after protection bits");
408 if (parseCOMDATType(
Type))
412 return TokError(
"expected comma in directive");
415 if (getParser().parseIdentifier(COMDATSymName))
416 return TokError(
"expected identifier in directive");
420 if (maybeParseUniqueID(UniqueID))
424 return TokError(
"unexpected token in directive");
427 const Triple &
T = getContext().getTargetTriple();
435bool COFFAsmParser::parseDirectivePushSection(
StringRef directive,
SMLoc loc) {
436 getStreamer().pushSection();
438 if (parseSectionArguments(directive, loc)) {
439 getStreamer().popSection();
447 if (!getStreamer().popSection())
448 return TokError(
".popsection without corresponding .pushsection");
455 if (getParser().parseIdentifier(SymbolName))
456 return TokError(
"expected identifier in directive");
458 MCSymbol *
Sym = getContext().getOrCreateSymbol(SymbolName);
460 getStreamer().beginCOFFSymbolDef(
Sym);
468 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
472 return TokError(
"unexpected token in directive");
475 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
481 if (getParser().parseAbsoluteExpression(
Type))
485 return TokError(
"unexpected token in directive");
488 getStreamer().emitCOFFSymbolType(
Type);
494 getStreamer().endCOFFSymbolDef();
500 if (getParser().parseIdentifier(SymbolID))
501 return TokError(
"expected identifier in directive");
506 OffsetLoc = getLexer().getLoc();
507 if (getParser().parseAbsoluteExpression(
Offset))
512 return TokError(
"unexpected token in directive");
514 if (Offset < 0 || Offset > std::numeric_limits<uint32_t>::max())
517 "invalid '.secrel32' directive offset, can't be less "
518 "than zero or greater than std::numeric_limits<uint32_t>::max()");
523 getStreamer().emitCOFFSecRel32(Symbol,
Offset);
528 auto parseOp = [&]() ->
bool {
530 if (getParser().parseIdentifier(SymbolID))
531 return TokError(
"expected identifier in directive");
536 OffsetLoc = getLexer().getLoc();
537 if (getParser().parseAbsoluteExpression(
Offset))
541 if (
Offset < std::numeric_limits<int32_t>::min() ||
542 Offset > std::numeric_limits<int32_t>::max())
543 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less "
544 "than -2147483648 or greater than "
549 getStreamer().emitCOFFImgRel32(Symbol,
Offset);
553 if (getParser().parseMany(parseOp))
554 return addErrorSuffix(
" in directive");
560 if (getParser().parseIdentifier(SymbolID))
561 return TokError(
"expected identifier in directive");
564 return TokError(
"unexpected token in directive");
569 getStreamer().emitCOFFSafeSEH(Symbol);
575 if (getParser().parseIdentifier(SymbolID))
576 return TokError(
"expected identifier in directive");
579 return TokError(
"unexpected token in directive");
584 getStreamer().emitCOFFSectionIndex(Symbol);
590 if (getParser().parseIdentifier(SymbolID))
591 return TokError(
"expected identifier in directive");
594 return TokError(
"unexpected token in directive");
599 getStreamer().emitCOFFSymbolIndex(Symbol);
605 if (getParser().parseIdentifier(SymbolID))
606 return TokError(
"expected identifier in directive");
609 return TokError(
"unexpected token in directive");
614 getStreamer().emitCOFFSecNumber(Symbol);
620 if (getParser().parseIdentifier(SymbolID))
621 return TokError(
"expected identifier in directive");
624 return TokError(
"unexpected token in directive");
629 getStreamer().emitCOFFSecOffset(Symbol);
635 StringRef TypeId = getTok().getIdentifier();
648 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
660 if (parseCOMDATType(
Type))
664 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
667 return Error(Loc,
"cannot make section associative with .linkonce");
671 "' is already linkonce");
676 return TokError(
"unexpected token in directive");
681bool COFFAsmParser::parseSEHDirectiveStartProc(
StringRef,
SMLoc Loc) {
683 if (getParser().parseIdentifier(SymbolID))
687 return TokError(
"unexpected token in directive");
692 getStreamer().emitWinCFIStartProc(Symbol, Loc);
696bool COFFAsmParser::parseSEHDirectiveEndProc(
StringRef,
SMLoc Loc) {
698 getStreamer().emitWinCFIEndProc(Loc);
702bool COFFAsmParser::parseSEHDirectiveEndFuncletOrFunc(
StringRef,
SMLoc Loc) {
704 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
708bool COFFAsmParser::parseSEHDirectiveStartChained(
StringRef,
SMLoc Loc) {
710 getStreamer().emitWinCFIStartChained(Loc);
714bool COFFAsmParser::parseSEHDirectiveEndChained(
StringRef,
SMLoc Loc) {
716 getStreamer().emitWinCFIEndChained(Loc);
720bool COFFAsmParser::parseSEHDirectiveHandler(
StringRef,
SMLoc Loc) {
722 if (getParser().parseIdentifier(SymbolID))
726 return TokError(
"you must specify one or both of @unwind or @except");
728 bool unwind =
false, except =
false;
729 if (parseAtUnwindOrAtExcept(unwind, except))
733 if (parseAtUnwindOrAtExcept(unwind, except))
737 return TokError(
"unexpected token in directive");
739 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
742 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
746bool COFFAsmParser::parseSEHDirectiveHandlerData(
StringRef,
SMLoc Loc) {
748 getStreamer().emitWinEHHandlerData();
752bool COFFAsmParser::parseSEHDirectiveAllocStack(
StringRef,
SMLoc Loc) {
754 if (getParser().parseAbsoluteExpression(
Size))
758 return TokError(
"unexpected token in directive");
761 getStreamer().emitWinCFIAllocStack(
Size, Loc);
765bool COFFAsmParser::parseSEHDirectiveEndProlog(
StringRef,
SMLoc Loc) {
767 getStreamer().emitWinCFIEndProlog(Loc);
771bool COFFAsmParser::ParseSEHDirectiveBeginEpilog(
StringRef,
SMLoc Loc) {
773 getStreamer().emitWinCFIBeginEpilogue(Loc);
777bool COFFAsmParser::ParseSEHDirectiveEndEpilog(
StringRef,
SMLoc Loc) {
779 getStreamer().emitWinCFIEndEpilogue(Loc);
783bool COFFAsmParser::ParseSEHDirectiveUnwindV2Start(
StringRef,
SMLoc Loc) {
785 getStreamer().emitWinCFIUnwindV2Start(Loc);
789bool COFFAsmParser::ParseSEHDirectiveUnwindVersion(
StringRef,
SMLoc Loc) {
791 if (getParser().parseIntToken(Version,
"expected unwind version number"))
794 if ((Version < 1) || (Version > UINT8_MAX))
795 return Error(Loc,
"invalid unwind version");
798 return TokError(
"unexpected token in directive");
801 getStreamer().emitWinCFIUnwindVersion(Version, Loc);
805bool COFFAsmParser::parseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
808 return TokError(
"a handler attribute must begin with '@' or '%'");
809 SMLoc startLoc = getLexer().getLoc();
811 if (getParser().parseIdentifier(identifier))
812 return Error(startLoc,
"expected @unwind or @except");
813 if (identifier ==
"unwind")
815 else if (identifier ==
"except")
818 return Error(startLoc,
"expected @unwind or @except");
825 return new COFFAsmParser;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
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
static constexpr unsigned NonUniqueID
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.