summaryrefslogtreecommitdiff
path: root/src/tools/wasm-opcodecnt.cc
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/wasm-opcodecnt.cc
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/wasm-opcodecnt.cc')
-rw-r--r--src/tools/wasm-opcodecnt.cc13
1 files changed, 5 insertions, 8 deletions
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>