summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-12-20 19:35:01 -0800
committerGitHub <noreply@github.com>2021-12-20 19:35:01 -0800
commite59cf9369004a521814222afbc05ae6b59446cd5 (patch)
treed1a0483a4e6ec6334182a42bf1d0a532f9e3b8e9 /src/tools
parent8b92c44494ea3c03b38c12275098b682071b6101 (diff)
downloadwabt-e59cf9369004a521814222afbc05ae6b59446cd5.tar.gz
wabt-e59cf9369004a521814222afbc05ae6b59446cd5.tar.bz2
wabt-e59cf9369004a521814222afbc05ae6b59446cd5.zip
Clang-format codebase (#1684)
This applies clang-format to the whole codebase. I noticed we have .clang-format in wabt but the codebase is not very well formatted. This kind of mass-formatting PR has fans and skeptics because it can mess with `git blame`, but we did a similar thing in Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in WebAssembly/binaryen#2059) and it was not very confusing after all. If we are ever going to format the codebase, I think it is easier to do it in a single big PR than dozens of smaller PRs. This is using the existing .clang-format file in this repo, which follows the style of Chromium. If we think this does not suit the current formatting style, we can potentially tweak .clang-format too. For example, I noticed the current codebase puts many `case` statements within a single line when they are short, but the current .clang-format does not allow that. This does not include files in src/prebuilt, because they are generated. This also manually fixes some comment lines, because mechanically applying clang-format to long inline comments can look weird. I also added a clang-format check hook in the Github CI in #1683, which I think can be less controversial, given that it only checks the diff. --- After discussions, we ended up reverting many changes, especially one-liner functions and switch-cases, which are too many to wrap in `// clang-format off` and `// clang-format on`. I also considered fixing `.clang-format` to allow those one-liners but it caused a larger churn in other parts. So currently the codebase does not conform to `.clang-format` 100%, but we decided it's fine.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/spectest-interp.cc71
-rw-r--r--src/tools/wasm-decompile.cc25
-rw-r--r--src/tools/wasm-interp.cc17
-rw-r--r--src/tools/wasm-objdump.cc8
-rw-r--r--src/tools/wasm-opcodecnt.cc13
-rw-r--r--src/tools/wasm-strip.cc9
-rw-r--r--src/tools/wasm-validate.cc4
-rw-r--r--src/tools/wasm2c.cc3
-rw-r--r--src/tools/wasm2wat.cc4
-rw-r--r--src/tools/wast2json.cc6
-rw-r--r--src/tools/wat-desugar.cc2
-rw-r--r--src/tools/wat2wasm.cc4
12 files changed, 82 insertions, 84 deletions
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc
index e1bec2f6..bf428424 100644
--- a/src/tools/spectest-interp.cc
+++ b/src/tools/spectest-interp.cc
@@ -164,7 +164,7 @@ class RegisterCommand : public CommandMixin<CommandType::Register> {
struct ExpectedValue {
TypedValue value;
- Type lane_type; // Only valid if value.type == Type::V128.
+ Type lane_type; // Only valid if value.type == Type::V128.
// Up to 4 NaN values used, depending on |value.type| and |lane_type|:
// | type | lane_type | valid |
// | f32 | | nan[0] |
@@ -898,7 +898,8 @@ wabt::Result JSONParser::ParseExpectedValues(
return wabt::Result::Ok;
}
-wabt::Result JSONParser::ParseConstVector(ValueTypes* out_types, Values* out_values) {
+wabt::Result JSONParser::ParseConstVector(ValueTypes* out_types,
+ Values* out_values) {
out_values->clear();
EXPECT("[");
bool first = true;
@@ -1205,16 +1206,16 @@ class CommandRunner {
wabt::Result ReadInvalidTextModule(string_view module_filename,
const std::string& header);
wabt::Result ReadInvalidModule(int line_number,
- string_view module_filename,
- ModuleType module_type,
- const char* desc);
+ string_view module_filename,
+ ModuleType module_type,
+ const char* desc);
wabt::Result ReadUnlinkableModule(int line_number,
- string_view module_filename,
- ModuleType module_type,
- const char* desc);
+ string_view module_filename,
+ ModuleType module_type,
+ const char* desc);
Store store_;
- Registry registry_; // Used when importing.
+ Registry registry_; // Used when importing.
Registry instances_; // Used when referencing module by name in invoke.
ExportMap last_instance_;
int passed_ = 0;
@@ -1241,15 +1242,15 @@ CommandRunner::CommandRunner() : store_(s_features) {
for (auto&& print : print_funcs) {
auto import_name = StringPrintf("spectest.%s", print.name);
- spectest[print.name] = HostFunc::New(
- store_, print.type,
- [=](Thread& inst, const Values& params, Values& results,
- Trap::Ptr* trap) -> wabt::Result {
- printf("called host ");
- WriteCall(s_stdout_stream.get(), import_name, print.type, params,
- results, *trap);
- return wabt::Result::Ok;
- });
+ spectest[print.name] =
+ HostFunc::New(store_, print.type,
+ [=](Thread& inst, const Values& params, Values& results,
+ Trap::Ptr* trap) -> wabt::Result {
+ printf("called host ");
+ WriteCall(s_stdout_stream.get(), import_name,
+ print.type, params, results, *trap);
+ return wabt::Result::Ok;
+ });
}
spectest["table"] =
@@ -1257,14 +1258,18 @@ CommandRunner::CommandRunner() : store_(s_features) {
spectest["memory"] = interp::Memory::New(store_, MemoryType{Limits{1, 2}});
- spectest["global_i32"] = interp::Global::New(
- store_, GlobalType{ValueType::I32, Mutability::Const}, Value::Make(u32{666}));
- spectest["global_i64"] = interp::Global::New(
- store_, GlobalType{ValueType::I64, Mutability::Const}, Value::Make(u64{666}));
- spectest["global_f32"] = interp::Global::New(
- store_, GlobalType{ValueType::F32, Mutability::Const}, Value::Make(f32{666}));
- spectest["global_f64"] = interp::Global::New(
- store_, GlobalType{ValueType::F64, Mutability::Const}, Value::Make(f64{666}));
+ spectest["global_i32"] =
+ interp::Global::New(store_, GlobalType{ValueType::I32, Mutability::Const},
+ Value::Make(u32{666}));
+ spectest["global_i64"] =
+ interp::Global::New(store_, GlobalType{ValueType::I64, Mutability::Const},
+ Value::Make(u64{666}));
+ spectest["global_f32"] =
+ interp::Global::New(store_, GlobalType{ValueType::F32, Mutability::Const},
+ Value::Make(f32{666}));
+ spectest["global_f64"] =
+ interp::Global::New(store_, GlobalType{ValueType::F64, Mutability::Const},
+ Value::Make(f64{666}));
}
wabt::Result CommandRunner::Run(const Script& script) {
@@ -1377,7 +1382,7 @@ ActionResult CommandRunner::RunAction(int line_number,
}
wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
- const std::string& header) {
+ const std::string& header) {
std::vector<uint8_t> file_data;
wabt::Result result = ReadFile(module_filename, &file_data);
std::unique_ptr<WastLexer> lexer = WastLexer::CreateBufferLexer(
@@ -1396,7 +1401,7 @@ wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
}
interp::Module::Ptr CommandRunner::ReadModule(string_view module_filename,
- Errors* errors) {
+ Errors* errors) {
std::vector<uint8_t> file_data;
if (Failed(ReadFile(module_filename, &file_data))) {
@@ -1423,9 +1428,9 @@ interp::Module::Ptr CommandRunner::ReadModule(string_view module_filename,
}
wabt::Result CommandRunner::ReadInvalidModule(int line_number,
- string_view module_filename,
- ModuleType module_type,
- const char* desc) {
+ string_view module_filename,
+ ModuleType module_type,
+ const char* desc) {
std::string header = StringPrintf(
"%s:%d: %s passed", source_filename_.c_str(), line_number, desc);
@@ -1527,7 +1532,7 @@ wabt::Result CommandRunner::OnActionCommand(const ActionCommand* command) {
wabt::Result CommandRunner::OnAssertMalformedCommand(
const AssertMalformedCommand* command) {
wabt::Result result = ReadInvalidModule(command->line, command->filename,
- command->type, "assert_malformed");
+ command->type, "assert_malformed");
if (Succeeded(result)) {
PrintError(command->line, "expected module to be malformed: \"%s\"",
command->filename.c_str());
@@ -1583,7 +1588,7 @@ wabt::Result CommandRunner::OnAssertUnlinkableCommand(
wabt::Result CommandRunner::OnAssertInvalidCommand(
const AssertInvalidCommand* command) {
wabt::Result result = ReadInvalidModule(command->line, command->filename,
- command->type, "assert_invalid");
+ command->type, "assert_invalid");
if (Succeeded(result)) {
PrintError(command->line, "expected module to be invalid: \"%s\"",
command->filename.c_str());
diff --git a/src/tools/wasm-decompile.cc b/src/tools/wasm-decompile.cc
index 74491e55..df2bd2b5 100644
--- a/src/tools/wasm-decompile.cc
+++ b/src/tools/wasm-decompile.cc
@@ -20,8 +20,9 @@
#include <cstdlib>
#include "src/apply-names.h"
-#include "src/binary-reader.h"
#include "src/binary-reader-ir.h"
+#include "src/binary-reader.h"
+#include "src/decompiler.h"
#include "src/error-formatter.h"
#include "src/feature.h"
#include "src/generate-names.h"
@@ -30,7 +31,6 @@
#include "src/stream.h"
#include "src/validator.h"
#include "src/wast-lexer.h"
-#include "src/decompiler.h"
using namespace wabt;
@@ -45,12 +45,12 @@ int ProgramMain(int argc, char** argv) {
{
const char s_description[] =
- " Read a file in the WebAssembly binary format, and convert it to\n"
- " a decompiled text file.\n"
- "\n"
- "examples:\n"
- " # parse binary file test.wasm and write text file test.dcmp\n"
- " $ wasm-decompile test.wasm -o test.dcmp\n";
+ " Read a file in the WebAssembly binary format, and convert it to\n"
+ " a decompiled text file.\n"
+ "\n"
+ "examples:\n"
+ " # parse binary file test.wasm and write text file test.dcmp\n"
+ " $ wasm-decompile test.wasm -o test.dcmp\n";
OptionParser parser("wasm-decompile", s_description);
parser.AddOption(
'o', "output", "FILENAME",
@@ -77,8 +77,7 @@ int ProgramMain(int argc, char** argv) {
Errors errors;
Module module;
const bool kStopOnFirstError = true;
- ReadBinaryOptions options(features, nullptr,
- true, kStopOnFirstError,
+ ReadBinaryOptions options(features, nullptr, true, kStopOnFirstError,
fail_on_custom_section_error);
result = ReadBinaryIr(infile.c_str(), file_data.data(), file_data.size(),
options, &errors, &module);
@@ -86,8 +85,8 @@ int ProgramMain(int argc, char** argv) {
ValidateOptions options(features);
result = ValidateModule(&module, &errors, options);
if (Succeeded(result)) {
- result = GenerateNames(&module,
- static_cast<NameOpts>(NameOpts::AlphaNames));
+ result =
+ GenerateNames(&module, static_cast<NameOpts>(NameOpts::AlphaNames));
}
if (Succeeded(result)) {
// Must be called after ReadBinaryIr & GenerateNames, and before
@@ -103,7 +102,7 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
auto s = Decompile(module, decompile_options);
FileStream stream(!outfile.empty() ? FileStream(outfile)
- : FileStream(stdout));
+ : FileStream(stdout));
stream.WriteData(s.data(), s.size());
}
}
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc
index c4d44ebe..465ad611 100644
--- a/src/tools/wasm-interp.cc
+++ b/src/tools/wasm-interp.cc
@@ -173,15 +173,14 @@ static void BindImports(const Module::Ptr& module, RefVec& imports) {
auto import_name = StringPrintf("%s.%s", import.type.module.c_str(),
import.type.name.c_str());
- auto host_func =
- HostFunc::New(s_store, func_type,
- [=](Thread& thread, const Values& params,
- Values& results, Trap::Ptr* trap) -> Result {
- printf("called host ");
- WriteCall(stream, import_name, func_type, params,
- results, *trap);
- return Result::Ok;
- });
+ auto host_func = HostFunc::New(
+ s_store, func_type,
+ [=](Thread& thread, const Values& params, Values& results,
+ Trap::Ptr* trap) -> Result {
+ printf("called host ");
+ WriteCall(stream, import_name, func_type, params, results, *trap);
+ return Result::Ok;
+ });
imports.push_back(host_func.ref());
continue;
}
diff --git a/src/tools/wasm-objdump.cc b/src/tools/wasm-objdump.cc
index fbfed12c..59060432 100644
--- a/src/tools/wasm-objdump.cc
+++ b/src/tools/wasm-objdump.cc
@@ -18,16 +18,16 @@
#include <cstdlib>
#include <cstring>
+#include "src/binary-reader-objdump.h"
+#include "src/binary-reader.h"
#include "src/common.h"
#include "src/option-parser.h"
#include "src/stream.h"
-#include "src/binary-reader.h"
-#include "src/binary-reader-objdump.h"
using namespace wabt;
static const char s_description[] =
-R"( Print information about the contents of wasm binaries.
+ R"( Print information about the contents of wasm binaries.
examples:
$ wasm-objdump test.wasm
@@ -133,7 +133,7 @@ int ProgramMain(int argc, char** argv) {
return 1;
}
- for (const char* filename: s_infiles) {
+ for (const char* filename : s_infiles) {
if (Failed(dump_file(filename))) {
return 1;
}
diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc
index 5d6225f0..4df8598b 100644
--- a/src/tools/wasm-opcodecnt.cc
+++ b/src/tools/wasm-opcodecnt.cc
@@ -23,8 +23,8 @@
#include <map>
#include <vector>
-#include "src/binary-reader.h"
#include "src/binary-reader-opcnt.h"
+#include "src/binary-reader.h"
#include "src/option-parser.h"
#include "src/stream.h"
@@ -44,7 +44,7 @@ static std::unique_ptr<FileStream> s_log_stream;
static Features s_features;
static const char s_description[] =
-R"( Read a file in the wasm binary format, and count opcode usage for
+ R"( Read a file in the wasm binary format, and count opcode usage for
instructions.
examples:
@@ -85,9 +85,7 @@ struct SortByCountDescending {
template <typename T>
struct WithinCutoff {
- bool operator()(const T& pair) const {
- return pair.second >= s_cutoff;
- }
+ bool operator()(const T& pair) const { return pair.second >= s_cutoff; }
};
static size_t SumCounts(const OpcodeInfoCounts& info_counts) {
@@ -102,7 +100,7 @@ void WriteCounts(Stream& stream, const OpcodeInfoCounts& info_counts) {
typedef std::pair<Opcode, size_t> OpcodeCountPair;
std::map<Opcode, size_t> counts;
- for (auto& info_count_pair: info_counts) {
+ for (auto& info_count_pair : info_counts) {
Opcode opcode = info_count_pair.first.opcode();
size_t count = info_count_pair.second;
counts[opcode] += count;
@@ -124,8 +122,7 @@ void WriteCounts(Stream& stream, const OpcodeInfoCounts& info_counts) {
}
}
-void WriteCountsWithImmediates(Stream& stream,
- const OpcodeInfoCounts& counts) {
+void WriteCountsWithImmediates(Stream& stream, const OpcodeInfoCounts& counts) {
// Remove const from the key type so we can sort below.
typedef std::pair<std::remove_const<OpcodeInfoCounts::key_type>::type,
OpcodeInfoCounts::mapped_type>
diff --git a/src/tools/wasm-strip.cc b/src/tools/wasm-strip.cc
index 44915443..c8f3f83c 100644
--- a/src/tools/wasm-strip.cc
+++ b/src/tools/wasm-strip.cc
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#include "src/binary.h"
-#include "src/binary-reader.h"
#include "src/binary-reader-nop.h"
+#include "src/binary-reader.h"
+#include "src/binary.h"
#include "src/error-formatter.h"
#include "src/leb128.h"
#include "src/option-parser.h"
@@ -27,7 +27,7 @@ using namespace wabt;
static std::string s_filename;
static const char s_description[] =
-R"( Remove sections of a WebAssembly binary file.
+ R"( Remove sections of a WebAssembly binary file.
examples:
# Remove all custom sections from test.wasm
@@ -47,8 +47,7 @@ static void ParseOptions(int argc, char** argv) {
class BinaryReaderStrip : public BinaryReaderNop {
public:
- explicit BinaryReaderStrip(Errors* errors)
- : errors_(errors) {
+ explicit BinaryReaderStrip(Errors* errors) : errors_(errors) {
stream_.WriteU32(WABT_BINARY_MAGIC, "WASM_BINARY_MAGIC");
stream_.WriteU32(WABT_BINARY_VERSION, "WASM_BINARY_VERSION");
}
diff --git a/src/tools/wasm-validate.cc b/src/tools/wasm-validate.cc
index a55c5ed8..dd48e121 100644
--- a/src/tools/wasm-validate.cc
+++ b/src/tools/wasm-validate.cc
@@ -19,8 +19,8 @@
#include <cstdio>
#include <cstdlib>
-#include "src/binary-reader.h"
#include "src/binary-reader-ir.h"
+#include "src/binary-reader.h"
#include "src/error-formatter.h"
#include "src/ir.h"
#include "src/option-parser.h"
@@ -38,7 +38,7 @@ static bool s_fail_on_custom_section_error = true;
static std::unique_ptr<FileStream> s_log_stream;
static const char s_description[] =
-R"( Read a file in the WebAssembly binary format, and validate it.
+ R"( Read a file in the WebAssembly binary format, and validate it.
examples:
# validate binary file test.wasm
diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc
index be96a819..a20b7e4b 100644
--- a/src/tools/wasm2c.cc
+++ b/src/tools/wasm2c.cc
@@ -45,7 +45,7 @@ static bool s_read_debug_names = true;
static std::unique_ptr<FileStream> s_log_stream;
static const char s_description[] =
-R"( Read a file in the WebAssembly binary format, and convert it to
+ R"( Read a file in the WebAssembly binary format, and convert it to
a C source file and header.
examples:
@@ -164,4 +164,3 @@ int main(int argc, char** argv) {
return ProgramMain(argc, argv);
WABT_CATCH_BAD_ALLOC_AND_EXIT
}
-
diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc
index 58e89849..2c50fea7 100644
--- a/src/tools/wasm2wat.cc
+++ b/src/tools/wasm2wat.cc
@@ -20,8 +20,8 @@
#include <cstdlib>
#include "src/apply-names.h"
-#include "src/binary-reader.h"
#include "src/binary-reader-ir.h"
+#include "src/binary-reader.h"
#include "src/error-formatter.h"
#include "src/feature.h"
#include "src/generate-names.h"
@@ -46,7 +46,7 @@ static std::unique_ptr<FileStream> s_log_stream;
static bool s_validate = true;
static const char s_description[] =
-R"( Read a file in the WebAssembly binary format, and convert it to
+ R"( Read a file in the WebAssembly binary format, and convert it to
the WebAssembly text format.
examples:
diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc
index a5c9a47d..0418c9a7 100644
--- a/src/tools/wast2json.cc
+++ b/src/tools/wast2json.cc
@@ -17,14 +17,14 @@
#include <cassert>
#include <cstdarg>
#include <cstdint>
-#include <cstdlib>
#include <cstdio>
+#include <cstdlib>
#include <string>
#include "config.h"
-#include "src/binary-writer.h"
#include "src/binary-writer-spec.h"
+#include "src/binary-writer.h"
#include "src/common.h"
#include "src/error-formatter.h"
#include "src/feature.h"
@@ -49,7 +49,7 @@ static Features s_features;
static std::unique_ptr<FileStream> s_log_stream;
static const char s_description[] =
-R"( read a file in the wasm spec test format, check it for errors, and
+ R"( read a file in the wasm spec test format, check it for errors, and
convert it to a JSON file and associated wasm binary files.
examples:
diff --git a/src/tools/wat-desugar.cc b/src/tools/wat-desugar.cc
index cc6a2cba..85c2d8a5 100644
--- a/src/tools/wat-desugar.cc
+++ b/src/tools/wat-desugar.cc
@@ -43,7 +43,7 @@ static bool s_debug_parsing;
static Features s_features;
static const char s_description[] =
-R"( read a file in the wasm s-expression format and format it.
+ R"( read a file in the wasm s-expression format and format it.
examples:
# write output to stdout
diff --git a/src/tools/wat2wasm.cc b/src/tools/wat2wasm.cc
index f77dad27..4a71b572 100644
--- a/src/tools/wat2wasm.cc
+++ b/src/tools/wat2wasm.cc
@@ -17,8 +17,8 @@
#include <cassert>
#include <cstdarg>
#include <cstdint>
-#include <cstdlib>
#include <cstdio>
+#include <cstdlib>
#include <string>
#include "config.h"
@@ -49,7 +49,7 @@ static Features s_features;
static std::unique_ptr<FileStream> s_log_stream;
static const char s_description[] =
-R"( read a file in the wasm text format, check it for errors, and
+ R"( read a file in the wasm text format, check it for errors, and
convert it to the wasm binary format.
examples: