llvm-mc: Diagnose misuse (mix) of defined symbols and labels.
[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
19 namespace llvm {
20 class MCSymbol;
21
22 /// MCValue - This represents an "assembler immediate".  In its most general
23 /// form, this can hold "SymbolA - SymbolB + imm64".  Not all targets supports
24 /// relocations of this general form, but we need to represent this anyway.
25 ///
26 /// Note that this class must remain a simple POD value class, because we need
27 /// it to live in unions etc.
28 class MCValue {
29   MCSymbol *SymA, *SymB;
30   int64_t Cst;
31 public:
32
33   int64_t getConstant() const { return Cst; }
34   MCSymbol *getSymA() const { return SymA; }
35   MCSymbol *getSymB() const { return SymB; }
36
37   bool isConstant() const { return !SymA && !SymB; }
38   
39   static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) {
40     MCValue R;
41     R.Cst = Val;
42     R.SymA = SymA;
43     R.SymB = SymB;
44     return R;
45   }
46   
47   static MCValue get(int64_t Val) {
48     MCValue R;
49     R.Cst = Val;
50     R.SymA = 0;
51     R.SymB = 0;
52     return R;
53   }
54   
55 };
56
57 } // end namespace llvm
58
59 #endif