summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm-opcodecnt.cc13
-rw-r--r--test/help/wasm-opcodecnt.txt22
-rw-r--r--test/opcodecnt/basic.txt2
-rw-r--r--test/opcodecnt/cutoff.txt2
-rw-r--r--test/opcodecnt/immediates.txt2
5 files changed, 36 insertions, 5 deletions
diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc
index 087f4e63..6915dc82 100644
--- a/src/tools/wasm-opcodecnt.cc
+++ b/src/tools/wasm-opcodecnt.cc
@@ -41,6 +41,7 @@ static const char* s_separator = ": ";
static ReadBinaryOptions s_read_binary_options;
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
@@ -60,6 +61,7 @@ static void ParseOptions(int argc, char** argv) {
s_read_binary_options.log_stream = s_log_stream.get();
});
parser.AddHelpOption();
+ s_features.AddOptions(&parser);
parser.AddOption('o', "output", "FILENAME",
"Output file for the opcode counts, by default use stdout",
[](const char* argument) { s_outfile = argument; });
@@ -89,6 +91,14 @@ struct WithinCutoff {
}
};
+static size_t SumCounts(const OpcodeInfoCounts& info_counts) {
+ size_t sum = 0;
+ for (auto& pair : info_counts) {
+ sum += pair.second;
+ }
+ return sum;
+}
+
void WriteCounts(Stream& stream, const OpcodeInfoCounts& info_counts) {
typedef std::pair<Opcode, size_t> OpcodeCountPair;
@@ -155,9 +165,12 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
OpcodeInfoCounts counts;
+ s_read_binary_options.features = s_features;
result = ReadBinaryOpcnt(file_data.data(), file_data.size(),
s_read_binary_options, &counts);
if (Succeeded(result)) {
+ stream.Writef("Total opcodes: %" PRIzd "\n\n", SumCounts(counts));
+
stream.Writef("Opcode counts:\n");
WriteCounts(stream, counts);
diff --git a/test/help/wasm-opcodecnt.txt b/test/help/wasm-opcodecnt.txt
index 618067b4..eab38eec 100644
--- a/test/help/wasm-opcodecnt.txt
+++ b/test/help/wasm-opcodecnt.txt
@@ -11,9 +11,21 @@ examples:
$ wasm-opcodecnt test.wasm -o test.dist
options:
- -v, --verbose Use multiple times for more info
- --help Print this help message
- -o, --output=FILENAME Output file for the opcode counts, by default use stdout
- -c, --cutoff=N Cutoff for reporting counts less than N
- -s, --separator=SEPARATOR Separator text between element and count when reporting counts
+ -v, --verbose Use multiple times for more info
+ --help Print this help message
+ --enable-exceptions Enable Experimental exception handling
+ --disable-mutable-globals Disable Import/export mutable globals
+ --enable-saturating-float-to-int Enable Saturating float-to-int operators
+ --enable-sign-extension Enable Sign-extension operators
+ --enable-simd Enable SIMD support
+ --enable-threads Enable Threading support
+ --enable-multi-value Enable Multi-value
+ --enable-tail-call Enable Tail-call support
+ --enable-bulk-memory Enable Bulk-memory operations
+ --enable-reference-types Enable Reference types (anyref)
+ --enable-annotations Enable Custom annotation syntax
+ --enable-all Enable all features
+ -o, --output=FILENAME Output file for the opcode counts, by default use stdout
+ -c, --cutoff=N Cutoff for reporting counts less than N
+ -s, --separator=SEPARATOR Separator text between element and count when reporting counts
;;; STDOUT ;;)
diff --git a/test/opcodecnt/basic.txt b/test/opcodecnt/basic.txt
index 981639be..a9d573ba 100644
--- a/test/opcodecnt/basic.txt
+++ b/test/opcodecnt/basic.txt
@@ -20,6 +20,8 @@
f32.add
br 0))
(;; STDOUT ;;;
+Total opcodes: 16
+
Opcode counts:
local.get: 5
i32.const: 3
diff --git a/test/opcodecnt/cutoff.txt b/test/opcodecnt/cutoff.txt
index cf0aa617..ca85ad1f 100644
--- a/test/opcodecnt/cutoff.txt
+++ b/test/opcodecnt/cutoff.txt
@@ -13,6 +13,8 @@
f64.const 9
return))
(;; STDOUT ;;;
+Total opcodes: 11
+
Opcode counts:
i32.const: 5
f32.const: 3
diff --git a/test/opcodecnt/immediates.txt b/test/opcodecnt/immediates.txt
index 7ded6b7c..af902e78 100644
--- a/test/opcodecnt/immediates.txt
+++ b/test/opcodecnt/immediates.txt
@@ -35,6 +35,8 @@
return))
(;; STDOUT ;;;
+Total opcodes: 19
+
Opcode counts:
i32.const: 5
end: 3