From d78c794ffd61946bf2035042cbda082f042272db Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 4 Aug 2020 13:06:37 -0700 Subject: 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 --- test/example/cpp-unit.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'test/example/cpp-unit.cpp') 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 +#include -#include +#include #include +#include 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; -- cgit v1.2.3