2001-06-06 20:29:01 +00:00
|
|
|
//===-- WriterInternals.h - Data structures shared by the Writer -*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
#include "llvm/Bytecode/Format.h"
|
|
|
|
#include "llvm/Analysis/SlotCalculator.h"
|
2001-09-07 16:39:41 +00:00
|
|
|
#include "llvm/Bytecode/Primitives.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Instruction.h"
|
2001-09-07 16:39:41 +00:00
|
|
|
#include <deque>
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-09-07 16:39:41 +00:00
|
|
|
class BytecodeWriter {
|
|
|
|
deque<unsigned char> &Out;
|
2001-06-06 20:29:01 +00:00
|
|
|
SlotCalculator Table;
|
|
|
|
public:
|
2001-09-07 16:39:41 +00:00
|
|
|
BytecodeWriter(deque<unsigned char> &o, const Module *M);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
protected:
|
2001-09-07 16:39:41 +00:00
|
|
|
void outputConstants(bool isMethod);
|
|
|
|
void processMethod(const Method *M);
|
|
|
|
void processBasicBlock(const BasicBlock *BB);
|
|
|
|
void processInstruction(const Instruction *I);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
private :
|
|
|
|
inline void outputSignature() {
|
|
|
|
static const unsigned char *Sig = (const unsigned char*)"llvm";
|
|
|
|
Out.insert(Out.end(), Sig, Sig+4); // output the bytecode signature...
|
|
|
|
}
|
|
|
|
|
|
|
|
void outputModuleInfoBlock(const Module *C);
|
|
|
|
void outputSymbolTable(const SymbolTable &ST);
|
|
|
|
bool outputConstant(const ConstPoolVal *CPV);
|
|
|
|
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;
|
2001-09-07 16:39:41 +00:00
|
|
|
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:
|
2001-09-07 16:39:41 +00:00
|
|
|
inline BytecodeBlock(unsigned ID, 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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|