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/Analysis/SlotCalculator.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Instruction.h"
22 class BytecodeWriter : public ModuleAnalyzer {
23 vector<unsigned char> &Out;
26 BytecodeWriter(vector<unsigned char> &o, const Module *M);
29 virtual bool processConstPool(const ConstantPool &CP, bool isMethod);
30 virtual bool processMethod(const Method *M);
31 virtual bool processBasicBlock(const BasicBlock *BB);
32 virtual bool processInstruction(const Instruction *I);
35 inline void outputSignature() {
36 static const unsigned char *Sig = (const unsigned char*)"llvm";
37 Out.insert(Out.end(), Sig, Sig+4); // output the bytecode signature...
40 void outputModuleInfoBlock(const Module *C);
41 void outputSymbolTable(const SymbolTable &ST);
42 bool outputConstant(const ConstPoolVal *CPV);
43 void outputType(const Type *T);
49 // BytecodeBlock - Little helper class that helps us do backpatching of bytecode
50 // block sizes really easily. It backpatches when it goes out of scope.
54 vector<unsigned char> &Out;
56 BytecodeBlock(const BytecodeBlock &); // do not implement
57 void operator=(const BytecodeBlock &); // do not implement
59 inline BytecodeBlock(unsigned ID, vector<unsigned char> &o) : Out(o) {
61 output((unsigned)0, Out); // Reserve the space for the block size...
65 inline ~BytecodeBlock() { // Do backpatch when block goes out
67 // cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = " << (NewLoc-Loc) << endl;
68 output((unsigned)(Out.size()-Loc), Out, (int)Loc-4);
69 align32(Out); // Blocks must ALWAYS be aligned