Skip to content
Closed
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
66 changes: 63 additions & 3 deletions src/ir/type-updating.h → src/ir/type-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

#ifndef wasm_ir_type_updating_h
#define wasm_ir_type_updating_h
#ifndef wasm_ir_type_utils_h
#define wasm_ir_type_utils_h

#include "wasm-traversal.h"

Expand Down Expand Up @@ -316,6 +316,66 @@ struct TypeUpdater
}
};

// core AST type checking
struct TypeSeeker : public PostWalker<TypeSeeker> {
Expression* target; // look for this one
Name targetName;
std::vector<Type> types;

TypeSeeker(Expression* target, Name targetName)
: target(target), targetName(targetName) {
Expression* temp = target;
walk(temp);
}

void visitBreak(Break* curr) {
if (curr->name == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}

void visitSwitch(Switch* curr) {
for (auto name : curr->targets) {
if (name == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}
if (curr->default_ == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}

void visitBrOnExn(BrOnExn* curr) {
if (curr->name == targetName) {
types.push_back(curr->sent);
}
}

void visitBlock(Block* curr) {
if (curr == target) {
if (curr->list.size() > 0) {
types.push_back(curr->list.back()->type);
} else {
types.push_back(none);
}
} else if (curr->name == targetName) {
// ignore all breaks til now, they were captured by someone with the same
// name
types.clear();
}
}

void visitLoop(Loop* curr) {
if (curr == target) {
types.push_back(curr->body->type);
} else if (curr->name == targetName) {
// ignore all breaks til now, they were captured by someone with the same
// name
types.clear();
}
}
};

} // namespace wasm

#endif // wasm_ir_type_updating_h
#endif // wasm_ir_type_utils_h
2 changes: 1 addition & 1 deletion src/passes/DeadCodeElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include <ir/block-utils.h>
#include <ir/branch-utils.h>
#include <ir/type-updating.h>
#include <ir/type-utils.h>
#include <pass.h>
#include <vector>
#include <wasm-builder.h>
Expand Down
2 changes: 1 addition & 1 deletion src/passes/Vacuum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <ir/block-utils.h>
#include <ir/effects.h>
#include <ir/literal-utils.h>
#include <ir/type-updating.h>
#include <ir/type-utils.h>
#include <ir/utils.h>
#include <pass.h>
#include <wasm-builder.h>
Expand Down
62 changes: 1 addition & 61 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "wasm.h"
#include "ir/branch-utils.h"
#include "ir/type-utils.h"
#include "wasm-traversal.h"

namespace wasm {
Expand Down Expand Up @@ -187,67 +188,6 @@ const char* getExpressionName(Expression* curr) {
WASM_UNREACHABLE();
}

// core AST type checking

struct TypeSeeker : public PostWalker<TypeSeeker> {
Expression* target; // look for this one
Name targetName;
std::vector<Type> types;

TypeSeeker(Expression* target, Name targetName)
: target(target), targetName(targetName) {
Expression* temp = target;
walk(temp);
}

void visitBreak(Break* curr) {
if (curr->name == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}

void visitSwitch(Switch* curr) {
for (auto name : curr->targets) {
if (name == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}
if (curr->default_ == targetName) {
types.push_back(curr->value ? curr->value->type : none);
}
}

void visitBrOnExn(BrOnExn* curr) {
if (curr->name == targetName) {
types.push_back(curr->sent);
}
}

void visitBlock(Block* curr) {
if (curr == target) {
if (curr->list.size() > 0) {
types.push_back(curr->list.back()->type);
} else {
types.push_back(none);
}
} else if (curr->name == targetName) {
// ignore all breaks til now, they were captured by someone with the same
// name
types.clear();
}
}

void visitLoop(Loop* curr) {
if (curr == target) {
types.push_back(curr->body->type);
} else if (curr->name == targetName) {
// ignore all breaks til now, they were captured by someone with the same
// name
types.clear();
}
}
};

static Type mergeTypes(std::vector<Type>& types) {
Type type = unreachable;
for (auto other : types) {
Expand Down