LLVM API Documentation
00001 //===- WriterInternals.h - Data structures shared by the Writer -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header defines the interface used between components of the bytecode 00011 // writer. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H 00016 #define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H 00017 00018 #include "SlotCalculator.h" 00019 #include "llvm/Bytecode/Writer.h" 00020 #include "llvm/Bytecode/Format.h" 00021 #include "llvm/Instruction.h" 00022 #include "llvm/Support/DataTypes.h" 00023 #include <string> 00024 #include <vector> 00025 00026 namespace llvm { 00027 class InlineAsm; 00028 00029 class BytecodeWriter { 00030 std::vector<unsigned char> &Out; 00031 SlotCalculator Table; 00032 public: 00033 BytecodeWriter(std::vector<unsigned char> &o, const Module *M); 00034 00035 private: 00036 void outputConstants(bool isFunction); 00037 void outputConstantStrings(); 00038 void outputFunction(const Function *F); 00039 void outputCompactionTable(); 00040 void outputCompactionTypes(unsigned StartNo); 00041 void outputCompactionTablePlane(unsigned PlaneNo, 00042 const std::vector<const Value*> &TypePlane, 00043 unsigned StartNo); 00044 void outputInstructions(const Function *F); 00045 void outputInstruction(const Instruction &I); 00046 void outputInstructionFormat0(const Instruction *I, unsigned Opcode, 00047 const SlotCalculator &Table, 00048 unsigned Type); 00049 void outputInstrVarArgsCall(const Instruction *I, 00050 unsigned Opcode, 00051 const SlotCalculator &Table, 00052 unsigned Type) ; 00053 inline void outputInstructionFormat1(const Instruction *I, 00054 unsigned Opcode, 00055 unsigned *Slots, 00056 unsigned Type) ; 00057 inline void outputInstructionFormat2(const Instruction *I, 00058 unsigned Opcode, 00059 unsigned *Slots, 00060 unsigned Type) ; 00061 inline void outputInstructionFormat3(const Instruction *I, 00062 unsigned Opcode, 00063 unsigned *Slots, 00064 unsigned Type) ; 00065 00066 void outputModuleInfoBlock(const Module *C); 00067 void outputSymbolTable(const SymbolTable &ST); 00068 void outputTypes(unsigned StartNo); 00069 void outputConstantsInPlane(const std::vector<const Value*> &Plane, 00070 unsigned StartNo); 00071 void outputConstant(const Constant *CPV); 00072 void outputInlineAsm(const InlineAsm *IA); 00073 void outputType(const Type *T); 00074 00075 /// @brief Unsigned integer output primitive 00076 inline void output(unsigned i, int pos = -1); 00077 00078 /// @brief Signed integer output primitive 00079 inline void output(int i); 00080 00081 /// @brief 64-bit variable bit rate output primitive. 00082 inline void output_vbr(uint64_t i); 00083 00084 /// @brief 32-bit variable bit rate output primitive. 00085 inline void output_vbr(unsigned i); 00086 00087 /// @brief Signed 64-bit variable bit rate output primitive. 00088 inline void output_vbr(int64_t i); 00089 00090 /// @brief Signed 32-bit variable bit rate output primitive. 00091 inline void output_vbr(int i); 00092 00093 inline void output(const std::string &s); 00094 00095 inline void output_data(const void *Ptr, const void *End); 00096 00097 inline void output_float(float& FloatVal); 00098 inline void output_double(double& DoubleVal); 00099 00100 inline void output_typeid(unsigned i); 00101 00102 inline size_t size() const { return Out.size(); } 00103 inline void resize(size_t S) { Out.resize(S); } 00104 friend class BytecodeBlock; 00105 }; 00106 00107 /// BytecodeBlock - Little helper class is used by the bytecode writer to help 00108 /// do backpatching of bytecode block sizes really easily. It backpatches when 00109 /// it goes out of scope. 00110 /// 00111 class BytecodeBlock { 00112 unsigned Id; 00113 unsigned Loc; 00114 BytecodeWriter& Writer; 00115 00116 /// ElideIfEmpty - If this is true and the bytecode block ends up being empty, 00117 /// the block can remove itself from the output stream entirely. 00118 bool ElideIfEmpty; 00119 00120 /// If this is true then the block is written with a long format header using 00121 /// a uint (32-bits) for both the block id and size. Otherwise, it uses the 00122 /// short format which is a single uint with 27 bits for size and 5 bits for 00123 /// the block id. Both formats are used in a bc file with version 1.3. 00124 /// Previously only the long format was used. 00125 bool HasLongFormat; 00126 00127 BytecodeBlock(const BytecodeBlock &); // do not implement 00128 void operator=(const BytecodeBlock &); // do not implement 00129 public: 00130 inline BytecodeBlock(unsigned ID, BytecodeWriter& w, 00131 bool elideIfEmpty = false, bool hasLongFormat = false); 00132 00133 inline ~BytecodeBlock(); 00134 }; 00135 00136 } // End llvm namespace 00137 00138 #endif