Skip to content
Open
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "test/spec"]
path = test/spec
url = https://github.com/WebAssembly/testsuite.git
[submodule "test/emscripten"]
path = test/emscripten
url = https://github.com/kripken/emscripten.git
30 changes: 15 additions & 15 deletions bin/wasm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ export_function "_BinaryenLeFloat64"
export_function "_BinaryenGtFloat64"
export_function "_BinaryenGeFloat64"
export_function "_BinaryenPageSize"
export_function "_BinaryenCurrentMemory"
export_function "_BinaryenGrowMemory"
export_function "_BinaryenMemorySize"
export_function "_BinaryenMemoryGrow"
export_function "_BinaryenHasFeature"
export_function "_BinaryenAtomicRMWAdd"
export_function "_BinaryenAtomicRMWSub"
Expand Down
2 changes: 1 addition & 1 deletion src/asm2wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
// exporting a function
IString value = pair[1]->getIString();
if (key == Name("_emscripten_replace_memory")) {
// asm.js memory growth provides this special non-asm function, which we don't need (we use grow_memory)
// asm.js memory growth provides this special non-asm function, which we don't need (we use memory.grow)
assert(!wasm.getFunctionOrNull(value));
continue;
} else if (key == UDIVMODDI4) {
Expand Down
4 changes: 2 additions & 2 deletions src/asmjs/shared-constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ cashew::IString GLOBAL("global"),
WASM_ROTL64("__wasm_rotl_i64"),
WASM_ROTR32("__wasm_rotr_i32"),
WASM_ROTR64("__wasm_rotr_i64"),
WASM_GROW_MEMORY("__wasm_grow_memory"),
WASM_CURRENT_MEMORY("__wasm_current_memory"),
WASM_MEMORY_GROW("__wasm_memory_grow"),
WASM_MEMORY_SIZE("__wasm_memory_size"),
WASM_FETCH_HIGH_BITS("__wasm_fetch_high_bits"),
INT64_TO_32_HIGH_BITS("i64toi32_i32$HIGH_BITS"),
WASM_NEAREST_F32("__wasm_nearest_f32"),
Expand Down
4 changes: 2 additions & 2 deletions src/asmjs/shared-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ extern cashew::IString GLOBAL,
WASM_ROTL64,
WASM_ROTR32,
WASM_ROTR64,
WASM_GROW_MEMORY,
WASM_CURRENT_MEMORY,
WASM_MEMORY_GROW,
WASM_MEMORY_SIZE,
WASM_FETCH_HIGH_BITS,
INT64_TO_32_HIGH_BITS,
WASM_NEAREST_F32,
Expand Down
4 changes: 2 additions & 2 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ BinaryenOp BinaryenLeFloat64(void) { return LeFloat64; }
BinaryenOp BinaryenGtFloat64(void) { return GtFloat64; }
BinaryenOp BinaryenGeFloat64(void) { return GeFloat64; }
BinaryenOp BinaryenPageSize(void) { return PageSize; }
BinaryenOp BinaryenCurrentMemory(void) { return CurrentMemory; }
BinaryenOp BinaryenGrowMemory(void) { return GrowMemory; }
BinaryenOp BinaryenMemorySize(void) { return MemorySize; }
BinaryenOp BinaryenMemoryGrow(void) { return MemoryGrow; }
BinaryenOp BinaryenHasFeature(void) { return HasFeature; }
BinaryenOp BinaryenAtomicRMWAdd(void) { return AtomicRMWOp::Add; }
BinaryenOp BinaryenAtomicRMWSub(void) { return AtomicRMWOp::Sub; }
Expand Down
4 changes: 2 additions & 2 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ BinaryenOp BinaryenLeFloat64(void);
BinaryenOp BinaryenGtFloat64(void);
BinaryenOp BinaryenGeFloat64(void);
BinaryenOp BinaryenPageSize(void);
BinaryenOp BinaryenCurrentMemory(void);
BinaryenOp BinaryenGrowMemory(void);
BinaryenOp BinaryenMemorySize(void);
BinaryenOp BinaryenMemoryGrow(void);
BinaryenOp BinaryenHasFeature(void);
BinaryenOp BinaryenAtomicRMWAdd(void);
BinaryenOp BinaryenAtomicRMWSub(void);
Expand Down
6 changes: 3 additions & 3 deletions src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer> {
// can't move them in a way that would cause other noticeable
// (global) side effects
bool isAtomic = false; // An atomic load/store/RMW/Cmpxchg or an operator that
// has a defined ordering wrt atomics (e.g. grow_memory)
// has a defined ordering wrt atomics (e.g. memory.grow)

bool accessesLocal() { return localsRead.size() + localsWritten.size() > 0; }
bool accessesGlobal() { return globalsRead.size() + globalsWritten.size() > 0; }
Expand Down Expand Up @@ -268,9 +268,9 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer> {
void visitReturn(Return *curr) { branches = true; }
void visitHost(Host *curr) {
calls = true;
// grow_memory modifies the set of valid addresses, and thus can be modeled as modifying memory
// memory.grow modifies the set of valid addresses, and thus can be modeled as modifying memory
writesMemory = true;
// Atomics are also sequentially consistent with grow_memory.
// Atomics are also sequentially consistent with memory.grow.
isAtomic = true;
}
void visitUnreachable(Unreachable *curr) { branches = true; }
Expand Down
12 changes: 6 additions & 6 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ Module['LeFloat64'] = Module['_BinaryenLeFloat64']();
Module['GtFloat64'] = Module['_BinaryenGtFloat64']();
Module['GeFloat64'] = Module['_BinaryenGeFloat64']();
Module['PageSize'] = Module['_BinaryenPageSize']();
Module['CurrentMemory'] = Module['_BinaryenCurrentMemory']();
Module['GrowMemory'] = Module['_BinaryenGrowMemory']();
Module['MemorySize'] = Module['_BinaryenMemorySize']();
Module['MemoryGrow'] = Module['_BinaryenMemoryGrow']();
Module['HasFeature'] = Module['_BinaryenHasFeature']();
Module['AtomicRMWAdd'] = Module['_BinaryenAtomicRMWAdd']();
Module['AtomicRMWSub'] = Module['_BinaryenAtomicRMWSub']();
Expand Down Expand Up @@ -277,11 +277,11 @@ Module['Module'] = function(module) {
this['setGlobal'] = this['set_global'] = function(name, value) {
return Module['_BinaryenSetGlobal'](module, strToStack(name), value);
}
this['currentMemory'] = this['current_memory'] = function() {
return Module['_BinaryenHost'](module, Module['CurrentMemory']);
this['memorySize'] = this['memory_size'] = function() {
return Module['_BinaryenHost'](module, Module['MemorySize']);
}
this['growMemory'] = this['grow_memory'] = function(value) {
return Module['_BinaryenHost'](module, Module['GrowMemory'], null, i32sToStack([value]), 1);
this['memoryGrow'] = this['memory_grow'] = function(value) {
return Module['_BinaryenHost'](module, Module['MemoryGrow'], null, i32sToStack([value]), 1);
}
this['hasFeature'] = this['has_feature'] = function(name) {
return Module['_BinaryenHost'](module, Module['HasFeature'], strToStack(name));
Expand Down
6 changes: 3 additions & 3 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ struct PrintExpressionContents : public Visitor<PrintExpressionContents> {
void visitHost(Host* curr) {
switch (curr->op) {
case PageSize: printMedium(o, "pagesize"); break;
case CurrentMemory: printMedium(o, "current_memory"); break;
case GrowMemory: printMedium(o, "grow_memory"); break;
case MemorySize: printMedium(o, "memory.size"); break;
case MemoryGrow: printMedium(o, "memory.grow"); break;
case HasFeature: printMedium(o, "hasfeature ") << curr->nameOperand; break;
default: WASM_UNREACHABLE();
}
Expand Down Expand Up @@ -767,7 +767,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
switch (curr->op) {
case GrowMemory: {
case MemoryGrow: {
incIndent();
printFullLine(curr->operands[0]);
decIndent();
Expand Down
2 changes: 1 addition & 1 deletion src/passes/RemoveUnusedModuleElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
usesMemory = true;
}
void visitHost(Host* curr) {
if (curr->op == CurrentMemory || curr->op == GrowMemory) {
if (curr->op == MemorySize || curr->op == MemoryGrow) {
usesMemory = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ struct ShellExternalInterface final : ModuleInstance::ExternalInterface {
void store32(Address addr, int32_t value) override { memory.set<int32_t>(addr, value); }
void store64(Address addr, int64_t value) override { memory.set<int64_t>(addr, value); }

void growMemory(Address /*oldSize*/, Address newSize) override {
void memoryGrow(Address /*oldSize*/, Address newSize) override {
memory.resize(newSize);
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/wasm-ctor-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
void store32(Address addr, int32_t value) override { doStore<int32_t>(addr, value); }
void store64(Address addr, int64_t value) override { doStore<int64_t>(addr, value); }

void growMemory(Address /*oldSize*/, Address newSize) override {
throw FailToEvalException("grow memory");
void memoryGrow(Address /*oldSize*/, Address newSize) override {
throw FailToEvalException("memory.grow");
}

void trap(const char* why) override {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ enum ASTNodes {
I64StoreMem16 = 0x3d,
I64StoreMem32 = 0x3e,

CurrentMemory = 0x3f,
GrowMemory = 0x40,
MemorySize = 0x3f,
MemoryGrow = 0x40,

I32Const = 0x41,
I64Const = 0x42,
Expand Down
8 changes: 4 additions & 4 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class ModuleInstanceBase {
virtual void importGlobals(GlobalManager& globals, Module& wasm) = 0;
virtual Literal callImport(Import* import, LiteralList& arguments) = 0;
virtual Literal callTable(Index index, LiteralList& arguments, Type result, SubType& instance) = 0;
virtual void growMemory(Address oldSize, Address newSize) = 0;
virtual void memoryGrow(Address oldSize, Address newSize) = 0;
virtual void trap(const char* why) = 0;

// the default impls for load and store switch on the sizes. you can either
Expand Down Expand Up @@ -926,8 +926,8 @@ class ModuleInstanceBase {
NOTE_ENTER("Host");
switch (curr->op) {
case PageSize: return Literal((int32_t)Memory::kPageSize);
case CurrentMemory: return Literal(int32_t(instance.memorySize));
case GrowMemory: {
case MemorySize: return Literal(int32_t(instance.memorySize));
case MemoryGrow: {
auto fail = Literal(int32_t(-1));
Flow flow = this->visit(curr->operands[0]);
if (flow.breaking()) return flow;
Expand All @@ -937,7 +937,7 @@ class ModuleInstanceBase {
if (instance.memorySize >= uint32_t(-1) - delta) return fail;
uint32_t newSize = instance.memorySize + delta;
if (newSize > instance.wasm.memory.max) return fail;
instance.externalInterface->growMemory(instance.memorySize * Memory::kPageSize, newSize * Memory::kPageSize);
instance.externalInterface->memoryGrow(instance.memorySize * Memory::kPageSize, newSize * Memory::kPageSize);
instance.memorySize = newSize;
return Literal(int32_t(ret));
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() {
}
}

void growMemory(Address oldSize, Address newSize) override {
void memoryGrow(Address oldSize, Address newSize) override {
EM_ASM_({
var size = $0;
var buffer;
Expand Down
12 changes: 6 additions & 6 deletions src/wasm-stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,23 +1084,23 @@ template<StackWriterMode Mode, typename Parent>
void StackWriter<Mode, Parent>::visitHost(Host* curr) {
if (debug) std::cerr << "zz node: Host" << std::endl;
switch (curr->op) {
case CurrentMemory: {
case MemorySize: {
break;
}
case GrowMemory: {
case MemoryGrow: {
visitChild(curr->operands[0]);
break;
}
default: WASM_UNREACHABLE();
}
if (justAddToStack(curr)) return;
switch (curr->op) {
case CurrentMemory: {
o << int8_t(BinaryConsts::CurrentMemory);
case MemorySize: {
o << int8_t(BinaryConsts::MemorySize);
break;
}
case GrowMemory: {
o << int8_t(BinaryConsts::GrowMemory);
case MemoryGrow: {
o << int8_t(BinaryConsts::MemoryGrow);
break;
}
default: WASM_UNREACHABLE();
Expand Down
2 changes: 1 addition & 1 deletion src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ enum BinaryOp {
};

enum HostOp {
PageSize, CurrentMemory, GrowMemory, HasFeature
PageSize, MemorySize, MemoryGrow, HasFeature
};

enum AtomicRMWOp {
Expand Down
10 changes: 5 additions & 5 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2374,15 +2374,15 @@ void WasmBinaryBuilder::visitReturn(Return* curr) {
bool WasmBinaryBuilder::maybeVisitHost(Expression*& out, uint8_t code) {
Host* curr;
switch (code) {
case BinaryConsts::CurrentMemory: {
case BinaryConsts::MemorySize: {
curr = allocator.alloc<Host>();
curr->op = CurrentMemory;
curr->op = MemorySize;
curr->type = i32;
break;
}
case BinaryConsts::GrowMemory: {
case BinaryConsts::MemoryGrow: {
curr = allocator.alloc<Host>();
curr->op = GrowMemory;
curr->op = MemoryGrow;
curr->operands.resize(1);
curr->operands[0] = popNonVoidExpression();
break;
Expand All @@ -2391,7 +2391,7 @@ bool WasmBinaryBuilder::maybeVisitHost(Expression*& out, uint8_t code) {
}
if (debug) std::cerr << "zz node: Host" << std::endl;
auto reserved = getU32LEB();
if (reserved != 0) throwError("Invalid reserved field on grow_memory/current_memory");
if (reserved != 0) throwError("Invalid reserved field on memory.grow/memory.size");
curr->finalize();
out = curr;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Function* EmscriptenGlueGenerator::generateMemoryGrowthFunction() {
name, std::move(params), i32, {}
);
growFunction->body = builder.makeHost(
GrowMemory,
MemoryGrow,
Name(),
{ builder.makeGetLocal(0, i32) }
);
Expand Down
17 changes: 13 additions & 4 deletions src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,22 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
const char *str = id.str;
const char *dot = strchr(str, '.');
if (dot) {
// memory.
if (str[0] == 'm') {
// memory.size
if (str[7] == 's') return makeHost(s, HostOp::MemorySize);
// memory.grow
if (str[7] == 'g') return makeHost(s, HostOp::MemoryGrow);
abort_on(str);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the changes so far are naive find-and-replaces with case sensitivity. I've fixed a few spots where I found that it made things incorrect. e.g. memory.size() vs memory_size() but there might be others.

This was one such spot, where I needed to change the parser itself because it assumed that anything with a dot was i32|i64|f32|f64 operations.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, yeah, that's what I was thinking before I saw this comment.

In general I'd say if the test suite passes we should be good - we have good coverage of this stuff.

// type.operation (e.g. i32.add)
Type type = stringToType(str, false, true);
// Local copy to index into op without bounds checking.
enum { maxNameSize = 15 };
char op[maxNameSize + 1] = {'\0'};
strncpy(op, dot + 1, maxNameSize);

#define BINARY_INT_OR_FLOAT(op) (type == i32 ? BinaryOp::op##Int32 : (type == i64 ? BinaryOp::op##Int64 : (type == f32 ? BinaryOp::op##Float32 : BinaryOp::op##Float64)))
#define BINARY_INT(op) (type == i32 ? BinaryOp::op##Int32 : BinaryOp::op##Int64)
#define BINARY_FLOAT(op) (type == f32 ? BinaryOp::op##Float32 : BinaryOp::op##Float64)
Expand Down Expand Up @@ -812,7 +822,7 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
if (id == CALL) return makeCall(s);
if (id == CALL_IMPORT) return makeCallImport(s);
if (id == CALL_INDIRECT) return makeCallIndirect(s);
} else if (str[1] == 'u') return makeHost(s, HostOp::CurrentMemory);
}
abort_on(str);
}
case 'd': {
Expand All @@ -828,7 +838,6 @@ Expression* SExpressionWasmBuilder::makeExpression(Element& s) {
if (str[4] == 'l') return makeGetLocal(s);
if (str[4] == 'g') return makeGetGlobal(s);
}
if (str[1] == 'r') return makeHost(s, HostOp::GrowMemory);
abort_on(str);
}
case 'h': {
Expand Down Expand Up @@ -980,9 +989,9 @@ Expression* SExpressionWasmBuilder::makeHost(Element& s, HostOp op) {
} else {
parseCallOperands(s, 1, s.size(), ret);
}
if (ret->op == HostOp::GrowMemory) {
if (ret->op == HostOp::MemoryGrow) {
if (ret->operands.size() != 1) {
throw ParseException("grow_memory needs one operand");
throw ParseException("memory.grow needs one operand");
}
} else {
if (ret->operands.size() != 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,13 @@ void FunctionValidator::visitReturn(Return* curr) {

void FunctionValidator::visitHost(Host* curr) {
switch (curr->op) {
case GrowMemory: {
shouldBeEqual(curr->operands.size(), size_t(1), curr, "grow_memory must have 1 operand");
shouldBeEqualOrFirstIsUnreachable(curr->operands[0]->type, i32, curr, "grow_memory must have i32 operand");
case MemoryGrow: {
shouldBeEqual(curr->operands.size(), size_t(1), curr, "memory.grow must have 1 operand");
shouldBeEqualOrFirstIsUnreachable(curr->operands[0]->type, i32, curr, "memory.grow must have i32 operand");
break;
}
case PageSize:
case CurrentMemory:
case MemorySize:
case HasFeature: break;
default: WASM_UNREACHABLE();
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ void Drop::finalize() {

void Host::finalize() {
switch (op) {
case PageSize: case CurrentMemory: case HasFeature: {
case PageSize: case MemorySize: case HasFeature: {
type = i32;
break;
}
case GrowMemory: {
case MemoryGrow: {
// if the single operand is not reachable, so are we
if (operands[0]->type == unreachable) {
type = unreachable;
Expand Down
Loading