1 //===- WriterInternals.h - Data structures shared by the Writer -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines the interface used between components of the bytecode
13 // Note that the performance of this library is not terribly important, because
14 // it shouldn't be used by JIT type applications... so it is not a huge focus
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
20 #define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
22 #include "llvm/Bytecode/Writer.h"
23 #include "llvm/Bytecode/Format.h"
24 #include "llvm/Bytecode/Primitives.h"
25 #include "llvm/SlotCalculator.h"
26 #include "llvm/Instruction.h"
28 class BytecodeWriter {
29 std::deque<unsigned char> &Out;
32 BytecodeWriter(std::deque<unsigned char> &o, const Module *M);
35 void outputConstants(bool isFunction);
36 void outputFunction(const Function *F);
37 void processBasicBlock(const BasicBlock &BB);
38 void processInstruction(const Instruction &I);
41 inline void outputSignature() {
42 static const unsigned char *Sig = (const unsigned char*)"llvm";
43 Out.insert(Out.end(), Sig, Sig+4); // output the bytecode signature...
46 void outputModuleInfoBlock(const Module *C);
47 void outputSymbolTable(const SymbolTable &ST);
48 void outputConstantsInPlane(const std::vector<const Value*> &Plane,
50 bool outputConstant(const Constant *CPV);
51 void outputType(const Type *T);
57 // BytecodeBlock - Little helper class that helps us do backpatching of bytecode
58 // block sizes really easily. It backpatches when it goes out of scope.
62 std::deque<unsigned char> &Out;
64 BytecodeBlock(const BytecodeBlock &); // do not implement
65 void operator=(const BytecodeBlock &); // do not implement
67 inline BytecodeBlock(unsigned ID, std::deque<unsigned char> &o) : Out(o) {
69 output((unsigned)0, Out); // Reserve the space for the block size...
73 inline ~BytecodeBlock() { // Do backpatch when block goes out
75 //cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = "
76 // << (NewLoc-Loc) << endl;
77 output((unsigned)(Out.size()-Loc), Out, (int)Loc-4);
78 align32(Out); // Blocks must ALWAYS be aligned