MCCodeEmitter: Add target independent fixup flag for is-pc-relative.
[oota-llvm.git] / include / llvm / MC / MCCodeEmitter.h
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
17 namespace llvm {
18 class MCExpr;
19 class MCInst;
20 class raw_ostream;
21 template<typename T> class SmallVectorImpl;
22
23 /// MCFixupKindInfo - Target independent information on a fixup kind.
24 struct 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
31   /// A target specific name for the fixup kind. The names will be unique for
32   /// distinct kinds on any given target.
33   const char *Name;
34
35   /// The bit offset to write the relocation into.
36   //
37   // FIXME: These two fields are under-specified and not general enough, but it
38   // is covers many things, and is enough to let the AsmStreamer pretty-print
39   // the encoding.
40   unsigned TargetOffset;
41
42   /// The number of bits written by this fixup. The bits are assumed to be
43   /// contiguous.
44   unsigned TargetSize;
45
46   /// Flags describing additional information on this fixup kind.
47   unsigned Flags;
48 };
49
50 /// MCCodeEmitter - Generic instruction encoding interface.
51 class MCCodeEmitter {
52 private:
53   MCCodeEmitter(const MCCodeEmitter &);   // DO NOT IMPLEMENT
54   void operator=(const MCCodeEmitter &);  // DO NOT IMPLEMENT
55 protected: // Can only create subclasses.
56   MCCodeEmitter();
57
58 public:
59   virtual ~MCCodeEmitter();
60
61   /// @name Target Independent Fixup Information
62   /// @{
63
64   /// getNumFixupKinds - Get the number of target specific fixup kinds.
65   virtual unsigned getNumFixupKinds() const = 0;
66
67   /// getFixupKindInfo - Get information on a fixup kind.
68   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
69
70   /// @}
71
72   /// EncodeInstruction - Encode the given \arg Inst to bytes on the output
73   /// stream \arg OS.
74   virtual void EncodeInstruction(const MCInst &Inst, raw_ostream &OS,
75                                  SmallVectorImpl<MCFixup> &Fixups) const = 0;
76 };
77
78 } // End llvm namespace
79
80 #endif