2003-10-13 03:32:08 +00:00
|
|
|
//===- WriterInternals.h - Data structures shared by the Writer -*- C++ -*-===//
|
2003-10-21 15:17:13 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This header defines the interface used between components of the bytecode
|
|
|
|
// writer.
|
|
|
|
//
|
|
|
|
// Note that the performance of this library is not terribly important, because
|
|
|
|
// it shouldn't be used by JIT type applications... so it is not a huge focus
|
|
|
|
// at least. :)
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
|
|
|
|
#define LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H
|
|
|
|
|
2004-07-04 11:44:27 +00:00
|
|
|
#include "SlotCalculator.h"
|
|
|
|
#include "llvm/Bytecode/Writer.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Bytecode/Format.h"
|
|
|
|
#include "llvm/Instruction.h"
|
2004-07-25 18:07:36 +00:00
|
|
|
#include "Support/DataTypes.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-09-07 16:39:41 +00:00
|
|
|
class BytecodeWriter {
|
2004-07-25 18:07:36 +00:00
|
|
|
std::vector<unsigned char> &Out;
|
2001-06-06 20:29:01 +00:00
|
|
|
SlotCalculator Table;
|
|
|
|
public:
|
2004-07-25 18:07:36 +00:00
|
|
|
BytecodeWriter(std::vector<unsigned char> &o, const Module *M);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-14 23:36:54 +00:00
|
|
|
private:
|
2003-03-19 20:56:46 +00:00
|
|
|
void outputConstants(bool isFunction);
|
2004-01-14 23:36:54 +00:00
|
|
|
void outputConstantStrings();
|
2003-03-19 20:56:46 +00:00
|
|
|
void outputFunction(const Function *F);
|
2004-01-18 21:08:52 +00:00
|
|
|
void outputCompactionTable();
|
2004-07-04 11:44:27 +00:00
|
|
|
void outputCompactionTypes(unsigned StartNo);
|
2004-01-18 21:08:52 +00:00
|
|
|
void outputCompactionTablePlane(unsigned PlaneNo,
|
|
|
|
const std::vector<const Value*> &TypePlane,
|
|
|
|
unsigned StartNo);
|
|
|
|
void outputInstructions(const Function *F);
|
|
|
|
void outputInstruction(const Instruction &I);
|
2004-07-25 18:07:36 +00:00
|
|
|
void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
|
|
|
|
const SlotCalculator &Table,
|
|
|
|
unsigned Type);
|
|
|
|
void outputInstrVarArgsCall(const Instruction *I,
|
|
|
|
unsigned Opcode,
|
|
|
|
const SlotCalculator &Table,
|
|
|
|
unsigned Type) ;
|
|
|
|
inline void outputInstructionFormat1(const Instruction *I,
|
|
|
|
unsigned Opcode,
|
|
|
|
unsigned *Slots,
|
|
|
|
unsigned Type) ;
|
|
|
|
inline void outputInstructionFormat2(const Instruction *I,
|
|
|
|
unsigned Opcode,
|
|
|
|
unsigned *Slots,
|
|
|
|
unsigned Type) ;
|
|
|
|
inline void outputInstructionFormat3(const Instruction *I,
|
|
|
|
unsigned Opcode,
|
|
|
|
unsigned *Slots,
|
|
|
|
unsigned Type) ;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
void outputModuleInfoBlock(const Module *C);
|
|
|
|
void outputSymbolTable(const SymbolTable &ST);
|
2004-07-04 11:44:27 +00:00
|
|
|
void outputTypes(unsigned StartNo);
|
2002-07-14 23:05:53 +00:00
|
|
|
void outputConstantsInPlane(const std::vector<const Value*> &Plane,
|
|
|
|
unsigned StartNo);
|
2004-01-14 23:36:54 +00:00
|
|
|
void outputConstant(const Constant *CPV);
|
2001-06-06 20:29:01 +00:00
|
|
|
void outputType(const Type *T);
|
|
|
|
|
2004-07-25 18:07:36 +00:00
|
|
|
/// @brief Unsigned integer output primitive
|
|
|
|
inline void output(unsigned i, int pos = -1);
|
|
|
|
|
|
|
|
/// @brief Signed integer output primitive
|
|
|
|
inline void output(int i);
|
|
|
|
|
|
|
|
/// @brief 64-bit variable bit rate output primitive.
|
|
|
|
inline void output_vbr(uint64_t i);
|
|
|
|
|
|
|
|
/// @brief 32-bit variable bit rate output primitive.
|
|
|
|
inline void output_vbr(unsigned i);
|
|
|
|
|
|
|
|
/// @brief Signed 64-bit variable bit rate output primitive.
|
|
|
|
inline void output_vbr(int64_t i);
|
|
|
|
|
|
|
|
/// @brief Signed 32-bit variable bit rate output primitive.
|
|
|
|
inline void output_vbr(int i);
|
|
|
|
|
|
|
|
/// Emit the minimal number of bytes that will bring us to 32 bit alignment.
|
|
|
|
/// @brief 32-bit alignment output primitive
|
|
|
|
inline void align32();
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-07-25 18:07:36 +00:00
|
|
|
inline void output(const std::string &s, bool Aligned = true);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-07-25 18:07:36 +00:00
|
|
|
inline void output_data(const void *Ptr, const void *End);
|
|
|
|
|
|
|
|
inline void output_float(float& FloatVal);
|
|
|
|
inline void output_double(double& DoubleVal);
|
|
|
|
|
|
|
|
inline void output_typeid(unsigned i);
|
|
|
|
|
|
|
|
inline size_t size() const { return Out.size(); }
|
|
|
|
inline void resize(size_t S) { Out.resize(S); }
|
|
|
|
friend class BytecodeBlock;
|
|
|
|
};
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-15 21:06:57 +00:00
|
|
|
/// BytecodeBlock - Little helper class is used by the bytecode writer to help
|
|
|
|
/// do backpatching of bytecode block sizes really easily. It backpatches when
|
|
|
|
/// it goes out of scope.
|
|
|
|
///
|
2001-06-06 20:29:01 +00:00
|
|
|
class BytecodeBlock {
|
2004-07-25 18:07:36 +00:00
|
|
|
unsigned Id;
|
2001-06-06 20:29:01 +00:00
|
|
|
unsigned Loc;
|
2004-07-25 18:07:36 +00:00
|
|
|
BytecodeWriter& Writer;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-01-15 21:06:57 +00:00
|
|
|
/// ElideIfEmpty - If this is true and the bytecode block ends up being empty,
|
|
|
|
/// the block can remove itself from the output stream entirely.
|
|
|
|
bool ElideIfEmpty;
|
|
|
|
|
2004-07-25 18:07:36 +00:00
|
|
|
/// If this is true then the block is written with a long format header using
|
|
|
|
/// a uint (32-bits) for both the block id and size. Otherwise, it uses the
|
|
|
|
/// short format which is a single uint with 27 bits for size and 5 bits for
|
|
|
|
/// the block id. Both formats are used in a bc file with version 1.3.
|
|
|
|
/// Previously only the long format was used.
|
|
|
|
bool HasLongFormat;
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
BytecodeBlock(const BytecodeBlock &); // do not implement
|
|
|
|
void operator=(const BytecodeBlock &); // do not implement
|
|
|
|
public:
|
2004-07-25 18:07:36 +00:00
|
|
|
inline BytecodeBlock(unsigned ID, BytecodeWriter& w,
|
|
|
|
bool elideIfEmpty = false, bool hasLongFormat = false);
|
|
|
|
|
|
|
|
inline ~BytecodeBlock();
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
#endif
|