summaryrefslogtreecommitdiff
path: root/src/type.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/type.h')
-rw-r--r--src/type.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/type.h b/src/type.h
index 096471e5..64c71c7e 100644
--- a/src/type.h
+++ b/src/type.h
@@ -23,6 +23,7 @@
#include "config.h"
#include "src/base-types.h"
+#include "src/string-format.h"
namespace wabt {
@@ -57,9 +58,10 @@ class Type {
};
Type() = default; // Provided so Type can be member of a union.
- Type(int32_t code) : enum_(static_cast<Enum>(code)), index_(kInvalidIndex) {}
- Type(Enum e) : enum_(e), index_(kInvalidIndex) {}
- Type(Enum e, Index index) : enum_(e), index_(index) {
+ Type(int32_t code)
+ : enum_(static_cast<Enum>(code)), type_index_(kInvalidIndex) {}
+ Type(Enum e) : enum_(e), type_index_(kInvalidIndex) {}
+ Type(Enum e, Index type_index) : enum_(e), type_index_(type_index) {
assert(e == Enum::Reference);
}
operator Enum() const { return enum_; }
@@ -76,7 +78,7 @@ class Type {
return IsRef();
}
- const char* GetName() const {
+ std::string GetName() const {
switch (enum_) {
case Type::I32: return "i32";
case Type::I64: return "i64";
@@ -90,11 +92,10 @@ class Type {
case Type::Void: return "void";
case Type::Any: return "any";
case Type::ExternRef: return "externref";
-
- // TODO(dbezhetskov): add index for reference type.
case Type::Reference:
- return "reference";
- default: return "<type_index>";
+ return StringPrintf("(ref %d)", type_index_);
+ default:
+ return StringPrintf("<type_index[%d]>", enum_);
}
}
@@ -129,7 +130,7 @@ class Type {
Index GetReferenceIndex() const {
assert(enum_ == Enum::Reference);
- return index_;
+ return type_index_;
}
TypeVector GetInlineVector() const {
@@ -155,7 +156,7 @@ class Type {
private:
Enum enum_;
- Index index_;
+ Index type_index_; // Only used for for Type::Reference
};
} // namespace wabt