mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-28 06:27:16 +00:00
Added serialization support for APInt.
llvm-svn: 43405
This commit is contained in:
parent
5b2ac3504a
commit
3f3b4818ef
@ -16,6 +16,7 @@
|
||||
#define LLVM_APINT_H
|
||||
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
#include "llvm/Bitcode/SerializationFwd.h"
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
@ -203,6 +204,16 @@ public:
|
||||
|
||||
/// @brief Destructor.
|
||||
~APInt();
|
||||
|
||||
/// Default constructor that creates an uninitialized APInt. This is useful
|
||||
/// for object deserialization (pair this with the static method Read).
|
||||
explicit APInt() {}
|
||||
|
||||
/// @brief Used by the Bitcode serializer to emit APInts to Bitcode.
|
||||
void Emit(Serializer& S) const;
|
||||
|
||||
/// @brief Used by the Bitcode deserializer to deserialize APInts.
|
||||
void Read(Deserializer& D);
|
||||
|
||||
/// @}
|
||||
/// @name Value Tests
|
||||
|
33
lib/Bitcode/Reader/DeserializeAPInt.cpp
Normal file
33
lib/Bitcode/Reader/DeserializeAPInt.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
//===-- DeserializeAPInt.cpp - Deserialization for APInts ------*- C++ -*--===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Ted Kremenek and is distributed under the
|
||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements deserialization of APInts.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/Bitcode/Deserialize.h"
|
||||
#include <cassert>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void APInt::Read(Deserializer& D) {
|
||||
BitWidth = D.ReadInt();
|
||||
|
||||
if (isSingleWord())
|
||||
VAL = D.ReadInt();
|
||||
else {
|
||||
uint32_t NumWords = D.ReadInt();
|
||||
assert (NumWords > 1);
|
||||
pVal = new uint64_t[NumWords];
|
||||
assert (pVal && "Allocation in deserialization of APInt failed.");
|
||||
for (unsigned i = 0; i < NumWords; ++i)
|
||||
pVal[i] = D.ReadInt();
|
||||
}
|
||||
}
|
31
lib/Bitcode/Writer/SerializeAPInt.cpp
Normal file
31
lib/Bitcode/Writer/SerializeAPInt.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
//===-- SerializeAPInt.cpp - Serialization for APInts ----------*- C++ -*--===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Ted Kremenek and is distributed under the
|
||||
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements serialization of APInts.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/Bitcode/Serialize.h"
|
||||
#include <cassert>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void APInt::Emit(Serializer& S) const {
|
||||
S.EmitInt(BitWidth);
|
||||
|
||||
if (isSingleWord())
|
||||
S.EmitInt(VAL);
|
||||
else {
|
||||
uint32_t NumWords = getNumWords();
|
||||
S.EmitInt(NumWords);
|
||||
for (unsigned i = 0; i < NumWords; ++i)
|
||||
S.EmitInt(pVal[i]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user