[llvm-commits] [llvm] r43405 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/Bitcode/Reader/DeserializeAPInt.cpp lib/Bitcode/Writer/SerializeAPInt.cpp
Ted Kremenek
kremenek at apple.com
Fri Oct 26 14:50:10 PDT 2007
Author: kremenek
Date: Fri Oct 26 16:50:10 2007
New Revision: 43405
URL: http://llvm.org/viewvc/llvm-project?rev=43405&view=rev
Log:
Added serialization support for APInt.
Added:
llvm/trunk/lib/Bitcode/Reader/DeserializeAPInt.cpp
llvm/trunk/lib/Bitcode/Writer/SerializeAPInt.cpp
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=43405&r1=43404&r2=43405&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Fri Oct 26 16:50:10 2007
@@ -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 @@
/// @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
Added: llvm/trunk/lib/Bitcode/Reader/DeserializeAPInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/DeserializeAPInt.cpp?rev=43405&view=auto
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/DeserializeAPInt.cpp (added)
+++ llvm/trunk/lib/Bitcode/Reader/DeserializeAPInt.cpp Fri Oct 26 16:50:10 2007
@@ -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();
+ }
+}
Added: llvm/trunk/lib/Bitcode/Writer/SerializeAPInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/SerializeAPInt.cpp?rev=43405&view=auto
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/SerializeAPInt.cpp (added)
+++ llvm/trunk/lib/Bitcode/Writer/SerializeAPInt.cpp Fri Oct 26 16:50:10 2007
@@ -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]);
+ }
+}
More information about the llvm-commits
mailing list