summaryrefslogtreecommitdiff
path: root/test/example/cpp-unit.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-08-04 13:06:37 -0700
committerGitHub <noreply@github.com>2020-08-04 13:06:37 -0700
commitd78c794ffd61946bf2035042cbda082f042272db (patch)
tree5aa662b7a48d14211a6413832bd359f373ace81d /test/example/cpp-unit.cpp
parentb44c1af1eb3c4900863b1b4e6b96713cbdb98609 (diff)
downloadbinaryen-d78c794ffd61946bf2035042cbda082f042272db.tar.gz
binaryen-d78c794ffd61946bf2035042cbda082f042272db.tar.bz2
binaryen-d78c794ffd61946bf2035042cbda082f042272db.zip
Refactor getMaxBits() out of OptimizeInstructions and add beginnings of unit testing for it (#3019)
getMaxBits just moves around, no logic is changed. Aside from adding getMaxBits, the change in bits.h is 99% whitespace. helps #2879
Diffstat (limited to 'test/example/cpp-unit.cpp')
-rw-r--r--test/example/cpp-unit.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp
index e6189d9d1..2ba4388d1 100644
--- a/test/example/cpp-unit.cpp
+++ b/test/example/cpp-unit.cpp
@@ -1,17 +1,41 @@
// test multiple uses of the threadPool
-#include <assert.h>
+#include <iostream>
-#include <wasm.h>
+#include <ir/bits.h>
#include <ir/cost.h>
+#include <wasm.h>
using namespace wasm;
-int main()
-{
+void compare(size_t x, size_t y) {
+ if (x != y) {
+ std::cout << "comparison error!\n" << x << '\n' << y << '\n';
+ abort();
+ }
+}
+
+void test_bits() {
+ Const c;
+ c.type = Type::i32;
+ c.value = Literal(int32_t(1));
+ compare(Bits::getMaxBits(&c), 1);
+ c.value = Literal(int32_t(2));
+ compare(Bits::getMaxBits(&c), 2);
+ c.value = Literal(int32_t(3));
+ compare(Bits::getMaxBits(&c), 2);
+}
+
+void test_cost() {
// Some optimizations assume that the cost of a get is zero, e.g. local-cse.
LocalGet get;
- assert(CostAnalyzer(&get).cost == 0);
+ compare(CostAnalyzer(&get).cost, 0);
+}
+
+int main() {
+ test_bits();
+
+ test_cost();
std::cout << "Success.\n";
return 0;