now that MCSymbol::print doesn't use it's MAI argument, we can
[oota-llvm.git] / include / llvm / MC / MCValue.h
1 //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- 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 // This file contains the declaration of the MCValue class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCVALUE_H
15 #define LLVM_MC_MCVALUE_H
16
17 #include "llvm/System/DataTypes.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include <cassert>
20
21 namespace llvm {
22 class MCSymbol;
23 class MCAsmInfo;
24 class raw_ostream;
25
26 /// MCValue - This represents an "assembler immediate".  In its most general
27 /// form, this can hold "SymbolA - SymbolB + imm64".  Not all targets supports
28 /// relocations of this general form, but we need to represent this anyway.
29 ///
30 /// In the general form, SymbolB can only be defined if SymbolA is, and both
31 /// must be in the same (non-external) section. The latter constraint is not
32 /// enforced, since a symbol's section may not be known at construction.
33 ///
34 /// Note that this class must remain a simple POD value class, because we need
35 /// it to live in unions etc.
36 class MCValue {
37   const MCSymbol *SymA, *SymB;
38   int64_t Cst;
39 public:
40
41   int64_t getConstant() const { return Cst; }
42   const MCSymbol *getSymA() const { return SymA; }
43   const MCSymbol *getSymB() const { return SymB; }
44
45   /// isAbsolute - Is this an absolute (as opposed to relocatable) value.
46   bool isAbsolute() const { return !SymA && !SymB; }
47
48   /// getAssociatedSection - For relocatable values, return the section the
49   /// value is associated with.
50   ///
51   /// @result - The value's associated section, or null for external or constant
52   /// values.
53   //
54   // FIXME: Switch to a tagged section, so this can return the tagged section
55   // value.
56   const MCSection *getAssociatedSection() const;
57
58   /// print - Print the value to the stream \arg OS.
59   void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
60   
61   /// dump - Print the value to stderr.
62   void dump() const;
63
64   static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB = 0,
65                      int64_t Val = 0) {
66     MCValue R;
67     assert((!SymB || SymA) && "Invalid relocatable MCValue!");
68     R.Cst = Val;
69     R.SymA = SymA;
70     R.SymB = SymB;
71     return R;
72   }
73   
74   static MCValue get(int64_t Val) {
75     MCValue R;
76     R.Cst = Val;
77     R.SymA = 0;
78     R.SymB = 0;
79     return R;
80   }
81   
82 };
83
84 } // end namespace llvm
85
86 #endif