mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
Added preliminary implementation of generic object serialization to bitcode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43261 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
52
lib/Bitcode/Writer/Serialize.cpp
Normal file
52
lib/Bitcode/Writer/Serialize.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
//==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- 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 defines the internal methods used for object serialization.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/Serialization.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
Serializer::Serializer(BitstreamWriter& stream, unsigned BlockID)
|
||||
: Stream(stream), inBlock(BlockID >= 8) {
|
||||
|
||||
if (inBlock) Stream.EnterSubblock(8,3);
|
||||
}
|
||||
|
||||
Serializer::~Serializer() {
|
||||
if (inRecord())
|
||||
EmitRecord();
|
||||
|
||||
if (inBlock)
|
||||
Stream.ExitBlock();
|
||||
|
||||
Stream.FlushToWord();
|
||||
}
|
||||
|
||||
void Serializer::EmitRecord() {
|
||||
assert(Record.size() > 0 && "Cannot emit empty record.");
|
||||
Stream.EmitRecord(8,Record);
|
||||
Record.clear();
|
||||
}
|
||||
|
||||
void Serializer::EmitInt(unsigned X, unsigned bits) {
|
||||
Record.push_back(X);
|
||||
}
|
||||
|
||||
void Serializer::EmitCString(const char* cstr) {
|
||||
unsigned l = strlen(cstr);
|
||||
Record.push_back(l);
|
||||
|
||||
for (unsigned i = 0; i < l; i++)
|
||||
Record.push_back(cstr[i]);
|
||||
|
||||
EmitRecord();
|
||||
}
|
Reference in New Issue
Block a user