summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominic Chen <d.c.ddcc@gmail.com>2016-07-22 16:39:57 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-07-22 16:39:57 -0700
commit3dc2e2579199fb0457846a22b3759ef16531b3da (patch)
tree9be92a57f899b1793c172fcd1a982c1e7959a1a5 /src
parentb17a18ada8a6b4bdc8fcd9957f88f566bcbfa766 (diff)
downloadbinaryen-3dc2e2579199fb0457846a22b3759ef16531b3da.tar.gz
binaryen-3dc2e2579199fb0457846a22b3759ef16531b3da.tar.bz2
binaryen-3dc2e2579199fb0457846a22b3759ef16531b3da.zip
Fix trailing whitespace, single-character strings, checking map element presence, and eliminate explicit index counter (#633)
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp22
-rw-r--r--src/s2wasm.h1
-rw-r--r--src/wasm-binary.h8
-rw-r--r--src/wasm-s-parser.h2
-rw-r--r--src/wasm.h86
5 files changed, 55 insertions, 64 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index e967d1850..47e503fa4 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -181,7 +181,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printName(curr->name);
if (!curr->value || curr->value->is<Nop>()) {
// avoid a new line just for the parens
- o << ")";
+ o << ')';
return;
}
incIndent();
@@ -195,9 +195,9 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
void visitSwitch(Switch *curr) {
printOpening(o, "br_table");
for (auto& t : curr->targets) {
- o << " " << t;
+ o << ' ' << t;
}
- o << " " << curr->default_;
+ o << ' ' << curr->default_;
incIndent();
if (curr->value && !curr->value->is<Nop>()) printFullLine(curr->value);
printFullLine(curr->condition);
@@ -470,7 +470,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
printOpening(o, "return");
if (!curr->value || curr->value->is<Nop>()) {
// avoid a new line just for the parens
- o << ")";
+ o << ')';
return;
}
incIndent();
@@ -549,17 +549,17 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
if (curr->params.size() > 0) {
for (size_t i = 0; i < curr->params.size(); i++) {
o << maybeSpace;
- printMinorOpening(o, "param ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ")";
+ printMinorOpening(o, "param ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ')';
}
}
if (curr->result != none) {
o << maybeSpace;
- printMinorOpening(o, "result ") << printWasmType(curr->result) << ")";
+ printMinorOpening(o, "result ") << printWasmType(curr->result) << ')';
}
incIndent();
for (size_t i = curr->getVarIndexBase(); i < curr->getNumLocals(); i++) {
doIndent(o, indent);
- printMinorOpening(o, "local ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ")";
+ printMinorOpening(o, "local ") << printableLocal(i) << ' ' << printWasmType(curr->getLocalType(i)) << ')';
o << maybeNewLine;
}
// It is ok to emit a block here, as a function can directly contain a list, even if our
@@ -587,8 +587,8 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
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;
+ printOpening(o, "memory") << ' ' << curr->memory.initial;
+ if (curr->memory.max && curr->memory.max != Memory::kMaxSize) o << ' ' << curr->memory.max;
for (auto segment : curr->memory.segments) {
o << maybeNewLine;
o << (minify ? "" : " ") << "(segment " << segment.offset << " \"";
@@ -614,7 +614,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
o << "\")";
}
- o << ((curr->memory.segments.size() > 0 && !minify) ? "\n " : "") << ")";
+ o << ((curr->memory.segments.size() > 0 && !minify) ? "\n " : "") << ')';
o << maybeNewLine;
if (curr->memory.exportName.is()) {
doIndent(o, indent);
@@ -624,7 +624,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> {
}
if (curr->start.is()) {
doIndent(o, indent);
- printOpening(o, "start") << " " << curr->start << ")";
+ printOpening(o, "start") << ' ' << curr->start << ')';
o << maybeNewLine;
}
for (auto& child : curr->functionTypes) {
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 8595bdb44..729e060f9 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -862,7 +862,6 @@ class S2WasmBuilder {
assert(type == funcType->result);
auto* indirect = builder.makeCallIndirect(funcType, target, std::move(operands));
setOutput(indirect, assign);
-
} else {
// non-indirect call
Name assign = getAssign();
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index bb2b9b1fc..aad142d44 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -715,11 +715,11 @@ public:
std::map<Name, uint32_t> mappedImports; // name of the Import => index
uint32_t getImportIndex(Name name) {
if (!mappedImports.size()) {
- // Create name => index mapping.
+ // Create name => index mapping.
for (size_t i = 0; i < wasm->imports.size(); i++) {
assert(mappedImports.count(wasm->imports[i]->name) == 0);
mappedImports[wasm->imports[i]->name] = i;
- }
+ }
}
assert(mappedImports.count(name));
return mappedImports[name];
@@ -728,11 +728,11 @@ public:
std::map<Name, uint32_t> mappedFunctions; // name of the Function => index
uint32_t getFunctionIndex(Name name) {
if (!mappedFunctions.size()) {
- // Create name => index mapping.
+ // Create name => index mapping.
for (size_t i = 0; i < wasm->functions.size(); i++) {
assert(mappedFunctions.count(wasm->functions[i]->name) == 0);
mappedFunctions[wasm->functions[i]->name] = i;
- }
+ }
}
assert(mappedFunctions.count(name));
return mappedFunctions[name];
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index b93494c76..8f62c8af8 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -170,7 +170,7 @@ private:
curr = stack.back();
assert(stack.size());
stack.pop_back();
- curr->list().push_back(last);
+ curr->list().push_back(last);
} else {
curr->list().push_back(parseString());
}
diff --git a/src/wasm.h b/src/wasm.h
index f3eee7375..5c1baaf09 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1251,35 +1251,35 @@ public:
switch (op) {
case EqFloat64:
case NeFloat64:
- case LtFloat64:
- case LeFloat64:
- case GtFloat64:
+ case LtFloat64:
+ case LeFloat64:
+ case GtFloat64:
case GeFloat64:
- case EqInt32:
+ case EqInt32:
case NeInt32:
- case LtSInt32:
- case LtUInt32:
- case LeSInt32:
- case LeUInt32:
- case GtSInt32:
- case GtUInt32:
- case GeSInt32:
+ case LtSInt32:
+ case LtUInt32:
+ case LeSInt32:
+ case LeUInt32:
+ case GtSInt32:
+ case GtUInt32:
+ case GeSInt32:
case GeUInt32:
- case EqInt64:
+ case EqInt64:
case NeInt64:
- case LtSInt64:
- case LtUInt64:
- case LeSInt64:
- case LeUInt64:
- case GtSInt64:
- case GtUInt64:
- case GeSInt64:
+ case LtSInt64:
+ case LtUInt64:
+ case LeSInt64:
+ case LeUInt64:
+ case GtSInt64:
+ case GtUInt64:
+ case GeSInt64:
case GeUInt64:
- case EqFloat32:
+ case EqFloat32:
case NeFloat32:
- case LtFloat32:
- case LeFloat32:
- case GtFloat32:
+ case LtFloat32:
+ case LeFloat32:
+ case GtFloat32:
case GeFloat32: return true;
default: return false;
}
@@ -1487,7 +1487,7 @@ private:
std::map<Name, Global*> globalsMap;
public:
- Module() : functionTypeIndex(0), importIndex(0), exportIndex(0), functionIndex(0), globalIndex(0) {}
+ Module() {};
FunctionType* getFunctionType(Index i) { assert(i < functionTypes.size()); return functionTypes[i].get(); }
Import* getImport(Index i) { assert(i < imports.size()); return imports[i].get(); }
@@ -1495,17 +1495,17 @@ public:
Function* getFunction(Index i) { assert(i < functions.size()); return functions[i].get(); }
Global* getGlobal(Index i) { assert(i < globals.size()); return globals[i].get(); }
- FunctionType* getFunctionType(Name name) { assert(functionTypesMap[name]); return functionTypesMap[name]; }
- Import* getImport(Name name) { assert(importsMap[name]); return importsMap[name]; }
- Export* getExport(Name name) { assert(exportsMap[name]); return exportsMap[name]; }
- Function* getFunction(Name name) { assert(functionsMap[name]); return functionsMap[name]; }
- Global* getGlobal(Name name) { assert(globalsMap[name]); return globalsMap[name]; }
+ FunctionType* getFunctionType(Name name) { assert(functionTypesMap.count(name)); return functionTypesMap[name]; }
+ Import* getImport(Name name) { assert(importsMap.count(name)); return importsMap[name]; }
+ Export* getExport(Name name) { assert(exportsMap.count(name)); return exportsMap[name]; }
+ Function* getFunction(Name name) { assert(functionsMap.count(name)); return functionsMap[name]; }
+ Global* getGlobal(Name name) { assert(globalsMap.count(name)); return globalsMap[name]; }
- FunctionType* checkFunctionType(Name name) { if (functionTypesMap.find(name) == functionTypesMap.end()) return nullptr; return functionTypesMap[name]; }
- Import* checkImport(Name name) { if (importsMap.find(name) == importsMap.end()) return nullptr; return importsMap[name]; }
- Export* checkExport(Name name) { if (exportsMap.find(name) == exportsMap.end()) return nullptr; return exportsMap[name]; }
- Function* checkFunction(Name name) { if (functionsMap.find(name) == functionsMap.end()) return nullptr; return functionsMap[name]; }
- Global* checkGlobal(Name name) { if (globalsMap.find(name) == globalsMap.end()) return nullptr; return globalsMap[name]; }
+ FunctionType* checkFunctionType(Name name) { if (!functionTypesMap.count(name)) return nullptr; return functionTypesMap[name]; }
+ Import* checkImport(Name name) { if (!importsMap.count(name)) return nullptr; return importsMap[name]; }
+ Export* checkExport(Name name) { if (!exportsMap.count(name)) return nullptr; return exportsMap[name]; }
+ Function* checkFunction(Name name) { if (!functionsMap.count(name)) return nullptr; return functionsMap[name]; }
+ Global* checkGlobal(Name name) { if (!globalsMap.count(name)) return nullptr; return globalsMap[name]; }
FunctionType* checkFunctionType(Index i) { if (i >= functionTypes.size()) return nullptr; return functionTypes[i].get(); }
Import* checkImport(Index i) { if (i >= imports.size()) return nullptr; return imports[i].get(); }
@@ -1514,54 +1514,49 @@ public:
Global* checkGlobal(Index i) { if (i >= globals.size()) return nullptr; return globals[i].get(); }
void addFunctionType(FunctionType* curr) {
- Name numericName = Name::fromInt(functionTypeIndex); // TODO: remove all these, assert on names already existing, do numeric stuff in wasm-s-parser etc.
+ Name numericName = Name::fromInt(functionTypes.size()); // TODO: remove all these, assert on names already existing, do numeric stuff in wasm-s-parser etc.
if (curr->name.isNull()) {
curr->name = numericName;
}
functionTypes.push_back(std::unique_ptr<FunctionType>(curr));
functionTypesMap[curr->name] = curr;
functionTypesMap[numericName] = curr;
- functionTypeIndex++;
}
void addImport(Import* curr) {
- Name numericName = Name::fromInt(importIndex);
+ Name numericName = Name::fromInt(imports.size());
if (curr->name.isNull()) {
curr->name = numericName;
}
imports.push_back(std::unique_ptr<Import>(curr));
importsMap[curr->name] = curr;
importsMap[numericName] = curr;
- importIndex++;
}
void addExport(Export* curr) {
- Name numericName = Name::fromInt(exportIndex);
+ Name numericName = Name::fromInt(exports.size());
if (curr->name.isNull()) {
curr->name = numericName;
}
exports.push_back(std::unique_ptr<Export>(curr));
exportsMap[curr->name] = curr;
exportsMap[numericName] = curr;
- exportIndex++;
}
void addFunction(Function* curr) {
- Name numericName = Name::fromInt(functionIndex);
+ Name numericName = Name::fromInt(functions.size());
if (curr->name.isNull()) {
curr->name = numericName;
}
functions.push_back(std::unique_ptr<Function>(curr));
functionsMap[curr->name] = curr;
functionsMap[numericName] = curr;
- functionIndex++;
}
void addGlobal(Global* curr) {
- Name numericName = Name::fromInt(globalIndex);
+ Name numericName = Name::fromInt(globals.size());
if (curr->name.isNull()) {
curr->name = numericName;
}
globals.push_back(std::unique_ptr<Global>(curr));
globalsMap[curr->name] = curr;
globalsMap[numericName] = curr;
- globalIndex++;
}
void addStart(const Name &s) {
@@ -1585,9 +1580,6 @@ public:
functionsMap[func->name] = func.get();
}
}
-
-private:
- size_t functionTypeIndex, importIndex, exportIndex, functionIndex, globalIndex;
};
} // namespace wasm