diff options
Diffstat (limited to 'src')
51 files changed, 436 insertions, 396 deletions
diff --git a/src/binary-reader-interp.cc b/src/binary-reader-interp.cc index 6766ce38..38817b32 100644 --- a/src/binary-reader-interp.cc +++ b/src/binary-reader-interp.cc @@ -1181,8 +1181,8 @@ wabt::Result BinaryReaderInterp::OnTernaryExpr(wabt::Opcode opcode) { return wabt::Result::Ok; } -wabt::Result BinaryReaderInterp::OnSimdLaneOpExpr(wabt::Opcode opcode, - uint64_t value) { +wabt::Result BinaryReaderInterp::OnSimdLaneOpExpr(wabt::Opcode opcode, + uint64_t value) { CHECK_RESULT(typechecker_.OnSimdLaneOp(opcode, value)); CHECK_RESULT(EmitOpcode(opcode)); CHECK_RESULT(EmitI8(static_cast<uint8_t>(value))); @@ -1190,7 +1190,7 @@ wabt::Result BinaryReaderInterp::OnSimdLaneOpExpr(wabt::Opcode opcode, } wabt::Result BinaryReaderInterp::OnSimdShuffleOpExpr(wabt::Opcode opcode, - v128 value) { + v128 value) { CHECK_RESULT(typechecker_.OnSimdShuffleOp(opcode, value)); CHECK_RESULT(EmitOpcode(opcode)); CHECK_RESULT(EmitV128(value)); diff --git a/src/binary-reader-ir.h b/src/binary-reader-ir.h index 74ed6b22..7c4e4244 100644 --- a/src/binary-reader-ir.h +++ b/src/binary-reader-ir.h @@ -32,6 +32,6 @@ Result ReadBinaryIr(const char* filename, ErrorHandler*, Module* out_module); -} // namespace wabt +} // namespace wabt #endif /* WABT_BINARY_READER_IR_H_ */ diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc index 544666e4..03a17cd6 100644 --- a/src/binary-reader-logging.cc +++ b/src/binary-reader-logging.cc @@ -308,8 +308,8 @@ Result BinaryReaderLogging::OnF64ConstExpr(uint64_t value_bits) { } Result BinaryReaderLogging::OnV128ConstExpr(v128 value_bits) { - LOGF("OnV128ConstExpr(0x%08x 0x%08x 0x%08x 0x%08x)\n", value_bits.v[0],\ - value_bits.v[1], value_bits.v[2], value_bits.v[3]); + LOGF("OnV128ConstExpr(0x%08x 0x%08x 0x%08x 0x%08x)\n", value_bits.v[0], + value_bits.v[1], value_bits.v[2], value_bits.v[3]); return reader_->OnV128ConstExpr(value_bits); } @@ -353,14 +353,14 @@ Result BinaryReaderLogging::OnTryExpr(Index num_types, Type* sig_types) { return reader_->OnTryExpr(num_types, sig_types); } -Result BinaryReaderLogging::OnSimdLaneOpExpr(Opcode opcode, uint64_t value) { +Result BinaryReaderLogging::OnSimdLaneOpExpr(Opcode opcode, uint64_t value) { LOGF("OnSimdLaneOpExpr (lane: %" PRIu64 ")\n", value); return reader_->OnSimdLaneOpExpr(opcode, value); } -Result BinaryReaderLogging::OnSimdShuffleOpExpr(Opcode opcode, v128 value) { +Result BinaryReaderLogging::OnSimdShuffleOpExpr(Opcode opcode, v128 value) { LOGF("OnSimdShuffleOpExpr (lane: 0x%08x %08x %08x %08x)\n", value.v[0], - value.v[1], value.v[2], value.v[3]); + value.v[1], value.v[2], value.v[3]); return reader_->OnSimdShuffleOpExpr(opcode, value); } @@ -426,9 +426,10 @@ Result BinaryReaderLogging::OnInitExprF64ConstExpr(Index index, Result BinaryReaderLogging::OnInitExprV128ConstExpr(Index index, v128 value_bits) { - LOGF("OnInitExprV128ConstExpr(index: %" PRIindex " value: (\ - 0x%08x 0x%08x 0x%08x 0x%08x))\n", index, value_bits.v[0],\ - value_bits.v[1], value_bits.v[2], value_bits.v[3]); + LOGF("OnInitExprV128ConstExpr(index: %" PRIindex + " value: ( 0x%08x 0x%08x 0x%08x 0x%08x))\n", + index, value_bits.v[0], value_bits.v[1], value_bits.v[2], + value_bits.v[3]); return reader_->OnInitExprV128ConstExpr(index, value_bits); } diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h index 6691f069..2acf7ae5 100644 --- a/src/binary-reader-logging.h +++ b/src/binary-reader-logging.h @@ -210,10 +210,8 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result BeginElemSegment(Index index, Index table_index) override; Result BeginElemSegmentInitExpr(Index index) override; Result EndElemSegmentInitExpr(Index index) override; - Result OnElemSegmentFunctionIndexCount(Index index, - Index count) override; - Result OnElemSegmentFunctionIndex(Index index, - Index func_index) override; + Result OnElemSegmentFunctionIndexCount(Index index, Index count) override; + Result OnElemSegmentFunctionIndex(Index index, Index func_index) override; Result EndElemSegment(Index index) override; Result EndElemSection() override; @@ -239,8 +237,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate { uint32_t name_type, Offset subsection_size) override; Result OnLocalNameFunctionCount(Index num_functions) override; - Result OnLocalNameLocalCount(Index function_index, - Index num_locals) override; + Result OnLocalNameLocalCount(Index function_index, Index num_locals) override; Result OnLocalName(Index function_index, Index local_index, string_view local_name) override; @@ -292,8 +289,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnInitExprF32ConstExpr(Index index, uint32_t value) override; Result OnInitExprF64ConstExpr(Index index, uint64_t value) override; Result OnInitExprV128ConstExpr(Index index, v128 value) override; - Result OnInitExprGetGlobalExpr(Index index, - Index global_index) override; + Result OnInitExprGetGlobalExpr(Index index, Index global_index) override; Result OnInitExprI32ConstExpr(Index index, uint32_t value) override; Result OnInitExprI64ConstExpr(Index index, uint64_t value) override; diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 44ffd4cb..96dffbbf 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -570,7 +570,7 @@ struct InitExpr { uint32_t f32; uint64_t i64; uint64_t f64; - v128 v128_v; + v128 v128_v; } value; }; @@ -1079,8 +1079,9 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) { break; } case InitExprType::V128: { - PrintDetails(" - init v128=0x%08x 0x%08x 0x%08x 0x%08x \n", expr.value.v128_v.v[0],\ - expr.value.v128_v.v[1], expr.value.v128_v.v[2], expr.value.v128_v.v[3]); + PrintDetails(" - init v128=0x%08x 0x%08x 0x%08x 0x%08x \n", + expr.value.v128_v.v[0], expr.value.v128_v.v[1], + expr.value.v128_v.v[2], expr.value.v128_v.v[3]); break; } case InitExprType::Global: @@ -1115,8 +1116,7 @@ Result BinaryReaderObjdump::OnInitExprF64ConstExpr(Index index, return Result::Ok; } -Result BinaryReaderObjdump::OnInitExprV128ConstExpr(Index index, - v128 value) { +Result BinaryReaderObjdump::OnInitExprV128ConstExpr(Index index, v128 value) { InitExpr expr; expr.type = InitExprType::V128; expr.value.v128_v = value; @@ -1384,7 +1384,6 @@ Result BinaryReaderObjdump::OnSegmentInfo(Index index, return Result::Ok; } - Result BinaryReaderObjdump::OnInitFunctionCount(Index count) { PrintDetails(" - init functions [count=%d]\n", count); return Result::Ok; diff --git a/src/binary-reader-opcnt.cc b/src/binary-reader-opcnt.cc index 72a4fdc9..9338572c 100644 --- a/src/binary-reader-opcnt.cc +++ b/src/binary-reader-opcnt.cc @@ -143,12 +143,24 @@ bool operator!=(const OpcodeInfo& lhs, const OpcodeInfo& rhs) { } bool operator<(const OpcodeInfo& lhs, const OpcodeInfo& rhs) { - if (lhs.opcode_ < rhs.opcode_) { return true; } - if (lhs.opcode_ > rhs.opcode_) { return false; } - if (lhs.kind_ < rhs.kind_) { return true; } - if (lhs.kind_ > rhs.kind_) { return false; } - if (lhs.data_ < rhs.data_) { return true; } - if (lhs.data_ > rhs.data_) { return false; } + if (lhs.opcode_ < rhs.opcode_) { + return true; + } + if (lhs.opcode_ > rhs.opcode_) { + return false; + } + if (lhs.kind_ < rhs.kind_) { + return true; + } + if (lhs.kind_ > rhs.kind_) { + return false; + } + if (lhs.data_ < rhs.data_) { + return true; + } + if (lhs.data_ > rhs.data_) { + return false; + } return false; } diff --git a/src/binary-reader.cc b/src/binary-reader.cc index d5d2fedc..89bb4c38 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -26,8 +26,8 @@ #include "config.h" -#include "src/binary.h" #include "src/binary-reader-logging.h" +#include "src/binary.h" #include "src/leb128.h" #include "src/stream.h" #include "src/utf8.h" @@ -51,9 +51,8 @@ } \ } while (0) -#define CALLBACK0(member) \ - ERROR_UNLESS(Succeeded(delegate_->member()), #member \ - " callback failed") +#define CALLBACK0(member) \ + ERROR_UNLESS(Succeeded(delegate_->member()), #member " callback failed") #define CALLBACK(member, ...) \ ERROR_UNLESS(Succeeded(delegate_->member(__VA_ARGS__)), \ @@ -127,7 +126,7 @@ class BinaryReader { Result ReadSections() WABT_WARN_UNUSED; Result ReportUnexpectedOpcode(Opcode opcode, const char* message = nullptr); - size_t read_end_ = 0; // Either the section end or data_size. + size_t read_end_ = 0; // Either the section end or data_size. BinaryReaderDelegate::State state_; BinaryReaderLogging logging_delegate_; BinaryReaderDelegate* delegate_ = nullptr; @@ -187,8 +186,8 @@ Result BinaryReader::ReportUnexpectedOpcode(Opcode opcode, opcode.GetPrefix(), opcode.GetCode(), opcode.GetPrefix(), opcode.GetCode()); } else { - PrintError("unexpected opcode%s%s: %d (0x%x)", - maybe_space, message, opcode.GetCode(), opcode.GetCode()); + PrintError("unexpected opcode%s%s: %d (0x%x)", maybe_space, message, + opcode.GetCode(), opcode.GetCode()); } return Result::Error; } diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc index 1ccffe6e..a2d8845c 100644 --- a/src/binary-writer-spec.cc +++ b/src/binary-writer-spec.cc @@ -21,8 +21,8 @@ #include "config.h" -#include "src/binary.h" #include "src/binary-writer.h" +#include "src/binary.h" #include "src/cast.h" #include "src/filenames.h" #include "src/ir.h" diff --git a/src/binary-writer.cc b/src/binary-writer.cc index b53d8c0d..7f3d0f96 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -237,7 +237,8 @@ static void write_inline_signature_type(Stream* stream, } } -void BinaryWriter::WriteSectionHeader(const char* desc, BinarySection section_code) { +void BinaryWriter::WriteSectionHeader(const char* desc, + BinarySection section_code) { assert(last_section_leb_size_guess_ == 0); WriteHeader(desc, PRINT_HEADER_NO_INDEX); stream_->WriteU8Enum(section_code, "section code"); @@ -268,8 +269,9 @@ void BinaryWriter::EndSection() { Offset delta = WriteFixupU32Leb128Size( last_section_offset_, last_section_leb_size_guess_, "FIXUP section size"); if (current_reloc_section_ && delta != 0) { - for (Reloc& reloc: current_reloc_section_->relocations) + for (Reloc& reloc : current_reloc_section_->relocations) { reloc.offset += delta; + } } last_section_leb_size_guess_ = 0; } @@ -591,13 +593,15 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { case ExprType::SimdLaneOp: { const Opcode opcode = cast<SimdLaneOpExpr>(expr)->opcode; WriteOpcode(stream_, opcode); - stream_->WriteU8(static_cast<uint8_t>(cast<SimdLaneOpExpr>(expr)->val), "Simd Lane literal"); + stream_->WriteU8(static_cast<uint8_t>(cast<SimdLaneOpExpr>(expr)->val), + "Simd Lane literal"); break; } case ExprType::SimdShuffleOp: { const Opcode opcode = cast<SimdShuffleOpExpr>(expr)->opcode; WriteOpcode(stream_, opcode); - stream_->WriteU128(cast<SimdShuffleOpExpr>(expr)->val, "Simd Lane[16] literal"); + stream_->WriteU128(cast<SimdShuffleOpExpr>(expr)->val, + "Simd Lane[16] literal"); break; } case ExprType::Unreachable: @@ -607,8 +611,9 @@ void BinaryWriter::WriteExpr(const Func* func, const Expr* expr) { } void BinaryWriter::WriteExprList(const Func* func, const ExprList& exprs) { - for (const Expr& expr : exprs) + for (const Expr& expr : exprs) { WriteExpr(func, &expr); + } } void BinaryWriter::WriteInitExpr(const ExprList& expr) { @@ -680,8 +685,9 @@ void BinaryWriter::WriteGlobalHeader(const Global* global) { void BinaryWriter::WriteExceptType(const TypeVector* except_types) { WriteU32Leb128(stream_, except_types->size(), "exception type count"); - for (Type ty : *except_types) + for (Type ty : *except_types) { WriteType(stream_, ty); + } } void BinaryWriter::WriteRelocSection(const RelocSection* reloc_section) { @@ -765,12 +771,14 @@ Result BinaryWriter::WriteModule() { Index num_params = sig->param_types.size(); Index num_results = sig->result_types.size(); WriteU32Leb128(stream_, num_params, "num params"); - for (size_t j = 0; j < num_params; ++j) + for (size_t j = 0; j < num_params; ++j) { WriteType(stream_, sig->param_types[j]); + } WriteU32Leb128(stream_, num_results, "num results"); - for (size_t j = 0; j < num_results; ++j) + for (size_t j = 0; j < num_results; ++j) { WriteType(stream_, sig->result_types[j]); + } } EndSection(); } diff --git a/src/binding-hash.h b/src/binding-hash.h index 84730668..07795270 100644 --- a/src/binding-hash.h +++ b/src/binding-hash.h @@ -19,8 +19,8 @@ #include <functional> #include <string> -#include <vector> #include <unordered_map> +#include <vector> #include "src/common.h" #include "src/string-view.h" diff --git a/src/c-writer.cc b/src/c-writer.cc index 5be29c19..43cf50d8 100644 --- a/src/c-writer.cc +++ b/src/c-writer.cc @@ -488,8 +488,9 @@ std::string CWriter::MangleTypes(const TypeVector& types) { return std::string("v"); std::string result; - for (auto type: types) + for (auto type : types) { result += MangleType(type); + } return result; } @@ -499,7 +500,7 @@ std::string CWriter::MangleName(string_view name) { std::string result = "Z_"; if (!name.empty()) { - for (char c: name) { + for (char c : name) { if ((isalnum(c) && c != kPrefix) || c == '_') { result += c; } else { @@ -547,7 +548,7 @@ std::string CWriter::LegalizeName(string_view name) { std::string CWriter::DefineName(SymbolSet* set, string_view name) { std::string legal = LegalizeName(name); if (set->find(legal) != set->end()) { - std::string base = legal + "_";; + std::string base = legal + "_"; size_t count = 0; do { legal = base + std::to_string(count++); @@ -558,7 +559,7 @@ std::string CWriter::DefineName(SymbolSet* set, string_view name) { } string_view StripLeadingDollar(string_view name) { - if(!name.empty() && name[0] == '$') { + if (!name.empty() && name[0] == '$') { name.remove_prefix(1); } return name; @@ -785,7 +786,7 @@ void CWriter::Write(const ResultType& rt) { void CWriter::Write(const Const& const_) { switch (const_.type) { case Type::I32: - Writef("%u" "u", static_cast<int32_t>(const_.u32)); + Writef("%uu", static_cast<int32_t>(const_.u32)); break; case Type::I64: @@ -862,8 +863,9 @@ void CWriter::WriteInitExpr(const ExprList& expr_list) { } void CWriter::InitGlobalSymbols() { - for (const char* symbol : s_global_symbols) + for (const char* symbol : s_global_symbols) { global_syms_.insert(symbol); + } } std::string CWriter::GenerateHeaderGuard() const { @@ -896,11 +898,13 @@ void CWriter::WriteFuncTypes() { Index num_results = func_type->GetNumResults(); Write(" func_types[", func_type_index, "] = wasm_rt_register_func_type(", num_params, ", ", num_results); - for (Index i = 0; i < num_params; ++i) + for (Index i = 0; i < num_params; ++i) { Write(", ", TypeEnum(func_type->GetParamType(i))); + } - for (Index i = 0; i < num_results; ++i) + for (Index i = 0; i < num_results; ++i) { Write(", ", TypeEnum(func_type->GetResultType(i))); + } Write(");", Newline()); ++func_type_index; @@ -1226,7 +1230,8 @@ void CWriter::WriteExports(WriteExportsKind kind) { break; } - default: WABT_UNREACHABLE; + default: + WABT_UNREACHABLE; } if (kind == WriteExportsKind::Initializers) { @@ -1359,7 +1364,7 @@ void CWriter::WriteLocals() { void CWriter::WriteStackVarDeclarations() { for (Type type : {Type::I32, Type::I64, Type::F32, Type::F64}) { size_t count = 0; - for (const auto& pair: stack_var_sym_map_) { + for (const auto& pair : stack_var_sym_map_) { Type stp_type = pair.first.second; const std::string& name = pair.second; @@ -1385,7 +1390,7 @@ void CWriter::WriteStackVarDeclarations() { } void CWriter::Write(const ExprList& exprs) { - for (const Expr& expr: exprs) { + for (const Expr& expr : exprs) { switch (expr.type()) { case ExprType::Binary: Write(*cast<BinaryExpr>(&expr)); @@ -1419,8 +1424,9 @@ void CWriter::Write(const ExprList& exprs) { Write("switch (", StackVar(0), ") ", OpenBrace()); DropTypes(1); Index i = 0; - for (const Var& var : bt_expr->targets) + for (const Var& var : bt_expr->targets) { Write("case ", i++, ": ", GotoLabel(var), Newline()); + } Write("default: "); Write(GotoLabel(bt_expr->default_target), Newline(), CloseBrace(), Newline()); @@ -1441,8 +1447,9 @@ void CWriter::Write(const ExprList& exprs) { Write(GlobalVar(var), "("); for (Index i = 0; i < num_params; ++i) { - if (i != 0) + if (i != 0) { Write(", "); + } Write(StackVar(num_params - i - 1)); } Write(");", Newline()); @@ -2172,9 +2179,8 @@ void CWriter::Write(const TernaryExpr& expr) { switch (expr.opcode) { case Opcode::V128BitSelect: { Type result_type = expr.opcode.GetResultType(); - Write(StackVar(2, result_type), " = ", "v128.bitselect", "(" , - StackVar(0),", ", StackVar(1),", ", StackVar(2), ");", - Newline()); + Write(StackVar(2, result_type), " = ", "v128.bitselect", "(", StackVar(0), + ", ", StackVar(1), ", ", StackVar(2), ");", Newline()); DropTypes(3); PushType(result_type); break; @@ -2196,8 +2202,8 @@ void CWriter::Write(const SimdLaneOpExpr& expr) { case Opcode::I64X2ExtractLane: case Opcode::F32X4ExtractLane: case Opcode::F64X2ExtractLane: { - Write(StackVar(0, result_type), " = ", expr.opcode.GetName(), "(" , - StackVar(0),", lane Imm: ", expr.val, ");", Newline()); + Write(StackVar(0, result_type), " = ", expr.opcode.GetName(), "(", + StackVar(0), ", lane Imm: ", expr.val, ");", Newline()); DropTypes(1); break; } @@ -2207,9 +2213,9 @@ void CWriter::Write(const SimdLaneOpExpr& expr) { case Opcode::I64X2ReplaceLane: case Opcode::F32X4ReplaceLane: case Opcode::F64X2ReplaceLane: { - Write(StackVar(1, result_type), " = ", expr.opcode.GetName(), "(" , - StackVar(0),", ", StackVar(1), ", lane Imm: ", expr.val, ");", - Newline()); + Write(StackVar(1, result_type), " = ", expr.opcode.GetName(), "(", + StackVar(0), ", ", StackVar(1), ", lane Imm: ", expr.val, ");", + Newline()); DropTypes(2); break; } @@ -2222,9 +2228,10 @@ void CWriter::Write(const SimdLaneOpExpr& expr) { void CWriter::Write(const SimdShuffleOpExpr& expr) { Type result_type = expr.opcode.GetResultType(); - Write(StackVar(1, result_type), " = ", expr.opcode.GetName(), "(", StackVar(1), - " ", StackVar(0), ", lane Imm: $0x%08x %08x %08x %08x", expr.val.v[0], - expr.val.v[1], expr.val.v[2], expr.val.v[3], ")", Newline()); + Write(StackVar(1, result_type), " = ", expr.opcode.GetName(), "(", + StackVar(1), " ", StackVar(0), ", lane Imm: $0x%08x %08x %08x %08x", + expr.val.v[0], expr.val.v[1], expr.val.v[2], expr.val.v[3], ")", + Newline()); DropTypes(2); PushType(result_type); } @@ -2266,7 +2273,6 @@ Result CWriter::WriteModule(const Module& module) { return result_; } - } // end anonymous namespace Result WriteC(Stream* c_stream, @@ -104,6 +104,6 @@ std::unique_ptr<Derived> cast(std::unique_ptr<Base>&& base) { return std::unique_ptr<Derived>(static_cast<Derived*>(base.release())); }; -} // namespace wabt +} // namespace wabt -#endif // WABT_CAST_H_ +#endif // WABT_CAST_H_ diff --git a/src/circular-array.h b/src/circular-array.h index c14721fd..afdead77 100644 --- a/src/circular-array.h +++ b/src/circular-array.h @@ -26,7 +26,7 @@ namespace wabt { // TODO(karlschimpf) Complete the API // Note: Capacity must be a power of 2. -template<class T, size_t kCapacity> +template <class T, size_t kCapacity> class CircularArray { public: typedef T value_type; @@ -41,14 +41,12 @@ class CircularArray { } CircularArray(const CircularArray&) = default; - CircularArray& operator =(const CircularArray&) = default; + CircularArray& operator=(const CircularArray&) = default; CircularArray(CircularArray&&) = default; - CircularArray& operator =(CircularArray&&) = default; + CircularArray& operator=(CircularArray&&) = default; - ~CircularArray() { - clear(); - } + ~CircularArray() { clear(); } reference at(size_type index) { assert(index < size_); @@ -60,31 +58,21 @@ class CircularArray { return (*this)[index]; } - reference operator[](size_type index) { - return contents_[position(index)]; - } + reference operator[](size_type index) { return contents_[position(index)]; } const_reference operator[](size_type index) const { return contents_[position(index)]; } - reference back() { - return at(size_ - 1); - } + reference back() { return at(size_ - 1); } - const_reference back() const { - return at(size_ - 1); - } + const_reference back() const { return at(size_ - 1); } bool empty() const { return size_ == 0; } - reference front() { - return at(0); - } + reference front() { return at(0); } - const_reference front() const { - return at(0); - } + const_reference front() const { return at(0); } size_type max_size() const { return kCapacity; } @@ -130,6 +118,6 @@ class CircularArray { size_type front_ = 0; }; -} +} // namespace wabt -#endif // WABT_CIRCULAR_ARRAY_H_ +#endif // WABT_CIRCULAR_ARRAY_H_ diff --git a/src/color.h b/src/color.h index ba64e5d2..7c358d9d 100644 --- a/src/color.h +++ b/src/color.h @@ -38,19 +38,19 @@ class Color { public: Color(FILE*, bool enabled = true); - // Write the given color to the file, if enabled. +// Write the given color to the file, if enabled. #define WABT_COLOR(Name, code) \ void Name() const { WriteCode(Name##Code()); } WABT_FOREACH_COLOR_CODE(WABT_COLOR) #undef WABT_COLOR - // Get the color code as a string, if enabled. +// Get the color code as a string, if enabled. #define WABT_COLOR(Name, code) \ const char* Maybe##Name##Code() const { return enabled_ ? Name##Code() : ""; } WABT_FOREACH_COLOR_CODE(WABT_COLOR) #undef WABT_COLOR - // Get the color code as a string. +// Get the color code as a string. #define WABT_COLOR(Name, code) \ static const char* Name##Code() { return code; } WABT_FOREACH_COLOR_CODE(WABT_COLOR) diff --git a/src/common.h b/src/common.h index 009913b6..0d7fa7b5 100644 --- a/src/common.h +++ b/src/common.h @@ -42,7 +42,8 @@ #define WABT_USE(x) static_cast<void>(x) #define WABT_PAGE_SIZE 0x10000 /* 64k */ -#define WABT_MAX_PAGES 0x10000 /* # of pages that fit in 32-bit address space */ +#define WABT_MAX_PAGES 0x10000 /* # of pages that fit in 32-bit address space \ + */ #define WABT_BYTES_TO_PAGES(x) ((x) >> 16) #define WABT_ALIGN_UP_TO_PAGE(x) \ (((x) + WABT_PAGE_SIZE - 1) & ~(WABT_PAGE_SIZE - 1)) @@ -117,7 +118,7 @@ Dst Bitcast(Src&& value) { return result; } -template<typename T> +template <typename T> void ZeroMemory(T& v) { WABT_STATIC_ASSERT(std::is_pod<T>::value); memset(&v, 0, sizeof(v)); @@ -369,4 +370,4 @@ inline void ConvertBackslashToSlash(std::string* s) { } // namespace wabt -#endif // WABT_COMMON_H_ +#endif // WABT_COMMON_H_ diff --git a/src/config.h.in b/src/config.h.in index 8416fb99..6f2e2085 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -65,8 +65,8 @@ #if COMPILER_IS_CLANG || COMPILER_IS_GNU -#define WABT_UNUSED __attribute__ ((unused)) -#define WABT_WARN_UNUSED __attribute__ ((warn_unused_result)) +#define WABT_UNUSED __attribute__((unused)) +#define WABT_WARN_UNUSED __attribute__((warn_unused_result)) #define WABT_INLINE inline #define WABT_UNLIKELY(x) __builtin_expect(!!(x), 0) #define WABT_LIKELY(x) __builtin_expect(!!(x), 1) @@ -99,8 +99,8 @@ #elif COMPILER_IS_MSVC -#include <cstring> #include <intrin.h> +#include <cstring> #define WABT_UNUSED #define WABT_WARN_UNUSED _Check_return_ @@ -118,7 +118,6 @@ #endif - namespace wabt { #if COMPILER_IS_CLANG || COMPILER_IS_GNU @@ -237,8 +236,7 @@ inline int Popcount(unsigned __int64 value) { #endif -} // namespace wabt - +} // namespace wabt #if COMPILER_IS_MSVC @@ -265,7 +263,6 @@ inline int Popcount(unsigned __int64 value) { #endif - #if HAVE_SNPRINTF #define wabt_snprintf snprintf #elif COMPILER_IS_MSVC diff --git a/src/emscripten-helpers.cc b/src/emscripten-helpers.cc index 841f5086..75afcf22 100644 --- a/src/emscripten-helpers.cc +++ b/src/emscripten-helpers.cc @@ -26,15 +26,15 @@ #include <vector> #include "src/apply-names.h" -#include "src/binary-reader.h" #include "src/binary-reader-ir.h" -#include "src/binary-writer.h" +#include "src/binary-reader.h" #include "src/binary-writer-spec.h" +#include "src/binary-writer.h" #include "src/common.h" #include "src/error-handler.h" #include "src/filenames.h" -#include "src/ir.h" #include "src/generate-names.h" +#include "src/ir.h" #include "src/resolve-names.h" #include "src/stream.h" #include "src/validator.h" @@ -74,7 +74,6 @@ struct WabtParseWastResult { std::unique_ptr<wabt::Script> script; }; - extern "C" { wabt::WastLexer* wabt_new_wast_buffer_lexer(const char* filename, @@ -95,7 +94,7 @@ WabtParseWatResult* wabt_parse_wat(wabt::WastLexer* lexer, } WabtParseWastResult* wabt_parse_wast(wabt::WastLexer* lexer, - wabt::ErrorHandlerBuffer* error_handler) { + wabt::ErrorHandlerBuffer* error_handler) { WabtParseWastResult* result = new WabtParseWastResult(); std::unique_ptr<wabt::Script> script; result->result = wabt::ParseWastScript(lexer, &script, error_handler); @@ -103,9 +102,6 @@ WabtParseWastResult* wabt_parse_wast(wabt::WastLexer* lexer, return result; } - - - WabtReadBinaryResult* wabt_read_binary( const void* data, size_t size, @@ -188,7 +184,6 @@ WabtWriteScriptResult* wabt_write_binary_spec_script( return result; } - wabt::Result::Enum wabt_apply_names_module(wabt::Module* module) { return ApplyNames(module); } @@ -295,7 +290,6 @@ void wabt_destroy_parse_wast_result(WabtParseWastResult* result) { delete result; } - // WabtReadBinaryResult wabt::Result::Enum wabt_read_binary_result_get_result( WabtReadBinaryResult* result) { diff --git a/src/error-handler.h b/src/error-handler.h index 84e96dc8..5bee0639 100644 --- a/src/error-handler.h +++ b/src/error-handler.h @@ -126,4 +126,4 @@ class ErrorHandlerBuffer : public ErrorHandler { } // namespace wabt -#endif // WABT_ERROR_HANDLER_H_ +#endif // WABT_ERROR_HANDLER_H_ diff --git a/src/expr-visitor.cc b/src/expr-visitor.cc index bd71c2d2..5a479c04 100644 --- a/src/expr-visitor.cc +++ b/src/expr-visitor.cc @@ -332,7 +332,8 @@ Result ExprVisitor::HandleDefaultState(Expr* expr) { } case ExprType::SimdShuffleOp: { - CHECK_RESULT(delegate_->OnSimdShuffleOpExpr(cast<SimdShuffleOpExpr>(expr))); + CHECK_RESULT( + delegate_->OnSimdShuffleOpExpr(cast<SimdShuffleOpExpr>(expr))); break; } diff --git a/src/feature.cc b/src/feature.cc index 1c691216..193e53f2 100644 --- a/src/feature.cc +++ b/src/feature.cc @@ -22,8 +22,7 @@ namespace wabt { void Features::AddOptions(OptionParser* parser) { #define WABT_FEATURE(variable, flag, help) \ - parser->AddOption("enable-" flag, help, \ - [this]() { enable_##variable(); }); + parser->AddOption("enable-" flag, help, [this]() { enable_##variable(); }); #include "src/feature.def" #undef WABT_FEATURE diff --git a/src/feature.h b/src/feature.h index c563a45e..8d9b093b 100644 --- a/src/feature.h +++ b/src/feature.h @@ -33,19 +33,18 @@ class Features { #undef WABT_FEATURE } -#define WABT_FEATURE(variable, flag, help) \ +#define WABT_FEATURE(variable, flag, help) \ bool variable##_enabled() const { return variable##_enabled_; } \ void enable_##variable() { variable##_enabled_ = true; } #include "src/feature.def" #undef WABT_FEATURE private: -#define WABT_FEATURE(variable, flag, help) \ - bool variable##_enabled_ = false; +#define WABT_FEATURE(variable, flag, help) bool variable##_enabled_ = false; #include "src/feature.def" #undef WABT_FEATURE }; } // namespace wabt -#endif // WABT_FEATURE_H_ +#endif // WABT_FEATURE_H_ diff --git a/src/hash-util.h b/src/hash-util.h index 21d96562..0a135d5e 100644 --- a/src/hash-util.h +++ b/src/hash-util.h @@ -24,8 +24,12 @@ namespace wabt { typedef std::size_t hash_code; -inline hash_code HashCombine() { return 0; } -inline hash_code HashCombine(hash_code seed) { return seed; } +inline hash_code HashCombine() { + return 0; +} +inline hash_code HashCombine(hash_code seed) { + return seed; +} hash_code HashCombine(hash_code x, hash_code y); template <typename T, typename... U> diff --git a/src/interp.cc b/src/interp.cc index 2bd73412..5f19662e 100644 --- a/src/interp.cc +++ b/src/interp.cc @@ -72,8 +72,9 @@ std::string TypedValueToString(const TypedValue& tv) { } case Type::V128: - return StringPrintf("v128:0x%08x 0x%08x 0x%08x 0x%08x", tv.value.v128_bits.v[0], - tv.value.v128_bits.v[1],tv.value.v128_bits.v[2],tv.value.v128_bits.v[3]); + return StringPrintf("v128:0x%08x 0x%08x 0x%08x 0x%08x", + tv.value.v128_bits.v[0], tv.value.v128_bits.v[1], + tv.value.v128_bits.v[2], tv.value.v128_bits.v[3]); default: WABT_UNREACHABLE; @@ -152,10 +153,8 @@ Module* Environment::FindRegisteredModule(string_view name) { return modules_[iter->second.index].get(); } -Thread::Options::Options(uint32_t value_stack_size, - uint32_t call_stack_size) - : value_stack_size(value_stack_size), - call_stack_size(call_stack_size) {} +Thread::Options::Options(uint32_t value_stack_size, uint32_t call_stack_size) + : value_stack_size(value_stack_size), call_stack_size(call_stack_size) {} Thread::Thread(Environment* env, const Options& options) : env_(env), @@ -843,7 +842,7 @@ Result Thread::SimdUnop(UnopFunc<R, P> func) { auto value = PopRep<T>(); // Calculate how many Lanes according to input lane data type. - constexpr int32_t lanes = sizeof(T)/sizeof(L); + constexpr int32_t lanes = sizeof(T) / sizeof(L); // Define SIMD data array for Simd add by Lanes. L simd_data_ret[lanes]; @@ -853,7 +852,7 @@ Result Thread::SimdUnop(UnopFunc<R, P> func) { memcpy(simd_data_0, &value, sizeof(T)); // Constuct the Simd value by Lane data and Lane nums. - for(int32_t i = 0; i < lanes; i++) { + for (int32_t i = 0; i < lanes; i++) { simd_data_ret[i] = static_cast<L>(func(simd_data_0[i])); } @@ -882,7 +881,7 @@ Result Thread::SimdBinop(BinopFunc<R, P> func) { auto lhs_rep = PopRep<T>(); // Calculate how many Lanes according to input lane data type. - constexpr int32_t lanes = sizeof(T)/sizeof(L); + constexpr int32_t lanes = sizeof(T) / sizeof(L); // Define SIMD data array for Simd add by Lanes. L simd_data_ret[lanes]; @@ -894,7 +893,7 @@ Result Thread::SimdBinop(BinopFunc<R, P> func) { memcpy(simd_data_1, &rhs_rep, sizeof(T)); // Constuct the Simd value by Lane data and Lane nums. - for(int32_t i = 0; i < lanes; i++) { + for (int32_t i = 0; i < lanes; i++) { simd_data_ret[i] = static_cast<L>(func(simd_data_0[i], simd_data_1[i])); } @@ -919,10 +918,10 @@ ValueTypeRep<T> Add(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { template <typename T, typename R> ValueTypeRep<T> AddSaturate(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { T max = std::numeric_limits<R>::max(); - T min = std::numeric_limits<R>::min(); + T min = std::numeric_limits<R>::min(); T result = static_cast<T>(lhs_rep) + static_cast<T>(rhs_rep); - if(result < min) { + if (result < min) { return ToRep(min); } else if (result > max) { return ToRep(max); @@ -934,10 +933,10 @@ ValueTypeRep<T> AddSaturate(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { template <typename T, typename R> ValueTypeRep<T> SubSaturate(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { T max = std::numeric_limits<R>::max(); - T min = std::numeric_limits<R>::min(); + T min = std::numeric_limits<R>::min(); T result = static_cast<T>(lhs_rep) - static_cast<T>(rhs_rep); - if(result < min) { + if (result < min) { return ToRep(min); } else if (result > max) { return ToRep(max); @@ -947,11 +946,11 @@ ValueTypeRep<T> SubSaturate(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { } template <typename T, typename L> -int32_t SimdIsLaneTrue(ValueTypeRep<T> value, int32_t true_cond ) { +int32_t SimdIsLaneTrue(ValueTypeRep<T> value, int32_t true_cond) { int true_count = 0; // Calculate how many Lanes according to input lane data type. - constexpr int32_t lanes = sizeof(T)/sizeof(L); + constexpr int32_t lanes = sizeof(T) / sizeof(L); // Define SIMD data array for Simd Lanes. L simd_data_0[lanes]; @@ -960,8 +959,8 @@ int32_t SimdIsLaneTrue(ValueTypeRep<T> value, int32_t true_cond ) { memcpy(simd_data_0, &value, sizeof(T)); // Constuct the Simd value by Lane data and Lane nums. - for(int32_t i = 0; i < lanes; i++) { - if(simd_data_0[i] != 0) + for (int32_t i = 0; i < lanes; i++) { + if (simd_data_0[i] != 0) true_count++; } @@ -1292,7 +1291,8 @@ ValueTypeRep<R> SimdConvert(ValueTypeRep<T> v_rep) { // f64x2.convert_u/i64x2 use this instance due to MSVC issue. template <> -ValueTypeRep<double> SimdConvert<double, uint64_t>(ValueTypeRep<uint64_t> v_rep) { +ValueTypeRep<double> SimdConvert<double, uint64_t>( + ValueTypeRep<uint64_t> v_rep) { return ToRep(wabt_convert_uint64_to_double(v_rep)); } @@ -1347,13 +1347,13 @@ ValueTypeRep<T> Xchg(ValueTypeRep<T> lhs_rep, ValueTypeRep<T> rhs_rep) { template <typename T, typename V> ValueTypeRep<T> SimdSplat(V lane_data) { // Calculate how many Lanes according to input lane data type. - int32_t lanes = sizeof(T)/sizeof(V); + int32_t lanes = sizeof(T) / sizeof(V); // Define SIMD data array by Lanes. - V simd_data[sizeof(T)/sizeof(V)]; + V simd_data[sizeof(T) / sizeof(V)]; // Constuct the Simd value by Land data and Lane nums. - for(int32_t i = 0; i < lanes; i++) { + for (int32_t i = 0; i < lanes; i++) { simd_data[i] = lane_data; } @@ -1366,7 +1366,7 @@ ValueTypeRep<T> SimdSplat(V lane_data) { template <typename R, typename V, typename T> ValueTypeRep<R> SimdExtractLane(V value, uint32_t laneidx) { // Calculate how many Lanes according to input lane data type. - constexpr int32_t lanes = sizeof(V)/sizeof(T); + constexpr int32_t lanes = sizeof(V) / sizeof(T); // Define SIMD data array for Simd add by Lanes. T simd_data_0[lanes]; @@ -1383,7 +1383,7 @@ ValueTypeRep<R> SimdExtractLane(V value, uint32_t laneidx) { template <typename R, typename V, typename T> ValueTypeRep<R> SimdReplaceLane(V value, uint32_t lane_idx, T lane_val) { // Calculate how many Lanes according to input lane data type. - constexpr int32_t lanes = sizeof(V)/sizeof(T); + constexpr int32_t lanes = sizeof(V) / sizeof(T); // Define SIMD data array for Simd add by Lanes. T simd_data_0[lanes]; @@ -1391,7 +1391,7 @@ ValueTypeRep<R> SimdReplaceLane(V value, uint32_t lane_idx, T lane_val) { // Convert intput SIMD data to array. memcpy(simd_data_0, &value, sizeof(V)); - // Replace the indicated lane. + // Replace the indicated lane. simd_data_0[lane_idx] = lane_val; return ToRep(Bitcast<R>(simd_data_0)); @@ -2456,56 +2456,64 @@ Result Thread::Run(int num_instructions) { case Opcode::I8X16ExtractLaneS: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int32_t>(SimdExtractLane<int32_t, v128, int8_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int32_t>( + SimdExtractLane<int32_t, v128, int8_t>(lane_val, lane_idx))); break; } case Opcode::I8X16ExtractLaneU: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int32_t>(SimdExtractLane<int32_t, v128, uint8_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int32_t>( + SimdExtractLane<int32_t, v128, uint8_t>(lane_val, lane_idx))); break; } case Opcode::I16X8ExtractLaneS: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int32_t>(SimdExtractLane<int32_t, v128, int16_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int32_t>( + SimdExtractLane<int32_t, v128, int16_t>(lane_val, lane_idx))); break; } case Opcode::I16X8ExtractLaneU: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int32_t>(SimdExtractLane<int32_t, v128, uint16_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int32_t>( + SimdExtractLane<int32_t, v128, uint16_t>(lane_val, lane_idx))); break; } case Opcode::I32X4ExtractLane: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int32_t>(SimdExtractLane<int32_t, v128, int32_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int32_t>( + SimdExtractLane<int32_t, v128, int32_t>(lane_val, lane_idx))); break; } case Opcode::I64X2ExtractLane: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<int64_t>(SimdExtractLane<int64_t, v128, int64_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<int64_t>( + SimdExtractLane<int64_t, v128, int64_t>(lane_val, lane_idx))); break; } case Opcode::F32X4ExtractLane: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<float>(SimdExtractLane<int32_t, v128, int32_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<float>( + SimdExtractLane<int32_t, v128, int32_t>(lane_val, lane_idx))); break; } case Opcode::F64X2ExtractLane: { v128 lane_val = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(PushRep<double>(SimdExtractLane<int64_t, v128, int64_t>(lane_val, lane_idx))); + CHECK_TRAP(PushRep<double>( + SimdExtractLane<int64_t, v128, int64_t>(lane_val, lane_idx))); break; } @@ -2513,7 +2521,8 @@ Result Thread::Run(int num_instructions) { int8_t lane_val = static_cast<int8_t>(Pop<int32_t>()); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, int8_t>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, int8_t>(value, lane_idx, lane_val))); break; } @@ -2521,7 +2530,8 @@ Result Thread::Run(int num_instructions) { int16_t lane_val = static_cast<int16_t>(Pop<int32_t>()); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, int16_t>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, int16_t>(value, lane_idx, lane_val))); break; } @@ -2529,7 +2539,8 @@ Result Thread::Run(int num_instructions) { int32_t lane_val = Pop<int32_t>(); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, int32_t>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, int32_t>(value, lane_idx, lane_val))); break; } @@ -2537,7 +2548,8 @@ Result Thread::Run(int num_instructions) { int64_t lane_val = Pop<int64_t>(); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, int64_t>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, int64_t>(value, lane_idx, lane_val))); break; } @@ -2545,7 +2557,8 @@ Result Thread::Run(int num_instructions) { float lane_val = Pop<float>(); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, float>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, float>(value, lane_idx, lane_val))); break; } @@ -2553,7 +2566,8 @@ Result Thread::Run(int num_instructions) { double lane_val = Pop<double>(); v128 value = static_cast<v128>(Pop<v128>()); uint32_t lane_idx = ReadU8(&pc); - CHECK_TRAP(Push<v128>(SimdReplaceLane<v128, v128, double>(value, lane_idx, lane_val))); + CHECK_TRAP(Push<v128>( + SimdReplaceLane<v128, v128, double>(value, lane_idx, lane_val))); break; } @@ -2565,20 +2579,20 @@ Result Thread::Run(int num_instructions) { int8_t simd_data_1[lanes]; int8_t simd_shuffle[lanes]; - v128 v2 = PopRep<v128>(); - v128 v1 = PopRep<v128>(); + v128 v2 = PopRep<v128>(); + v128 v1 = PopRep<v128>(); v128 shuffle_imm = ReadV128(&pc); // Convert intput SIMD data to array. memcpy(simd_data_0, &v1, sizeof(v128)); memcpy(simd_data_1, &v2, sizeof(v128)); - memcpy(simd_shuffle,&shuffle_imm, sizeof(v128)); + memcpy(simd_shuffle, &shuffle_imm, sizeof(v128)); // Constuct the Simd value by Lane data and Lane nums. - for(int32_t i = 0; i < lanes; i++) { + for (int32_t i = 0; i < lanes; i++) { int8_t lane_idx = simd_shuffle[i]; - simd_data_ret[i] = (lane_idx < lanes) ? simd_data_0[lane_idx] : - simd_data_1[lane_idx - lanes]; + simd_data_ret[i] = (lane_idx < lanes) ? simd_data_0[lane_idx] + : simd_data_1[lane_idx - lanes]; } CHECK_TRAP(PushRep<v128>(Bitcast<v128>(simd_data_ret))); @@ -2793,8 +2807,8 @@ Result Thread::Run(int num_instructions) { // Follow Wasm Simd spec to compute V128BitSelect: // v128.or(v128.and(v1, c), v128.and(v2, v128.not(c))) v128 c_mask = PopRep<v128>(); - v128 v2 = PopRep<v128>(); - v128 v1 = PopRep<v128>(); + v128 v2 = PopRep<v128>(); + v128 v1 = PopRep<v128>(); // 1. v128.and(v1, c) CHECK_TRAP(Push<v128>(v1)); CHECK_TRAP(Push<v128>(c_mask)); @@ -2810,52 +2824,52 @@ Result Thread::Run(int num_instructions) { } case Opcode::I8X16AnyTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint8_t>(value, 1))); break; - } + } case Opcode::I16X8AnyTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint16_t>(value, 1))); break; - } + } case Opcode::I32X4AnyTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint32_t>(value, 1))); break; - } + } case Opcode::I64X2AnyTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint64_t>(value, 1))); break; - } + } case Opcode::I8X16AllTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint8_t>(value, 16))); break; - } + } case Opcode::I16X8AllTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint16_t>(value, 8))); break; - } + } case Opcode::I32X4AllTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint32_t>(value, 4))); break; - } + } case Opcode::I64X2AllTrue: { - v128 value = PopRep<v128>(); + v128 value = PopRep<v128>(); CHECK_TRAP(Push<int32_t>(SimdIsLaneTrue<v128, uint64_t>(value, 2))); break; - } + } case Opcode::I8X16Eq: CHECK_TRAP(SimdBinop<v128, int8_t>(Eq<int32_t>)); @@ -3594,8 +3608,9 @@ void Thread::Trace(Stream* stream) { break; case Opcode::V128Const: { - stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x \n", opcode.GetName(), - ReadU32At(pc), ReadU32At(pc+4),ReadU32At(pc+8),ReadU32At(pc+12)); + stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x\n", opcode.GetName(), + ReadU32At(pc), ReadU32At(pc + 4), ReadU32At(pc + 8), + ReadU32At(pc + 12)); break; } @@ -3632,18 +3647,22 @@ void Thread::Trace(Stream* stream) { case Opcode::I32X4TruncUF32X4Sat: case Opcode::I64X2TruncSF64X2Sat: case Opcode::I64X2TruncUF64X2Sat: { - stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x \n", opcode.GetName(), Top().v128_bits.v[0], - Top().v128_bits.v[1], Top().v128_bits.v[2], Top().v128_bits.v[3]); + stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x\n", opcode.GetName(), + Top().v128_bits.v[0], Top().v128_bits.v[1], + Top().v128_bits.v[2], Top().v128_bits.v[3]); break; } case Opcode::V128BitSelect: - stream->Writef("%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x\n", - opcode.GetName(), Pick(3).v128_bits.v[0], Pick(3).v128_bits.v[1], - Pick(3).v128_bits.v[2], Pick(3).v128_bits.v[3], Pick(2).v128_bits.v[0], - Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3], - Pick(1).v128_bits.v[0], Pick(1).v128_bits.v[1], Pick(1).v128_bits.v[2], - Pick(1).v128_bits.v[3]); + stream->Writef( + "%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x $0x%08x %08x %08x " + "%08x\n", + opcode.GetName(), Pick(3).v128_bits.v[0], Pick(3).v128_bits.v[1], + Pick(3).v128_bits.v[2], Pick(3).v128_bits.v[3], + Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], + Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3], + Pick(1).v128_bits.v[0], Pick(1).v128_bits.v[1], + Pick(1).v128_bits.v[2], Pick(1).v128_bits.v[3]); break; case Opcode::I8X16ExtractLaneS: @@ -3654,76 +3673,86 @@ void Thread::Trace(Stream* stream) { case Opcode::I64X2ExtractLane: case Opcode::F32X4ExtractLane: case Opcode::F64X2ExtractLane: { - stream->Writef("%s : LaneIdx %d From $0x%08x 0x%08x 0x%08x 0x%08x \n", opcode.GetName(), ReadU8At(pc),\ - Top().v128_bits.v[0], Top().v128_bits.v[1], Top().v128_bits.v[2], Top().v128_bits.v[3]); + stream->Writef("%s : LaneIdx %d From $0x%08x 0x%08x 0x%08x 0x%08x\n", + opcode.GetName(), ReadU8At(pc), Top().v128_bits.v[0], + Top().v128_bits.v[1], Top().v128_bits.v[2], + Top().v128_bits.v[3]); break; } case Opcode::I8X16ReplaceLane: case Opcode::I16X8ReplaceLane: case Opcode::I32X4ReplaceLane: { - stream->Writef("%s : Set %u to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x \n", - opcode.GetName(), Pick(1).i32, ReadU8At(pc),Pick(2).v128_bits.v[0],\ - Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3]); + stream->Writef( + "%s : Set %u to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x\n", + opcode.GetName(), Pick(1).i32, ReadU8At(pc), Pick(2).v128_bits.v[0], + Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], + Pick(2).v128_bits.v[3]); break; } - case Opcode::I64X2ReplaceLane:{ - stream->Writef("%s : Set %" PRIu64 " to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x \n", - opcode.GetName(), Pick(1).i64, ReadU8At(pc),Pick(2).v128_bits.v[0],\ - Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3]); + case Opcode::I64X2ReplaceLane: { + stream->Writef("%s : Set %" PRIu64 + " to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x\n", + opcode.GetName(), Pick(1).i64, ReadU8At(pc), + Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], + Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3]); break; } case Opcode::F32X4ReplaceLane: { - stream->Writef("%s : Set %g to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x \n", - opcode.GetName(), Bitcast<float>(Pick(1).f32_bits), ReadU8At(pc), - Pick(2).v128_bits.v[0],Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], - Pick(2).v128_bits.v[3]); + stream->Writef( + "%s : Set %g to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x\n", + opcode.GetName(), Bitcast<float>(Pick(1).f32_bits), ReadU8At(pc), + Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], + Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3]); break; } case Opcode::F64X2ReplaceLane: { - stream->Writef("%s : Set %g to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x \n", - opcode.GetName(), Bitcast<double>(Pick(1).f64_bits), ReadU8At(pc), - Pick(2).v128_bits.v[0],Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], - Pick(2).v128_bits.v[3]); + stream->Writef( + "%s : Set %g to LaneIdx %d In $0x%08x 0x%08x 0x%08x 0x%08x\n", + opcode.GetName(), Bitcast<double>(Pick(1).f64_bits), ReadU8At(pc), + Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], + Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3]); break; } case Opcode::V8X16Shuffle: - stream->Writef("%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x : with lane imm:\ - $0x%08x %08x %08x %08x\n", opcode.GetName(), Pick(2).v128_bits.v[0], - Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3], - Pick(1).v128_bits.v[0], Pick(1).v128_bits.v[1], Pick(1).v128_bits.v[2], - Pick(1).v128_bits.v[3], ReadU32At(pc), ReadU32At(pc+4),ReadU32At(pc+8), - ReadU32At(pc+12)); + stream->Writef( + "%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x : with lane imm: " + "$0x%08x %08x %08x %08x\n", + opcode.GetName(), Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], + Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3], + Pick(1).v128_bits.v[0], Pick(1).v128_bits.v[1], + Pick(1).v128_bits.v[2], Pick(1).v128_bits.v[3], ReadU32At(pc), + ReadU32At(pc + 4), ReadU32At(pc + 8), ReadU32At(pc + 12)); break; - case Opcode::I8X16Add: - case Opcode::I16X8Add: - case Opcode::I32X4Add: + case Opcode::I8X16Add: + case Opcode::I16X8Add: + case Opcode::I32X4Add: case Opcode::I64X2Add: - case Opcode::I8X16Sub: - case Opcode::I16X8Sub: - case Opcode::I32X4Sub: + case Opcode::I8X16Sub: + case Opcode::I16X8Sub: + case Opcode::I32X4Sub: case Opcode::I64X2Sub: - case Opcode::I8X16Mul: - case Opcode::I16X8Mul: - case Opcode::I32X4Mul: - case Opcode::I8X16AddSaturateS: - case Opcode::I8X16AddSaturateU: - case Opcode::I16X8AddSaturateS: - case Opcode::I16X8AddSaturateU: - case Opcode::I8X16SubSaturateS: - case Opcode::I8X16SubSaturateU: - case Opcode::I16X8SubSaturateS: - case Opcode::I16X8SubSaturateU: - case Opcode::V128And: - case Opcode::V128Or: - case Opcode::V128Xor: - case Opcode::I8X16Eq: - case Opcode::I16X8Eq: - case Opcode::I32X4Eq: - case Opcode::F32X4Eq: + case Opcode::I8X16Mul: + case Opcode::I16X8Mul: + case Opcode::I32X4Mul: + case Opcode::I8X16AddSaturateS: + case Opcode::I8X16AddSaturateU: + case Opcode::I16X8AddSaturateS: + case Opcode::I16X8AddSaturateU: + case Opcode::I8X16SubSaturateS: + case Opcode::I8X16SubSaturateU: + case Opcode::I16X8SubSaturateS: + case Opcode::I16X8SubSaturateU: + case Opcode::V128And: + case Opcode::V128Or: + case Opcode::V128Xor: + case Opcode::I8X16Eq: + case Opcode::I16X8Eq: + case Opcode::I32X4Eq: + case Opcode::F32X4Eq: case Opcode::F64X2Eq: case Opcode::I8X16Ne: case Opcode::I16X8Ne: @@ -3774,16 +3803,19 @@ void Thread::Trace(Stream* stream) { case Opcode::F64X2Div: case Opcode::F32X4Mul: case Opcode::F64X2Mul: { - stream->Writef("%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x\n", opcode.GetName(), Pick(2).v128_bits.v[0], - Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3],Pick(1).v128_bits.v[0], - Pick(1).v128_bits.v[1], Pick(1).v128_bits.v[2], Pick(1).v128_bits.v[3]); + stream->Writef("%s $0x%08x %08x %08x %08x $0x%08x %08x %08x %08x\n", + opcode.GetName(), Pick(2).v128_bits.v[0], + Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], + Pick(2).v128_bits.v[3], Pick(1).v128_bits.v[0], + Pick(1).v128_bits.v[1], Pick(1).v128_bits.v[2], + Pick(1).v128_bits.v[3]); break; } case Opcode::I8X16Shl: case Opcode::I16X8Shl: case Opcode::I32X4Shl: - case Opcode::I64X2Shl: + case Opcode::I64X2Shl: case Opcode::I8X16ShrS: case Opcode::I8X16ShrU: case Opcode::I16X8ShrS: @@ -3791,7 +3823,7 @@ void Thread::Trace(Stream* stream) { case Opcode::I32X4ShrS: case Opcode::I32X4ShrU: case Opcode::I64X2ShrS: - case Opcode::I64X2ShrU: { + case Opcode::I64X2ShrU: { stream->Writef("%s $0x%08x %08x %08x %08x $0x%08x\n", opcode.GetName(), Pick(2).v128_bits.v[0], Pick(2).v128_bits.v[1], Pick(2).v128_bits.v[2], Pick(2).v128_bits.v[3], @@ -4294,7 +4326,8 @@ void Environment::Disassemble(Stream* stream, case Opcode::I64X2ExtractLane: case Opcode::F32X4ExtractLane: case Opcode::F64X2ExtractLane: { - stream->Writef("%s %%[-1] : (Lane imm: %d) \n", opcode.GetName(),ReadU8(&pc)); + stream->Writef("%s %%[-1] : (Lane imm: %d)\n", opcode.GetName(), + ReadU8(&pc)); break; } @@ -4304,15 +4337,16 @@ void Environment::Disassemble(Stream* stream, case Opcode::I64X2ReplaceLane: case Opcode::F32X4ReplaceLane: case Opcode::F64X2ReplaceLane: { - stream->Writef("%s %%[-1], %%[-2] : (Lane imm: %d) \n", opcode.GetName(), - ReadU8(&pc)); + stream->Writef("%s %%[-1], %%[-2] : (Lane imm: %d)\n", + opcode.GetName(), ReadU8(&pc)); break; } case Opcode::V8X16Shuffle: - stream->Writef("%s %%[-2], %%[-1] : (Lane imm: $0x%08x 0x%08x 0x%08x \ - 0x%08x )\n", opcode.GetName(), ReadU32(&pc), ReadU32(&pc), - ReadU32(&pc),ReadU32(&pc)); + stream->Writef( + "%s %%[-2], %%[-1] : (Lane imm: $0x%08x 0x%08x 0x%08x 0x%08x )\n", + opcode.GetName(), ReadU32(&pc), ReadU32(&pc), ReadU32(&pc), + ReadU32(&pc)); break; case Opcode::GrowMemory: { @@ -4364,8 +4398,8 @@ void Environment::Disassemble(Stream* stream, } case Opcode::V128Const: { - stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x \n", opcode.GetName(), - ReadU32(&pc), ReadU32(&pc),ReadU32(&pc),ReadU32(&pc)); + stream->Writef("%s $0x%08x 0x%08x 0x%08x 0x%08x\n", opcode.GetName(), + ReadU32(&pc), ReadU32(&pc), ReadU32(&pc), ReadU32(&pc)); break; } @@ -4407,9 +4441,9 @@ ExecResult Executor::RunFunction(Index func_index, const TypedValues& args) { exec_result.result = PushArgs(sig, args); if (exec_result.result == Result::Ok) { - exec_result.result = func->is_host - ? thread_.CallHost(cast<HostFunc>(func)) - : RunDefinedFunction(cast<DefinedFunc>(func)->offset); + exec_result.result = + func->is_host ? thread_.CallHost(cast<HostFunc>(func)) + : RunDefinedFunction(cast<DefinedFunc>(func)->offset); if (exec_result.result == Result::Ok) { CopyResults(sig, &exec_result.values); } diff --git a/src/intrusive-list.h b/src/intrusive-list.h index 38606373..7d9611a7 100644 --- a/src/intrusive-list.h +++ b/src/intrusive-list.h @@ -424,8 +424,7 @@ inline void intrusive_list<T>::emplace_back(Args&&... args) { template <typename T> inline void intrusive_list<T>::push_front(std::unique_ptr<T> node) { - assert(node->prev_ == nullptr && - node->next_ == nullptr); + assert(node->prev_ == nullptr && node->next_ == nullptr); T* node_p = node.release(); if (first_) { @@ -445,8 +444,7 @@ inline void intrusive_list<T>::push_front(T&& node) { template <typename T> inline void intrusive_list<T>::push_back(std::unique_ptr<T> node) { - assert(node->prev_ == nullptr && - node->next_ == nullptr); + assert(node->prev_ == nullptr && node->next_ == nullptr); T* node_p = node.release(); if (last_) { @@ -516,8 +514,7 @@ template <typename T> inline typename intrusive_list<T>::iterator intrusive_list<T>::insert( iterator pos, std::unique_ptr<T> node) { - assert(node->prev_ == nullptr && - node->next_ == nullptr); + assert(node->prev_ == nullptr && node->next_ == nullptr); T* node_p; if (pos == end()) { @@ -633,4 +630,4 @@ inline void intrusive_list<T>::splice(iterator pos, } // namespace wabt -#endif // WABT_INTRUSIVE_LIST_H_ +#endif // WABT_INTRUSIVE_LIST_H_ @@ -240,7 +240,6 @@ FuncType* Module::GetFuncType(const Var& var) { return func_types[index]; } - Index Module::GetFuncTypeIndex(const FuncSignature& sig) const { for (size_t i = 0; i < func_types.size(); ++i) { if (func_types[i]->sig == sig) { @@ -551,23 +550,18 @@ void Var::Destroy() { } Const::Const(I32Tag, uint32_t value, const Location& loc_) - : loc(loc_), type(Type::I32), u32(value) { -} + : loc(loc_), type(Type::I32), u32(value) {} Const::Const(I64Tag, uint64_t value, const Location& loc_) - : loc(loc_), type(Type::I64), u64(value) { -} + : loc(loc_), type(Type::I64), u64(value) {} Const::Const(F32Tag, uint32_t value, const Location& loc_) - : loc(loc_), type(Type::F32), f32_bits(value) { -} + : loc(loc_), type(Type::F32), f32_bits(value) {} Const::Const(F64Tag, uint64_t value, const Location& loc_) - : loc(loc_), type(Type::F64), f64_bits(value) { -} + : loc(loc_), type(Type::F64), f64_bits(value) {} Const::Const(V128Tag, v128 value, const Location& loc_) - : loc(loc_), type(Type::V128), v128_bits(value) { -} + : loc(loc_), type(Type::V128), v128_bits(value) {} } // namespace wabt @@ -22,8 +22,8 @@ #include <cstdint> #include <memory> #include <string> -#include <vector> #include <type_traits> +#include <vector> #include "src/binding-hash.h" #include "src/common.h" @@ -43,8 +43,8 @@ struct Var { explicit Var(string_view name, const Location& loc = Location()); Var(Var&&); Var(const Var&); - Var& operator =(const Var&); - Var& operator =(Var&&); + Var& operator=(const Var&); + Var& operator=(Var&&); ~Var(); VarType type() const { return type_; } @@ -101,7 +101,7 @@ struct Const { uint64_t u64; uint32_t f32_bits; uint64_t f64_bits; - v128 v128_bits; + v128 v128_bits; }; private: @@ -271,7 +271,7 @@ typedef OpcodeExpr<ExprType::Ternary> TernaryExpr; class SimdLaneOpExpr : public ExprMixin<ExprType::SimdLaneOp> { public: SimdLaneOpExpr(Opcode opcode, uint64_t val, const Location& loc = Location()) - : ExprMixin<ExprType::SimdLaneOp>(loc), opcode(opcode), val(val) {} + : ExprMixin<ExprType::SimdLaneOp>(loc), opcode(opcode), val(val) {} Opcode opcode; uint64_t val; @@ -280,7 +280,7 @@ class SimdLaneOpExpr : public ExprMixin<ExprType::SimdLaneOp> { class SimdShuffleOpExpr : public ExprMixin<ExprType::SimdShuffleOp> { public: SimdShuffleOpExpr(Opcode opcode, v128 val, const Location& loc = Location()) - : ExprMixin<ExprType::SimdShuffleOp>(loc), opcode(opcode), val(val) {} + : ExprMixin<ExprType::SimdShuffleOp>(loc), opcode(opcode), val(val) {} Opcode opcode; v128 val; @@ -655,7 +655,7 @@ class MemoryModuleField : public ModuleFieldMixin<ModuleFieldType::Memory> { class DataSegmentModuleField : public ModuleFieldMixin<ModuleFieldType::DataSegment> { public: - explicit DataSegmentModuleField( const Location& loc = Location()) + explicit DataSegmentModuleField(const Location& loc = Location()) : ModuleFieldMixin<ModuleFieldType::DataSegment>(loc) {} DataSegment data_segment; @@ -672,8 +672,7 @@ class ExceptionModuleField : public ModuleFieldMixin<ModuleFieldType::Except> { class StartModuleField : public ModuleFieldMixin<ModuleFieldType::Start> { public: - explicit StartModuleField(Var start = Var(), - const Location& loc = Location()) + explicit StartModuleField(Var start = Var(), const Location& loc = Location()) : ModuleFieldMixin<ModuleFieldType::Start>(loc), start(start) {} Var start; @@ -971,7 +970,7 @@ struct Script { void MakeTypeBindingReverseMapping( const TypeVector& types, - const BindingHash& bindings, + const BindingHash& bindings, std::vector<std::string>* out_reverse_mapping); } // namespace wabt diff --git a/src/leb128.h b/src/leb128.h index 7cc019d9..2fa0b4ec 100644 --- a/src/leb128.h +++ b/src/leb128.h @@ -63,4 +63,4 @@ size_t ReadS64Leb128(const uint8_t* p, const uint8_t* end, uint64_t* out_value); } // namespace wabt -#endif // WABT_LEB128_H_ +#endif // WABT_LEB128_H_ diff --git a/src/lexer-source.cc b/src/lexer-source.cc index 2a64cffb..762aea7e 100644 --- a/src/lexer-source.cc +++ b/src/lexer-source.cc @@ -20,8 +20,7 @@ namespace wabt { -LexerSourceFile::LexerSourceFile(string_view filename) - : filename_(filename) { +LexerSourceFile::LexerSourceFile(string_view filename) : filename_(filename) { file_ = fopen(filename_.c_str(), "rb"); } @@ -56,7 +55,7 @@ Result LexerSourceFile::Tell(Offset* out_offset) { return Result::Ok; } -size_t LexerSourceFile::Fill(void* dest, size_t size) { +size_t LexerSourceFile::Fill(void* dest, size_t size) { if (!file_) { return 0; } diff --git a/src/literal.h b/src/literal.h index 53f8fbdb..40b395ed 100644 --- a/src/literal.h +++ b/src/literal.h @@ -23,7 +23,8 @@ namespace wabt { -/* These functions all return Result::Ok on success and Result::Error on failure. +/* These functions all return Result::Ok on success and Result::Error on + * failure. * * NOTE: the functions are written for use with the re2c lexer, assuming that * the literal has already matched the regular expressions defined there. As a diff --git a/src/make-unique.h b/src/make-unique.h index 43acb969..46d3ac14 100644 --- a/src/make-unique.h +++ b/src/make-unique.h @@ -37,6 +37,6 @@ std::unique_ptr<T> MakeUnique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } -} // namespace wabt +} // namespace wabt #endif // WABT_MAKE_UNIQUE_H_ diff --git a/src/opcode.cc b/src/opcode.cc index 98cfe99e..8a93f645 100644 --- a/src/opcode.cc +++ b/src/opcode.cc @@ -366,4 +366,4 @@ uint32_t Opcode::GetSimdLaneCount() const { } } -} // end anonymous namespace +} // namespace wabt diff --git a/src/opcode.h b/src/opcode.h index 61d7a3ad..c7dae08a 100644 --- a/src/opcode.h +++ b/src/opcode.h @@ -37,7 +37,7 @@ struct Opcode { Invalid, }; - // Static opcode objects. +// Static opcode objects. #define WABT_OPCODE(rtype, type1, type2, type3, mem_size, prefix, code, Name, \ text) \ static Opcode Name##_Opcode; @@ -134,6 +134,6 @@ struct Opcode { Enum enum_; }; -} // end anonymous namespace +} // namespace wabt #endif // WABT_OPCODE_H_ diff --git a/src/option-parser.cc b/src/option-parser.cc index f0a02cdb..91516135 100644 --- a/src/option-parser.cc +++ b/src/option-parser.cc @@ -73,7 +73,7 @@ void OptionParser::AddOption(char short_name, void OptionParser::AddOption(const char* long_name, const char* help, - const NullCallback& callback){ + const NullCallback& callback) { Option option('\0', long_name, std::string(), HasArgument::No, help, [callback](const char*) { callback(); }); AddOption(option); @@ -210,7 +210,7 @@ void OptionParser::Parse(int argc, char* argv[]) { // Allow short names to be combined, e.g. "-d -v" => "-dv". for (int k = 1; arg[k]; ++k) { bool matched = false; - for (const Option& option: options_) { + for (const Option& option : options_) { if (option.short_name && arg[k] == option.short_name) { const char* option_argument = nullptr; if (option.has_argument) { @@ -278,7 +278,7 @@ void OptionParser::PrintHelp() { const size_t kExtraSpace = 8; size_t longest_name_length = 0; - for (const Option& option: options_) { + for (const Option& option : options_) { size_t length; if (!option.long_name.empty()) { length = option.long_name.size(); @@ -295,7 +295,7 @@ void OptionParser::PrintHelp() { } } - for (const Option& option: options_) { + for (const Option& option : options_) { if (!option.short_name && option.long_name.empty()) { continue; } diff --git a/src/range.h b/src/range.h index aba816f3..fa0310ee 100644 --- a/src/range.h +++ b/src/range.h @@ -32,6 +32,6 @@ struct Range { typedef Range<Offset> OffsetRange; typedef Range<int> ColumnRange; -} // namespace wabt +} // namespace wabt #endif // WABT_RANGE_H_ diff --git a/src/result.h b/src/result.h index 016a4248..a40faab7 100644 --- a/src/result.h +++ b/src/result.h @@ -44,8 +44,12 @@ inline Result& Result::operator|=(Result rhs) { return *this; } -inline bool Succeeded(Result result) { return result == Result::Ok; } -inline bool Failed(Result result) { return result == Result::Error; } +inline bool Succeeded(Result result) { + return result == Result::Ok; +} +inline bool Failed(Result result) { + return result == Result::Error; +} #define CHECK_RESULT(expr) \ do { \ diff --git a/src/stream.cc b/src/stream.cc index a127e706..ad0d08a5 100644 --- a/src/stream.cc +++ b/src/stream.cc @@ -278,5 +278,4 @@ std::unique_ptr<FileStream> FileStream::CreateStderr() { return std::unique_ptr<FileStream>(new FileStream(stderr)); } - } // namespace wabt diff --git a/src/stream.h b/src/stream.h index 8a0f1c80..87cae087 100644 --- a/src/stream.h +++ b/src/stream.h @@ -98,8 +98,8 @@ class Stream { Write(value, desc, print_chars); } void WriteU128(v128 value, - const char* desc = nullptr, - PrintChars print_chars = PrintChars::No) { + const char* desc = nullptr, + PrintChars print_chars = PrintChars::No) { Write(value, desc, print_chars); } diff --git a/src/string-view.cc b/src/string-view.cc index 8a1312d9..bb32410a 100644 --- a/src/string-view.cc +++ b/src/string-view.cc @@ -123,7 +123,7 @@ string_view::size_type string_view::find(const char* s, size_type pos) const { string_view::size_type string_view::rfind(string_view s, size_type pos) const noexcept { - pos = std::min(std::min(pos, size_ - s.size_) + s.size_, size_); + pos = std::min(std::min(pos, size_ - s.size_) + s.size_, size_); reverse_iterator iter = std::search(reverse_iterator(begin() + pos), rend(), s.rbegin(), s.rend()); return iter == rend() ? npos : (rend() - iter - s.size_); diff --git a/src/string-view.h b/src/string-view.h index 4b8f5487..3d16dec5 100644 --- a/src/string-view.h +++ b/src/string-view.h @@ -134,8 +134,8 @@ class string_view { /*constexpr*/ size_type find_last_of(const char* s, size_type pos = npos) const; - // TODO(binji): These are defined by C++17 basic_string_view but not - // implemented here. +// TODO(binji): These are defined by C++17 basic_string_view but not +// implemented here. #if 0 constexpr size_type find_first_not_of(string_view s, size_type pos = 0) const noexcept; @@ -271,7 +271,7 @@ constexpr inline string_view::const_pointer string_view::data() const noexcept { return data_; } -} // namespace wabt +} // namespace wabt namespace std { @@ -283,6 +283,6 @@ struct hash<::wabt::string_view> { } }; -} +} // namespace std #endif // WABT_STRING_VIEW_H_ diff --git a/src/test-circular-array.cc b/src/test-circular-array.cc index 50c465f4..aefea514 100644 --- a/src/test-circular-array.cc +++ b/src/test-circular-array.cc @@ -43,9 +43,7 @@ struct TestObject { return *this; } - TestObject(TestObject&& other) { - *this = std::move(other); - } + TestObject(TestObject&& other) { *this = std::move(other); } TestObject& operator=(TestObject&& other) { data = other.data; @@ -108,7 +106,6 @@ class CircularArrayTest : public ::testing::Test { } // end anonymous namespace - // Basic API tests TEST_F(CircularArrayTest, default_constructor) { diff --git a/src/test-intrusive-list.cc b/src/test-intrusive-list.cc index 217ea251..dfc3dbb3 100644 --- a/src/test-intrusive-list.cc +++ b/src/test-intrusive-list.cc @@ -73,9 +73,7 @@ class IntrusiveListTest : public ::testing::Test { TestObject::creation_count = 0; } - virtual void TearDown() { - ASSERT_EQ(0, TestObject::creation_count); - } + virtual void TearDown() { ASSERT_EQ(0, TestObject::creation_count); } TestObjectList NewList(const std::vector<int>& data_values) { TestObjectList result; @@ -179,7 +177,6 @@ class IntrusiveListIteratorTest : public IntrusiveListTest { ASSERT_EQ(count, expected.size()); } - TestObjectList list_; const TestObjectList& clist_ = list_; }; diff --git a/src/test-utf8.cc b/src/test-utf8.cc index d0e95acd..8e420628 100644 --- a/src/test-utf8.cc +++ b/src/test-utf8.cc @@ -58,21 +58,15 @@ TEST(utf8, valid_empty) { } TEST(utf8, valid_1_byte) { - FOR_RANGE(cu0, 0, 0x80) { - assert_is_valid_utf8(true, 1, cu0); - } + FOR_RANGE(cu0, 0, 0x80) { assert_is_valid_utf8(true, 1, cu0); } } TEST(utf8, invalid_continuation_bytes) { - FOR_RANGE(cu0, 0x80, 0xc0) { - assert_is_valid_utf8(false, 1, cu0); - } + FOR_RANGE(cu0, 0x80, 0xc0) { assert_is_valid_utf8(false, 1, cu0); } } TEST(utf8, invalid_2_byte) { - FOR_RANGE(cu0, 0xc0, 0xc2) { - assert_is_valid_utf8(false, 1, cu0); - } + FOR_RANGE(cu0, 0xc0, 0xc2) { assert_is_valid_utf8(false, 1, cu0); } } TEST(utf8, valid_2_bytes) { diff --git a/src/token.h b/src/token.h index c763e136..391a3073 100644 --- a/src/token.h +++ b/src/token.h @@ -199,9 +199,15 @@ struct Token { return text_; } - Type type() const { assert(HasType()); return type_; } + Type type() const { + assert(HasType()); + return type_; + } - Opcode opcode() const { assert(HasOpcode()); return opcode_; } + Opcode opcode() const { + assert(HasOpcode()); + return opcode_; + } const Literal& literal() const { assert(HasLiteral()); @@ -226,4 +232,4 @@ struct Token { } // namespace wabt -#endif // WABT_TOKEN_H_ +#endif // WABT_TOKEN_H_ diff --git a/src/tracing.h b/src/tracing.h index dbba716c..86daf63c 100644 --- a/src/tracing.h +++ b/src/tracing.h @@ -41,7 +41,7 @@ struct TraceScope { WABT_DISALLOW_COPY_AND_ASSIGN(TraceScope); TraceScope() = delete; TraceScope(const char* method); - template<typename... Args> + template <typename... Args> TraceScope(const char* method, const char* format, Args&&... args) : method_(method) { PrintEnter(method); @@ -70,4 +70,4 @@ struct TraceScope { } // end namespace wabt -#endif // WABT_TRACING_H_ +#endif // WABT_TRACING_H_ diff --git a/src/type-checker.cc b/src/type-checker.cc index 52001139..101ee731 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -286,8 +286,7 @@ void TypeChecker::PrintStackIfFailed(Result result, message += ", expected "; message += TypesToString(expected); message += " but got "; - message += - TypesToString(actual, incomplete_actual_stack ? "... " : nullptr); + message += TypesToString(actual, incomplete_actual_stack ? "... " : nullptr); PrintError("%s", message.c_str()); } @@ -25,4 +25,4 @@ bool IsValidUtf8(const char* s, size_t length); } // namespace wabt -#endif // WABT_UTF8_H_ +#endif // WABT_UTF8_H_ diff --git a/src/validator.cc b/src/validator.cc index b977fa73..f29e0ce5 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -25,8 +25,8 @@ #include "src/binary-reader.h" #include "src/cast.h" -#include "src/expr-visitor.h" #include "src/error-handler.h" +#include "src/expr-visitor.h" #include "src/ir.h" #include "src/type-checker.h" #include "src/wast-parser-lexer-shared.h" @@ -267,7 +267,8 @@ Result Validator::CheckVar(Index max_index, Result Validator::CheckFuncVar(const Var* var, const Func** out_func) { Index index; - CHECK_RESULT(CheckVar(current_module_->funcs.size(), var, "function", &index)); + CHECK_RESULT( + CheckVar(current_module_->funcs.size(), var, "function", &index)); if (out_func) { *out_func = current_module_->funcs[index]; } @@ -885,8 +886,8 @@ void Validator::CheckConstInitExpr(const Location* loc, case ExprType::GetGlobal: { const Global* ref_global = nullptr; Index ref_global_index; - if (Failed(CheckGlobalVar(&cast<GetGlobalExpr>(expr)->var, - &ref_global, &ref_global_index))) { + if (Failed(CheckGlobalVar(&cast<GetGlobalExpr>(expr)->var, &ref_global, + &ref_global_index))) { return; } @@ -918,8 +919,10 @@ void Validator::CheckGlobal(const Location* loc, const Global* global) { "global initializer expression"); } -void Validator::CheckLimits(const Location* loc, const Limits* limits, - uint64_t absolute_max, const char* desc) { +void Validator::CheckLimits(const Location* loc, + const Limits* limits, + uint64_t absolute_max, + const char* desc) { if (limits->initial > absolute_max) { PrintError(loc, "initial %s (%" PRIu64 ") must be <= (%" PRIu64 ")", desc, limits->initial, absolute_max); @@ -1064,14 +1067,15 @@ void Validator::CheckExport(const Location* loc, const Export* export_) { } void Validator::CheckDuplicateExportBindings(const Module* module) { - module->export_bindings.FindDuplicates([this]( - const BindingHash::value_type& a, const BindingHash::value_type& b) { - // Choose the location that is later in the file. - const Location& a_loc = a.second.loc; - const Location& b_loc = b.second.loc; - const Location& loc = a_loc.line > b_loc.line ? a_loc : b_loc; - PrintError(&loc, "redefinition of export \"%s\"", a.first.c_str()); - }); + module->export_bindings.FindDuplicates( + [this](const BindingHash::value_type& a, + const BindingHash::value_type& b) { + // Choose the location that is later in the file. + const Location& a_loc = a.second.loc; + const Location& b_loc = b.second.loc; + const Location& loc = a_loc.line > b_loc.line ? a_loc : b_loc; + PrintError(&loc, "redefinition of export \"%s\"", a.first.c_str()); + }); } Result Validator::CheckModule(const Module* module) { @@ -1184,8 +1188,9 @@ const TypeVector* Validator::CheckInvoke(const InvokeAction* action) { size_t actual_args = action->args.size(); size_t expected_args = func->GetNumParams(); if (expected_args != actual_args) { - PrintError(&action->loc, "too %s parameters to function. got %" PRIzd - ", expected %" PRIzd, + PrintError(&action->loc, + "too %s parameters to function. got %" PRIzd + ", expected %" PRIzd, actual_args > expected_args ? "many" : "few", actual_args, expected_args); return nullptr; diff --git a/src/wast-lexer.h b/src/wast-lexer.h index f6bfcad8..6a97bb8e 100644 --- a/src/wast-lexer.h +++ b/src/wast-lexer.h @@ -62,8 +62,8 @@ class WastLexer { std::string filename_; int line_; int comment_nesting_; - size_t buffer_file_offset_; // File offset of the start of the buffer. - size_t line_file_offset_; // File offset of the start of the current line. + size_t buffer_file_offset_; // File offset of the start of the buffer. + size_t line_file_offset_; // File offset of the start of the current line. // Lexing data needed by re2c. bool eof_; diff --git a/src/wast-parser.cc b/src/wast-parser.cc index 4d94b245..a86ab4e1 100644 --- a/src/wast-parser.cc +++ b/src/wast-parser.cc @@ -16,11 +16,11 @@ #include "src/wast-parser.h" -#include "src/binary-reader.h" #include "src/binary-reader-ir.h" +#include "src/binary-reader.h" #include "src/cast.h" -#include "src/expr-visitor.h" #include "src/error-handler.h" +#include "src/expr-visitor.h" #include "src/make-unique.h" #include "src/utf8.h" #include "src/wast-parser-lexer-shared.h" @@ -1294,7 +1294,6 @@ Result WastParser::ParsePlainLoadStoreInstr(Location loc, return Result::Ok; } - Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) { WABT_TRACE(ParsePlainInstr); Location loc = GetLocation(); @@ -1511,7 +1510,8 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) { ErrorUnlessOpcodeEnabled(token); Const const_; CHECK_RESULT((ParseSimdConst(&const_, Type::I32, sizeof(v128)))); - out_expr->reset(new SimdShuffleOpExpr(token.opcode(), const_.v128_bits, loc)); + out_expr->reset( + new SimdShuffleOpExpr(token.opcode(), const_.v128_bits, loc)); break; } @@ -1527,16 +1527,18 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) { // Current Simd const type is V128 const only. // The current expected V128 const lists is: // i32 0xXXXXXXXX 0xXXXXXXXX 0xXXXXXXXX 0xXXXXXXXX -Result WastParser::ParseSimdConst(Const* const_, Type in_type, int32_t nSimdConstBytes) { +Result WastParser::ParseSimdConst(Const* const_, + Type in_type, + int32_t nSimdConstBytes) { WABT_TRACE(ParseSimdConst); // Parse the Simd Consts according to input data type. switch (in_type) { case Type::I32: { const_->loc = GetLocation(); - int Count = nSimdConstBytes/sizeof(uint32_t); + int Count = nSimdConstBytes / sizeof(uint32_t); // Meet expected "i32" token. start parse 4 i32 consts - for(int i=0; i<Count; i++) { + for (int i = 0; i < Count; i++) { Location loc = GetLocation(); // Expected one 0xXXXXXXXX number @@ -1550,8 +1552,8 @@ Result WastParser::ParseSimdConst(Const* const_, Type in_type, int32_t nSimdCons const char* end = sv.end(); Result result; - result = - ParseInt32(s, end, &(const_->v128_bits.v[i]), ParseIntType::SignedAndUnsigned); + result = ParseInt32(s, end, &(const_->v128_bits.v[i]), + ParseIntType::SignedAndUnsigned); if (Failed(result)) { Error(loc, "invalid literal \"%s\"", literal.text.c_str()); @@ -1593,8 +1595,9 @@ Result WastParser::ParseConst(Const* const_) { } case TokenType::ValueType: { // ValueType token is valid here only when after a Simd const opcode. - if(opcode != Opcode::V128Const) { - return ErrorExpected({"a numeric literal for non-simd const opcode"}, "123, -45, 6.7e8"); + if (opcode != Opcode::V128Const) { + return ErrorExpected({"a numeric literal for non-simd const opcode"}, + "123, -45, 6.7e8"); } // Get Simd Const input type. in_type = Consume().type(); @@ -1633,8 +1636,11 @@ Result WastParser::ParseConst(Const* const_) { const_->type = Type::V128; // Parse V128 Simd Const (16 bytes). result = ParseSimdConst(const_, in_type, sizeof(v128)); - // ParseSimdConst report error already, just return here if parser get errors. - if (Failed(result)) return Result::Error; + // ParseSimdConst report error already, just return here if parser get + // errors. + if (Failed(result)) { + return Result::Error; + } break; default: @@ -2320,15 +2326,14 @@ void WastParser::CheckImportOrdering(Module* module) { } Result ParseWatModule(WastLexer* lexer, - std::unique_ptr<Module>* out_module, - ErrorHandler* error_handler, - WastParseOptions* options) { + std::unique_ptr<Module>* out_module, + ErrorHandler* error_handler, + WastParseOptions* options) { assert(out_module != nullptr); WastParser parser(lexer, error_handler, options); return parser.ParseModule(out_module); } - Result ParseWastScript(WastLexer* lexer, std::unique_ptr<Script>* out_script, ErrorHandler* error_handler, diff --git a/src/wast-parser.h b/src/wast-parser.h index b0341869..bdecdec9 100644 --- a/src/wast-parser.h +++ b/src/wast-parser.h @@ -21,8 +21,8 @@ #include "src/circular-array.h" #include "src/feature.h" -#include "src/ir.h" #include "src/intrusive-list.h" +#include "src/ir.h" #include "src/wast-lexer.h" namespace wabt { diff --git a/src/wat-writer.cc b/src/wat-writer.cc index c5e51f08..c9db2f83 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -21,8 +21,8 @@ #include <cinttypes> #include <cstdarg> #include <cstdio> -#include <map> #include <iterator> +#include <map> #include <string> #include <vector> @@ -409,8 +409,9 @@ void WatWriter::WriteTypes(const TypeVector& types, const char* name) { if (name) { WriteOpenSpace(name); } - for (Type type : types) + for (Type type : types) { WriteType(type, NextChar::Space); + } if (name) { WriteCloseSpace(); } @@ -502,8 +503,9 @@ void WatWriter::WriteConst(const Const& const_) { case Type::V128: { WritePutsSpace(Opcode::V128Const_Opcode.GetName()); - Writef("i32 0x%08x 0x%08x 0x%08x 0x%08x", const_.v128_bits.v[0], const_.v128_bits.v[1],\ - const_.v128_bits.v[2], const_.v128_bits.v[3]); + Writef("i32 0x%08x 0x%08x 0x%08x 0x%08x", const_.v128_bits.v[0], + const_.v128_bits.v[1], const_.v128_bits.v[2], + const_.v128_bits.v[3]); WriteNewline(NO_FORCE_NEWLINE); break; } @@ -614,8 +616,9 @@ Result WatWriter::ExprVisitorDelegate::OnBrIfExpr(BrIfExpr* expr) { Result WatWriter::ExprVisitorDelegate::OnBrTableExpr(BrTableExpr* expr) { writer_->WritePutsSpace(Opcode::BrTable_Opcode.GetName()); - for (const Var& var : expr->targets) + for (const Var& var : expr->targets) { writer_->WriteBrVar(var, NextChar::Space); + } writer_->WriteBrVar(expr->default_target, NextChar::Newline); return Result::Ok; } @@ -862,10 +865,11 @@ Result WatWriter::ExprVisitorDelegate::OnSimdLaneOpExpr(SimdLaneOpExpr* expr) { return Result::Ok; } -Result WatWriter::ExprVisitorDelegate::OnSimdShuffleOpExpr(SimdShuffleOpExpr* expr) { +Result WatWriter::ExprVisitorDelegate::OnSimdShuffleOpExpr( + SimdShuffleOpExpr* expr) { writer_->WritePutsSpace(expr->opcode.GetName()); writer_->Writef(" $0x%08x %08x %08x %08x", (expr->val.v[0]), (expr->val.v[1]), - (expr->val.v[2]), (expr->val.v[3])); + (expr->val.v[2]), (expr->val.v[3])); writer_->WritePutsNewline(""); return Result::Ok; } @@ -899,7 +903,6 @@ Label* WatWriter::GetLabel(const Var& var) { return nullptr; } - Index WatWriter::GetLabelArity(const Var& var) { Label* label = GetLabel(var); return label && label->label_type != LabelType::Loop ? label->sig.size() : 0; @@ -1057,8 +1060,8 @@ void WatWriter::WriteFoldedExpr(const Expr* expr) { break; default: - fprintf(stderr, "Invalid Opcode for expr type: %s\n", - GetExprTypeName(*expr)); + fprintf(stderr, "Invalid Opcode for expr type: %s\n", + GetExprTypeName(*expr)); assert(0); } break; @@ -1077,15 +1080,16 @@ void WatWriter::WriteFoldedExpr(const Expr* expr) { void WatWriter::WriteFoldedExprList(const ExprList& exprs) { WABT_TRACE(WriteFoldedExprList); - for (const Expr& expr : exprs) + for (const Expr& expr : exprs) { WriteFoldedExpr(&expr); + } } void WatWriter::PushExpr(const Expr* expr, Index operand_count, Index result_count) { WABT_TRACE_ARGS(PushExpr, "%s, %" PRIindex ", %" PRIindex "", - GetExprTypeName(*expr), operand_count, result_count); + GetExprTypeName(*expr), operand_count, result_count); if (operand_count <= expr_tree_stack_.size()) { auto last_operand = expr_tree_stack_.end(); auto first_operand = last_operand - operand_count; @@ -1191,8 +1195,9 @@ void WatWriter::FlushExprTree(const ExprTree& expr_tree) { void WatWriter::FlushExprTreeVector(const std::vector<ExprTree>& expr_trees) { WABT_TRACE_ARGS(FlushExprTreeVector, "%zu", expr_trees.size()); - for (auto expr_tree : expr_trees) - FlushExprTree(expr_tree); + for (auto expr_tree : expr_trees) { + FlushExprTree(expr_tree); + } } void WatWriter::FlushExprTreeStack() { @@ -1356,8 +1361,9 @@ void WatWriter::WriteTable(const Table& table) { void WatWriter::WriteElemSegment(const ElemSegment& segment) { WriteOpenSpace("elem"); WriteInitExpr(segment.offset); - for (const Var& var : segment.vars) + for (const Var& var : segment.vars) { WriteVar(var, NextChar::Space); + } WriteCloseNewline(); } |