Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ class Literal {
assert(type == Type::funcref);
return func;
}
const ExceptionPackage& getExceptionPackage() const {
assert(type == Type::exnref);
return *exn.get();
}
ExceptionPackage getExceptionPackage() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move this body to the cpp? all the siblings are here it seems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ExceptionPackage is now returned by value, it needs to be a complete type at the point of this function definition. But the definition of ExceptionPackage can't move before the definition of Literal for the same reason, so the only choice was to move getExceptionPackage to be defined out of line, which means it needs to be in the .cpp file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks...


// careful!
int32_t* geti32Ptr() {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
if (flow.getType() == Type::nullref) {
trap("br_on_exn: argument is null");
}
const ExceptionPackage& ex = flow.getSingleValue().getExceptionPackage();
auto ex = flow.getSingleValue().getExceptionPackage();
if (curr->event != ex.event) { // Not taken
return flow;
}
Expand Down
18 changes: 14 additions & 4 deletions src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ Literal::Literal(const uint8_t init[16]) : type(Type::v128) {
memcpy(&v128, init, 16);
}

Literal::Literal(const Literal& other) { *this = other; }

Literal& Literal::operator=(const Literal& other) {
type = other.type;
Literal::Literal(const Literal& other) : type(other.type) {
TODO_SINGLE_COMPOUND(type);
switch (type.getBasic()) {
case Type::i32:
Expand All @@ -54,6 +51,7 @@ Literal& Literal::operator=(const Literal& other) {
func = other.func;
break;
case Type::exnref:
// Avoid calling the destructor on an uninitialized value
new (&exn) auto(std::make_unique<ExceptionPackage>(*other.exn));
break;
case Type::none:
Expand All @@ -63,6 +61,13 @@ Literal& Literal::operator=(const Literal& other) {
case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
}
}

Literal& Literal::operator=(const Literal& other) {
if (this != &other) {
this->~Literal();
new (this) auto(other);
}
return *this;
}

Expand Down Expand Up @@ -124,6 +129,11 @@ std::array<uint8_t, 16> Literal::getv128() const {
return ret;
}

ExceptionPackage Literal::getExceptionPackage() const {
assert(type == Type::exnref);
return *exn.get();
}

Literal Literal::castToF32() {
assert(type == Type::i32);
Literal ret(i32);
Expand Down