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 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
16 #define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
18 #include "SlotCalculator.h"
19 #include "llvm/Bytecode/Writer.h"
20 #include "llvm/Bytecode/Format.h"
21 #include "llvm/Instruction.h"
22 #include "llvm/Support/DataTypes.h"
28 class TypeSymbolTable;
29 class ValueSymbolTable;
31 class BytecodeWriter {
32 std::vector<unsigned char> &Out;
35 BytecodeWriter(std::vector<unsigned char> &o, const Module *M);
38 void outputConstants(bool isFunction);
39 void outputConstantStrings();
40 void outputFunction(const Function *F);
41 void outputCompactionTable();
42 void outputCompactionTypes(unsigned StartNo);
43 void outputCompactionTablePlane(unsigned PlaneNo,
44 const std::vector<const Value*> &TypePlane,
46 void outputInstructions(const Function *F);
47 void outputInstruction(const Instruction &I);
48 void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
49 const SlotCalculator &Table,
51 void outputInstrVarArgsCall(const Instruction *I,
53 const SlotCalculator &Table,
55 inline void outputInstructionFormat1(const Instruction *I,
59 inline void outputInstructionFormat2(const Instruction *I,
63 inline void outputInstructionFormat3(const Instruction *I,
68 void outputModuleInfoBlock(const Module *C);
69 void outputTypeSymbolTable(const TypeSymbolTable &TST);
70 void outputValueSymbolTable(const ValueSymbolTable &ST);
71 void outputTypes(unsigned StartNo);
72 void outputConstantsInPlane(const std::vector<const Value*> &Plane,
74 void outputConstant(const Constant *CPV);
75 void outputInlineAsm(const InlineAsm *IA);
76 void outputType(const Type *T);
78 /// @brief Unsigned integer output primitive
79 inline void output(unsigned i, int pos = -1);
81 /// @brief Signed integer output primitive
82 inline void output(int i);
84 /// @brief 64-bit variable bit rate output primitive.
85 inline void output_vbr(uint64_t i);
87 /// @brief 32-bit variable bit rate output primitive.
88 inline void output_vbr(unsigned i);
90 /// @brief Signed 64-bit variable bit rate output primitive.
91 inline void output_vbr(int64_t i);
93 /// @brief Signed 32-bit variable bit rate output primitive.
94 inline void output_vbr(int i);
96 inline void output(const std::string &s);
98 inline void output_data(const void *Ptr, const void *End);
100 inline void output_float(float& FloatVal);
101 inline void output_double(double& DoubleVal);
103 inline void output_typeid(unsigned i);
105 inline size_t size() const { return Out.size(); }
106 inline void resize(size_t S) { Out.resize(S); }
107 friend class BytecodeBlock;
110 /// BytecodeBlock - Little helper class is used by the bytecode writer to help
111 /// do backpatching of bytecode block sizes really easily. It backpatches when
112 /// it goes out of scope.
114 class BytecodeBlock {
117 BytecodeWriter& Writer;
119 /// ElideIfEmpty - If this is true and the bytecode block ends up being empty,
120 /// the block can remove itself from the output stream entirely.
123 /// If this is true then the block is written with a long format header using
124 /// a uint (32-bits) for both the block id and size. Otherwise, it uses the
125 /// short format which is a single uint with 27 bits for size and 5 bits for
126 /// the block id. Both formats are used in a bc file with version 1.3.
127 /// Previously only the long format was used.
130 BytecodeBlock(const BytecodeBlock &); // do not implement
131 void operator=(const BytecodeBlock &); // do not implement
133 inline BytecodeBlock(unsigned ID, BytecodeWriter& w,
134 bool elideIfEmpty = false, bool hasLongFormat = false);
136 inline ~BytecodeBlock();
139 } // End llvm namespace