LLVM 19.0.0git
COFFAsmParser.cpp
Go to the documentation of this file.
1//===- COFFAsmParser.cpp - COFF Assembly Parser ---------------------------===//
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
11#include "llvm/ADT/Twine.h"
13#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/SectionKind.h"
20#include "llvm/Support/SMLoc.h"
22#include <cassert>
23#include <cstdint>
24#include <limits>
25#include <utility>
26
27using namespace llvm;
28
29namespace {
30
31class COFFAsmParser : public MCAsmParserExtension {
32 template<bool (COFFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
33 void addDirectiveHandler(StringRef Directive) {
34 MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
35 this, HandleDirective<COFFAsmParser, HandlerMethod>);
37 }
38
39 bool ParseSectionSwitch(StringRef Section,
40 unsigned Characteristics,
41 SectionKind Kind);
42
43 bool ParseSectionSwitch(StringRef Section, unsigned Characteristics,
44 SectionKind Kind, StringRef COMDATSymName,
46
47 bool ParseSectionName(StringRef &SectionName);
48 bool ParseSectionFlags(StringRef SectionName, StringRef FlagsString,
49 unsigned *Flags);
50
51 void Initialize(MCAsmParser &Parser) override {
52 // Call the base implementation.
54
55 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(".text");
56 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(".data");
57 addDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(".bss");
58 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSection>(".section");
59 addDirectiveHandler<&COFFAsmParser::ParseDirectivePushSection>(
60 ".pushsection");
61 addDirectiveHandler<&COFFAsmParser::ParseDirectivePopSection>(
62 ".popsection");
63 addDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(".def");
64 addDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(".scl");
65 addDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(".type");
66 addDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(".endef");
67 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecRel32>(".secrel32");
68 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymIdx>(".symidx");
69 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSafeSEH>(".safeseh");
70 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(".secidx");
71 addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(".linkonce");
72 addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(".rva");
73 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
74 addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak_anti_dep");
75 addDirectiveHandler<&COFFAsmParser::ParseDirectiveCGProfile>(".cg_profile");
76
77 // Win64 EH directives.
78 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
79 ".seh_proc");
80 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>(
81 ".seh_endproc");
82 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc>(
83 ".seh_endfunclet");
84 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>(
85 ".seh_startchained");
86 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>(
87 ".seh_endchained");
88 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>(
89 ".seh_handler");
90 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>(
91 ".seh_handlerdata");
92 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>(
93 ".seh_stackalloc");
94 addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
95 ".seh_endprologue");
96 }
97
98 bool ParseSectionDirectiveText(StringRef, SMLoc) {
99 return ParseSectionSwitch(".text",
104 }
105
106 bool ParseSectionDirectiveData(StringRef, SMLoc) {
107 return ParseSectionSwitch(".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
111 }
112
113 bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
114 return ParseSectionSwitch(".bss",
119 }
120
121 bool ParseDirectiveSection(StringRef, SMLoc);
122 bool parseSectionArguments(StringRef, SMLoc);
123 bool ParseDirectivePushSection(StringRef, SMLoc);
124 bool ParseDirectivePopSection(StringRef, SMLoc);
125 bool ParseDirectiveDef(StringRef, SMLoc);
126 bool ParseDirectiveScl(StringRef, SMLoc);
127 bool ParseDirectiveType(StringRef, SMLoc);
128 bool ParseDirectiveEndef(StringRef, SMLoc);
129 bool ParseDirectiveSecRel32(StringRef, SMLoc);
130 bool ParseDirectiveSecIdx(StringRef, SMLoc);
131 bool ParseDirectiveSafeSEH(StringRef, SMLoc);
132 bool ParseDirectiveSymIdx(StringRef, SMLoc);
133 bool parseCOMDATType(COFF::COMDATType &Type);
134 bool ParseDirectiveLinkOnce(StringRef, SMLoc);
135 bool ParseDirectiveRVA(StringRef, SMLoc);
137
138 // Win64 EH directives.
139 bool ParseSEHDirectiveStartProc(StringRef, SMLoc);
140 bool ParseSEHDirectiveEndProc(StringRef, SMLoc);
141 bool ParseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc);
142 bool ParseSEHDirectiveStartChained(StringRef, SMLoc);
143 bool ParseSEHDirectiveEndChained(StringRef, SMLoc);
144 bool ParseSEHDirectiveHandler(StringRef, SMLoc);
145 bool ParseSEHDirectiveHandlerData(StringRef, SMLoc);
146 bool ParseSEHDirectiveAllocStack(StringRef, SMLoc);
147 bool ParseSEHDirectiveEndProlog(StringRef, SMLoc);
148
149 bool ParseAtUnwindOrAtExcept(bool &unwind, bool &except);
150 bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc);
151
152public:
153 COFFAsmParser() = default;
154};
155
156} // end anonymous namespace.
157
158static SectionKind computeSectionKind(unsigned Flags) {
159 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
160 return SectionKind::getText();
161 if (Flags & COFF::IMAGE_SCN_MEM_READ &&
162 (Flags & COFF::IMAGE_SCN_MEM_WRITE) == 0)
164 return SectionKind::getData();
165}
166
167bool COFFAsmParser::ParseSectionFlags(StringRef SectionName,
168 StringRef FlagsString, unsigned *Flags) {
169 enum {
170 None = 0,
171 Alloc = 1 << 0,
172 Code = 1 << 1,
173 Load = 1 << 2,
174 InitData = 1 << 3,
175 Shared = 1 << 4,
176 NoLoad = 1 << 5,
177 NoRead = 1 << 6,
178 NoWrite = 1 << 7,
179 Discardable = 1 << 8,
180 Info = 1 << 9,
181 };
182
183 bool ReadOnlyRemoved = false;
184 unsigned SecFlags = None;
185
186 for (char FlagChar : FlagsString) {
187 switch (FlagChar) {
188 case 'a':
189 // Ignored.
190 break;
191
192 case 'b': // bss section
193 SecFlags |= Alloc;
194 if (SecFlags & InitData)
195 return TokError("conflicting section flags 'b' and 'd'.");
196 SecFlags &= ~Load;
197 break;
198
199 case 'd': // data section
200 SecFlags |= InitData;
201 if (SecFlags & Alloc)
202 return TokError("conflicting section flags 'b' and 'd'.");
203 SecFlags &= ~NoWrite;
204 if ((SecFlags & NoLoad) == 0)
205 SecFlags |= Load;
206 break;
207
208 case 'n': // section is not loaded
209 SecFlags |= NoLoad;
210 SecFlags &= ~Load;
211 break;
212
213 case 'D': // discardable
214 SecFlags |= Discardable;
215 break;
216
217 case 'r': // read-only
218 ReadOnlyRemoved = false;
219 SecFlags |= NoWrite;
220 if ((SecFlags & Code) == 0)
221 SecFlags |= InitData;
222 if ((SecFlags & NoLoad) == 0)
223 SecFlags |= Load;
224 break;
225
226 case 's': // shared section
227 SecFlags |= Shared | InitData;
228 SecFlags &= ~NoWrite;
229 if ((SecFlags & NoLoad) == 0)
230 SecFlags |= Load;
231 break;
232
233 case 'w': // writable
234 SecFlags &= ~NoWrite;
235 ReadOnlyRemoved = true;
236 break;
237
238 case 'x': // executable section
239 SecFlags |= Code;
240 if ((SecFlags & NoLoad) == 0)
241 SecFlags |= Load;
242 if (!ReadOnlyRemoved)
243 SecFlags |= NoWrite;
244 break;
245
246 case 'y': // not readable
247 SecFlags |= NoRead | NoWrite;
248 break;
249
250 case 'i': // info
251 SecFlags |= Info;
252 break;
253
254 default:
255 return TokError("unknown flag");
256 }
257 }
258
259 *Flags = 0;
260
261 if (SecFlags == None)
262 SecFlags = InitData;
263
264 if (SecFlags & Code)
266 if (SecFlags & InitData)
268 if ((SecFlags & Alloc) && (SecFlags & Load) == 0)
270 if (SecFlags & NoLoad)
272 if ((SecFlags & Discardable) ||
275 if ((SecFlags & NoRead) == 0)
277 if ((SecFlags & NoWrite) == 0)
279 if (SecFlags & Shared)
281 if (SecFlags & Info)
283
284 return false;
285}
286
287/// ParseDirectiveSymbolAttribute
288/// ::= { ".weak", ... } [ identifier ( , identifier )* ]
289bool COFFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
291 .Case(".weak", MCSA_Weak)
292 .Case(".weak_anti_dep", MCSA_WeakAntiDep)
294 assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
295 if (getLexer().isNot(AsmToken::EndOfStatement)) {
296 while (true) {
298
299 if (getParser().parseIdentifier(Name))
300 return TokError("expected identifier in directive");
301
302 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
303
304 getStreamer().emitSymbolAttribute(Sym, Attr);
305
306 if (getLexer().is(AsmToken::EndOfStatement))
307 break;
308
309 if (getLexer().isNot(AsmToken::Comma))
310 return TokError("unexpected token in directive");
311 Lex();
312 }
313 }
314
315 Lex();
316 return false;
317}
318
319bool COFFAsmParser::ParseDirectiveCGProfile(StringRef S, SMLoc Loc) {
321}
322
323bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
324 unsigned Characteristics,
325 SectionKind Kind) {
326 return ParseSectionSwitch(Section, Characteristics, Kind, "", (COFF::COMDATType)0);
327}
328
329bool COFFAsmParser::ParseSectionSwitch(StringRef Section,
330 unsigned Characteristics,
331 SectionKind Kind,
332 StringRef COMDATSymName,
334 if (getLexer().isNot(AsmToken::EndOfStatement))
335 return TokError("unexpected token in section switching directive");
336 Lex();
337
338 getStreamer().switchSection(getContext().getCOFFSection(
339 Section, Characteristics, Kind, COMDATSymName, Type));
340
341 return false;
342}
343
344bool COFFAsmParser::ParseSectionName(StringRef &SectionName) {
345 if (!getLexer().is(AsmToken::Identifier) && !getLexer().is(AsmToken::String))
346 return true;
347
348 SectionName = getTok().getIdentifier();
349 Lex();
350 return false;
351}
352
353bool COFFAsmParser::ParseDirectiveSection(StringRef directive, SMLoc loc) {
354 return parseSectionArguments(directive, loc);
355}
356
357// .section name [, "flags"] [, identifier [ identifier ], identifier]
358// .pushsection <same as above>
359//
360// Supported flags:
361// a: Ignored.
362// b: BSS section (uninitialized data)
363// d: data section (initialized data)
364// n: "noload" section (removed by linker)
365// D: Discardable section
366// r: Readable section
367// s: Shared section
368// w: Writable section
369// x: Executable section
370// y: Not-readable section (clears 'r')
371//
372// Subsections are not supported.
373bool COFFAsmParser::parseSectionArguments(StringRef, SMLoc) {
375
376 if (ParseSectionName(SectionName))
377 return TokError("expected identifier in directive");
378
382
383 if (getLexer().is(AsmToken::Comma)) {
384 Lex();
385
386 if (getLexer().isNot(AsmToken::String))
387 return TokError("expected string in directive");
388
389 StringRef FlagsStr = getTok().getStringContents();
390 Lex();
391
392 if (ParseSectionFlags(SectionName, FlagsStr, &Flags))
393 return true;
394 }
395
397 StringRef COMDATSymName;
398 if (getLexer().is(AsmToken::Comma)) {
400 Lex();
401
403
404 if (!getLexer().is(AsmToken::Identifier))
405 return TokError("expected comdat type such as 'discard' or 'largest' "
406 "after protection bits");
407
408 if (parseCOMDATType(Type))
409 return true;
410
411 if (getLexer().isNot(AsmToken::Comma))
412 return TokError("expected comma in directive");
413 Lex();
414
415 if (getParser().parseIdentifier(COMDATSymName))
416 return TokError("expected identifier in directive");
417 }
418
419 if (getLexer().isNot(AsmToken::EndOfStatement))
420 return TokError("unexpected token in directive");
421
423 if (Kind.isText()) {
424 const Triple &T = getContext().getTargetTriple();
425 if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
427 }
428 ParseSectionSwitch(SectionName, Flags, Kind, COMDATSymName, Type);
429 return false;
430}
431
432bool COFFAsmParser::ParseDirectivePushSection(StringRef directive, SMLoc loc) {
433 getStreamer().pushSection();
434
435 if (parseSectionArguments(directive, loc)) {
436 getStreamer().popSection();
437 return true;
438 }
439
440 return false;
441}
442
443bool COFFAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
444 if (!getStreamer().popSection())
445 return TokError(".popsection without corresponding .pushsection");
446 return false;
447}
448
449bool COFFAsmParser::ParseDirectiveDef(StringRef, SMLoc) {
451
452 if (getParser().parseIdentifier(SymbolName))
453 return TokError("expected identifier in directive");
454
455 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
456
457 getStreamer().beginCOFFSymbolDef(Sym);
458
459 Lex();
460 return false;
461}
462
463bool COFFAsmParser::ParseDirectiveScl(StringRef, SMLoc) {
464 int64_t SymbolStorageClass;
465 if (getParser().parseAbsoluteExpression(SymbolStorageClass))
466 return true;
467
468 if (getLexer().isNot(AsmToken::EndOfStatement))
469 return TokError("unexpected token in directive");
470
471 Lex();
472 getStreamer().emitCOFFSymbolStorageClass(SymbolStorageClass);
473 return false;
474}
475
476bool COFFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
477 int64_t Type;
478 if (getParser().parseAbsoluteExpression(Type))
479 return true;
480
481 if (getLexer().isNot(AsmToken::EndOfStatement))
482 return TokError("unexpected token in directive");
483
484 Lex();
485 getStreamer().emitCOFFSymbolType(Type);
486 return false;
487}
488
489bool COFFAsmParser::ParseDirectiveEndef(StringRef, SMLoc) {
490 Lex();
491 getStreamer().endCOFFSymbolDef();
492 return false;
493}
494
495bool COFFAsmParser::ParseDirectiveSecRel32(StringRef, SMLoc) {
496 StringRef SymbolID;
497 if (getParser().parseIdentifier(SymbolID))
498 return TokError("expected identifier in directive");
499
500 int64_t Offset = 0;
501 SMLoc OffsetLoc;
502 if (getLexer().is(AsmToken::Plus)) {
503 OffsetLoc = getLexer().getLoc();
504 if (getParser().parseAbsoluteExpression(Offset))
505 return true;
506 }
507
508 if (getLexer().isNot(AsmToken::EndOfStatement))
509 return TokError("unexpected token in directive");
510
511 if (Offset < 0 || Offset > std::numeric_limits<uint32_t>::max())
512 return Error(
513 OffsetLoc,
514 "invalid '.secrel32' directive offset, can't be less "
515 "than zero or greater than std::numeric_limits<uint32_t>::max()");
516
517 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
518
519 Lex();
520 getStreamer().emitCOFFSecRel32(Symbol, Offset);
521 return false;
522}
523
524bool COFFAsmParser::ParseDirectiveRVA(StringRef, SMLoc) {
525 auto parseOp = [&]() -> bool {
526 StringRef SymbolID;
527 if (getParser().parseIdentifier(SymbolID))
528 return TokError("expected identifier in directive");
529
530 int64_t Offset = 0;
531 SMLoc OffsetLoc;
532 if (getLexer().is(AsmToken::Plus) || getLexer().is(AsmToken::Minus)) {
533 OffsetLoc = getLexer().getLoc();
534 if (getParser().parseAbsoluteExpression(Offset))
535 return true;
536 }
537
538 if (Offset < std::numeric_limits<int32_t>::min() ||
539 Offset > std::numeric_limits<int32_t>::max())
540 return Error(OffsetLoc, "invalid '.rva' directive offset, can't be less "
541 "than -2147483648 or greater than "
542 "2147483647");
543
544 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
545
546 getStreamer().emitCOFFImgRel32(Symbol, Offset);
547 return false;
548 };
549
550 if (getParser().parseMany(parseOp))
551 return addErrorSuffix(" in directive");
552 return false;
553}
554
555bool COFFAsmParser::ParseDirectiveSafeSEH(StringRef, SMLoc) {
556 StringRef SymbolID;
557 if (getParser().parseIdentifier(SymbolID))
558 return TokError("expected identifier in directive");
559
560 if (getLexer().isNot(AsmToken::EndOfStatement))
561 return TokError("unexpected token in directive");
562
563 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
564
565 Lex();
566 getStreamer().emitCOFFSafeSEH(Symbol);
567 return false;
568}
569
570bool COFFAsmParser::ParseDirectiveSecIdx(StringRef, SMLoc) {
571 StringRef SymbolID;
572 if (getParser().parseIdentifier(SymbolID))
573 return TokError("expected identifier in directive");
574
575 if (getLexer().isNot(AsmToken::EndOfStatement))
576 return TokError("unexpected token in directive");
577
578 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
579
580 Lex();
581 getStreamer().emitCOFFSectionIndex(Symbol);
582 return false;
583}
584
585bool COFFAsmParser::ParseDirectiveSymIdx(StringRef, SMLoc) {
586 StringRef SymbolID;
587 if (getParser().parseIdentifier(SymbolID))
588 return TokError("expected identifier in directive");
589
590 if (getLexer().isNot(AsmToken::EndOfStatement))
591 return TokError("unexpected token in directive");
592
593 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
594
595 Lex();
596 getStreamer().emitCOFFSymbolIndex(Symbol);
597 return false;
598}
599
600/// ::= [ identifier ]
601bool COFFAsmParser::parseCOMDATType(COFF::COMDATType &Type) {
602 StringRef TypeId = getTok().getIdentifier();
603
613
614 if (Type == 0)
615 return TokError(Twine("unrecognized COMDAT type '" + TypeId + "'"));
616
617 Lex();
618
619 return false;
620}
621
622/// ParseDirectiveLinkOnce
623/// ::= .linkonce [ identifier ]
624bool COFFAsmParser::ParseDirectiveLinkOnce(StringRef, SMLoc Loc) {
626 if (getLexer().is(AsmToken::Identifier))
627 if (parseCOMDATType(Type))
628 return true;
629
630 const MCSectionCOFF *Current =
631 static_cast<const MCSectionCOFF *>(getStreamer().getCurrentSectionOnly());
632
634 return Error(Loc, "cannot make section associative with .linkonce");
635
637 return Error(Loc, Twine("section '") + Current->getName() +
638 "' is already linkonce");
639
640 Current->setSelection(Type);
641
642 if (getLexer().isNot(AsmToken::EndOfStatement))
643 return TokError("unexpected token in directive");
644
645 return false;
646}
647
648bool COFFAsmParser::ParseSEHDirectiveStartProc(StringRef, SMLoc Loc) {
649 StringRef SymbolID;
650 if (getParser().parseIdentifier(SymbolID))
651 return true;
652
653 if (getLexer().isNot(AsmToken::EndOfStatement))
654 return TokError("unexpected token in directive");
655
656 MCSymbol *Symbol = getContext().getOrCreateSymbol(SymbolID);
657
658 Lex();
659 getStreamer().emitWinCFIStartProc(Symbol, Loc);
660 return false;
661}
662
663bool COFFAsmParser::ParseSEHDirectiveEndProc(StringRef, SMLoc Loc) {
664 Lex();
665 getStreamer().emitWinCFIEndProc(Loc);
666 return false;
667}
668
669bool COFFAsmParser::ParseSEHDirectiveEndFuncletOrFunc(StringRef, SMLoc Loc) {
670 Lex();
671 getStreamer().emitWinCFIFuncletOrFuncEnd(Loc);
672 return false;
673}
674
675bool COFFAsmParser::ParseSEHDirectiveStartChained(StringRef, SMLoc Loc) {
676 Lex();
677 getStreamer().emitWinCFIStartChained(Loc);
678 return false;
679}
680
681bool COFFAsmParser::ParseSEHDirectiveEndChained(StringRef, SMLoc Loc) {
682 Lex();
683 getStreamer().emitWinCFIEndChained(Loc);
684 return false;
685}
686
687bool COFFAsmParser::ParseSEHDirectiveHandler(StringRef, SMLoc Loc) {
688 StringRef SymbolID;
689 if (getParser().parseIdentifier(SymbolID))
690 return true;
691
692 if (getLexer().isNot(AsmToken::Comma))
693 return TokError("you must specify one or both of @unwind or @except");
694 Lex();
695 bool unwind = false, except = false;
696 if (ParseAtUnwindOrAtExcept(unwind, except))
697 return true;
698 if (getLexer().is(AsmToken::Comma)) {
699 Lex();
700 if (ParseAtUnwindOrAtExcept(unwind, except))
701 return true;
702 }
703 if (getLexer().isNot(AsmToken::EndOfStatement))
704 return TokError("unexpected token in directive");
705
706 MCSymbol *handler = getContext().getOrCreateSymbol(SymbolID);
707
708 Lex();
709 getStreamer().emitWinEHHandler(handler, unwind, except, Loc);
710 return false;
711}
712
713bool COFFAsmParser::ParseSEHDirectiveHandlerData(StringRef, SMLoc Loc) {
714 Lex();
715 getStreamer().emitWinEHHandlerData();
716 return false;
717}
718
719bool COFFAsmParser::ParseSEHDirectiveAllocStack(StringRef, SMLoc Loc) {
720 int64_t Size;
721 if (getParser().parseAbsoluteExpression(Size))
722 return true;
723
724 if (getLexer().isNot(AsmToken::EndOfStatement))
725 return TokError("unexpected token in directive");
726
727 Lex();
728 getStreamer().emitWinCFIAllocStack(Size, Loc);
729 return false;
730}
731
732bool COFFAsmParser::ParseSEHDirectiveEndProlog(StringRef, SMLoc Loc) {
733 Lex();
734 getStreamer().emitWinCFIEndProlog(Loc);
735 return false;
736}
737
738bool COFFAsmParser::ParseAtUnwindOrAtExcept(bool &unwind, bool &except) {
739 StringRef identifier;
740 if (getLexer().isNot(AsmToken::At) && getLexer().isNot(AsmToken::Percent))
741 return TokError("a handler attribute must begin with '@' or '%'");
742 SMLoc startLoc = getLexer().getLoc();
743 Lex();
744 if (getParser().parseIdentifier(identifier))
745 return Error(startLoc, "expected @unwind or @except");
746 if (identifier == "unwind")
747 unwind = true;
748 else if (identifier == "except")
749 except = true;
750 else
751 return Error(startLoc, "expected @unwind or @except");
752 return false;
753}
754
755namespace llvm {
756
758 return new COFFAsmParser;
759}
760
761} // end namespace llvm
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static SectionKind computeSectionKind(unsigned Flags)
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:331
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
@ None
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
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>
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:123
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
Definition: MCAsmParser.h:127
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:85
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:66
void setSelection(int Selection) const
StringRef getName() const
Definition: MCSection.h:124
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Represents a location in source code.
Definition: SMLoc.h:23
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
static SectionKind getText()
Definition: SectionKind.h:190
static SectionKind getData()
Definition: SectionKind.h:213
static SectionKind getBSS()
Definition: SectionKind.h:209
static SectionKind getReadOnly()
Definition: SectionKind.h:192
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ IMAGE_SCN_MEM_SHARED
Definition: COFF.h:333
@ IMAGE_SCN_LNK_REMOVE
Definition: COFF.h:307
@ IMAGE_SCN_CNT_CODE
Definition: COFF.h:302
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:335
@ IMAGE_SCN_MEM_EXECUTE
Definition: COFF.h:334
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: COFF.h:304
@ IMAGE_SCN_MEM_DISCARDABLE
Definition: COFF.h:330
@ IMAGE_SCN_LNK_INFO
Definition: COFF.h:306
@ IMAGE_SCN_MEM_16BIT
Definition: COFF.h:311
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:303
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:308
@ IMAGE_SCN_MEM_WRITE
Definition: COFF.h:336
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: COFF.h:217
COMDATType
Definition: COFF.h:420
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition: COFF.h:421
@ IMAGE_COMDAT_SELECT_LARGEST
Definition: COFF.h:426
@ IMAGE_COMDAT_SELECT_NEWEST
Definition: COFF.h:427
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition: COFF.h:423
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:425
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition: COFF.h:424
@ IMAGE_COMDAT_SELECT_ANY
Definition: COFF.h:422
NodeAddr< CodeNode * > Code
Definition: RDFGraph.h:388
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
MCAsmParserExtension * createCOFFAsmParser()
MCSymbolAttr
Definition: MCDirectives.h:18
@ MCSA_Weak
.weak
Definition: MCDirectives.h:45
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
Definition: MCDirectives.h:49
@ MCSA_Invalid
Not a valid directive.
Definition: MCDirectives.h:19