[PATCH] D85795: [WebAssembly][AsmParser] Name missing features in error message
Thomas Lively via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 16:04:43 PDT 2020
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100.
Herald added a project: LLVM.
tlively requested review of this revision.
Rather than just saying that some feature is missing, report the exact
features to make the error message more useful and actionable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85795
Files:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/test/MC/WebAssembly/missing-features.s
Index: llvm/test/MC/WebAssembly/missing-features.s
===================================================================
--- /dev/null
+++ llvm/test/MC/WebAssembly/missing-features.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple=wasm32-unknown-unknown < %s 2>&1 | FileCheck %s
+
+# Check that missing features are named in the error message
+
+# CHECK: error: instruction requires: simd128
+needs_simd:
+ .functype needs_simd () -> (v128)
+ i32.const 42
+ i32x4.splat
+ drop
+ end_function
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -35,6 +35,8 @@
#define DEBUG_TYPE "wasm-asm-parser"
+static const char *getSubtargetFeatureName(uint64_t Val);
+
namespace {
/// WebAssemblyOperand - Instances of this class represent the operands in a
@@ -836,8 +838,9 @@
bool MatchingInlineAsm) override {
MCInst Inst;
Inst.setLoc(IDLoc);
- unsigned MatchResult =
- MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
+ FeatureBitset MissingFeatures;
+ unsigned MatchResult = MatchInstructionImpl(
+ Operands, Inst, ErrorInfo, MissingFeatures, MatchingInlineAsm);
switch (MatchResult) {
case Match_Success: {
ensureLocals(Out);
@@ -866,9 +869,17 @@
}
return false;
}
- case Match_MissingFeature:
- return Parser.Error(
- IDLoc, "instruction requires a Wasm feature not currently enabled");
+ case Match_MissingFeature: {
+ auto NumMissing = MissingFeatures.count();
+ assert(NumMissing > 0 && "Expected missing features");
+ SmallString<128> Message;
+ raw_svector_ostream OS(Message);
+ OS << "instruction requires:";
+ for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
+ if (MissingFeatures.test(i))
+ OS << ' ' << getSubtargetFeatureName(i);
+ return Parser.Error(IDLoc, Message);
+ }
case Match_MnemonicFail:
return Parser.Error(IDLoc, "invalid instruction");
case Match_NearMisses:
@@ -932,5 +943,6 @@
}
#define GET_REGISTER_MATCHER
+#define GET_SUBTARGET_FEATURE_NAME
#define GET_MATCHER_IMPLEMENTATION
#include "WebAssemblyGenAsmMatcher.inc"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85795.284927.patch
Type: text/x-patch
Size: 2413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/15f7ae36/attachment.bin>
More information about the llvm-commits
mailing list