36 MCAsmParser *Parser =
nullptr;
37 AsmLexer *Lexer =
nullptr;
39 template<
bool (WasmAsmParser::*HandlerMethod)(StringRef, SMLoc)>
40 void addDirectiveHandler(StringRef Directive) {
42 this, HandleDirective<WasmAsmParser, HandlerMethod>);
44 getParser().addDirectiveHandler(Directive, Handler);
48 WasmAsmParser() { BracketExpressionsSupported =
true; }
50 void Initialize(MCAsmParser &
P)
override {
52 Lexer = &Parser->getLexer();
56 addDirectiveHandler<&WasmAsmParser::parseSectionDirectiveText>(
".text");
57 addDirectiveHandler<&WasmAsmParser::parseSectionDirectiveData>(
".data");
58 addDirectiveHandler<&WasmAsmParser::parseSectionDirective>(
".section");
59 addDirectiveHandler<&WasmAsmParser::parseDirectiveSize>(
".size");
60 addDirectiveHandler<&WasmAsmParser::parseDirectiveType>(
".type");
61 addDirectiveHandler<&WasmAsmParser::ParseDirectiveIdent>(
".ident");
63 &WasmAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
65 &WasmAsmParser::ParseDirectiveSymbolAttribute>(
".local");
67 &WasmAsmParser::ParseDirectiveSymbolAttribute>(
".internal");
69 &WasmAsmParser::ParseDirectiveSymbolAttribute>(
".hidden");
72 bool error(
const StringRef &Msg,
const AsmToken &Tok) {
77 auto Ok = Lexer->is(Kind);
85 return error(std::string(
"Expected ") + KindName +
", instead got: ",
90 bool parseSectionDirectiveText(StringRef, SMLoc) {
95 bool parseSectionDirectiveData(StringRef, SMLoc) {
96 auto *S =
getContext().getObjectFileInfo()->getDataSection();
97 getStreamer().switchSection(S);
103 for (
char C : FlagStr) {
127 bool parseGroup(StringRef &GroupName) {
129 return TokError(
"expected group name");
132 GroupName = getTok().getString();
134 }
else if (Parser->parseIdentifier(GroupName)) {
135 return TokError(
"invalid group name");
140 if (Parser->parseIdentifier(
Linkage))
141 return TokError(
"invalid linkage");
143 return TokError(
"Linkage must be 'comdat'");
148 bool parseSectionDirective(StringRef, SMLoc loc) {
150 if (Parser->parseIdentifier(Name))
151 return TokError(
"expected identifier in directive");
157 return error(
"expected string in directive, instead got: ", Lexer->getTok());
159 auto Kind = StringSwitch<std::optional<SectionKind>>(
Name)
179 return TokError(
"unknown flag");
187 if (Group && parseGroup(GroupName))
194 MCSectionWasm *WS =
getContext().getWasmSection(
198 Parser->Error(loc,
"changed section flags for " + Name +
204 return Parser->Error(loc,
"Only data sections can be passive");
208 getStreamer().switchSection(WS);
214 bool parseDirectiveSize(StringRef, SMLoc Loc) {
216 if (Parser->parseIdentifier(Name))
217 return TokError(
"expected identifier in directive");
218 auto Sym =
getContext().getOrCreateSymbol(Name);
222 if (Parser->parseExpression(Expr))
226 auto WasmSym =
static_cast<const MCSymbolWasm *
>(Sym);
227 if (WasmSym->isFunction()) {
230 Warning(Loc,
".size directive ignored for function symbols");
232 getStreamer().emitELFSize(Sym, Expr);
237 bool parseDirectiveType(StringRef, SMLoc) {
241 return error(
"Expected label after .type directive, got: ",
243 auto *WasmSym =
static_cast<MCSymbolWasm *
>(
244 getStreamer().getContext().getOrCreateSymbol(
245 Lexer->getTok().getString()));
249 return error(
"Expected label,@type declaration, got: ", Lexer->getTok());
250 auto TypeName = Lexer->getTok().getString();
251 if (TypeName ==
"function") {
254 static_cast<MCSectionWasm *
>(getStreamer().getCurrentSectionOnly());
255 if (Current->getGroup())
256 WasmSym->setComdat(
true);
257 }
else if (TypeName ==
"global")
259 else if (TypeName ==
"object")
262 return error(
"Unknown WASM symbol type: ", Lexer->getTok());
270 bool ParseDirectiveIdent(StringRef, SMLoc) {
272 return TokError(
"unexpected token in '.ident' directive");
273 StringRef
Data = getTok().getIdentifier();
276 return TokError(
"unexpected token in '.ident' directive");
278 getStreamer().emitIdent(
Data);
285 bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
286 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
297 if (getParser().parseIdentifier(Name))
298 return TokError(
"expected identifier in directive");
300 getStreamer().emitSymbolAttribute(Sym, Attr);
304 return TokError(
"unexpected token in directive");
318 return new WasmAsmParser;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr, bool *UseLastGroup)
LLVM_ABI SMLoc getLoc() const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
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.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
void setPassive(bool V=true)
unsigned getSegmentFlags() const
static constexpr unsigned NonUniqueID
static SectionKind getThreadData()
static SectionKind getMetadata()
static SectionKind getText()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getReadOnly()
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
@ C
The default llvm calling convention, compatible with C.
Context & getContext() const
@ WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_FUNCTION
This is an optimization pass for GlobalISel generic memory operations.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
MCAsmParserExtension * createWasmAsmParser()
FunctionAddr VTableAddr uintptr_t uintptr_t Data
@ MCSA_Protected
.protected (ELF)
@ MCSA_Internal
.internal (ELF)
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_Invalid
Not a valid directive.