diff options
author | JF Bastien <jfb@chromium.org> | 2016-01-28 10:42:01 -0800 |
---|---|---|
committer | JF Bastien <jfb@chromium.org> | 2016-01-28 10:42:01 -0800 |
commit | 876c24812ae7660553b47797bb45461fcea1cc20 (patch) | |
tree | 7d267af38895f92d3a81833f43f126e79479a6ec /src/wasm.h | |
parent | 76b1a52626151906b769d8537c16a5144b1cd3b3 (diff) | |
download | binaryen-876c24812ae7660553b47797bb45461fcea1cc20.tar.gz binaryen-876c24812ae7660553b47797bb45461fcea1cc20.tar.bz2 binaryen-876c24812ae7660553b47797bb45461fcea1cc20.zip |
Factor out bit_cast.
Diffstat (limited to 'src/wasm.h')
-rw-r--r-- | src/wasm.h | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/wasm.h b/src/wasm.h index 8cba16e8c..97e0bfc12 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -58,6 +58,7 @@ #include "emscripten-optimizer/simple_ast.h" #include "mixed_arena.h" #include "pretty_printing.h" +#include "support/utilities.h" namespace wasm { @@ -190,15 +191,9 @@ struct Literal { static void printFloat(std::ostream &o, float f) { if (isnan(f)) { - union { - float ff; - uint32_t ll; - } fu, iu; - fu.ff = f; - memcpy(&iu, &fu, sizeof(fu)); const char *sign = std::signbit(f) ? "-" : ""; o << sign << "nan"; - if (uint32_t payload = ~0xffc00000u & iu.ll) { + if (uint32_t payload = ~0xffc00000u & bit_cast<uint32_t>(f)) { o << ":0x" << std::hex << payload << std::dec; } return; @@ -212,15 +207,9 @@ struct Literal { return; } if (isnan(d)) { - union { - double dd; - uint64_t ll; - } du, iu; - du.dd = d; - memcpy(&iu, &du, sizeof(du)); const char *sign = std::signbit(d) ? "-" : ""; o << sign << "nan"; - if (uint64_t payload = ~0xfff8000000000000ull & iu.ll) { + if (uint64_t payload = ~0xfff8000000000000ull & bit_cast<uint64_t>(d)) { o << ":0x" << std::hex << payload << std::dec; } return; |