Rename MCValue::isConstant to isAbsolute.
[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/Support/DataTypes.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include <cassert>
20
21 namespace llvm {
22 class MCSymbol;
23
24 /// MCValue - This represents an "assembler immediate".  In its most general
25 /// form, this can hold "SymbolA - SymbolB + imm64".  Not all targets supports
26 /// relocations of this general form, but we need to represent this anyway.
27 ///
28 /// In the general form, SymbolB can only be defined if SymbolA is, and both
29 /// must be in the same (non-external) section. The latter constraint is not
30 /// enforced, since a symbol's section may not be known at construction.
31 ///
32 /// Note that this class must remain a simple POD value class, because we need
33 /// it to live in unions etc.
34 class MCValue {
35   MCSymbol *SymA, *SymB;
36   int64_t Cst;
37 public:
38
39   int64_t getConstant() const { return Cst; }
40   MCSymbol *getSymA() const { return SymA; }
41   MCSymbol *getSymB() const { return SymB; }
42
43   /// isAbsolute - Is this an absolute (as opposed to relocatable) value.
44   bool isAbsolute() const { return !SymA && !SymB; }
45
46   /// getAssociatedSection - For relocatable values, return the section the
47   /// value is associated with.
48   ///
49   /// @result - The value's associated section, or null for external or constant
50   /// values.
51   MCSection *getAssociatedSection() const {
52     return SymA ? SymA->getSection() : 0;
53   }
54
55   static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) {
56     MCValue R;
57     assert((!SymB || SymA) && "Invalid relocatable MCValue!");
58     R.Cst = Val;
59     R.SymA = SymA;
60     R.SymB = SymB;
61     return R;
62   }
63   
64   static MCValue get(int64_t Val) {
65     MCValue R;
66     R.Cst = Val;
67     R.SymA = 0;
68     R.SymB = 0;
69     return R;
70   }
71   
72 };
73
74 } // end namespace llvm
75
76 #endif