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->parseSymbol(Sym))
217 return TokError(
"expected identifier in directive");
221 if (Parser->parseExpression(Expr))
225 auto WasmSym =
static_cast<const MCSymbolWasm *
>(Sym);
226 if (WasmSym->isFunction()) {
229 Warning(Loc,
".size directive ignored for function symbols");
231 getStreamer().emitELFSize(Sym, Expr);
236 bool parseDirectiveType(StringRef, SMLoc) {
240 return error(
"Expected label after .type directive, got: ",
242 auto *WasmSym =
static_cast<MCSymbolWasm *
>(
243 getStreamer().getContext().parseSymbol(Lexer->getTok().getString()));
247 return error(
"Expected label,@type declaration, got: ", Lexer->getTok());
248 auto TypeName = Lexer->getTok().getString();
249 if (TypeName ==
"function") {
252 static_cast<MCSectionWasm *
>(getStreamer().getCurrentSectionOnly());
253 if (Current->getGroup())
254 WasmSym->setComdat(
true);
255 }
else if (TypeName ==
"global")
257 else if (TypeName ==
"object")
260 return error(
"Unknown WASM symbol type: ", Lexer->getTok());
268 bool ParseDirectiveIdent(StringRef, SMLoc) {
270 return TokError(
"unexpected token in '.ident' directive");
271 StringRef
Data = getTok().getIdentifier();
274 return TokError(
"unexpected token in '.ident' directive");
276 getStreamer().emitIdent(
Data);
283 bool ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
284 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
296 return TokError(
"expected identifier in directive");
297 getStreamer().emitSymbolAttribute(Sym, Attr);
301 return TokError(
"unexpected token in directive");
315 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.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
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.