35 template<
bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
38 this, HandleDirective<COFFAsmParser, HandlerMethod>);
39 getParser().addDirectiveHandler(Directive, Handler);
58 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(
".text");
59 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(
".data");
60 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(
".bss");
61 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(
".section");
62 addDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(
".def");
63 addDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(
".scl");
64 addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(
".type");
65 addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(
".endef");
66 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(
".secrel32");
67 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymIdx>(
".symidx");
68 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSafeSEH>(
".safeseh");
69 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(
".secidx");
70 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(
".linkonce");
71 addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(
".rva");
72 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
75 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
77 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
79 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
81 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
83 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
85 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
87 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
89 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
94 return ParseSectionSwitch(
".text",
109 return ParseSectionSwitch(
".bss",
139 bool ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except);
140 bool ParseSEHRegisterNumber(
unsigned &RegNo);
144 COFFAsmParser() =
default;
159 StringRef FlagsString,
unsigned *Flags) {
170 Discardable = 1 << 8,
173 bool ReadOnlyRemoved =
false;
176 for (
char FlagChar : FlagsString) {
184 if (SecFlags & InitData)
185 return TokError(
"conflicting section flags 'b' and 'd'.");
190 SecFlags |= InitData;
191 if (SecFlags & Alloc)
192 return TokError(
"conflicting section flags 'b' and 'd'.");
193 SecFlags &= ~NoWrite;
194 if ((SecFlags & NoLoad) == 0)
204 SecFlags |= Discardable;
208 ReadOnlyRemoved =
false;
210 if ((SecFlags & Code) == 0)
211 SecFlags |= InitData;
212 if ((SecFlags & NoLoad) == 0)
217 SecFlags |= Shared | InitData;
218 SecFlags &= ~NoWrite;
219 if ((SecFlags & NoLoad) == 0)
224 SecFlags &= ~NoWrite;
225 ReadOnlyRemoved =
true;
230 if ((SecFlags & NoLoad) == 0)
232 if (!ReadOnlyRemoved)
237 SecFlags |= NoRead | NoWrite;
241 return TokError(
"unknown flag");
247 if (SecFlags ==
None)
252 if (SecFlags & InitData)
254 if ((SecFlags & Alloc) && (SecFlags &
Load) == 0)
256 if (SecFlags & NoLoad)
258 if ((SecFlags & Discardable) ||
261 if ((SecFlags & NoRead) == 0)
263 if ((SecFlags & NoWrite) == 0)
265 if (SecFlags & Shared)
273 bool COFFAsmParser::ParseDirectiveSymbolAttribute(
StringRef Directive,
SMLoc) {
282 if (getParser().parseIdentifier(Name))
283 return TokError(
"expected identifier in directive");
285 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
287 getStreamer().EmitSymbolAttribute(Sym, Attr);
293 return TokError(
"unexpected token in directive");
305 return ParseSectionSwitch(Section, Characteristics, Kind,
"", (
COFF::COMDATType)0);
308 bool COFFAsmParser::ParseSectionSwitch(
StringRef Section,
309 unsigned Characteristics,
314 return TokError(
"unexpected token in section switching directive");
317 getStreamer().SwitchSection(getContext().getCOFFSection(
318 Section, Characteristics, Kind, COMDATSymName, Type));
323 bool COFFAsmParser::ParseSectionName(
StringRef &SectionName) {
327 SectionName = getTok().getIdentifier();
350 if (ParseSectionName(SectionName))
351 return TokError(
"expected identifier in directive");
361 return TokError(
"expected string in directive");
363 StringRef FlagsStr = getTok().getStringContents();
366 if (ParseSectionFlags(SectionName, FlagsStr, &Flags))
379 return TokError(
"expected comdat type such as 'discard' or 'largest' " 380 "after protection bits");
382 if (parseCOMDATType(Type))
386 return TokError(
"expected comma in directive");
389 if (getParser().parseIdentifier(COMDATSymName))
390 return TokError(
"expected identifier in directive");
394 return TokError(
"unexpected token in directive");
398 const Triple &
T = getContext().getObjectFileInfo()->getTargetTriple();
402 ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
409 if (getParser().parseIdentifier(SymbolName))
410 return TokError(
"expected identifier in directive");
412 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
414 getStreamer().BeginCOFFSymbolDef(Sym);
422 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
426 return TokError(
"unexpected token in directive");
429 getStreamer().EmitCOFFSymbolStorageClass(SymbolStorageClass);
435 if (getParser().parseAbsoluteExpression(Type))
439 return TokError(
"unexpected token in directive");
442 getStreamer().EmitCOFFSymbolType(Type);
448 getStreamer().EndCOFFSymbolDef();
454 if (getParser().parseIdentifier(SymbolID))
455 return TokError(
"expected identifier in directive");
460 OffsetLoc = getLexer().getLoc();
461 if (getParser().parseAbsoluteExpression(Offset))
466 return TokError(
"unexpected token in directive");
471 "invalid '.secrel32' directive offset, can't be less " 472 "than zero or greater than std::numeric_limits<uint32_t>::max()");
477 getStreamer().EmitCOFFSecRel32(Symbol, Offset);
482 auto parseOp = [&]() ->
bool {
484 if (getParser().parseIdentifier(SymbolID))
485 return TokError(
"expected identifier in directive");
490 OffsetLoc = getLexer().getLoc();
491 if (getParser().parseAbsoluteExpression(Offset))
495 if (Offset < std::numeric_limits<int32_t>::min() ||
497 return Error(OffsetLoc,
"invalid '.rva' directive offset, can't be less " 498 "than -2147483648 or greater than " 503 getStreamer().EmitCOFFImgRel32(Symbol, Offset);
507 if (getParser().parseMany(parseOp))
508 return addErrorSuffix(
" in directive");
514 if (getParser().parseIdentifier(SymbolID))
515 return TokError(
"expected identifier in directive");
518 return TokError(
"unexpected token in directive");
523 getStreamer().EmitCOFFSafeSEH(Symbol);
529 if (getParser().parseIdentifier(SymbolID))
530 return TokError(
"expected identifier in directive");
533 return TokError(
"unexpected token in directive");
538 getStreamer().EmitCOFFSectionIndex(Symbol);
544 if (getParser().parseIdentifier(SymbolID))
545 return TokError(
"expected identifier in directive");
548 return TokError(
"unexpected token in directive");
553 getStreamer().EmitCOFFSymbolIndex(Symbol);
559 StringRef TypeId = getTok().getIdentifier();
572 return TokError(
Twine(
"unrecognized COMDAT type '" + TypeId +
"'"));
581 bool COFFAsmParser::ParseDirectiveLinkOnce(
StringRef,
SMLoc Loc) {
584 if (parseCOMDATType(Type))
588 static_cast<const MCSectionCOFF *
>(getStreamer().getCurrentSectionOnly());
591 return Error(Loc,
"cannot make section associative with .linkonce");
595 "' is already linkonce");
600 return TokError(
"unexpected token in directive");
605 bool COFFAsmParser::ParseSEHDirectiveStartProc(
StringRef,
SMLoc Loc) {
607 if (getParser().parseIdentifier(SymbolID))
611 return TokError(
"unexpected token in directive");
616 getStreamer().EmitWinCFIStartProc(Symbol, Loc);
620 bool COFFAsmParser::ParseSEHDirectiveEndProc(
StringRef,
SMLoc Loc) {
622 getStreamer().EmitWinCFIEndProc(Loc);
626 bool COFFAsmParser::ParseSEHDirectiveStartChained(
StringRef,
SMLoc Loc) {
628 getStreamer().EmitWinCFIStartChained(Loc);
632 bool COFFAsmParser::ParseSEHDirectiveEndChained(
StringRef,
SMLoc Loc) {
634 getStreamer().EmitWinCFIEndChained(Loc);
638 bool COFFAsmParser::ParseSEHDirectiveHandler(
StringRef,
SMLoc Loc) {
640 if (getParser().parseIdentifier(SymbolID))
644 return TokError(
"you must specify one or both of @unwind or @except");
646 bool unwind =
false, except =
false;
647 if (ParseAtUnwindOrAtExcept(unwind, except))
651 if (ParseAtUnwindOrAtExcept(unwind, except))
655 return TokError(
"unexpected token in directive");
657 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
660 getStreamer().EmitWinEHHandler(handler, unwind, except, Loc);
664 bool COFFAsmParser::ParseSEHDirectiveHandlerData(
StringRef,
SMLoc Loc) {
666 getStreamer().EmitWinEHHandlerData();
670 bool COFFAsmParser::ParseSEHDirectiveAllocStack(
StringRef,
SMLoc Loc) {
672 if (getParser().parseAbsoluteExpression(Size))
676 return TokError(
"unexpected token in directive");
679 getStreamer().EmitWinCFIAllocStack(Size, Loc);
683 bool COFFAsmParser::ParseSEHDirectiveEndProlog(
StringRef,
SMLoc Loc) {
685 getStreamer().EmitWinCFIEndProlog(Loc);
689 bool COFFAsmParser::ParseAtUnwindOrAtExcept(
bool &unwind,
bool &except) {
692 return TokError(
"a handler attribute must begin with '@'");
693 SMLoc startLoc = getLexer().getLoc();
695 if (getParser().parseIdentifier(identifier))
696 return Error(startLoc,
"expected @unwind or @except");
697 if (identifier ==
"unwind")
699 else if (identifier ==
"except")
702 return Error(startLoc,
"expected @unwind or @except");
709 return new COFFAsmParser;
static SectionKind getData()
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Generic assembler parser interface, for use by target specific assembly parsers.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
void setSelection(int Selection) const
StringSwitch & Case(StringLiteral S, T Value)
static SectionKind computeSectionKind(unsigned Flags)
This represents a section on Windows.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static SectionKind getBSS()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_NODISCARD R Default(T Value)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Directive
IDs for all OpenMP directives.
unsigned getCharacteristics() const
A switch()-like statement whose cases are string literals.
The instances of the Type class are immutable: once they are created, they are never changed...
SectionKind - This is a simple POD value that classifies the properties of a section.
MCAsmParserExtension * createCOFFAsmParser()
StringRef getSectionName() const
Triple - Helper class for working with autoconf configuration names.
Align max(MaybeAlign Lhs, Align Rhs)
SymbolStorageClass
Storage class tells where and what the symbol represents.
COFFYAML::WeakExternalCharacteristics Characteristics
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
static SectionKind getReadOnly()
static SectionKind getText()