2003-10-13 03:32:08 +00:00
|
|
|
//===- WriterInternals.h - Data structures shared by the Writer -*- C++ -*-===//
|
2003-10-21 15:17:13 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This header defines the interface used between components of the bytecode
|
|
|
|
// writer.
|
|
|
|
//
|
|
|
|
// Note that the performance of this library is not terribly important, because
|
|
|
|
// it shouldn't be used by JIT type applications... so it is not a huge focus
|
|
|
|
// at least. :)
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
|
|
|
|
#define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
|
|
|
|
|
|
|
|
#include "llvm/Bytecode/Writer.h"
|
2004-01-10 18:56:59 +00:00
|
|
|
#include "WriterPrimitives.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Bytecode/Format.h"
|
2002-04-07 22:49:37 +00:00
|
|
|
#include "llvm/SlotCalculator.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Instruction.h"
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-09-07 16:39:41 +00:00
|
|
|
class BytecodeWriter {
|
2002-01-20 22:54:45 +00:00
|
|
|
std::deque<unsigned char> &Out;
|
2001-06-06 20:29:01 +00:00
|
|
|
SlotCalculator Table;
|
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
BytecodeWriter(std::deque<unsigned char> &o, const Module *M);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-14 23:36:54 +00:00
|
|
|
private:
|
2003-03-19 20:56:46 +00:00
|
|
|
void outputConstants(bool isFunction);
|
2004-01-14 23:36:54 +00:00
|
|
|
void outputConstantStrings();
|
2003-03-19 20:56:46 +00:00
|
|
|
void outputFunction(const Function *F);
|
2002-06-25 16:13:21 +00:00
|
|
|
void processInstruction(const Instruction &I);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
void outputModuleInfoBlock(const Module *C);
|
|
|
|
void outputSymbolTable(const SymbolTable &ST);
|
2002-07-14 23:05:53 +00:00
|
|
|
void outputConstantsInPlane(const std::vector<const Value*> &Plane,
|
|
|
|
unsigned StartNo);
|
2004-01-14 23:36:54 +00:00
|
|
|
void outputConstant(const Constant *CPV);
|
2001-06-06 20:29:01 +00:00
|
|
|
void outputType(const Type *T);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// BytecodeBlock - Little helper class that helps us do backpatching of bytecode
|
|
|
|
// block sizes really easily. It backpatches when it goes out of scope.
|
|
|
|
//
|
|
|
|
class BytecodeBlock {
|
|
|
|
unsigned Loc;
|
2002-01-20 22:54:45 +00:00
|
|
|
std::deque<unsigned char> &Out;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
BytecodeBlock(const BytecodeBlock &); // do not implement
|
|
|
|
void operator=(const BytecodeBlock &); // do not implement
|
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
inline BytecodeBlock(unsigned ID, std::deque<unsigned char> &o) : Out(o) {
|
2001-06-06 20:29:01 +00:00
|
|
|
output(ID, Out);
|
|
|
|
output((unsigned)0, Out); // Reserve the space for the block size...
|
|
|
|
Loc = Out.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ~BytecodeBlock() { // Do backpatch when block goes out
|
|
|
|
// of scope...
|
2001-09-07 16:39:41 +00:00
|
|
|
//cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = "
|
|
|
|
// << (NewLoc-Loc) << endl;
|
2001-06-06 20:29:01 +00:00
|
|
|
output((unsigned)(Out.size()-Loc), Out, (int)Loc-4);
|
|
|
|
align32(Out); // Blocks must ALWAYS be aligned
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
#endif
|