1 //===-- WriterInternals.h - Data structures shared by the Writer -*- C++ -*--=//
3 // This header defines the interface used between components of the bytecode
6 // Note that the performance of this library is not terribly important, because
7 // it shouldn't be used by JIT type applications... so it is not a huge focus
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
13 #define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
15 #include "llvm/Bytecode/Writer.h"
16 #include "llvm/Bytecode/Format.h"
17 #include "llvm/Bytecode/Primitives.h"
18 #include "llvm/SlotCalculator.h"
19 #include "llvm/Instruction.h"
21 class BytecodeWriter {
22 std::deque<unsigned char> &Out;
25 BytecodeWriter(std::deque<unsigned char> &o, const Module *M);
28 void outputConstants(bool isMethod);
29 void processMethod(const Function *F);
30 void processBasicBlock(const BasicBlock &BB);
31 void processInstruction(const Instruction &I);
34 inline void outputSignature() {
35 static const unsigned char *Sig = (const unsigned char*)"llvm";
36 Out.insert(Out.end(), Sig, Sig+4); // output the bytecode signature...
39 void outputModuleInfoBlock(const Module *C);
40 void outputSymbolTable(const SymbolTable &ST);
41 void outputConstantsInPlane(const std::vector<const Value*> &Plane,
43 bool outputConstant(const Constant *CPV);
44 void outputType(const Type *T);
50 // BytecodeBlock - Little helper class that helps us do backpatching of bytecode
51 // block sizes really easily. It backpatches when it goes out of scope.
55 std::deque<unsigned char> &Out;
57 BytecodeBlock(const BytecodeBlock &); // do not implement
58 void operator=(const BytecodeBlock &); // do not implement
60 inline BytecodeBlock(unsigned ID, std::deque<unsigned char> &o) : Out(o) {
62 output((unsigned)0, Out); // Reserve the space for the block size...
66 inline ~BytecodeBlock() { // Do backpatch when block goes out
68 //cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = "
69 // << (NewLoc-Loc) << endl;
70 output((unsigned)(Out.size()-Loc), Out, (int)Loc-4);
71 align32(Out); // Blocks must ALWAYS be aligned