aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp21
-rw-r--r--lib/Bytecode/Writer/Writer.cpp37
2 files changed, 21 insertions, 37 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index f56c59ad18..6bb06c3ce4 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -27,6 +27,7 @@
#include "llvm/Config/alloca.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/Compressor.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/ADT/StringExtras.h"
#include <sstream>
#include <algorithm>
@@ -162,29 +163,19 @@ inline void BytecodeReader::read_data(void *Ptr, void *End) {
inline void BytecodeReader::read_float(float& FloatVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- float f;
- uint32_t i;
- } FloatUnion;
- FloatUnion.i = At[0] | (At[1] << 8) | (At[2] << 16) | (At[3] << 24);
+ FloatVal = BitsToFloat(At[0] | (At[1] << 8) | (At[2] << 16) | (At[3] << 24));
At+=sizeof(uint32_t);
- FloatVal = FloatUnion.f;
}
/// Read a double value in little-endian order
inline void BytecodeReader::read_double(double& DoubleVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- double d;
- uint64_t i;
- } DoubleUnion;
- DoubleUnion.i = (uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) |
- (uint64_t(At[2]) << 16) | (uint64_t(At[3]) << 24) |
- (uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) |
- (uint64_t(At[6]) << 48) | (uint64_t(At[7]) << 56);
+ DoubleVal = BitsToDouble((uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) |
+ (uint64_t(At[2]) << 16) | (uint64_t(At[3]) << 24) |
+ (uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) |
+ (uint64_t(At[6]) << 48) | (uint64_t(At[7]) << 56));
At+=sizeof(uint64_t);
- DoubleVal = DoubleUnion.d;
}
/// Read a block header and obtain its type and size
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 95bbd2e575..b1f2634296 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -27,6 +27,7 @@
#include "llvm/SymbolTable.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/Compressor.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include <cstring>
@@ -139,33 +140,25 @@ inline void BytecodeWriter::output_data(const void *Ptr, const void *End) {
inline void BytecodeWriter::output_float(float& FloatVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- float f;
- uint32_t i;
- } FloatUnion;
- FloatUnion.f = FloatVal;
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i & 0xFF )));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 8) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 16) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (FloatUnion.i >> 24) & 0xFF));
+ uint32_t i = FloatToBits(FloatVal);
+ Out.push_back( static_cast<unsigned char>( (i & 0xFF )));
+ Out.push_back( static_cast<unsigned char>( (i >> 8) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 16) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 24) & 0xFF));
}
inline void BytecodeWriter::output_double(double& DoubleVal) {
/// FIXME: This isn't optimal, it has size problems on some platforms
/// where FP is not IEEE.
- union {
- double d;
- uint64_t i;
- } DoubleUnion;
- DoubleUnion.d = DoubleVal;
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i & 0xFF )));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 8) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 16) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 24) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 32) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 40) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 48) & 0xFF));
- Out.push_back( static_cast<unsigned char>( (DoubleUnion.i >> 56) & 0xFF));
+ uint64_t i = DoubleToBits(DoubleVal);
+ Out.push_back( static_cast<unsigned char>( (i & 0xFF )));
+ Out.push_back( static_cast<unsigned char>( (i >> 8) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 16) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 24) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 32) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 40) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 48) & 0xFF));
+ Out.push_back( static_cast<unsigned char>( (i >> 56) & 0xFF));
}
inline BytecodeBlock::BytecodeBlock(unsigned ID, BytecodeWriter& w,