Skip to content

Commit

Permalink
new export syntax in spec repo
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Sep 2, 2016
1 parent c558ec2 commit 11b45e1
Show file tree
Hide file tree
Showing 34 changed files with 307 additions and 288 deletions.
39 changes: 23 additions & 16 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,21 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
void visitExport(Export *curr) {
printOpening(o, "export ");
printText(o, curr->name.str) << ' ';
printText(o, curr->name.str) << " (";
switch (curr->kind) {
case Export::Function: printName(curr->value); break;
case Export::Table: o << "table"; break;
case Export::Memory: o << "memory"; break;
case Export::Global: o << "global "; printName(curr->value); break;
case Export::Function: o << "func"; break;
case Export::Table: o << "table"; break;
case Export::Memory: o << "memory"; break;
case Export::Global: o << "global"; break;
default: WASM_UNREACHABLE();
}
o << ')';
o << ' ';
printName(curr->value) << "))";
}
void visitGlobal(Global *curr) {
printOpening(o, "global ");
printName(curr->name) << ' ' << printWasmType(curr->type) << ' ';
printName(curr->name) << ' ';
o << printWasmType(curr->type) << ' ';
visit(curr->init);
o << ')';
}
Expand Down Expand Up @@ -598,7 +600,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
decIndent();
}
void visitTable(Table *curr) {
printOpening(o, "table") << ' ' << curr->initial;
printOpening(o, "table") << ' ';
o << curr->initial;
if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max;
o << " anyfunc)\n";
doIndent(o, indent);
Expand All @@ -612,15 +615,12 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
o << ')';
}
}
void visitModule(Module *curr) {
currModule = curr;
printOpening(o, "module", true);
incIndent();
doIndent(o, indent);
printOpening(o, "memory") << ' ' << curr->memory.initial;
if (curr->memory.max && curr->memory.max != Memory::kMaxSize) o << ' ' << curr->memory.max;
void visitMemory(Memory* curr) {
printOpening(o, "memory") << ' ';
o << curr->initial;
if (curr->max && curr->max != Memory::kMaxSize) o << ' ' << curr->max;
o << ")\n";
for (auto segment : curr->memory.segments) {
for (auto segment : curr->segments) {
doIndent(o, indent);
printOpening(o, "data ", true);
visit(segment.offset);
Expand All @@ -647,6 +647,13 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
o << "\")\n";
}
}
void visitModule(Module *curr) {
currModule = curr;
printOpening(o, "module", true);
incIndent();
doIndent(o, indent);
visitMemory(&curr->memory);
if (curr->start.is()) {
doIndent(o, indent);
printOpening(o, "start") << ' ' << curr->start << ')';
Expand Down
6 changes: 6 additions & 0 deletions src/wasm-s-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ class SExpressionWasmBuilder {
void preParseFunctionType(Element& s) {
IString id = s[0]->str();
if (id == TYPE) return parseType(s);
/*
if (id == EXPORT && s.size() == 3 && s[2]->isList() && (*s[2])[0]->str() == FUNC) {
preParseFunctionType(*s[2]);
return;
}
*/
if (id != FUNC) return;
size_t i = 1;
Name name, exportName;
Expand Down
14 changes: 10 additions & 4 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ class Export {
Global = 3,
};

Name name; // exported name
Name name; // exported name - note that this is the key, as the internal name is non-unique (can have multiple exports for an internal, also over kinds)
Name value; // internal name
Kind kind;
};
Expand All @@ -1474,10 +1474,13 @@ class Table {
}
};

Name name;
Address initial, max;
std::vector<Segment> segments;

Table() : initial(0), max(kMaxSize) {}
Table() : initial(0), max(kMaxSize) {
name = Name::fromInt(0);
}
};

class Memory {
Expand All @@ -1499,10 +1502,13 @@ class Memory {
}
};

Name name;
Address initial, max; // sizes are in pages
std::vector<Segment> segments;

Memory() : initial(0), max(kMaxSize) {}
Memory() : initial(0), max(kMaxSize) {
name = Name::fromInt(0);
}
};

class Global {
Expand Down Expand Up @@ -1531,7 +1537,7 @@ class Module {
// TODO: add a build option where Names are just indices, and then these methods are not needed
std::map<Name, FunctionType*> functionTypesMap;
std::map<Name, Import*> importsMap;
std::map<Name, Export*> exportsMap;
std::map<Name, Export*> exportsMap; // exports map is by the *exported* name, which is unique
std::map<Name, Function*> functionsMap;
std::map<Name, Global*> globalsMap;

Expand Down
36 changes: 18 additions & 18 deletions test/emcc_O2_hello_world.fromasm
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
(import "env" "table" (table $table))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(export "_free" $_free)
(export "_main" $_main)
(export "_memset" $_memset)
(export "_malloc" $_malloc)
(export "_memcpy" $_memcpy)
(export "_fflush" $_fflush)
(export "___errno_location" $___errno_location)
(export "runPostSets" $runPostSets)
(export "stackAlloc" $stackAlloc)
(export "stackSave" $stackSave)
(export "stackRestore" $stackRestore)
(export "establishStackSpace" $establishStackSpace)
(export "setThrew" $setThrew)
(export "setTempRet0" $setTempRet0)
(export "getTempRet0" $getTempRet0)
(export "dynCall_ii" $dynCall_ii)
(export "dynCall_iiii" $dynCall_iiii)
(export "dynCall_vi" $dynCall_vi)
(export "_free" (func $_free))
(export "_main" (func $_main))
(export "_memset" (func $_memset))
(export "_malloc" (func $_malloc))
(export "_memcpy" (func $_memcpy))
(export "_fflush" (func $_fflush))
(export "___errno_location" (func $___errno_location))
(export "runPostSets" (func $runPostSets))
(export "stackAlloc" (func $stackAlloc))
(export "stackSave" (func $stackSave))
(export "stackRestore" (func $stackRestore))
(export "establishStackSpace" (func $establishStackSpace))
(export "setThrew" (func $setThrew))
(export "setTempRet0" (func $setTempRet0))
(export "getTempRet0" (func $getTempRet0))
(export "dynCall_ii" (func $dynCall_ii))
(export "dynCall_iiii" (func $dynCall_iiii))
(export "dynCall_vi" (func $dynCall_vi))
(global $__THREW__ i32 (i32.const 0))
(global $threwValue i32 (i32.const 0))
(global $setjmpId i32 (i32.const 0))
Expand Down
36 changes: 18 additions & 18 deletions test/emcc_O2_hello_world.fromasm.imprecise
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
(import "env" "table" (table $table))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(export "_free" $_free)
(export "_main" $_main)
(export "_memset" $_memset)
(export "_malloc" $_malloc)
(export "_memcpy" $_memcpy)
(export "_fflush" $_fflush)
(export "___errno_location" $___errno_location)
(export "runPostSets" $runPostSets)
(export "stackAlloc" $stackAlloc)
(export "stackSave" $stackSave)
(export "stackRestore" $stackRestore)
(export "establishStackSpace" $establishStackSpace)
(export "setThrew" $setThrew)
(export "setTempRet0" $setTempRet0)
(export "getTempRet0" $getTempRet0)
(export "dynCall_ii" $dynCall_ii)
(export "dynCall_iiii" $dynCall_iiii)
(export "dynCall_vi" $dynCall_vi)
(export "_free" (func $_free))
(export "_main" (func $_main))
(export "_memset" (func $_memset))
(export "_malloc" (func $_malloc))
(export "_memcpy" (func $_memcpy))
(export "_fflush" (func $_fflush))
(export "___errno_location" (func $___errno_location))
(export "runPostSets" (func $runPostSets))
(export "stackAlloc" (func $stackAlloc))
(export "stackSave" (func $stackSave))
(export "stackRestore" (func $stackRestore))
(export "establishStackSpace" (func $establishStackSpace))
(export "setThrew" (func $setThrew))
(export "setTempRet0" (func $setTempRet0))
(export "getTempRet0" (func $getTempRet0))
(export "dynCall_ii" (func $dynCall_ii))
(export "dynCall_iiii" (func $dynCall_iiii))
(export "dynCall_vi" (func $dynCall_vi))
(global $__THREW__ i32 (i32.const 0))
(global $threwValue i32 (i32.const 0))
(global $setjmpId i32 (i32.const 0))
Expand Down
36 changes: 18 additions & 18 deletions test/emcc_O2_hello_world.fromasm.imprecise.no-opts
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
(import "env" "table" (table $table))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(export "_free" $_free)
(export "_main" $_main)
(export "_memset" $_memset)
(export "_malloc" $_malloc)
(export "_memcpy" $_memcpy)
(export "_fflush" $_fflush)
(export "___errno_location" $___errno_location)
(export "runPostSets" $runPostSets)
(export "stackAlloc" $stackAlloc)
(export "stackSave" $stackSave)
(export "stackRestore" $stackRestore)
(export "establishStackSpace" $establishStackSpace)
(export "setThrew" $setThrew)
(export "setTempRet0" $setTempRet0)
(export "getTempRet0" $getTempRet0)
(export "dynCall_ii" $dynCall_ii)
(export "dynCall_iiii" $dynCall_iiii)
(export "dynCall_vi" $dynCall_vi)
(export "_free" (func $_free))
(export "_main" (func $_main))
(export "_memset" (func $_memset))
(export "_malloc" (func $_malloc))
(export "_memcpy" (func $_memcpy))
(export "_fflush" (func $_fflush))
(export "___errno_location" (func $___errno_location))
(export "runPostSets" (func $runPostSets))
(export "stackAlloc" (func $stackAlloc))
(export "stackSave" (func $stackSave))
(export "stackRestore" (func $stackRestore))
(export "establishStackSpace" (func $establishStackSpace))
(export "setThrew" (func $setThrew))
(export "setTempRet0" (func $setTempRet0))
(export "getTempRet0" (func $getTempRet0))
(export "dynCall_ii" (func $dynCall_ii))
(export "dynCall_iiii" (func $dynCall_iiii))
(export "dynCall_vi" (func $dynCall_vi))
(global $__THREW__ i32 (i32.const 0))
(global $threwValue i32 (i32.const 0))
(global $setjmpId i32 (i32.const 0))
Expand Down
36 changes: 18 additions & 18 deletions test/emcc_O2_hello_world.fromasm.no-opts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@
(import "env" "table" (table $table))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(export "_free" $_free)
(export "_main" $_main)
(export "_memset" $_memset)
(export "_malloc" $_malloc)
(export "_memcpy" $_memcpy)
(export "_fflush" $_fflush)
(export "___errno_location" $___errno_location)
(export "runPostSets" $runPostSets)
(export "stackAlloc" $stackAlloc)
(export "stackSave" $stackSave)
(export "stackRestore" $stackRestore)
(export "establishStackSpace" $establishStackSpace)
(export "setThrew" $setThrew)
(export "setTempRet0" $setTempRet0)
(export "getTempRet0" $getTempRet0)
(export "dynCall_ii" $dynCall_ii)
(export "dynCall_iiii" $dynCall_iiii)
(export "dynCall_vi" $dynCall_vi)
(export "_free" (func $_free))
(export "_main" (func $_main))
(export "_memset" (func $_memset))
(export "_malloc" (func $_malloc))
(export "_memcpy" (func $_memcpy))
(export "_fflush" (func $_fflush))
(export "___errno_location" (func $___errno_location))
(export "runPostSets" (func $runPostSets))
(export "stackAlloc" (func $stackAlloc))
(export "stackSave" (func $stackSave))
(export "stackRestore" (func $stackRestore))
(export "establishStackSpace" (func $establishStackSpace))
(export "setThrew" (func $setThrew))
(export "setTempRet0" (func $setTempRet0))
(export "getTempRet0" (func $getTempRet0))
(export "dynCall_ii" (func $dynCall_ii))
(export "dynCall_iiii" (func $dynCall_iiii))
(export "dynCall_vi" (func $dynCall_vi))
(global $__THREW__ i32 (i32.const 0))
(global $threwValue i32 (i32.const 0))
(global $setjmpId i32 (i32.const 0))
Expand Down
46 changes: 23 additions & 23 deletions test/emcc_hello_world.fromasm
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@
(import "env" "table" (table $table))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(export "_i64Subtract" $_i64Subtract)
(export "_free" $_free)
(export "_main" $_main)
(export "_i64Add" $_i64Add)
(export "_memset" $_memset)
(export "_malloc" $_malloc)
(export "_memcpy" $_memcpy)
(export "_bitshift64Lshr" $_bitshift64Lshr)
(export "_fflush" $_fflush)
(export "___errno_location" $___errno_location)
(export "_bitshift64Shl" $_bitshift64Shl)
(export "runPostSets" $runPostSets)
(export "stackAlloc" $stackAlloc)
(export "stackSave" $stackSave)
(export "stackRestore" $stackRestore)
(export "establishStackSpace" $establishStackSpace)
(export "setThrew" $setThrew)
(export "setTempRet0" $setTempRet0)
(export "getTempRet0" $getTempRet0)
(export "dynCall_ii" $dynCall_ii)
(export "dynCall_iiii" $dynCall_iiii)
(export "dynCall_vi" $dynCall_vi)
(export "___udivmoddi4" $___udivmoddi4)
(export "_i64Subtract" (func $_i64Subtract))
(export "_free" (func $_free))
(export "_main" (func $_main))
(export "_i64Add" (func $_i64Add))
(export "_memset" (func $_memset))
(export "_malloc" (func $_malloc))
(export "_memcpy" (func $_memcpy))
(export "_bitshift64Lshr" (func $_bitshift64Lshr))
(export "_fflush" (func $_fflush))
(export "___errno_location" (func $___errno_location))
(export "_bitshift64Shl" (func $_bitshift64Shl))
(export "runPostSets" (func $runPostSets))
(export "stackAlloc" (func $stackAlloc))
(export "stackSave" (func $stackSave))
(export "stackRestore" (func $stackRestore))
(export "establishStackSpace" (func $establishStackSpace))
(export "setThrew" (func $setThrew))
(export "setTempRet0" (func $setTempRet0))
(export "getTempRet0" (func $getTempRet0))
(export "dynCall_ii" (func $dynCall_ii))
(export "dynCall_iiii" (func $dynCall_iiii))
(export "dynCall_vi" (func $dynCall_vi))
(export "___udivmoddi4" (func $___udivmoddi4))
(global $__THREW__ i32 (i32.const 0))
(global $threwValue i32 (i32.const 0))
(global $setjmpId i32 (i32.const 0))
Expand Down
Loading

0 comments on commit 11b45e1

Please sign in to comment.