summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apply-names.cc18
-rw-r--r--src/ast-parser.y11
-rw-r--r--src/ast-writer.cc22
-rw-r--r--src/ast.cc21
-rw-r--r--src/binary-reader-ast.cc6
-rw-r--r--src/binary-reader-interpreter.cc26
-rw-r--r--src/binary-reader-linker.cc6
-rw-r--r--src/binary-reader-objdump.cc12
-rw-r--r--src/binary-reader-opcnt.cc6
-rw-r--r--src/binary-reader.cc64
-rw-r--r--src/binary-writer-spec.cc15
-rw-r--r--src/binary-writer.cc57
-rw-r--r--src/binding-hash.cc8
-rw-r--r--src/generate-names.cc14
-rw-r--r--src/interpreter.cc20
-rw-r--r--src/option-parser.cc16
-rw-r--r--src/resolve-names.cc23
-rw-r--r--src/stream.cc6
-rw-r--r--src/tools/wasm-interp.cc24
-rw-r--r--src/tools/wasm-link.cc95
-rw-r--r--src/tools/wasmopcodecnt.cc12
-rw-r--r--src/type-checker.cc9
-rw-r--r--src/validator.cc30
-rw-r--r--src/vector-sort.h6
-rw-r--r--src/vector.h3
25 files changed, 202 insertions, 328 deletions
diff --git a/src/apply-names.cc b/src/apply-names.cc
index e2dc52ab..7262131e 100644
--- a/src/apply-names.cc
+++ b/src/apply-names.cc
@@ -55,8 +55,7 @@ void pop_label(Context* ctx) {
Label* find_label_by_var(Context* ctx, Var* var) {
if (var->type == VarType::Name) {
- int i;
- for (i = ctx->labels.size - 1; i >= 0; --i) {
+ for (int i = ctx->labels.size - 1; i >= 0; --i) {
Label* label = ctx->labels.data[i];
if (string_slices_are_equal(label, &var->name))
return label;
@@ -192,9 +191,8 @@ Result on_br_if_expr(Expr* expr, void* user_data) {
Result on_br_table_expr(Expr* expr, void* user_data) {
Context* ctx = static_cast<Context*>(user_data);
- size_t i;
VarVector* targets = &expr->br_table.targets;
- for (i = 0; i < targets->size; ++i) {
+ for (size_t i = 0; i < targets->size; ++i) {
Var* target = &targets->data[i];
Label* label = find_label_by_var(ctx, target);
use_name_for_var(label, target);
@@ -291,9 +289,8 @@ Result visit_export(Context* ctx, uint32_t export_index, Export* export_) {
Result visit_elem_segment(Context* ctx,
uint32_t elem_segment_index,
ElemSegment* segment) {
- size_t i;
CHECK_RESULT(use_name_for_table_var(ctx->module, &segment->table_var));
- for (i = 0; i < segment->vars.size; ++i) {
+ for (size_t i = 0; i < segment->vars.size; ++i) {
CHECK_RESULT(use_name_for_func_var(ctx->module, &segment->vars.data[i]));
}
return Result::Ok;
@@ -307,14 +304,13 @@ Result visit_data_segment(Context* ctx,
}
Result visit_module(Context* ctx, Module* module) {
- size_t i;
- for (i = 0; i < module->funcs.size; ++i)
+ for (size_t i = 0; i < module->funcs.size; ++i)
CHECK_RESULT(visit_func(ctx, i, module->funcs.data[i]));
- for (i = 0; i < module->exports.size; ++i)
+ for (size_t i = 0; i < module->exports.size; ++i)
CHECK_RESULT(visit_export(ctx, i, module->exports.data[i]));
- for (i = 0; i < module->elem_segments.size; ++i)
+ for (size_t i = 0; i < module->elem_segments.size; ++i)
CHECK_RESULT(visit_elem_segment(ctx, i, module->elem_segments.data[i]));
- for (i = 0; i < module->data_segments.size; ++i)
+ for (size_t i = 0; i < module->data_segments.size; ++i)
CHECK_RESULT(visit_data_segment(ctx, i, module->data_segments.data[i]));
return Result::Ok;
}
diff --git a/src/ast-parser.y b/src/ast-parser.y
index 5f265042..cd769d70 100644
--- a/src/ast-parser.y
+++ b/src/ast-parser.y
@@ -1260,8 +1260,7 @@ raw_module :
/* resolve func type variables where the signature was not specified
* explicitly */
- size_t i;
- for (i = 0; i < $4->funcs.size; ++i) {
+ for (size_t i = 0; i < $4->funcs.size; ++i) {
Func* func = $4->funcs.data[i];
if (decl_has_func_type(&func->decl) &&
is_empty_signature(&func->decl.sig)) {
@@ -1446,8 +1445,7 @@ script :
$$.commands = $1;
int last_module_index = -1;
- size_t i;
- for (i = 0; i < $$.commands.size; ++i) {
+ for (size_t i = 0; i < $$.commands.size; ++i) {
Command* command = &$$.commands.data[i];
Var* module_var = nullptr;
switch (command->type) {
@@ -1621,8 +1619,7 @@ size_t copy_string_contents(StringSlice* text, char* dest) {
void dup_text_list(TextList* text_list, char** out_data, size_t* out_size) {
/* walk the linked list to see how much total space is needed */
size_t total_size = 0;
- TextListNode* node;
- for (node = text_list->first; node; node = node->next) {
+ for (TextListNode* node = text_list->first; node; node = node->next) {
/* Always allocate enough space for the entire string including the escape
* characters. It will only get shorter, and this way we only have to
* iterate through the string once. */
@@ -1633,7 +1630,7 @@ void dup_text_list(TextList* text_list, char** out_data, size_t* out_size) {
}
char* result = new char [total_size];
char* dest = result;
- for (node = text_list->first; node; node = node->next) {
+ for (TextListNode* node = text_list->first; node; node = node->next) {
size_t actual_size = copy_string_contents(&node->text, dest);
dest += actual_size;
}
diff --git a/src/ast-writer.cc b/src/ast-writer.cc
index f21a9a17..46abed59 100644
--- a/src/ast-writer.cc
+++ b/src/ast-writer.cc
@@ -209,8 +209,7 @@ static void write_quoted_data(Context* ctx, const void* data, size_t length) {
static const char s_hexdigits[] = "0123456789abcdef";
write_next_char(ctx);
write_putc(ctx, '\"');
- size_t i;
- for (i = 0; i < length; ++i) {
+ for (size_t i = 0; i < length; ++i) {
uint8_t c = u8_data[i];
if (s_is_char_escaped[c]) {
write_putc(ctx, '\\');
@@ -260,10 +259,9 @@ static void write_types(Context* ctx,
const TypeVector* types,
const char* name) {
if (types->size) {
- size_t i;
if (name)
write_open_space(ctx, name);
- for (i = 0; i < types->size; ++i)
+ for (size_t i = 0; i < types->size; ++i)
write_type(ctx, types->data[i], NextChar::Space);
if (name)
write_close_space(ctx);
@@ -372,8 +370,7 @@ static void write_expr(Context* ctx, const Expr* expr) {
case ExprType::BrTable: {
write_puts_space(ctx, get_opcode_name(Opcode::BrTable));
- size_t i;
- for (i = 0; i < expr->br_table.targets.size; ++i)
+ for (size_t i = 0; i < expr->br_table.targets.size; ++i)
write_br_var(ctx, &expr->br_table.targets.data[i], NextChar::Space);
write_br_var(ctx, &expr->br_table.default_target, NextChar::Newline);
break;
@@ -501,8 +498,7 @@ static void write_expr(Context* ctx, const Expr* expr) {
}
static void write_expr_list(Context* ctx, const Expr* first) {
- const Expr* expr;
- for (expr = first; expr; expr = expr->next)
+ for (const Expr* expr = first; expr; expr = expr->next)
write_expr(ctx, expr);
}
@@ -529,8 +525,7 @@ static void write_type_bindings(Context* ctx,
* (param i32 i64 f32)
*/
bool is_open = false;
- size_t i;
- for (i = 0; i < types->size; ++i) {
+ for (size_t i = 0; i < types->size; ++i) {
if (!is_open) {
write_open_space(ctx, prefix);
is_open = true;
@@ -610,8 +605,7 @@ static void write_table(Context* ctx, const Table* table) {
static void write_elem_segment(Context* ctx, const ElemSegment* segment) {
write_open_space(ctx, "elem");
write_init_expr(ctx, segment->offset);
- size_t i;
- for (i = 0; i < segment->vars.size; ++i)
+ for (size_t i = 0; i < segment->vars.size; ++i)
write_var(ctx, &segment->vars.data[i], NextChar::Space);
write_close_newline(ctx);
}
@@ -696,8 +690,8 @@ static void write_start_function(Context* ctx, const Var* start) {
static void write_module(Context* ctx, const Module* module) {
write_open_newline(ctx, "module");
- const ModuleField* field;
- for (field = module->first_field; field; field = field->next) {
+ for (const ModuleField* field = module->first_field; field;
+ field = field->next) {
switch (field->type) {
case ModuleFieldType::Func:
write_func(ctx, module, &field->func);
diff --git a/src/ast.cc b/src/ast.cc
index 0f539551..0e4892cd 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -110,8 +110,7 @@ FuncTypePtr get_func_type_by_var(const Module* module, const Var* var) {
}
int get_func_type_index_by_sig(const Module* module, const FuncSignature* sig) {
- size_t i;
- for (i = 0; i < module->func_types.size; ++i)
+ for (size_t i = 0; i < module->func_types.size; ++i)
if (signatures_are_equal(&module->func_types.data[i]->sig, sig))
return i;
return -1;
@@ -127,8 +126,7 @@ int get_func_type_index_by_decl(const Module* module,
}
Module* get_first_module(const Script* script) {
- size_t i;
- for (i = 0; i < script->commands.size; ++i) {
+ for (size_t i = 0; i < script->commands.size; ++i) {
Command* command = &script->commands.data[i];
if (command->type == CommandType::Module)
return &command->module;
@@ -154,8 +152,7 @@ void make_type_binding_reverse_mapping(const TypeVector* types,
memset(out_reverse_mapping->data, 0, num_names * sizeof(StringSlice));
/* map index to name */
- size_t i;
- for (i = 0; i < bindings->entries.capacity; ++i) {
+ for (size_t i = 0; i < bindings->entries.capacity; ++i) {
const BindingHashEntry* entry = &bindings->entries.data[i];
if (hash_entry_is_free(entry))
continue;
@@ -169,8 +166,7 @@ void make_type_binding_reverse_mapping(const TypeVector* types,
void find_duplicate_bindings(const BindingHash* bindings,
DuplicateBindingCallback callback,
void* user_data) {
- size_t i;
- for (i = 0; i < bindings->entries.capacity; ++i) {
+ for (size_t i = 0; i < bindings->entries.capacity; ++i) {
BindingHashEntry* entry = &bindings->entries.data[i];
if (hash_entry_is_free(entry))
continue;
@@ -179,10 +175,8 @@ void find_duplicate_bindings(const BindingHash* bindings,
if (entry->prev)
continue;
- BindingHashEntry* a = entry;
- for (; a; a = a->next) {
- BindingHashEntry* b = a->next;
- for (; b; b = b->next) {
+ for (BindingHashEntry* a = entry; a; a = a->next) {
+ for (BindingHashEntry* b = a->next; b; b = b->next) {
if (string_slices_are_equal(&a->binding.name, &b->binding.name))
callback(a, b, user_data);
}
@@ -567,8 +561,7 @@ void destroy_script(Script* script) {
static Result visit_expr(Expr* expr, ExprVisitor* visitor);
Result visit_expr_list(Expr* first, ExprVisitor* visitor) {
- Expr* expr;
- for (expr = first; expr; expr = expr->next)
+ for (Expr* expr = first; expr; expr = expr->next)
CHECK_RESULT(visit_expr(expr, visitor));
return Result::Ok;
}
diff --git a/src/binary-reader-ast.cc b/src/binary-reader-ast.cc
index a202c0b7..324f4a9b 100644
--- a/src/binary-reader-ast.cc
+++ b/src/binary-reader-ast.cc
@@ -464,8 +464,7 @@ static Result on_local_decl(uint32_t decl_index,
size_t new_local_count = old_local_count + count;
reserve_types(&ctx->current_func->local_types, new_local_count);
TypeVector* types = &ctx->current_func->local_types;
- size_t i;
- for (i = 0; i < count; ++i)
+ for (size_t i = 0; i < count; ++i)
types->data[old_local_count + i] = type;
types->size = new_local_count;
return Result::Ok;
@@ -517,8 +516,7 @@ static Result on_br_table_expr(BinaryReaderContext* context,
Expr* expr = new_br_table_expr();
reserve_vars(&expr->br_table.targets, num_targets);
expr->br_table.targets.size = num_targets;
- uint32_t i;
- for (i = 0; i < num_targets; ++i) {
+ for (uint32_t i = 0; i < num_targets; ++i) {
Var* var = &expr->br_table.targets.data[i];
var->type = VarType::Index;
var->index = target_depths[i];
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc
index 83c69805..37735a32 100644
--- a/src/binary-reader-interpreter.cc
+++ b/src/binary-reader-interpreter.cc
@@ -329,8 +329,7 @@ static Result fixup_top_label(Context* ctx) {
}
Uint32Vector* fixups = &ctx->depth_fixups.data[top];
- uint32_t i;
- for (i = 0; i < fixups->size; ++i)
+ for (uint32_t i = 0; i < fixups->size; ++i)
CHECK_RESULT(emit_i32_at(ctx, fixups->data[i], offset));
/* reduce the size to 0 in case this gets reused. Keep the allocations for
* later use */
@@ -357,8 +356,7 @@ static void on_error(BinaryReaderContext* ctx, const char* message) {
static Result on_signature_count(uint32_t count, void* user_data) {
Context* ctx = static_cast<Context*>(user_data);
resize_uint32_vector(&ctx->sig_index_mapping, count);
- uint32_t i;
- for (i = 0; i < count; ++i)
+ for (uint32_t i = 0; i < count; ++i)
ctx->sig_index_mapping.data[i] = ctx->env->sigs.size + i;
resize_interpreter_func_signature_vector(&ctx->env->sigs,
ctx->env->sigs.size + count);
@@ -665,8 +663,7 @@ static Result on_function_signatures_count(uint32_t count, void* user_data) {
Context* ctx = static_cast<Context*>(user_data);
size_t old_size = ctx->func_index_mapping.size;
resize_uint32_vector(&ctx->func_index_mapping, old_size + count);
- uint32_t i;
- for (i = 0; i < count; ++i)
+ for (uint32_t i = 0; i < count; ++i)
ctx->func_index_mapping.data[old_size + i] = ctx->env->funcs.size + i;
resize_interpreter_func_vector(&ctx->env->funcs,
ctx->env->funcs.size + count);
@@ -718,8 +715,7 @@ static Result on_global_count(uint32_t count, void* user_data) {
Context* ctx = static_cast<Context*>(user_data);
size_t old_size = ctx->global_index_mapping.size;
resize_uint32_vector(&ctx->global_index_mapping, old_size + count);
- uint32_t i;
- for (i = 0; i < count; ++i)
+ for (uint32_t i = 0; i < count; ++i)
ctx->global_index_mapping.data[old_size + i] = ctx->env->globals.size + i;
resize_interpreter_global_vector(&ctx->env->globals,
ctx->env->globals.size + count);
@@ -953,8 +949,7 @@ static void pop_label(Context* ctx) {
if (ctx->depth_fixups.size > ctx->label_stack.size) {
uint32_t from = ctx->label_stack.size;
uint32_t to = ctx->depth_fixups.size;
- uint32_t i;
- for (i = from; i < to; ++i)
+ for (uint32_t i = from; i < to; ++i)
destroy_uint32_vector(&ctx->depth_fixups.data[i]);
ctx->depth_fixups.size = ctx->label_stack.size;
}
@@ -978,13 +973,12 @@ static Result begin_function_body(BinaryReaderContext* context,
/* fixup function references */
uint32_t defined_index = translate_module_func_index_to_defined(ctx, index);
- uint32_t i;
Uint32Vector* fixups = &ctx->func_fixups.data[defined_index];
- for (i = 0; i < fixups->size; ++i)
+ for (uint32_t i = 0; i < fixups->size; ++i)
CHECK_RESULT(emit_i32_at(ctx, fixups->data[i], func->defined.offset));
/* append param types */
- for (i = 0; i < sig->param_types.size; ++i) {
+ for (uint32_t i = 0; i < sig->param_types.size; ++i) {
append_type_value(&func->defined.param_and_local_types,
&sig->param_types.data[i]);
}
@@ -1025,8 +1019,7 @@ static Result on_local_decl(uint32_t decl_index,
InterpreterFunc* func = ctx->current_func;
func->defined.local_count += count;
- uint32_t i;
- for (i = 0; i < count; ++i) {
+ for (uint32_t i = 0; i < count; ++i) {
append_type_value(&func->defined.param_and_local_types, &type);
}
@@ -1175,8 +1168,7 @@ static Result on_br_table_expr(BinaryReaderContext* context,
CHECK_RESULT(emit_i32(ctx, (num_targets + 1) * WABT_TABLE_ENTRY_SIZE));
CHECK_RESULT(emit_i32_at(ctx, fixup_table_offset, get_istream_offset(ctx)));
- uint32_t i;
- for (i = 0; i <= num_targets; ++i) {
+ for (uint32_t i = 0; i <= num_targets; ++i) {
uint32_t depth = i != num_targets ? target_depths[i] : default_target_depth;
CHECK_RESULT(typechecker_on_br_table_target(&ctx->typechecker, depth));
CHECK_RESULT(emit_br_table_offset(ctx, depth));
diff --git a/src/binary-reader-linker.cc b/src/binary-reader-linker.cc
index c0e3f933..e4e7ab16 100644
--- a/src/binary-reader-linker.cc
+++ b/src/binary-reader-linker.cc
@@ -42,8 +42,7 @@ static Result on_reloc_count(uint32_t count,
WABT_FATAL("relocation for custom sections not yet supported\n");
}
- uint32_t i;
- for (i = 0; i < binary->sections.size; i++) {
+ for (uint32_t i = 0; i < binary->sections.size; i++) {
Section* sec = &binary->sections.data[i];
if (sec->section_code != section_code)
continue;
@@ -176,9 +175,8 @@ static Result begin_custom_section(BinaryReaderContext* ctx,
/* We don't currently support merging name sections unless they contain
* a name for every function. */
- size_t i;
uint32_t total_funcs = binary->function_imports.size;
- for (i = 0; i < binary->sections.size; i++) {
+ for (size_t i = 0; i < binary->sections.size; i++) {
if (binary->sections.data[i].section_code == BinarySection::Function) {
total_funcs += binary->sections.data[i].count;
break;
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index a34965f2..f8706635 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -214,21 +214,20 @@ static void log_opcode(Context* ctx,
// Print binary data
printf(" %06" PRIzx ": %02x", offset - 1,
static_cast<unsigned>(ctx->current_opcode));
- size_t i;
- for (i = 0; i < data_size && i < IMMEDIATE_OCTET_COUNT; i++, offset++) {
+ for (size_t i = 0; i < data_size && i < IMMEDIATE_OCTET_COUNT;
+ i++, offset++) {
printf(" %02x", data[offset]);
}
- for (i = data_size + 1; i < IMMEDIATE_OCTET_COUNT; i++) {
+ for (size_t i = data_size + 1; i < IMMEDIATE_OCTET_COUNT; i++) {
printf(" ");
}
printf(" | ");
// Print disassemble
- int j;
int indent_level = ctx->indent_level;
if (ctx->current_opcode == Opcode::Else)
indent_level--;
- for (j = 0; j < indent_level; j++) {
+ for (int j = 0; j < indent_level; j++) {
printf(" ");
}
@@ -370,8 +369,7 @@ static Result on_signature(uint32_t index,
if (!should_print_details(ctx))
return Result::Ok;
printf(" - [%d] (", index);
- uint32_t i;
- for (i = 0; i < param_count; i++) {
+ for (uint32_t i = 0; i < param_count; i++) {
if (i != 0) {
printf(", ");
}
diff --git a/src/binary-reader-opcnt.cc b/src/binary-reader-opcnt.cc
index 9a122f2d..1598c936 100644
--- a/src/binary-reader-opcnt.cc
+++ b/src/binary-reader-opcnt.cc
@@ -33,8 +33,7 @@ struct Context {
static Result add_int_counter_value(IntCounterVector* vec,
intmax_t value) {
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].value == value) {
++vec->data[i].count;
return Result::Ok;
@@ -50,8 +49,7 @@ static Result add_int_counter_value(IntCounterVector* vec,
static Result add_int_pair_counter_value(IntPairCounterVector* vec,
intmax_t first,
intmax_t second) {
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].first == first && vec->data[i].second == second) {
++vec->data[i].count;
return Result::Ok;
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 1d9dd0cf..ccbba7c0 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -650,9 +650,8 @@ static void sprint_limits(char* dst, size_t size, const Limits* limits) {
}
static void log_types(LoggingContext* ctx, uint32_t type_count, Type* types) {
- uint32_t i;
LOGF_NOINDENT("[");
- for (i = 0; i < type_count; ++i) {
+ for (uint32_t i = 0; i < type_count; ++i) {
LOGF_NOINDENT("%s", get_type_name(types[i]));
if (i != type_count - 1)
LOGF_NOINDENT(", ");
@@ -830,8 +829,7 @@ static Result logging_on_br_table_expr(BinaryReaderContext* context,
uint32_t default_target_depth) {
LoggingContext* ctx = static_cast<LoggingContext*>(context->user_data);
LOGF("on_br_table_expr(num_targets: %u, depths: [", num_targets);
- uint32_t i;
- for (i = 0; i < num_targets; ++i) {
+ for (uint32_t i = 0; i < num_targets; ++i) {
LOGF_NOINDENT("%u", target_depths[i]);
if (i != num_targets - 1)
LOGF_NOINDENT(", ");
@@ -1211,8 +1209,7 @@ static void read_function_body(Context* ctx, uint32_t end_offset) {
ctx->target_depths.size = num_targets;
}
- uint32_t i;
- for (i = 0; i < num_targets; ++i) {
+ for (uint32_t i = 0; i < num_targets; ++i) {
uint32_t target_depth;
in_u32_leb128(ctx, &target_depth, "br_table target depth");
ctx->target_depths.data[i] = target_depth;
@@ -1580,9 +1577,8 @@ static void read_custom_section(Context* ctx, uint32_t section_size) {
if (subsection_size) {
uint32_t num_names;
in_u32_leb128(ctx, &num_names, "name count");
- uint32_t j;
CALLBACK(on_function_names_count, num_names);
- for (j = 0; j < num_names; ++j) {
+ for (uint32_t j = 0; j < num_names; ++j) {
uint32_t function_index;
StringSlice function_name;
@@ -1598,16 +1594,14 @@ static void read_custom_section(Context* ctx, uint32_t section_size) {
if (subsection_size) {
uint32_t num_funcs;
in_u32_leb128(ctx, &num_funcs, "function count");
- uint32_t j;
CALLBACK(on_local_name_function_count, num_funcs);
- for (j = 0; j < num_funcs; ++j) {
+ for (uint32_t j = 0; j < num_funcs; ++j) {
uint32_t function_index;
in_u32_leb128(ctx, &function_index, "function index");
uint32_t num_locals;
in_u32_leb128(ctx, &num_locals, "local count");
CALLBACK(on_local_name_local_count, function_index, num_locals);
- uint32_t k;
- for (k = 0; k < num_locals; ++k) {
+ for (uint32_t k = 0; k < num_locals; ++k) {
uint32_t local_index;
StringSlice local_name;
@@ -1629,7 +1623,7 @@ static void read_custom_section(Context* ctx, uint32_t section_size) {
} else if (strncmp(section_name.start, WABT_BINARY_SECTION_RELOC,
strlen(WABT_BINARY_SECTION_RELOC)) == 0) {
CALLBACK_SECTION(begin_reloc_section, section_size);
- uint32_t i, num_relocs, section;
+ uint32_t num_relocs, section;
in_u32_leb128(ctx, &section, "section");
WABT_ZERO_MEMORY(section_name);
if (static_cast<BinarySection>(section) == BinarySection::Custom)
@@ -1637,7 +1631,7 @@ static void read_custom_section(Context* ctx, uint32_t section_size) {
in_u32_leb128(ctx, &num_relocs, "relocation count");
CALLBACK(on_reloc_count, num_relocs, static_cast<BinarySection>(section),
section_name);
- for (i = 0; i < num_relocs; ++i) {
+ for (uint32_t i = 0; i < num_relocs; ++i) {
uint32_t reloc_type, offset;
in_u32_leb128(ctx, &reloc_type, "relocation type");
in_u32_leb128(ctx, &offset, "offset");
@@ -1653,11 +1647,10 @@ static void read_custom_section(Context* ctx, uint32_t section_size) {
static void read_type_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_signature_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_signatures, "type count");
CALLBACK(on_signature_count, ctx->num_signatures);
- for (i = 0; i < ctx->num_signatures; ++i) {
+ for (uint32_t i = 0; i < ctx->num_signatures; ++i) {
Type form;
in_type(ctx, &form, "type form");
RAISE_ERROR_UNLESS(form == Type::Func, "unexpected type form");
@@ -1668,8 +1661,7 @@ static void read_type_section(Context* ctx, uint32_t section_size) {
if (num_params > ctx->param_types.capacity)
reserve_types(&ctx->param_types, num_params);
- uint32_t j;
- for (j = 0; j < num_params; ++j) {
+ for (uint32_t j = 0; j < num_params; ++j) {
Type param_type;
in_type(ctx, &param_type, "function param type");
RAISE_ERROR_UNLESS(is_concrete_type(param_type),
@@ -1696,10 +1688,9 @@ static void read_type_section(Context* ctx, uint32_t section_size) {
static void read_import_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_import_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_imports, "import count");
CALLBACK(on_import_count, ctx->num_imports);
- for (i = 0; i < ctx->num_imports; ++i) {
+ for (uint32_t i = 0; i < ctx->num_imports; ++i) {
StringSlice module_name;
in_str(ctx, &module_name, "import module name");
StringSlice field_name;
@@ -1755,10 +1746,9 @@ static void read_import_section(Context* ctx, uint32_t section_size) {
static void read_function_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_function_signatures_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_function_signatures, "function signature count");
CALLBACK(on_function_signatures_count, ctx->num_function_signatures);
- for (i = 0; i < ctx->num_function_signatures; ++i) {
+ for (uint32_t i = 0; i < ctx->num_function_signatures; ++i) {
uint32_t func_index = ctx->num_func_imports + i;
uint32_t sig_index;
in_u32_leb128(ctx, &sig_index, "function signature index");
@@ -1771,12 +1761,11 @@ static void read_function_section(Context* ctx, uint32_t section_size) {
static void read_table_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_table_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_tables, "table count");
RAISE_ERROR_UNLESS(ctx->num_tables <= 1, "table count (%d) must be 0 or 1",
ctx->num_tables);
CALLBACK(on_table_count, ctx->num_tables);
- for (i = 0; i < ctx->num_tables; ++i) {
+ for (uint32_t i = 0; i < ctx->num_tables; ++i) {
uint32_t table_index = ctx->num_table_imports + i;
Type elem_type;
Limits elem_limits;
@@ -1788,11 +1777,10 @@ static void read_table_section(Context* ctx, uint32_t section_size) {
static void read_memory_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_memory_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_memories, "memory count");
RAISE_ERROR_UNLESS(ctx->num_memories <= 1, "memory count must be 0 or 1");
CALLBACK(on_memory_count, ctx->num_memories);
- for (i = 0; i < ctx->num_memories; ++i) {
+ for (uint32_t i = 0; i < ctx->num_memories; ++i) {
uint32_t memory_index = ctx->num_memory_imports + i;
Limits page_limits;
read_memory(ctx, &page_limits);
@@ -1803,10 +1791,9 @@ static void read_memory_section(Context* ctx, uint32_t section_size) {
static void read_global_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_global_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_globals, "global count");
CALLBACK(on_global_count, ctx->num_globals);
- for (i = 0; i < ctx->num_globals; ++i) {
+ for (uint32_t i = 0; i < ctx->num_globals; ++i) {
uint32_t global_index = ctx->num_global_imports + i;
Type global_type;
bool mutable_;
@@ -1822,10 +1809,9 @@ static void read_global_section(Context* ctx, uint32_t section_size) {
static void read_export_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_export_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_exports, "export count");
CALLBACK(on_export_count, ctx->num_exports);
- for (i = 0; i < ctx->num_exports; ++i) {
+ for (uint32_t i = 0; i < ctx->num_exports; ++i) {
StringSlice name;
in_str(ctx, &name, "export item name");
@@ -1873,12 +1859,12 @@ static void read_start_section(Context* ctx, uint32_t section_size) {
static void read_elem_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_elem_section, section_size);
- uint32_t i, num_elem_segments;
+ uint32_t num_elem_segments;
in_u32_leb128(ctx, &num_elem_segments, "elem segment count");
CALLBACK(on_elem_segment_count, num_elem_segments);
RAISE_ERROR_UNLESS(num_elem_segments == 0 || num_total_tables(ctx) > 0,
"elem section without table section");
- for (i = 0; i < num_elem_segments; ++i) {
+ for (uint32_t i = 0; i < num_elem_segments; ++i) {
uint32_t table_index;
in_u32_leb128(ctx, &table_index, "elem segment table index");
CALLBACK(begin_elem_segment, i, table_index);
@@ -1886,11 +1872,11 @@ static void read_elem_section(Context* ctx, uint32_t section_size) {
read_init_expr(ctx, i);
CALLBACK(end_elem_segment_init_expr, i);
- uint32_t j, num_function_indexes;
+ uint32_t num_function_indexes;
in_u32_leb128(ctx, &num_function_indexes,
"elem segment function index count");
CALLBACK_CTX(on_elem_segment_function_index_count, i, num_function_indexes);
- for (j = 0; j < num_function_indexes; ++j) {
+ for (uint32_t j = 0; j < num_function_indexes; ++j) {
uint32_t func_index;
in_u32_leb128(ctx, &func_index, "elem segment function index");
CALLBACK(on_elem_segment_function_index, i, func_index);
@@ -1902,12 +1888,11 @@ static void read_elem_section(Context* ctx, uint32_t section_size) {
static void read_code_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_function_bodies_section, section_size);
- uint32_t i;
in_u32_leb128(ctx, &ctx->num_function_bodies, "function body count");
RAISE_ERROR_UNLESS(ctx->num_function_signatures == ctx->num_function_bodies,
"function signature count != function body count");
CALLBACK(on_function_bodies_count, ctx->num_function_bodies);
- for (i = 0; i < ctx->num_function_bodies; ++i) {
+ for (uint32_t i = 0; i < ctx->num_function_bodies; ++i) {
uint32_t func_index = ctx->num_func_imports + i;
uint32_t func_offset = ctx->offset;
ctx->offset = func_offset;
@@ -1920,8 +1905,7 @@ static void read_code_section(Context* ctx, uint32_t section_size) {
uint32_t num_local_decls;
in_u32_leb128(ctx, &num_local_decls, "local declaration count");
CALLBACK(on_local_decl_count, num_local_decls);
- uint32_t k;
- for (k = 0; k < num_local_decls; ++k) {
+ for (uint32_t k = 0; k < num_local_decls; ++k) {
uint32_t num_local_types;
in_u32_leb128(ctx, &num_local_types, "local type count");
Type local_type;
@@ -1940,12 +1924,12 @@ static void read_code_section(Context* ctx, uint32_t section_size) {
static void read_data_section(Context* ctx, uint32_t section_size) {
CALLBACK_SECTION(begin_data_section, section_size);
- uint32_t i, num_data_segments;
+ uint32_t num_data_segments;
in_u32_leb128(ctx, &num_data_segments, "data segment count");
CALLBACK(on_data_segment_count, num_data_segments);
RAISE_ERROR_UNLESS(num_data_segments == 0 || num_total_memories(ctx) > 0,
"data section without memory section");
- for (i = 0; i < num_data_segments; ++i) {
+ for (uint32_t i = 0; i < num_data_segments; ++i) {
uint32_t memory_index;
in_u32_leb128(ctx, &memory_index, "data segment memory index");
CALLBACK(begin_data_segment, i, memory_index);
diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc
index b409fec7..cb4edefb 100644
--- a/src/binary-writer-spec.cc
+++ b/src/binary-writer-spec.cc
@@ -40,8 +40,7 @@ struct Context {
};
static void convert_backslash_to_slash(char* s, size_t length) {
- size_t i = 0;
- for (; i < length; ++i)
+ for (size_t i = 0; i < length; ++i)
if (s[i] == '\\')
s[i] = '/';
}
@@ -120,9 +119,8 @@ static void write_separator(Context* ctx) {
}
static void write_escaped_string_slice(Context* ctx, StringSlice ss) {
- size_t i;
write_char(&ctx->json_stream, '"');
- for (i = 0; i < ss.length; ++i) {
+ for (size_t i = 0; i < ss.length; ++i) {
uint8_t c = ss.start[i];
if (c < 0x20 || c == '\\' || c == '"') {
writef(&ctx->json_stream, "\\u%04x", c);
@@ -215,8 +213,7 @@ static void write_const(Context* ctx, const Const* const_) {
static void write_const_vector(Context* ctx, const ConstVector* consts) {
writef(&ctx->json_stream, "[");
- size_t i;
- for (i = 0; i < consts->size; ++i) {
+ for (size_t i = 0; i < consts->size; ++i) {
const Const* const_ = &consts->data[i];
write_const(ctx, const_);
if (i != consts->size - 1)
@@ -266,8 +263,7 @@ static void write_action_result_type(Context* ctx,
assert(export_->kind == ExternalKind::Func);
Func* func = get_func_by_var(module, &export_->var);
size_t num_results = get_num_results(func);
- size_t i;
- for (i = 0; i < num_results; ++i)
+ for (size_t i = 0; i < num_results; ++i)
write_type_object(ctx, get_result_type(func, i));
break;
}
@@ -334,9 +330,8 @@ static void write_commands(Context* ctx, Script* script) {
writef(&ctx->json_stream, "{\"source_filename\": ");
write_escaped_string_slice(ctx, ctx->source_filename);
writef(&ctx->json_stream, ",\n \"commands\": [\n");
- size_t i;
int last_module_index = -1;
- for (i = 0; i < script->commands.size; ++i) {
+ for (size_t i = 0; i < script->commands.size; ++i) {
Command* command = &script->commands.data[i];
if (command->type == CommandType::AssertInvalidNonBinary)
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 9a7959b1..14c297d7 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -389,9 +389,8 @@ static void write_expr(Context* ctx,
write_opcode(&ctx->stream, Opcode::BrTable);
write_u32_leb128(&ctx->stream, expr->br_table.targets.size,
"num targets");
- size_t i;
uint32_t depth;
- for (i = 0; i < expr->br_table.targets.size; ++i) {
+ for (size_t i = 0; i < expr->br_table.targets.size; ++i) {
depth = get_label_var_depth(ctx, &expr->br_table.targets.data[i]);
write_u32_leb128(&ctx->stream, depth, "break depth");
}
@@ -539,8 +538,7 @@ static void write_expr_list(Context* ctx,
const Module* module,
const Func* func,
const Expr* first) {
- const Expr* expr;
- for (expr = first; expr; expr = expr->next)
+ for (const Expr* expr = first; expr; expr = expr->next)
write_expr(ctx, module, func, expr);
}
@@ -570,8 +568,7 @@ static void write_func_locals(Context* ctx,
/* loop through once to count the number of local declaration runs */
Type current_type = GET_LOCAL_TYPE(FIRST_LOCAL_INDEX);
uint32_t local_decl_count = 1;
- uint32_t i;
- for (i = FIRST_LOCAL_INDEX + 1; i < LAST_LOCAL_INDEX; ++i) {
+ for (uint32_t i = FIRST_LOCAL_INDEX + 1; i < LAST_LOCAL_INDEX; ++i) {
Type type = GET_LOCAL_TYPE(i);
if (current_type != type) {
local_decl_count++;
@@ -583,7 +580,7 @@ static void write_func_locals(Context* ctx,
write_u32_leb128(&ctx->stream, local_decl_count, "local decl count");
current_type = GET_LOCAL_TYPE(FIRST_LOCAL_INDEX);
uint32_t local_type_count = 1;
- for (i = FIRST_LOCAL_INDEX + 1; i <= LAST_LOCAL_INDEX; ++i) {
+ for (uint32_t i = FIRST_LOCAL_INDEX + 1; i <= LAST_LOCAL_INDEX; ++i) {
/* loop through an extra time to catch the final type transition */
Type type = i == LAST_LOCAL_INDEX ? Type::Void : GET_LOCAL_TYPE(i);
if (current_type == type) {
@@ -635,8 +632,7 @@ static void write_reloc_section(Context* ctx, RelocSection* reloc_section) {
RelocVector* relocs = &reloc_section->relocations;
write_u32_leb128(&ctx->stream, relocs->size, "num relocs");
- size_t i;
- for (i = 0; i < relocs->size; i++) {
+ for (size_t i = 0; i < relocs->size; i++) {
write_u32_leb128_enum(&ctx->stream, relocs->data[i].type, "reloc type");
write_u32_leb128(&ctx->stream, relocs->data[i].offset, "reloc offset");
}
@@ -645,28 +641,26 @@ static void write_reloc_section(Context* ctx, RelocSection* reloc_section) {
}
static Result write_module(Context* ctx, const Module* module) {
- size_t i;
write_u32(&ctx->stream, WABT_BINARY_MAGIC, "WASM_BINARY_MAGIC");
write_u32(&ctx->stream, WABT_BINARY_VERSION, "WASM_BINARY_VERSION");
if (module->func_types.size) {
begin_known_section(ctx, BinarySection::Type, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->func_types.size, "num types");
- for (i = 0; i < module->func_types.size; ++i) {
+ for (size_t i = 0; i < module->func_types.size; ++i) {
const FuncType* func_type = module->func_types.data[i];
const FuncSignature* sig = &func_type->sig;
write_header(ctx, "type", i);
write_type(&ctx->stream, Type::Func);
- size_t j;
uint32_t num_params = sig->param_types.size;
uint32_t num_results = sig->result_types.size;
write_u32_leb128(&ctx->stream, num_params, "num params");
- for (j = 0; j < num_params; ++j)
+ for (size_t j = 0; j < num_params; ++j)
write_type(&ctx->stream, sig->param_types.data[j]);
write_u32_leb128(&ctx->stream, num_results, "num results");
- for (j = 0; j < num_results; ++j)
+ for (size_t j = 0; j < num_results; ++j)
write_type(&ctx->stream, sig->result_types.data[j]);
}
end_section(ctx);
@@ -676,7 +670,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Import, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->imports.size, "num imports");
- for (i = 0; i < module->imports.size; ++i) {
+ for (size_t i = 0; i < module->imports.size; ++i) {
const Import* import = module->imports.data[i];
write_header(ctx, "import header", i);
write_str(&ctx->stream, import->module_name.start,
@@ -712,10 +706,11 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Function, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, num_funcs, "num functions");
- for (i = 0; i < num_funcs; ++i) {
+ for (size_t i = 0; i < num_funcs; ++i) {
const Func* func = module->funcs.data[i + module->num_func_imports];
char desc[100];
- wabt_snprintf(desc, sizeof(desc), "function %" PRIzd " signature index", i);
+ wabt_snprintf(desc, sizeof(desc), "function %" PRIzd " signature index",
+ i);
write_u32_leb128(&ctx->stream,
get_func_type_index_by_decl(module, &func->decl), desc);
}
@@ -727,7 +722,7 @@ static Result write_module(Context* ctx, const Module* module) {
if (num_tables) {
begin_known_section(ctx, BinarySection::Table, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, num_tables, "num tables");
- for (i = 0; i < num_tables; ++i) {
+ for (size_t i = 0; i < num_tables; ++i) {
const Table* table = module->tables.data[i + module->num_table_imports];
write_header(ctx, "table", i);
write_table(ctx, table);
@@ -740,7 +735,7 @@ static Result write_module(Context* ctx, const Module* module) {
if (num_memories) {
begin_known_section(ctx, BinarySection::Memory, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, num_memories, "num memories");
- for (i = 0; i < num_memories; ++i) {
+ for (size_t i = 0; i < num_memories; ++i) {
const Memory* memory =
module->memories.data[i + module->num_memory_imports];
write_header(ctx, "memory", i);
@@ -755,7 +750,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Global, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, num_globals, "num globals");
- for (i = 0; i < num_globals; ++i) {
+ for (size_t i = 0; i < num_globals; ++i) {
const Global* global =
module->globals.data[i + module->num_global_imports];
write_global_header(ctx, global);
@@ -768,7 +763,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Export, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->exports.size, "num exports");
- for (i = 0; i < module->exports.size; ++i) {
+ for (size_t i = 0; i < module->exports.size; ++i) {
const Export* export_ = module->exports.data[i];
write_str(&ctx->stream, export_->name.start, export_->name.length,
PrintChars::Yes, "export name");
@@ -812,7 +807,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Elem, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->elem_segments.size,
"num elem segments");
- for (i = 0; i < module->elem_segments.size; ++i) {
+ for (size_t i = 0; i < module->elem_segments.size; ++i) {
ElemSegment* segment = module->elem_segments.data[i];
int table_index = get_table_index_by_var(module, &segment->table_var);
write_header(ctx, "elem segment header", i);
@@ -820,8 +815,7 @@ static Result write_module(Context* ctx, const Module* module) {
write_init_expr(ctx, module, segment->offset);
write_u32_leb128(&ctx->stream, segment->vars.size,
"num function indices");
- size_t j;
- for (j = 0; j < segment->vars.size; ++j) {
+ for (size_t j = 0; j < segment->vars.size; ++j) {
int index = get_func_index_by_var(module, &segment->vars.data[j]);
write_u32_leb128_with_reloc(ctx, index, "function index",
RelocType::FuncIndexLeb);
@@ -834,7 +828,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Code, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, num_funcs, "num functions");
- for (i = 0; i < num_funcs; ++i) {
+ for (size_t i = 0; i < num_funcs; ++i) {
write_header(ctx, "function body", i);
const Func* func = module->funcs.data[i + module->num_func_imports];
@@ -853,7 +847,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_known_section(ctx, BinarySection::Data, LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->data_segments.size,
"num data segments");
- for (i = 0; i < module->data_segments.size; ++i) {
+ for (size_t i = 0; i < module->data_segments.size; ++i) {
const DataSegment* segment = module->data_segments.data[i];
write_header(ctx, "data segment header", i);
int memory_index = get_memory_index_by_var(module, &segment->memory_var);
@@ -876,7 +870,7 @@ static Result write_module(Context* ctx, const Module* module) {
write_u32_leb128(&ctx->stream, 1, "function name type");
begin_subsection(ctx, "function name subsection", LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->funcs.size, "num functions");
- for (i = 0; i < module->funcs.size; ++i) {
+ for (size_t i = 0; i < module->funcs.size; ++i) {
const Func* func = module->funcs.data[i];
write_u32_leb128(&ctx->stream, i, "function index");
wabt_snprintf(desc, sizeof(desc), "func name %" PRIzd, i);
@@ -889,7 +883,7 @@ static Result write_module(Context* ctx, const Module* module) {
begin_subsection(ctx, "local name subsection", LEB_SECTION_SIZE_GUESS);
write_u32_leb128(&ctx->stream, module->funcs.size, "num functions");
- for (i = 0; i < module->funcs.size; ++i) {
+ for (size_t i = 0; i < module->funcs.size; ++i) {
const Func* func = module->funcs.data[i];
uint32_t num_params = get_num_params(func);
uint32_t num_locals = func->local_types.size;
@@ -900,8 +894,7 @@ static Result write_module(Context* ctx, const Module* module) {
make_type_binding_reverse_mapping(
&func->decl.sig.param_types, &func->param_bindings, &index_to_name);
- size_t j;
- for (j = 0; j < num_params; ++j) {
+ for (size_t j = 0; j < num_params; ++j) {
StringSlice name = index_to_name.data[j];
wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, j);
write_u32_leb128(&ctx->stream, j, "local index");
@@ -911,7 +904,7 @@ static Result write_module(Context* ctx, const Module* module) {
make_type_binding_reverse_mapping(
&func->local_types, &func->local_bindings, &index_to_name);
- for (j = 0; j < num_locals; ++j) {
+ for (size_t j = 0; j < num_locals; ++j) {
StringSlice name = index_to_name.data[j];
wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, num_params + j);
write_u32_leb128(&ctx->stream, num_params + j, "local index");
@@ -926,7 +919,7 @@ static Result write_module(Context* ctx, const Module* module) {
}
if (ctx->options->relocatable) {
- for (i = 0; i < ctx->reloc_sections.size; i++) {
+ for (size_t i = 0; i < ctx->reloc_sections.size; i++) {
write_reloc_section(ctx, &ctx->reloc_sections.data[i]);
}
WABT_DESTROY_VECTOR_AND_ELEMENTS(ctx->reloc_sections, reloc_section);
diff --git a/src/binding-hash.cc b/src/binding-hash.cc
index 464a4f3d..f39168c9 100644
--- a/src/binding-hash.cc
+++ b/src/binding-hash.cc
@@ -96,8 +96,7 @@ static void hash_resize(BindingHash* hash, size_t desired_capacity) {
reserve_binding_hash_entrys(&new_hash.entries, desired_capacity);
/* update the free list */
- size_t i;
- for (i = 0; i < new_hash.entries.capacity; ++i) {
+ for (size_t i = 0; i < new_hash.entries.capacity; ++i) {
BindingHashEntry* entry = &new_hash.entries.data[i];
if (new_hash.free_head)
new_hash.free_head->prev = entry;
@@ -109,7 +108,7 @@ static void hash_resize(BindingHash* hash, size_t desired_capacity) {
new_hash.free_head->prev = nullptr;
/* copy from the old hash to the new hash */
- for (i = 0; i < hash->entries.capacity; ++i) {
+ for (size_t i = 0; i < hash->entries.capacity; ++i) {
BindingHashEntry* old_entry = &hash->entries.data[i];
if (hash_entry_is_free(old_entry))
continue;
@@ -172,8 +171,7 @@ static void destroy_binding_hash_entry(BindingHashEntry* entry) {
void destroy_binding_hash(BindingHash* hash) {
/* Can't use WABT_DESTROY_VECTOR_AND_ELEMENTS, because it loops over size, not
* capacity. */
- size_t i;
- for (i = 0; i < hash->entries.capacity; ++i)
+ for (size_t i = 0; i < hash->entries.capacity; ++i)
destroy_binding_hash_entry(&hash->entries.data[i]);
destroy_binding_hash_entry_vector(&hash->entries);
}
diff --git a/src/generate-names.cc b/src/generate-names.cc
index 277d038f..e1d872c7 100644
--- a/src/generate-names.cc
+++ b/src/generate-names.cc
@@ -82,8 +82,7 @@ static void maybe_generate_and_bind_name(BindingHash* bindings,
static void generate_and_bind_local_names(StringSliceVector* index_to_name,
BindingHash* bindings,
const char* prefix) {
- size_t i;
- for (i = 0; i < index_to_name->size; ++i) {
+ for (size_t i = 0; i < index_to_name->size; ++i) {
StringSlice* old_name = &index_to_name->data[i];
if (has_name(old_name))
continue;
@@ -162,16 +161,15 @@ static Result visit_memory(Context* ctx,
}
static Result visit_module(Context* ctx, Module* module) {
- size_t i;
- for (i = 0; i < module->globals.size; ++i)
+ for (size_t i = 0; i < module->globals.size; ++i)
CHECK_RESULT(visit_global(ctx, i, module->globals.data[i]));
- for (i = 0; i < module->func_types.size; ++i)
+ for (size_t i = 0; i < module->func_types.size; ++i)
CHECK_RESULT(visit_func_type(ctx, i, module->func_types.data[i]));
- for (i = 0; i < module->funcs.size; ++i)
+ for (size_t i = 0; i < module->funcs.size; ++i)
CHECK_RESULT(visit_func(ctx, i, module->funcs.data[i]));
- for (i = 0; i < module->tables.size; ++i)
+ for (size_t i = 0; i < module->tables.size; ++i)
CHECK_RESULT(visit_table(ctx, i, module->tables.data[i]));
- for (i = 0; i < module->memories.size; ++i)
+ for (size_t i = 0; i < module->memories.size; ++i)
CHECK_RESULT(visit_memory(ctx, i, module->memories.data[i]));
return Result::Ok;
}
diff --git a/src/interpreter.cc b/src/interpreter.cc
index c9c2645d..cbcb7306 100644
--- a/src/interpreter.cc
+++ b/src/interpreter.cc
@@ -140,18 +140,16 @@ InterpreterEnvironmentMark mark_interpreter_environment(
void reset_interpreter_environment_to_mark(InterpreterEnvironment* env,
InterpreterEnvironmentMark mark) {
- size_t i;
-
#define DESTROY_PAST_MARK(destroy_name, names) \
do { \
assert(mark.names##_size <= env->names.size); \
- for (i = mark.names##_size; i < env->names.size; ++i) \
+ for (size_t i = mark.names##_size; i < env->names.size; ++i) \
destroy_interpreter_##destroy_name(&env->names.data[i]); \
env->names.size = mark.names##_size; \
} while (0)
/* Destroy entries in the binding hash. */
- for (i = mark.modules_size; i < env->modules.size(); ++i) {
+ for (size_t i = mark.modules_size; i < env->modules.size(); ++i) {
const StringSlice* name = &env->modules[i]->name;
if (!string_slice_is_empty(name))
remove_binding(&env->module_bindings, name);
@@ -160,7 +158,8 @@ void reset_interpreter_environment_to_mark(InterpreterEnvironment* env,
/* registered_module_bindings maps from an arbitrary name to a module index,
* so we have to iterate through the entire table to find entries to remove.
*/
- for (i = 0; i < env->registered_module_bindings.entries.capacity; ++i) {
+ for (size_t i = 0; i < env->registered_module_bindings.entries.capacity;
+ ++i) {
BindingHashEntry* entry = &env->registered_module_bindings.entries.data[i];
if (!hash_entry_is_free(entry) &&
entry->binding.index >= static_cast<int>(mark.modules_size)) {
@@ -767,8 +766,7 @@ InterpreterResult call_host(InterpreterThread* thread, InterpreterFunc* func) {
resize_interpreter_typed_value_vector(&thread->host_args, num_args);
}
- uint32_t i;
- for (i = num_args; i > 0; --i) {
+ for (uint32_t i = num_args; i > 0; --i) {
InterpreterValue value = POP();
InterpreterTypedValue* arg = &thread->host_args.data[i - 1];
arg->type = sig->param_types.data[i - 1];
@@ -785,7 +783,7 @@ InterpreterResult call_host(InterpreterThread* thread, InterpreterFunc* func) {
call_result_values, func->host.user_data);
TRAP_IF(call_result != Result::Ok, HostTrapped);
- for (i = 0; i < num_results; ++i) {
+ for (uint32_t i = 0; i < num_results; ++i) {
TRAP_IF(call_result_values[i].type != sig->result_types.data[i],
HostResultTypeMismatch);
PUSH(call_result_values[i].value);
@@ -804,8 +802,7 @@ InterpreterResult run_interpreter(InterpreterThread* thread,
const uint8_t* istream = reinterpret_cast<const uint8_t*>(env->istream.start);
const uint8_t* pc = &istream[thread->pc];
- uint32_t i;
- for (i = 0; i < num_instructions; ++i) {
+ for (uint32_t i = 0; i < num_instructions; ++i) {
InterpreterOpcode opcode = static_cast<InterpreterOpcode>(*pc++);
switch (opcode) {
case InterpreterOpcode::Select: {
@@ -2370,8 +2367,7 @@ void disassemble(InterpreterEnvironment* env,
* it as a list of table entries */
if (num_bytes % WABT_TABLE_ENTRY_SIZE == 0) {
uint32_t num_entries = num_bytes / WABT_TABLE_ENTRY_SIZE;
- uint32_t i;
- for (i = 0; i < num_entries; ++i) {
+ for (uint32_t i = 0; i < num_entries; ++i) {
writef(stream, "%4" PRIzd "| ", pc - istream);
uint32_t offset;
uint32_t drop;
diff --git a/src/option-parser.cc b/src/option-parser.cc
index 58e7d12a..1ab01327 100644
--- a/src/option-parser.cc
+++ b/src/option-parser.cc
@@ -62,10 +62,7 @@ static void WABT_PRINTF_FORMAT(2, 3)
void parse_options(OptionParser* parser, int argc, char** argv) {
parser->argv0 = argv[0];
- int i;
- int j;
- int k;
- for (i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; ++i) {
char* arg = argv[i];
if (arg[0] == '-') {
if (arg[1] == '-') {
@@ -73,7 +70,7 @@ void parse_options(OptionParser* parser, int argc, char** argv) {
int best_index = -1;
int best_length = 0;
int best_count = 0;
- for (j = 0; j < parser->num_options; ++j) {
+ for (int j = 0; j < parser->num_options; ++j) {
Option* option = &parser->options[j];
if (option->long_name) {
int match_length =
@@ -121,9 +118,9 @@ void parse_options(OptionParser* parser, int argc, char** argv) {
}
/* allow short names to be combined, e.g. "-d -v" => "-dv" */
- for (k = 1; arg[k]; ++k) {
+ for (int k = 1; arg[k]; ++k) {
bool matched = false;
- for (j = 0; j < parser->num_options; ++j) {
+ for (int j = 0; j < parser->num_options; ++j) {
Option* option = &parser->options[j];
if (option->short_name && arg[k] == option->short_name) {
const char* option_argument = nullptr;
@@ -164,7 +161,6 @@ void parse_options(OptionParser* parser, int argc, char** argv) {
}
void print_help(OptionParser* parser, const char* program_name) {
- int i;
/* TODO(binji): do something more generic for filename here */
printf("usage: %s [options] filename\n\n", program_name);
printf("%s\n", parser->description);
@@ -172,7 +168,7 @@ void print_help(OptionParser* parser, const char* program_name) {
const int extra_space = 8;
int longest_name_length = 0;
- for (i = 0; i < parser->num_options; ++i) {
+ for (int i = 0; i < parser->num_options; ++i) {
Option* option = &parser->options[i];
int length;
if (option->long_name) {
@@ -193,7 +189,7 @@ void print_help(OptionParser* parser, const char* program_name) {
size_t buffer_size = longest_name_length + 1;
char* buffer = static_cast<char*>(alloca(buffer_size));
- for (i = 0; i < parser->num_options; ++i) {
+ for (int i = 0; i < parser->num_options; ++i) {
Option* option = &parser->options[i];
if (!option->short_name && !option->long_name)
continue;
diff --git a/src/resolve-names.cc b/src/resolve-names.cc
index 3c0e80c8..90ded7d5 100644
--- a/src/resolve-names.cc
+++ b/src/resolve-names.cc
@@ -85,8 +85,7 @@ static void check_duplicate_bindings(Context* ctx,
static void resolve_label_var(Context* ctx, Var* var) {
if (var->type == VarType::Name) {
- int i;
- for (i = ctx->labels.size - 1; i >= 0; --i) {
+ for (int i = ctx->labels.size - 1; i >= 0; --i) {
Label* label = ctx->labels.data[i];
if (string_slices_are_equal(label, &var->name)) {
destroy_string_slice(&var->name);
@@ -195,9 +194,8 @@ static Result on_br_if_expr(Expr* expr, void* user_data) {
static Result on_br_table_expr(Expr* expr, void* user_data) {
Context* ctx = static_cast<Context*>(user_data);
- size_t i;
VarVector* targets = &expr->br_table.targets;
- for (i = 0; i < targets->size; ++i) {
+ for (size_t i = 0; i < targets->size; ++i) {
Var* target = &targets->data[i];
resolve_label_var(ctx, target);
}
@@ -297,10 +295,9 @@ static void visit_global(Context* ctx, Global* global) {
}
static void visit_elem_segment(Context* ctx, ElemSegment* segment) {
- size_t i;
resolve_table_var(ctx, &segment->table_var);
visit_expr_list(segment->offset, &ctx->visitor);
- for (i = 0; i < segment->vars.size; ++i)
+ for (size_t i = 0; i < segment->vars.size; ++i)
resolve_func_var(ctx, &segment->vars.data[i]);
}
@@ -317,16 +314,15 @@ static void visit_module(Context* ctx, Module* module) {
check_duplicate_bindings(ctx, &module->table_bindings, "table");
check_duplicate_bindings(ctx, &module->memory_bindings, "memory");
- size_t i;
- for (i = 0; i < module->funcs.size; ++i)
+ for (size_t i = 0; i < module->funcs.size; ++i)
visit_func(ctx, module->funcs.data[i]);
- for (i = 0; i < module->exports.size; ++i)
+ for (size_t i = 0; i < module->exports.size; ++i)
visit_export(ctx, module->exports.data[i]);
- for (i = 0; i < module->globals.size; ++i)
+ for (size_t i = 0; i < module->globals.size; ++i)
visit_global(ctx, module->globals.data[i]);
- for (i = 0; i < module->elem_segments.size; ++i)
+ for (size_t i = 0; i < module->elem_segments.size; ++i)
visit_elem_segment(ctx, module->elem_segments.data[i]);
- for (i = 0; i < module->data_segments.size; ++i)
+ for (size_t i = 0; i < module->data_segments.size; ++i)
visit_data_segment(ctx, module->data_segments.data[i]);
if (module->start)
resolve_func_var(ctx, module->start);
@@ -408,8 +404,7 @@ static void visit_command(Context* ctx, Command* command) {
}
static void visit_script(Context* ctx, Script* script) {
- size_t i;
- for (i = 0; i < script->commands.size; ++i)
+ for (size_t i = 0; i < script->commands.size; ++i)
visit_command(ctx, &script->commands.data[i]);
}
diff --git a/src/stream.cc b/src/stream.cc
index 211b7e6b..12510e93 100644
--- a/src/stream.cc
+++ b/src/stream.cc
@@ -135,8 +135,7 @@ void write_memory_dump(Stream* stream,
reinterpret_cast<intptr_t>(start) +
offset);
while (p < line_end) {
- int i;
- for (i = 0; i < DUMP_OCTETS_PER_GROUP; ++i, ++p) {
+ for (int i = 0; i < DUMP_OCTETS_PER_GROUP; ++i, ++p) {
if (p < end) {
writef(stream, "%02x", *p);
} else {
@@ -150,8 +149,7 @@ void write_memory_dump(Stream* stream,
if (print_chars == PrintChars::Yes) {
write_char(stream, ' ');
p = line;
- int i;
- for (i = 0; i < DUMP_OCTETS_PER_LINE && p < end; ++i, ++p)
+ for (int i = 0; i < DUMP_OCTETS_PER_LINE && p < end; ++i, ++p)
write_char(stream, isprint(*p) ? *p : '.');
}
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc
index bd0f19df..edde4a50 100644
--- a/src/tools/wasm-interp.cc
+++ b/src/tools/wasm-interp.cc
@@ -236,8 +236,7 @@ static void print_typed_value(const InterpreterTypedValue* tv) {
static void print_typed_values(const InterpreterTypedValue* values,
size_t num_values) {
- size_t i;
- for (i = 0; i < num_values; ++i) {
+ for (size_t i = 0; i < num_values; ++i) {
print_typed_value(&values[i]);
if (i != num_values - 1)
printf(", ");
@@ -298,8 +297,7 @@ static InterpreterResult push_args(InterpreterThread* thread,
if (sig->param_types.size != args->size)
return InterpreterResult::ArgumentTypeMismatch;
- size_t i;
- for (i = 0; i < sig->param_types.size; ++i) {
+ for (size_t i = 0; i < sig->param_types.size; ++i) {
if (sig->param_types.data[i] != args->data[i].type)
return InterpreterResult::ArgumentTypeMismatch;
@@ -325,8 +323,7 @@ static void copy_results(InterpreterThread* thread,
* size to zero. */
out_results->size = 0;
resize_interpreter_typed_value_vector(out_results, expected_results);
- size_t i;
- for (i = 0; i < expected_results; ++i) {
+ for (size_t i = 0; i < expected_results; ++i) {
out_results->data[i].type = sig->result_types.data[i];
out_results->data[i].value = thread->value_stack[i];
}
@@ -432,8 +429,7 @@ static void run_all_exports(InterpreterModule* module,
InterpreterTypedValueVector results;
WABT_ZERO_MEMORY(args);
WABT_ZERO_MEMORY(results);
- uint32_t i;
- for (i = 0; i < module->exports.size; ++i) {
+ for (uint32_t i = 0; i < module->exports.size; ++i) {
InterpreterExport* export_ = &module->exports.data[i];
InterpreterResult iresult = run_export(thread, export_, &args, &results);
if (verbose == RunVerbosity::Verbose) {
@@ -476,8 +472,7 @@ static Result default_host_callback(const InterpreterFunc* func,
InterpreterTypedValue* out_results,
void* user_data) {
memset(out_results, 0, sizeof(InterpreterTypedValue) * num_results);
- uint32_t i;
- for (i = 0; i < num_results; ++i)
+ for (uint32_t i = 0; i < num_results; ++i)
out_results[i].type = sig->result_types.data[i];
InterpreterTypedValueVector vec_args;
@@ -812,9 +807,8 @@ static Result parse_string(Context* ctx, StringSlice* out_string) {
print_parse_error(ctx, "expected escape: \\uxxxx");
return Result::Error;
}
- int i;
uint16_t code = 0;
- for (i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i) {
c = read_char(ctx);
int cval;
if (c >= '0' && c <= '9') {
@@ -1178,9 +1172,8 @@ static Result on_register_command(Context* ctx,
/* The module names can be different than their registered names. We don't
* keep a hash for the module names (just the registered names), so we'll
* just iterate over all the modules to find it. */
- size_t i;
module_index = -1;
- for (i = 0; i < ctx->env.modules.size(); ++i) {
+ for (size_t i = 0; i < ctx->env.modules.size(); ++i) {
const StringSlice* module_name = &ctx->env.modules[i]->name;
if (!string_slice_is_empty(module_name) &&
string_slices_are_equal(&name, module_name)) {
@@ -1320,8 +1313,7 @@ static Result on_assert_return_command(Context* ctx,
if (WABT_SUCCEEDED(result)) {
if (iresult == InterpreterResult::Ok) {
if (results.size == expected->size) {
- size_t i;
- for (i = 0; i < results.size; ++i) {
+ for (size_t i = 0; i < results.size; ++i) {
const InterpreterTypedValue* expected_tv = &expected->data[i];
const InterpreterTypedValue* actual_tv = &results.data[i];
if (!typed_values_are_equal(expected_tv, actual_tv)) {
diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc
index 08b03c87..256ee6ca 100644
--- a/src/tools/wasm-link.cc
+++ b/src/tools/wasm-link.cc
@@ -206,8 +206,7 @@ static void apply_relocations(Section* section) {
get_section_name(section->section_code));
/* Perform relocations in-place */
- size_t i;
- for (i = 0; i < section->relocations.size; i++) {
+ for (size_t i = 0; i < section->relocations.size; i++) {
Reloc* reloc = &section->relocations.data[i];
apply_relocation(section, reloc);
}
@@ -251,8 +250,7 @@ static void write_table_section(Context* ctx,
uint32_t flags = WABT_BINARY_LIMITS_HAS_MAX_FLAG;
uint32_t elem_count = 0;
- size_t i;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
elem_count += sec->binary->table_elem_count;
}
@@ -268,9 +266,8 @@ static void write_table_section(Context* ctx,
}
static void write_export_section(Context* ctx) {
- size_t i, j;
uint32_t total_exports = 0;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
total_exports += binary->exports.size;
}
@@ -279,9 +276,9 @@ static void write_export_section(Context* ctx) {
WRITE_UNKNOWN_SIZE(stream);
write_u32_leb128(stream, total_exports, "export count");
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
- for (j = 0; j < binary->exports.size; j++) {
+ for (size_t j = 0; j < binary->exports.size; j++) {
Export* export_ = &binary->exports.data[j];
write_slice(stream, export_->name, "export name");
write_u8_enum(stream, export_->kind, "export kind");
@@ -305,9 +302,8 @@ static void write_elem_section(Context* ctx, const SectionPtrVector* sections) {
Stream* stream = &ctx->stream;
WRITE_UNKNOWN_SIZE(stream);
- size_t i;
uint32_t total_elem_count = 0;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
total_elem_count += sec->binary->table_elem_count;
}
@@ -321,7 +317,7 @@ static void write_elem_section(Context* ctx, const SectionPtrVector* sections) {
ctx->current_section_payload_offset = stream->offset;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
apply_relocations(sec);
write_section_payload(ctx, sec);
@@ -340,8 +336,7 @@ static void write_memory_section(Context* ctx,
Limits limits;
WABT_ZERO_MEMORY(limits);
limits.has_max = true;
- size_t i;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
limits.initial += sec->memory_limits.initial;
}
@@ -371,11 +366,10 @@ static void write_global_import(Context* ctx, GlobalImport* import) {
static void write_import_section(Context* ctx) {
uint32_t num_imports = 0;
- size_t i, j;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
FunctionImportVector* imports = &binary->function_imports;
- for (j = 0; j < imports->size; j++) {
+ for (size_t j = 0; j < imports->size; j++) {
FunctionImport* import = &imports->data[j];
if (import->active)
num_imports++;
@@ -386,17 +380,17 @@ static void write_import_section(Context* ctx) {
WRITE_UNKNOWN_SIZE(&ctx->stream);
write_u32_leb128(&ctx->stream, num_imports, "num imports");
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
FunctionImportVector* imports = &binary->function_imports;
- for (j = 0; j < imports->size; j++) {
+ for (size_t j = 0; j < imports->size; j++) {
FunctionImport* import = &imports->data[j];
if (import->active)
write_function_import(ctx, import, binary->type_index_offset);
}
GlobalImportVector* globals = &binary->global_imports;
- for (j = 0; j < globals->size; j++) {
+ for (size_t j = 0; j < globals->size; j++) {
write_global_import(ctx, &globals->data[j]);
}
}
@@ -412,8 +406,7 @@ static void write_function_section(Context* ctx,
write_u32_leb128(stream, total_count, "function count");
- size_t i;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
uint32_t count = sec->count;
uint32_t input_offset = 0;
@@ -450,10 +443,9 @@ static void write_data_section(Context* ctx,
WRITE_UNKNOWN_SIZE(stream);
write_u32_leb128(stream, total_count, "data segment count");
- size_t i, j;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
- for (j = 0; j < sec->data_segments.size; j++) {
+ for (size_t j = 0; j < sec->data_segments.size; j++) {
DataSegment* segment = &sec->data_segments.data[j];
write_data_segment(stream, segment,
sec->binary->memory_page_offset * WABT_PAGE_SIZE);
@@ -465,10 +457,10 @@ static void write_data_section(Context* ctx,
static void write_names_section(Context* ctx) {
uint32_t total_count = 0;
- size_t i, j, k;
- for (i = 0; i < ctx->inputs.size; i++) {
+ size_t k;
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
- for (j = 0; j < binary->debug_names.size; j++) {
+ for (size_t j = 0; j < binary->debug_names.size; j++) {
if (j < binary->function_imports.size) {
if (!binary->function_imports.data[j].active)
continue;
@@ -489,9 +481,9 @@ static void write_names_section(Context* ctx) {
write_u32_leb128(stream, total_count, "element count");
k = 0;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
- for (j = 0; j < binary->debug_names.size; j++) {
+ for (size_t j = 0; j < binary->debug_names.size; j++) {
if (j < binary->function_imports.size) {
if (!binary->function_imports.data[j].active)
continue;
@@ -508,11 +500,10 @@ static void write_names_section(Context* ctx) {
static void write_reloc_section(Context* ctx,
BinarySection section_code,
SectionPtrVector* sections) {
- size_t i, j;
uint32_t total_relocs = 0;
/* First pass to know total reloc count */
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
total_relocs += sec->relocations.size;
}
@@ -531,10 +522,10 @@ static void write_reloc_section(Context* ctx,
write_u32_leb128_enum(&ctx->stream, section_code, "reloc section");
write_u32_leb128(&ctx->stream, total_relocs, "num relocs");
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
RelocVector* relocs = &sec->relocations;
- for (j = 0; j < relocs->size; j++) {
+ for (size_t j = 0; j < relocs->size; j++) {
write_u32_leb128_enum(&ctx->stream, relocs->data[j].type, "reloc type");
uint32_t new_offset = relocs->data[j].offset + sec->output_payload_offset;
write_u32_leb128(&ctx->stream, new_offset, "reloc offset");
@@ -555,12 +546,11 @@ static bool write_combined_section(Context* ctx,
get_section_name(section_code));
}
- size_t i;
uint32_t total_count = 0;
uint32_t total_size = 0;
/* Sum section size and element count */
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
total_size += sec->payload_size;
total_count += sec->count;
@@ -600,7 +590,7 @@ static bool write_combined_section(Context* ctx,
write_u32_leb128(stream, total_size, "section size");
write_u32_leb128(stream, total_count, "element count");
ctx->current_section_payload_offset = ctx->stream.offset;
- for (i = 0; i < sections->size; i++) {
+ for (size_t i = 0; i < sections->size; i++) {
Section* sec = sections->data[i];
apply_relocations(sec);
write_section_payload(ctx, sec);
@@ -624,10 +614,9 @@ static void resolve_symbols(Context* ctx) {
ExportInfoVector export_list;
WABT_ZERO_MEMORY(export_list);
- size_t i, j;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
- for (j = 0; j < binary->exports.size; j++) {
+ for (size_t j = 0; j < binary->exports.size; j++) {
Export* export_ = &binary->exports.data[j];
ExportInfo* info = append_export_info(&export_list);
info->export_ = export_;
@@ -644,9 +633,9 @@ static void resolve_symbols(Context* ctx) {
* Iterate through all imported functions resolving them against exported
* ones.
*/
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
- for (j = 0; j < binary->function_imports.size; j++) {
+ for (size_t j = 0; j < binary->function_imports.size; j++) {
FunctionImport* import = &binary->function_imports.data[j];
int export_index = find_binding_index_by_name(&export_map, &import->name);
if (export_index == -1) {
@@ -672,7 +661,6 @@ static void resolve_symbols(Context* ctx) {
}
static void calculate_reloc_offsets(Context* ctx) {
- size_t i, j;
uint32_t memory_page_offset = 0;
uint32_t type_count = 0;
uint32_t global_count = 0;
@@ -680,7 +668,7 @@ static void calculate_reloc_offsets(Context* ctx) {
uint32_t table_elem_count = 0;
uint32_t total_function_imports = 0;
uint32_t total_global_imports = 0;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
/* The imported_function_index_offset is the sum of all the function
* imports from objects that precede this one. i.e. the current running
@@ -693,11 +681,11 @@ static void calculate_reloc_offsets(Context* ctx) {
total_global_imports += binary->global_imports.size;
}
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (size_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
binary->table_index_offset = table_elem_count;
table_elem_count += binary->table_elem_count;
- for (j = 0; j < binary->sections.size; j++) {
+ for (size_t j = 0; j < binary->sections.size; j++) {
Section* sec = &binary->sections.data[j];
switch (sec->section_code) {
case BinarySection::Type:
@@ -728,10 +716,9 @@ static void write_binary(Context* ctx) {
SectionPtrVector sections[kBinarySectionCount];
WABT_ZERO_MEMORY(sections);
- size_t i, j;
- for (j = 0; j < ctx->inputs.size; j++) {
+ for (size_t j = 0; j < ctx->inputs.size; j++) {
LinkerInputBinary* binary = &ctx->inputs.data[j];
- for (i = 0; i < binary->sections.size; i++) {
+ for (size_t i = 0; i < binary->sections.size; i++) {
Section* s = &binary->sections.data[i];
SectionPtrVector* sec_list = &sections[static_cast<int>(s->section_code)];
append_section_ptr_value(sec_list, &s);
@@ -743,26 +730,25 @@ static void write_binary(Context* ctx) {
write_u32(&ctx->stream, WABT_BINARY_VERSION, "WABT_BINARY_VERSION");
/* Write known sections first */
- for (i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) {
+ for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) {
write_combined_section(ctx, static_cast<BinarySection>(i), &sections[i]);
}
write_names_section(ctx);
/* Generate a new set of reloction sections */
- for (i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) {
+ for (size_t i = FIRST_KNOWN_SECTION; i < kBinarySectionCount; i++) {
write_reloc_section(ctx, static_cast<BinarySection>(i), &sections[i]);
}
- for (i = 0; i < kBinarySectionCount; i++) {
+ for (size_t i = 0; i < kBinarySectionCount; i++) {
destroy_section_ptr_vector(&sections[i]);
}
}
static void dump_reloc_offsets(Context* ctx) {
if (s_debug) {
- uint32_t i;
- for (i = 0; i < ctx->inputs.size; i++) {
+ for (uint32_t i = 0; i < ctx->inputs.size; i++) {
LinkerInputBinary* binary = &ctx->inputs.data[i];
writef(&s_log_stream, "Relocation info for: %s\n", binary->filename);
writef(&s_log_stream, " - type index offset : %d\n",
@@ -817,8 +803,7 @@ int main(int argc, char** argv) {
parse_options(argc, argv);
Result result = Result::Ok;
- size_t i;
- for (i = 0; i < s_infiles.size; i++) {
+ for (size_t i = 0; i < s_infiles.size; i++) {
const char* input_filename = s_infiles.data[i];
if (s_debug)
writef(&s_log_stream, "reading file: %s\n", input_filename);
diff --git a/src/tools/wasmopcodecnt.cc b/src/tools/wasmopcodecnt.cc
index 4f09a958..15bb6b3c 100644
--- a/src/tools/wasmopcodecnt.cc
+++ b/src/tools/wasmopcodecnt.cc
@@ -158,8 +158,7 @@ static void display_int_counter_vector(FILE* out,
IntCounterVector* vec,
display_name_fcn display_fcn,
const char* opcode_name) {
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].count == 0)
continue;
if (opcode_name)
@@ -176,8 +175,7 @@ static void display_int_pair_counter_vector(FILE* out,
display_name_fcn display_first_fcn,
display_name_fcn display_second_fcn,
const char* opcode_name) {
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].count == 0)
continue;
if (opcode_name)
@@ -284,8 +282,7 @@ static void display_sorted_int_counter_vector(FILE* out,
/* First filter out values less than cutoff. This speeds up sorting. */
IntCounterVector filtered_vec;
WABT_ZERO_MEMORY(filtered_vec);
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].count < s_cutoff)
continue;
append_int_counter_value(&filtered_vec, &vec->data[i]);
@@ -314,8 +311,7 @@ static void display_sorted_int_pair_counter_vector(
IntPairCounterVector filtered_vec;
WABT_ZERO_MEMORY(filtered_vec);
IntPairCounterVector sorted_vec;
- size_t i;
- for (i = 0; i < vec->size; ++i) {
+ for (size_t i = 0; i < vec->size; ++i) {
if (vec->data[i].count < s_cutoff)
continue;
append_int_pair_counter_value(&filtered_vec, &vec->data[i]);
diff --git a/src/type-checker.cc b/src/type-checker.cc
index 8cd04633..5d91665d 100644
--- a/src/type-checker.cc
+++ b/src/type-checker.cc
@@ -147,8 +147,7 @@ static void push_type(TypeChecker* tc, Type type) {
}
static void push_types(TypeChecker* tc, const TypeVector* types) {
- size_t i;
- for (i = 0; i < types->size; ++i)
+ for (size_t i = 0; i < types->size; ++i)
push_type(tc, types->data[i]);
}
@@ -194,9 +193,8 @@ static Result check_signature(TypeChecker* tc,
const TypeVector* sig,
const char* desc) {
Result result = Result::Ok;
- size_t i;
COMBINE_RESULT(result, check_type_stack_limit(tc, sig->size, desc));
- for (i = 0; i < sig->size; ++i) {
+ for (size_t i = 0; i < sig->size; ++i) {
Type actual = Type::Any;
COMBINE_RESULT(result, peek_type(tc, sig->size - i - 1, &actual));
COMBINE_RESULT(result, check_type(tc, actual, sig->data[i], desc));
@@ -218,9 +216,8 @@ static Result pop_and_check_call(TypeChecker* tc,
const TypeVector* result_types,
const char* desc) {
Result result = Result::Ok;
- size_t i;
COMBINE_RESULT(result, check_type_stack_limit(tc, param_types->size, desc));
- for (i = 0; i < param_types->size; ++i) {
+ for (size_t i = 0; i < param_types->size; ++i) {
Type actual = Type::Any;
COMBINE_RESULT(result, peek_type(tc, param_types->size - i - 1, &actual));
COMBINE_RESULT(result, check_type(tc, actual, param_types->data[i], desc));
diff --git a/src/validator.cc b/src/validator.cc
index c00b23d3..07cdcc42 100644
--- a/src/validator.cc
+++ b/src/validator.cc
@@ -265,8 +265,7 @@ static void check_types(Context* ctx,
const char* desc,
const char* index_kind) {
if (actual->size == expected->size) {
- size_t i;
- for (i = 0; i < actual->size; ++i) {
+ for (size_t i = 0; i < actual->size; ++i) {
check_type_index(ctx, loc, actual->data[i], expected->data[i], desc, i,
index_kind);
}
@@ -282,8 +281,7 @@ static void check_const_types(Context* ctx,
const ConstVector* expected,
const char* desc) {
if (actual->size == expected->size) {
- size_t i;
- for (i = 0; i < actual->size; ++i) {
+ for (size_t i = 0; i < actual->size; ++i) {
check_type_index(ctx, loc, actual->data[i], expected->data[i].type, desc,
i, "result");
}
@@ -323,8 +321,7 @@ static void check_expr_list(Context* ctx,
const Location* loc,
const Expr* first) {
if (first) {
- const Expr* expr;
- for (expr = first; expr; expr = expr->next)
+ for (const Expr* expr = first; expr; expr = expr->next)
check_expr(ctx, expr);
}
}
@@ -360,8 +357,7 @@ static void check_expr(Context* ctx, const Expr* expr) {
case ExprType::BrTable: {
typechecker_begin_br_table(&ctx->typechecker);
- size_t i;
- for (i = 0; i < expr->br_table.targets.size; ++i) {
+ for (size_t i = 0; i < expr->br_table.targets.size; ++i) {
typechecker_on_br_table_target(&ctx->typechecker,
expr->br_table.targets.data[i].index);
}
@@ -638,8 +634,7 @@ static void check_table(Context* ctx, const Location* loc, const Table* table) {
}
static void check_elem_segments(Context* ctx, const Module* module) {
- ModuleField* field;
- for (field = module->first_field; field; field = field->next) {
+ for (ModuleField* field = module->first_field; field; field = field->next) {
if (field->type != ModuleFieldType::ElemSegment)
continue;
@@ -648,8 +643,7 @@ static void check_elem_segments(Context* ctx, const Module* module) {
if (!WABT_SUCCEEDED(check_table_var(ctx, &elem_segment->table_var, &table)))
continue;
- size_t i;
- for (i = 0; i < elem_segment->vars.size; ++i) {
+ for (size_t i = 0; i < elem_segment->vars.size; ++i) {
if (!WABT_SUCCEEDED(
check_func_var(ctx, &elem_segment->vars.data[i], nullptr)))
continue;
@@ -669,8 +663,7 @@ static void check_memory(Context* ctx,
}
static void check_data_segments(Context* ctx, const Module* module) {
- ModuleField* field;
- for (field = module->first_field; field; field = field->next) {
+ for (ModuleField* field = module->first_field; field; field = field->next) {
if (field->type != ModuleFieldType::DataSegment)
continue;
@@ -762,8 +755,7 @@ static void check_module(Context* ctx, const Module* module) {
ctx->current_global_index = 0;
ctx->num_imported_globals = 0;
- ModuleField* field;
- for (field = module->first_field; field; field = field->next) {
+ for (ModuleField* field = module->first_field; field; field = field->next) {
switch (field->type) {
case ModuleFieldType::Func:
check_func(ctx, &field->loc, &field->func);
@@ -865,8 +857,7 @@ static const TypeVector* check_invoke(Context* ctx, const Action* action) {
expected_args);
return nullptr;
}
- size_t i;
- for (i = 0; i < actual_args; ++i) {
+ for (size_t i = 0; i < actual_args; ++i) {
Const* const_ = &invoke->args.data[i];
check_type_index(ctx, &const_->loc, const_->type, get_param_type(func, i),
"invoke", i, "argument");
@@ -1015,8 +1006,7 @@ Result validate_script(AstLexer* lexer,
tc_error_handler.user_data = &ctx;
ctx.typechecker.error_handler = &tc_error_handler;
- size_t i;
- for (i = 0; i < script->commands.size; ++i)
+ for (size_t i = 0; i < script->commands.size; ++i)
check_command(&ctx, &script->commands.data[i]);
destroy_context(&ctx);
return ctx.result;
diff --git a/src/vector-sort.h b/src/vector-sort.h
index c3fdda48..64171363 100644
--- a/src/vector-sort.h
+++ b/src/vector-sort.h
@@ -30,15 +30,13 @@
void (*swap_fcn)(type * v1, type * v2), \
int (*lt_fcn)(type * v1, type * v2)) { \
/* TODO(karlschimpf) Use a faster sort. */ \
- size_t i; \
- size_t j; \
if (in_vec->size == 0) \
return; \
- for (i = 0; i < in_vec->size; ++i) { \
+ for (size_t i = 0; i < in_vec->size; ++i) { \
append_##name##_value(out_vec, &in_vec->data[i]); \
if (out_vec->size < 2) \
continue; \
- for (j = out_vec->size; j >= 2; --j) { \
+ for (size_t j = out_vec->size; j >= 2; --j) { \
type* v1 = &out_vec->data[j - 1]; \
type* v2 = &out_vec->data[j - 2]; \
if (lt_fcn(v1, v2)) \
diff --git a/src/vector.h b/src/vector.h
index 326cb4c7..6a3d0ad9 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -90,8 +90,7 @@
#define WABT_DESTROY_VECTOR_AND_ELEMENTS(v, name) \
{ \
- size_t i; \
- for (i = 0; i < (v).size; ++i) \
+ for (size_t i = 0; i < (v).size; ++i) \
destroy_##name(&((v).data[i])); \
destroy_##name##_vector(&(v)); \
}