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"
25 class TypeSymbolTable;
26 class ValueSymbolTable;
28 class BytecodeWriter {
29 std::vector<unsigned char> &Out;
32 BytecodeWriter(std::vector<unsigned char> &o, const Module *M);
35 void outputConstants();
36 void outputConstantStrings();
37 void outputFunction(const Function *F);
38 void outputInstructions(const Function *F);
39 void outputInstruction(const Instruction &I);
40 void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
41 const SlotCalculator &Table,
43 void outputInstrVarArgsCall(const Instruction *I,
45 const SlotCalculator &Table,
47 inline void outputInstructionFormat1(const Instruction *I,
51 inline void outputInstructionFormat2(const Instruction *I,
55 inline void outputInstructionFormat3(const Instruction *I,
60 void outputModuleInfoBlock(const Module *C);
61 void outputTypeSymbolTable(const TypeSymbolTable &TST);
62 void outputValueSymbolTable(const ValueSymbolTable &ST);
63 void outputTypes(unsigned StartNo);
64 void outputConstantsInPlane(const Value *const*Plane, unsigned PlaneSize,
66 void outputConstant(const Constant *CPV);
67 void outputInlineAsm(const InlineAsm *IA);
68 void outputType(const Type *T);
70 /// @brief Unsigned integer output primitive
71 inline void output(unsigned i, int pos = -1);
73 /// @brief Signed integer output primitive
74 inline void output(int i);
76 /// @brief 64-bit variable bit rate output primitive.
77 inline void output_vbr(uint64_t i);
79 /// @brief 32-bit variable bit rate output primitive.
80 inline void output_vbr(unsigned i);
82 /// @brief Signed 64-bit variable bit rate output primitive.
83 inline void output_vbr(int64_t i);
85 /// @brief Signed 32-bit variable bit rate output primitive.
86 inline void output_vbr(int i);
88 inline void output(const std::string &s);
90 inline void output_data(const void *Ptr, const void *End);
92 inline void output_float(float& FloatVal);
93 inline void output_double(double& DoubleVal);
95 inline void output_typeid(unsigned i);
97 inline size_t size() const { return Out.size(); }
98 inline void resize(size_t S) { Out.resize(S); }
99 friend class BytecodeBlock;
102 /// BytecodeBlock - Little helper class is used by the bytecode writer to help
103 /// do backpatching of bytecode block sizes really easily. It backpatches when
104 /// it goes out of scope.
106 class BytecodeBlock {
109 BytecodeWriter& Writer;
111 /// ElideIfEmpty - If this is true and the bytecode block ends up being empty,
112 /// the block can remove itself from the output stream entirely.
115 /// If this is true then the block is written with a long format header using
116 /// a uint (32-bits) for both the block id and size. Otherwise, it uses the
117 /// short format which is a single uint with 27 bits for size and 5 bits for
118 /// the block id. Both formats are used in a bc file with version 1.3.
119 /// Previously only the long format was used.
122 BytecodeBlock(const BytecodeBlock &); // do not implement
123 void operator=(const BytecodeBlock &); // do not implement
125 inline BytecodeBlock(unsigned ID, BytecodeWriter& w,
126 bool elideIfEmpty = false, bool hasLongFormat = false);
128 inline ~BytecodeBlock();
131 } // End llvm namespace