diff options
author | Alon Zakai <azakai@google.com> | 2021-01-27 19:40:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-27 11:40:08 -0800 |
commit | 5331e9d18b9359aa0e9d6e0df455883f62e46ea0 (patch) | |
tree | 7114cb1190a1a2c6c886b267092d613d74ad50b9 /src/wasm | |
parent | 2bdc4841b680ee44e132bbb07f5167eaa7226f99 (diff) | |
download | binaryen-5331e9d18b9359aa0e9d6e0df455883f62e46ea0.tar.gz binaryen-5331e9d18b9359aa0e9d6e0df455883f62e46ea0.tar.bz2 binaryen-5331e9d18b9359aa0e9d6e0df455883f62e46ea0.zip |
Simplfy getExpressionName (#3522)
This used to return a simple name like "if" for an If, but it is redundant with
our proper printing logic. This PR turns it into a trivial helper that just prints
out the name of the class, so it now prints "If" with a capital. That is useful
for some logging, like in Metrics I think it is clearer than it was earlier (since
we are actually counting the classes, and our old emitting of text-format-like
names are just confusing, as we emitted "binary" there which is not valid).
Also replace some usages of that method with proper printing.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 166 |
2 files changed, 10 insertions, 158 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 2e3a5cf23..8f0d4f9c8 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -310,7 +310,7 @@ void AsmConstWalker::visitCall(Call* curr) { } } - Fatal() << "Unexpected arg0 type (" << getExpressionName(arg) + Fatal() << "Unexpected arg0 type (" << *arg << ") in call to: " << importName; } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 2921f4974..690c96f67 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -102,164 +102,16 @@ void Expression::dump() { std::cout << *this << '\n'; } const char* getExpressionName(Expression* curr) { switch (curr->_id) { - case Expression::Id::InvalidId: - WASM_UNREACHABLE("invalid expr id"); - case Expression::Id::BlockId: - return "block"; - case Expression::Id::IfId: - return "if"; - case Expression::Id::LoopId: - return "loop"; - case Expression::Id::BreakId: - return "break"; - case Expression::Id::SwitchId: - return "switch"; - case Expression::Id::CallId: - return "call"; - case Expression::Id::CallIndirectId: - return "call_indirect"; - case Expression::Id::LocalGetId: - return "local.get"; - case Expression::Id::LocalSetId: - return "local.set"; - case Expression::Id::GlobalGetId: - return "global.get"; - case Expression::Id::GlobalSetId: - return "global.set"; - case Expression::Id::LoadId: - return "load"; - case Expression::Id::StoreId: - return "store"; - case Expression::Id::ConstId: - return "const"; - case Expression::Id::UnaryId: - return "unary"; - case Expression::Id::BinaryId: - return "binary"; - case Expression::Id::SelectId: - return "select"; - case Expression::Id::DropId: - return "drop"; - case Expression::Id::ReturnId: - return "return"; - case Expression::Id::MemorySizeId: - return "memory.size"; - case Expression::Id::MemoryGrowId: - return "memory.grow"; - case Expression::Id::NopId: - return "nop"; - case Expression::Id::UnreachableId: - return "unreachable"; - case Expression::Id::AtomicCmpxchgId: - return "atomic.cmpxchg"; - case Expression::Id::AtomicRMWId: - return "atomic.rmw"; - case Expression::Id::AtomicWaitId: - return "atomic.wait"; - case Expression::Id::AtomicNotifyId: - return "atomic.notify"; - case Expression::Id::AtomicFenceId: - return "atomic.fence"; - case Expression::Id::SIMDExtractId: - return "simd_extract"; - case Expression::Id::SIMDReplaceId: - return "simd_replace"; - case Expression::Id::SIMDShuffleId: - return "simd_shuffle"; - case Expression::Id::SIMDTernaryId: - return "simd_ternary"; - case Expression::Id::SIMDShiftId: - return "simd_shift"; - case Expression::Id::SIMDLoadId: - return "simd_load"; - case Expression::Id::SIMDLoadStoreLaneId: - return "simd_load_store_lane"; - case Expression::Id::PrefetchId: - return "prefetch"; - case Expression::Id::MemoryInitId: - return "memory.init"; - case Expression::Id::DataDropId: - return "data.drop"; - case Expression::Id::MemoryCopyId: - return "memory.copy"; - case Expression::Id::MemoryFillId: - return "memory.fill"; - case Expression::Id::PopId: - return "pop"; - case Expression::Id::RefNullId: - return "ref.null"; - case Expression::Id::RefIsId: - switch (curr->cast<RefIs>()->op) { - case RefIsNull: - return "ref.is_null"; - case RefIsFunc: - return "ref.is_func"; - case RefIsData: - return "ref.is_data"; - case RefIsI31: - return "ref.is_i31"; - default: - WASM_UNREACHABLE("unimplemented ref.is_*"); - } - case Expression::Id::RefFuncId: - return "ref.func"; - case Expression::Id::RefEqId: - return "ref.eq"; - case Expression::Id::TryId: - return "try"; - case Expression::Id::ThrowId: - return "throw"; - case Expression::Id::RethrowId: - return "rethrow"; - case Expression::Id::TupleMakeId: - return "tuple.make"; - case Expression::Id::TupleExtractId: - return "tuple.extract"; - case Expression::Id::I31NewId: - return "i31.new"; - case Expression::Id::I31GetId: - return "i31.get"; - case Expression::Id::CallRefId: - return "call_ref"; - case Expression::Id::RefTestId: - return "ref.test"; - case Expression::Id::RefCastId: - return "ref.cast"; - case Expression::Id::BrOnCastId: - return "br_on_cast"; - case Expression::Id::RttCanonId: - return "rtt.canon"; - case Expression::Id::RttSubId: - return "rtt.sub"; - case Expression::Id::StructNewId: - return "struct.new"; - case Expression::Id::StructGetId: - return "struct.get"; - case Expression::Id::StructSetId: - return "struct.set"; - case Expression::Id::ArrayNewId: - return "array.new"; - case Expression::Id::ArrayGetId: - return "array.get"; - case Expression::Id::ArraySetId: - return "array.set"; - case Expression::Id::ArrayLenId: - return "array.len"; - case Expression::Id::RefAsId: - switch (curr->cast<RefAs>()->op) { - case RefAsFunc: - return "ref.as_func"; - case RefAsData: - return "ref.as_data"; - case RefAsI31: - return "ref.as_i31"; - default: - WASM_UNREACHABLE("unimplemented ref.is_*"); - } - case Expression::Id::NumExpressionIds: - WASM_UNREACHABLE("invalid expr id"); + +#define DELEGATE(CLASS_TO_VISIT) \ + case Expression::Id::CLASS_TO_VISIT##Id: \ + return #CLASS_TO_VISIT; + +#include "wasm-delegations.h" + + default: + WASM_UNREACHABLE("invalid id"); } - WASM_UNREACHABLE("invalid expr id"); } Literal getLiteralFromConstExpression(Expression* curr) { |