Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file contains the declaration of the MCValue class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCVALUE_H
0014 #define LLVM_MC_MCVALUE_H
0015 
0016 #include "llvm/MC/MCExpr.h"
0017 #include "llvm/Support/DataTypes.h"
0018 
0019 namespace llvm {
0020 class raw_ostream;
0021 
0022 /// This represents an "assembler immediate".
0023 ///
0024 ///  In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
0025 ///  imm64)".  Not all targets supports relocations of this general form, but we
0026 ///  need to represent this anyway.
0027 ///
0028 /// In general both SymbolA and SymbolB will also have a modifier
0029 /// analogous to the top-level Kind. Current targets are not expected
0030 /// to make use of both though. The choice comes down to whether
0031 /// relocation modifiers apply to the closest symbol or the whole
0032 /// expression.
0033 ///
0034 /// Note that this class must remain a simple POD value class, because we need
0035 /// it to live in unions etc.
0036 class MCValue {
0037   const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
0038   int64_t Cst = 0;
0039   uint32_t RefKind = 0;
0040 
0041 public:
0042   MCValue() = default;
0043   int64_t getConstant() const { return Cst; }
0044   const MCSymbolRefExpr *getSymA() const { return SymA; }
0045   const MCSymbolRefExpr *getSymB() const { return SymB; }
0046   uint32_t getRefKind() const { return RefKind; }
0047 
0048   /// Is this an absolute (as opposed to relocatable) value.
0049   bool isAbsolute() const { return !SymA && !SymB; }
0050 
0051   /// Print the value to the stream \p OS.
0052   void print(raw_ostream &OS) const;
0053 
0054   /// Print the value to stderr.
0055   void dump() const;
0056 
0057   MCSymbolRefExpr::VariantKind getAccessVariant() const;
0058 
0059   static MCValue get(const MCSymbolRefExpr *SymA,
0060                      const MCSymbolRefExpr *SymB = nullptr,
0061                      int64_t Val = 0, uint32_t RefKind = 0) {
0062     MCValue R;
0063     R.Cst = Val;
0064     R.SymA = SymA;
0065     R.SymB = SymB;
0066     R.RefKind = RefKind;
0067     return R;
0068   }
0069 
0070   static MCValue get(int64_t Val) {
0071     MCValue R;
0072     R.Cst = Val;
0073     R.SymA = nullptr;
0074     R.SymB = nullptr;
0075     R.RefKind = 0;
0076     return R;
0077   }
0078 
0079 };
0080 
0081 } // end namespace llvm
0082 
0083 #endif