Added serialization support for APInt.

llvm-svn: 43405
This commit is contained in:
Ted Kremenek 2007-10-26 21:50:10 +00:00
parent 5b2ac3504a
commit 3f3b4818ef
3 changed files with 75 additions and 0 deletions

View File

@ -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

View 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();
}
}

View 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]);
}
}