• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MCAsmInfo;
23 class MCSymbol;
24 class MCSymbolRefExpr;
25 class raw_ostream;
26 
27 /// MCValue - This represents an "assembler immediate".  In its most general
28 /// form, this can hold "SymbolA - SymbolB + imm64".  Not all targets supports
29 /// relocations of this general form, but we need to represent this anyway.
30 ///
31 /// In the general form, SymbolB can only be defined if SymbolA is, and both
32 /// must be in the same (non-external) section. The latter constraint is not
33 /// enforced, since a symbol's section may not be known at construction.
34 ///
35 /// Note that this class must remain a simple POD value class, because we need
36 /// it to live in unions etc.
37 class MCValue {
38   const MCSymbolRefExpr *SymA, *SymB;
39   int64_t Cst;
40 public:
41 
getConstant()42   int64_t getConstant() const { return Cst; }
getSymA()43   const MCSymbolRefExpr *getSymA() const { return SymA; }
getSymB()44   const MCSymbolRefExpr *getSymB() const { return SymB; }
45 
46   /// isAbsolute - Is this an absolute (as opposed to relocatable) value.
isAbsolute()47   bool isAbsolute() const { return !SymA && !SymB; }
48 
49   /// print - Print the value to the stream \arg OS.
50   void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
51 
52   /// dump - Print the value to stderr.
53   void dump() const;
54 
55   static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=0,
56                      int64_t Val = 0) {
57     MCValue R;
58     assert((!SymB || SymA) && "Invalid relocatable MCValue!");
59     R.Cst = Val;
60     R.SymA = SymA;
61     R.SymB = SymB;
62     return R;
63   }
64 
get(int64_t Val)65   static MCValue get(int64_t Val) {
66     MCValue R;
67     R.Cst = Val;
68     R.SymA = 0;
69     R.SymB = 0;
70     return R;
71   }
72 
73 };
74 
75 } // end namespace llvm
76 
77 #endif
78