Skip to content

[WebAssembly] Remove Kind argument from WebAssemblyOperand (NFC) #107157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ struct WebAssemblyOperand : public MCParsedAsmOperand {
struct BrLOp BrL;
};

WebAssemblyOperand(KindTy K, SMLoc Start, SMLoc End, TokOp T)
: Kind(K), StartLoc(Start), EndLoc(End), Tok(T) {}
WebAssemblyOperand(KindTy K, SMLoc Start, SMLoc End, IntOp I)
: Kind(K), StartLoc(Start), EndLoc(End), Int(I) {}
WebAssemblyOperand(KindTy K, SMLoc Start, SMLoc End, FltOp F)
: Kind(K), StartLoc(Start), EndLoc(End), Flt(F) {}
WebAssemblyOperand(KindTy K, SMLoc Start, SMLoc End, SymOp S)
: Kind(K), StartLoc(Start), EndLoc(End), Sym(S) {}
WebAssemblyOperand(KindTy K, SMLoc Start, SMLoc End)
: Kind(K), StartLoc(Start), EndLoc(End), BrL() {}
WebAssemblyOperand(SMLoc Start, SMLoc End, TokOp T)
: Kind(Token), StartLoc(Start), EndLoc(End), Tok(T) {}
WebAssemblyOperand(SMLoc Start, SMLoc End, IntOp I)
: Kind(Integer), StartLoc(Start), EndLoc(End), Int(I) {}
WebAssemblyOperand(SMLoc Start, SMLoc End, FltOp F)
: Kind(Float), StartLoc(Start), EndLoc(End), Flt(F) {}
WebAssemblyOperand(SMLoc Start, SMLoc End, SymOp S)
: Kind(Symbol), StartLoc(Start), EndLoc(End), Sym(S) {}
WebAssemblyOperand(SMLoc Start, SMLoc End)
: Kind(BrList), StartLoc(Start), EndLoc(End), BrL() {}

~WebAssemblyOperand() {
if (isBrList())
Expand Down Expand Up @@ -388,8 +388,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (IsNegative)
Val = -Val;
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Integer, Int.getLoc(), Int.getEndLoc(),
WebAssemblyOperand::IntOp{Val}));
Int.getLoc(), Int.getEndLoc(), WebAssemblyOperand::IntOp{Val}));
Parser.Lex();
}

Expand All @@ -401,8 +400,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (IsNegative)
Val = -Val;
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Float, Flt.getLoc(), Flt.getEndLoc(),
WebAssemblyOperand::FltOp{Val}));
Flt.getLoc(), Flt.getEndLoc(), WebAssemblyOperand::FltOp{Val}));
Parser.Lex();
return false;
}
Expand All @@ -423,8 +421,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (IsNegative)
Val = -Val;
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Float, Flt.getLoc(), Flt.getEndLoc(),
WebAssemblyOperand::FltOp{Val}));
Flt.getLoc(), Flt.getEndLoc(), WebAssemblyOperand::FltOp{Val}));
Parser.Lex();
return false;
}
Expand Down Expand Up @@ -459,8 +456,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
// up later.
auto Tok = Lexer.getTok();
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Integer, Tok.getLoc(), Tok.getEndLoc(),
WebAssemblyOperand::IntOp{-1}));
Tok.getLoc(), Tok.getEndLoc(), WebAssemblyOperand::IntOp{-1}));
}
}
return false;
Expand All @@ -474,8 +470,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
NestingStack.back().Sig = Sig;
}
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Integer, NameLoc, NameLoc,
WebAssemblyOperand::IntOp{static_cast<int64_t>(BT)}));
NameLoc, NameLoc, WebAssemblyOperand::IntOp{static_cast<int64_t>(BT)}));
}

bool parseLimits(wasm::WasmLimits *Limits) {
Expand Down Expand Up @@ -512,25 +507,22 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
GetOrCreateFunctionTableSymbol(getContext(), Tok.getString(), is64);
const auto *Val = MCSymbolRefExpr::create(Sym, getContext());
*Op = std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Symbol, Tok.getLoc(), Tok.getEndLoc(),
WebAssemblyOperand::SymOp{Val});
Tok.getLoc(), Tok.getEndLoc(), WebAssemblyOperand::SymOp{Val});
Parser.Lex();
return expect(AsmToken::Comma, ",");
} else {
const auto *Val =
MCSymbolRefExpr::create(DefaultFunctionTable, getContext());
*Op = std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Symbol, SMLoc(), SMLoc(),
WebAssemblyOperand::SymOp{Val});
SMLoc(), SMLoc(), WebAssemblyOperand::SymOp{Val});
return false;
}
} else {
// For the MVP there is at most one table whose number is 0, but we can't
// write a table symbol or issue relocations. Instead we just ensure the
// table is live and write a zero.
getStreamer().emitSymbolAttribute(DefaultFunctionTable, MCSA_NoDeadStrip);
*Op = std::make_unique<WebAssemblyOperand>(WebAssemblyOperand::Integer,
SMLoc(), SMLoc(),
*Op = std::make_unique<WebAssemblyOperand>(SMLoc(), SMLoc(),
WebAssemblyOperand::IntOp{0});
return false;
}
Expand Down Expand Up @@ -564,7 +556,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {

// Now construct the name as first operand.
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Token, NameLoc, SMLoc::getFromPointer(Name.end()),
NameLoc, SMLoc::getFromPointer(Name.end()),
WebAssemblyOperand::TokOp{Name}));

// If this instruction is part of a control flow structure, ensure
Expand Down Expand Up @@ -645,8 +637,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
const MCExpr *Expr = MCSymbolRefExpr::create(
WasmSym, MCSymbolRefExpr::VK_WASM_TYPEINDEX, Ctx);
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Symbol, Loc.getLoc(), Loc.getEndLoc(),
WebAssemblyOperand::SymOp{Expr}));
Loc.getLoc(), Loc.getEndLoc(), WebAssemblyOperand::SymOp{Expr}));
}

while (Lexer.isNot(AsmToken::EndOfStatement)) {
Expand All @@ -671,8 +662,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
if (Parser.parseExpression(Val, End))
return error("Cannot parse symbol: ", Lexer.getTok());
Operands.push_back(std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::Symbol, Start, End,
WebAssemblyOperand::SymOp{Val}));
Start, End, WebAssemblyOperand::SymOp{Val}));
if (checkForP2AlignIfLoadStore(Operands, Name))
return true;
}
Expand Down Expand Up @@ -705,8 +695,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
}
case AsmToken::LCurly: {
Parser.Lex();
auto Op = std::make_unique<WebAssemblyOperand>(
WebAssemblyOperand::BrList, Tok.getLoc(), Tok.getEndLoc());
auto Op =
std::make_unique<WebAssemblyOperand>(Tok.getLoc(), Tok.getEndLoc());
if (!Lexer.is(AsmToken::RCurly))
for (;;) {
Op->BrL.List.push_back(Lexer.getTok().getIntVal());
Expand Down
Loading