MCCodeEmitter.h revision 9754ab010e3897457e75cbf0aa74e276fc944174
1//===-- llvm/MC/MCCodeEmitter.h - Instruction Encoding ----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_MC_MCCODEEMITTER_H 11#define LLVM_MC_MCCODEEMITTER_H 12 13#include "llvm/MC/MCFixup.h" 14 15#include <cassert> 16 17namespace llvm { 18class MCExpr; 19class MCInst; 20class raw_ostream; 21template<typename T> class SmallVectorImpl; 22 23/// MCFixupKindInfo - Target independent information on a fixup kind. 24struct MCFixupKindInfo { 25 enum FixupKindFlags { 26 /// Is this fixup kind PCrelative? This is used by the assembler backend to 27 /// evaluate fixup values in a target independent manner when possible. 28 FKF_IsPCRel = (1 << 0), 29 30 /// Should this fixup kind force a 4-byte aligned effective PC value? 31 FKF_IsAlignedDownTo32Bits = (1 << 1) 32 }; 33 34 /// A target specific name for the fixup kind. The names will be unique for 35 /// distinct kinds on any given target. 36 const char *Name; 37 38 /// The bit offset to write the relocation into. 39 unsigned TargetOffset; 40 41 /// The number of bits written by this fixup. The bits are assumed to be 42 /// contiguous. 43 unsigned TargetSize; 44 45 /// Flags describing additional information on this fixup kind. 46 unsigned Flags; 47}; 48 49/// MCCodeEmitter - Generic instruction encoding interface. 50class MCCodeEmitter { 51private: 52 MCCodeEmitter(const MCCodeEmitter &); // DO NOT IMPLEMENT 53 void operator=(const MCCodeEmitter &); // DO NOT IMPLEMENT 54protected: // Can only create subclasses. 55 MCCodeEmitter(); 56 57public: 58 virtual ~MCCodeEmitter(); 59 60 /// @name Target Independent Fixup Information 61 /// @{ 62 63 /// getNumFixupKinds - Get the number of target specific fixup kinds. 64 virtual unsigned getNumFixupKinds() const = 0; 65 66 /// getFixupKindInfo - Get information on a fixup kind. 67 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const; 68 69 /// @} 70 71 /// EncodeInstruction - Encode the given \arg Inst to bytes on the output 72 /// stream \arg OS. 73 virtual void EncodeInstruction(const MCInst &Inst, raw_ostream &OS, 74 SmallVectorImpl<MCFixup> &Fixups) const = 0; 75}; 76 77} // End llvm namespace 78 79#endif 80