Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use const modifier when dealing with types #3064

Merged
merged 1 commit into from
Aug 20, 2020
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
2 changes: 1 addition & 1 deletion src/asmjs/asm_v_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::string getSig(Type results, Type params) {
assert(!results.isMulti());
std::string sig;
sig += getSig(results);
for (auto& param : params) {
for (const auto& param : params) {
sig += getSig(param);
}
return sig;
Expand Down
2 changes: 1 addition & 1 deletion src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ uint32_t BinaryenTypeArity(BinaryenType t) { return Type(t).size(); }
void BinaryenTypeExpand(BinaryenType t, BinaryenType* buf) {
Type types(t);
size_t i = 0;
for (auto& type : types) {
for (const auto& type : types) {
buf[i++] = type.getID();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/passes/Asyncify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
}
auto localType = func->getLocalType(i);
SmallVector<Expression*, 1> loads;
for (auto& type : localType) {
for (const auto& type : localType) {
auto size = type.getByteSize();
assert(size % STACK_ALIGN == 0);
// TODO: higher alignment?
Expand Down Expand Up @@ -1350,7 +1350,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
}
auto localType = func->getLocalType(i);
size_t j = 0;
for (auto& type : localType) {
for (const auto& type : localType) {
auto size = type.getByteSize();
Expression* localGet = builder->makeLocalGet(i, localType);
if (localType.size() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/passes/FuncCastEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct FuncCastEmulation : public Pass {
Builder builder(*module);
std::vector<Expression*> callOperands;
Index i = 0;
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
callOperands.push_back(
fromABI(builder.makeLocalGet(i++, Type::i64), param, module));
}
Expand Down
2 changes: 1 addition & 1 deletion src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
visitGenericCall<CallIndirect>(
curr, [&](std::vector<Expression*>& args, Type results) {
std::vector<Type> params;
for (auto& param : curr->sig.params) {
for (const auto& param : curr->sig.params) {
if (param == Type::i64) {
params.push_back(Type::i32);
params.push_back(Type::i32);
Expand Down
6 changes: 3 additions & 3 deletions src/passes/LegalizeJSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct LegalizeJSInterface : public Pass {
std::map<Name, Name> illegalImportsToLegal;

template<typename T> bool isIllegal(T* t) {
for (auto& param : t->sig.params) {
for (const auto& param : t->sig.params) {
if (param == Type::i64) {
return true;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ struct LegalizeJSInterface : public Pass {
call->type = func->sig.results;

std::vector<Type> legalParams;
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
if (param == Type::i64) {
call->operands.push_back(I64Utilities::recreateI64(
builder, legalParams.size(), legalParams.size() + 1));
Expand Down Expand Up @@ -278,7 +278,7 @@ struct LegalizeJSInterface : public Pass {

std::vector<Type> params;
Index i = 0;
for (auto& param : im->sig.params) {
for (const auto& param : im->sig.params) {
if (param == Type::i64) {
call->operands.push_back(I64Utilities::getI64Low(builder, i));
call->operands.push_back(I64Utilities::getI64High(builder, i));
Expand Down
6 changes: 3 additions & 3 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static std::ostream& operator<<(std::ostream& o, const SExprType& localType) {
if (type.isMulti()) {
o << '(';
auto sep = "";
for (auto& t : type) {
for (const auto& t : type) {
o << sep << t;
sep = " ";
}
Expand All @@ -92,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, SigName sigName) {
os << "none";
} else {
auto sep = "";
for (auto& t : type) {
for (const auto& t : type) {
os << sep << t;
sep = "_";
}
Expand Down Expand Up @@ -2170,7 +2170,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
}
if (curr->sig.params.size() > 0) {
Index i = 0;
for (auto& param : curr->sig.params) {
for (const auto& param : curr->sig.params) {
o << maybeSpace;
o << '(';
printMinor(o, "param ");
Expand Down
2 changes: 1 addition & 1 deletion src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
trap("callIndirect: bad # of arguments");
}
size_t i = 0;
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
if (!Type::isSubType(arguments[i++].type, param)) {
trap("callIndirect: bad argument type");
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/execution-results.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct ExecutionResults {
instance.callFunction(ex->value, arguments);
}
// call the method
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
// zeros in arguments TODO: more?
arguments.push_back(Literal::makeSingleZero(param));
}
Expand Down
14 changes: 7 additions & 7 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class TranslateToFuzzReader {
Type getSubType(Type type) {
if (type.isMulti()) {
std::vector<Type> types;
for (auto& t : type) {
for (const auto& t : type) {
types.push_back(getSubType(t));
}
return Type(types);
Expand Down Expand Up @@ -770,7 +770,7 @@ class TranslateToFuzzReader {
std::vector<Expression*> invocations;
while (oneIn(2) && !finishedInput) {
std::vector<Expression*> args;
for (auto& type : func->sig.params) {
for (const auto& type : func->sig.params) {
args.push_back(makeConst(type));
}
Expression* invoke =
Expand Down Expand Up @@ -1166,7 +1166,7 @@ class TranslateToFuzzReader {
}
// we found one!
std::vector<Expression*> args;
for (auto& argType : target->sig.params) {
for (const auto& argType : target->sig.params) {
args.push_back(make(argType));
}
return builder.makeCall(target->name, args, type, isReturn);
Expand Down Expand Up @@ -1210,7 +1210,7 @@ class TranslateToFuzzReader {
target = make(Type::i32);
}
std::vector<Expression*> args;
for (auto& type : targetFn->sig.params) {
for (const auto& type : targetFn->sig.params) {
args.push_back(make(type));
}
return builder.makeCallIndirect(target, args, targetFn->sig, isReturn);
Expand Down Expand Up @@ -1267,7 +1267,7 @@ class TranslateToFuzzReader {
assert(wasm.features.hasMultivalue());
assert(type.isMulti());
std::vector<Expression*> elements;
for (auto& t : type) {
for (const auto& t : type) {
elements.push_back(make(t));
}
return builder.makeTupleMake(std::move(elements));
Expand All @@ -1281,7 +1281,7 @@ class TranslateToFuzzReader {
// Find indices from which we can extract `type`
std::vector<size_t> extractIndices;
size_t i = 0;
for (auto& t : tupleType) {
for (const auto& t : tupleType) {
if (t == type) {
extractIndices.push_back(i);
}
Expand Down Expand Up @@ -1767,7 +1767,7 @@ class TranslateToFuzzReader {
}
if (type.isMulti()) {
std::vector<Expression*> operands;
for (auto& t : type) {
for (const auto& t : type) {
operands.push_back(makeConst(t));
}
return builder.makeTupleMake(std::move(operands));
Expand Down
2 changes: 1 addition & 1 deletion src/tools/js-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static std::string generateJSWrapper(Module& wasm) {
}
ret += std::string("instance.exports.") + exp->name.str + "(";
bool first = true;
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
// zeros in arguments TODO more?
if (first) {
first = false;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/spec-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static std::string generateSpecWrapper(Module& wasm) {
}
ret += std::string("(invoke \"hangLimitInitializer\") (invoke \"") +
exp->name.str + "\" ";
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
// zeros in arguments TODO more?
TODO_SINGLE_COMPOUND(param);
switch (param.getBasic()) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/wasm-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void run_asserts(Name moduleName,
std::cerr << "Unknown entry " << entry << std::endl;
} else {
LiteralList arguments;
for (auto& param : function->sig.params) {
for (const auto& param : function->sig.params) {
arguments.push_back(Literal(param));
}
try {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/wasm2c-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int main(int argc, char** argv) {

ret += wasm2cSignature(result);
if (func->sig.params.isMulti()) {
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
ret += wasm2cSignature(param);
}
} else {
Expand All @@ -175,7 +175,7 @@ int main(int argc, char** argv) {

// Emit the parameters (all 0s, like the other wrappers).
bool first = true;
for (auto& param : func->sig.params) {
for (const auto& param : func->sig.params) {
WASM_UNUSED(param);
if (!first) {
ret += ", ";
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Type {

private:
template<bool (Type::*pred)() const> bool hasPredicate() {
for (auto& type : *this) {
for (const auto& type : *this) {
if ((type.*pred)()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Literal::Literal(const LaneArray<2>& lanes) : type(Type::v128) {
Literals Literal::makeZero(Type type) {
assert(type.isConcrete());
Literals zeroes;
for (auto& t : type) {
for (const auto& t : type) {
zeroes.push_back(makeSingleZero(t));
}
return zeroes;
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void WasmBinaryWriter::writeTypes() {
o << S32LEB(BinaryConsts::EncodedType::Func);
for (auto& sigType : {sig.params, sig.results}) {
o << U32LEB(sigType.size());
for (auto& type : sigType) {
for (const auto& type : sigType) {
o << binaryType(type);
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ void WasmBinaryWriter::writeGlobals() {
ModuleUtils::iterDefinedGlobals(*wasm, [&](Global* global) {
BYN_TRACE("write one\n");
size_t i = 0;
for (auto& t : global->type) {
for (const auto& t : global->type) {
o << binaryType(t);
o << U32LEB(global->mutable_);
if (global->type.size() == 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/wasm-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ void EmscriptenGlueGenerator::generateDynCallThunk(Signature sig) {
std::vector<NameType> params;
params.emplace_back("fptr", Type::i32); // function pointer param
int p = 0;
for (auto& param : sig.params) {
for (const auto& param : sig.params) {
params.emplace_back(std::to_string(p++), param);
}
Function* f = builder.makeFunction(name, std::move(params), sig.results, {});
Expression* fptr = builder.makeLocalGet(0, Type::i32);
std::vector<Expression*> args;
Index i = 0;
for (auto& param : sig.params) {
for (const auto& param : sig.params) {
args.push_back(builder.makeLocalGet(++i, param));
}
Expression* call = builder.makeCallIndirect(fptr, args, sig);
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-s-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ SExpressionWasmBuilder::parseTypeUse(Element& s,
// If only (type) is specified, populate `namedParams`
if (!paramsOrResultsExist) {
size_t index = 0;
for (auto& param : functionSignature.params) {
for (const auto& param : functionSignature.params) {
namedParams.emplace_back(Name::fromInt(index++), param);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,15 +1808,15 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() {
return;
}
for (auto type : func->vars) {
for (auto& t : type) {
for (const auto& t : type) {
numLocalsByType[t]++;
}
}
countScratchLocals();
std::map<Type, size_t> currLocalsByType;
for (Index i = func->getVarIndexBase(); i < func->getNumLocals(); i++) {
Index j = 0;
for (auto& type : func->getLocalType(i)) {
for (const auto& type : func->getLocalType(i)) {
auto fullIndex = std::make_pair(i, j++);
Index index = func->getVarIndexBase();
for (auto& typeCount : numLocalsByType) {
Expand Down
8 changes: 4 additions & 4 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ unsigned Type::getByteSize() const {

if (isMulti()) {
unsigned size = 0;
for (auto& t : *this) {
for (const auto& t : *this) {
size += getSingleByteSize(t);
}
return size;
Expand Down Expand Up @@ -197,7 +197,7 @@ FeatureSet Type::getFeatures() const {

if (isMulti()) {
FeatureSet feats = FeatureSet::Multivalue;
for (auto& t : *this) {
for (const auto& t : *this) {
feats |= getSingleFeatures(t);
}
return feats;
Expand Down Expand Up @@ -284,7 +284,7 @@ namespace {
std::ostream&
printPrefixedTypes(std::ostream& os, const char* prefix, Type type) {
os << '(' << prefix;
for (auto& t : type) {
for (const auto& t : type) {
os << " " << t;
}
os << ')';
Expand Down Expand Up @@ -319,7 +319,7 @@ std::ostream& operator<<(std::ostream& os, Type type) {
if (type.isMulti()) {
os << '(';
auto sep = "";
for (auto& t : type) {
for (const auto& t : type) {
os << sep << t;
sep = ", ";
}
Expand Down
Loading