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"
29 class BytecodeWriter {
30 std::vector<unsigned char> &Out;
33 BytecodeWriter(std::vector<unsigned char> &o, const Module *M);
36 void outputConstants(bool isFunction);
37 void outputConstantStrings();
38 void outputFunction(const Function *F);
39 void outputCompactionTable();
40 void outputCompactionTypes(unsigned StartNo);
41 void outputCompactionTablePlane(unsigned PlaneNo,
42 const std::vector<const Value*> &TypePlane,
44 void outputInstructions(const Function *F);
45 void outputInstruction(const Instruction &I);
46 void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
47 const SlotCalculator &Table,
49 void outputInstrVarArgsCall(const Instruction *I,
51 const SlotCalculator &Table,
53 inline void outputInstructionFormat1(const Instruction *I,
57 inline void outputInstructionFormat2(const Instruction *I,
61 inline void outputInstructionFormat3(const Instruction *I,
66 void outputModuleInfoBlock(const Module *C);
67 void outputSymbolTable(const SymbolTable &ST);
68 void outputTypes(unsigned StartNo);
69 void outputConstantsInPlane(const std::vector<const Value*> &Plane,
71 void outputConstant(const Constant *CPV);
72 void outputInlineAsm(const InlineAsm *IA);
73 void outputType(const Type *T);
75 /// @brief Unsigned integer output primitive
76 inline void output(unsigned i, int pos = -1);
78 /// @brief Signed integer output primitive
79 inline void output(int i);
81 /// @brief 64-bit variable bit rate output primitive.
82 inline void output_vbr(uint64_t i);
84 /// @brief 32-bit variable bit rate output primitive.
85 inline void output_vbr(unsigned i);
87 /// @brief Signed 64-bit variable bit rate output primitive.
88 inline void output_vbr(int64_t i);
90 /// @brief Signed 32-bit variable bit rate output primitive.
91 inline void output_vbr(int i);
93 inline void output(const std::string &s);
95 inline void output_data(const void *Ptr, const void *End);
97 inline void output_float(float& FloatVal);
98 inline void output_double(double& DoubleVal);
100 inline void output_typeid(unsigned i);
102 inline size_t size() const { return Out.size(); }
103 inline void resize(size_t S) { Out.resize(S); }
104 friend class BytecodeBlock;
107 /// BytecodeBlock - Little helper class is used by the bytecode writer to help
108 /// do backpatching of bytecode block sizes really easily. It backpatches when
109 /// it goes out of scope.
111 class BytecodeBlock {
114 BytecodeWriter& Writer;
116 /// ElideIfEmpty - If this is true and the bytecode block ends up being empty,
117 /// the block can remove itself from the output stream entirely.
120 /// If this is true then the block is written with a long format header using
121 /// a uint (32-bits) for both the block id and size. Otherwise, it uses the
122 /// short format which is a single uint with 27 bits for size and 5 bits for
123 /// the block id. Both formats are used in a bc file with version 1.3.
124 /// Previously only the long format was used.
127 BytecodeBlock(const BytecodeBlock &); // do not implement
128 void operator=(const BytecodeBlock &); // do not implement
130 inline BytecodeBlock(unsigned ID, BytecodeWriter& w,
131 bool elideIfEmpty = false, bool hasLongFormat = false);
133 inline ~BytecodeBlock();
136 } // End llvm namespace