2009-06-23 23:31:52 +00:00
|
|
|
//===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===//
|
2009-06-23 18:58:00 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-06-23 23:31:52 +00:00
|
|
|
// This file contains the declaration of the MCValue class.
|
2009-06-23 18:58:00 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-06-23 23:31:52 +00:00
|
|
|
#ifndef LLVM_MC_MCVALUE_H
|
|
|
|
#define LLVM_MC_MCVALUE_H
|
2009-06-23 18:58:00 +00:00
|
|
|
|
2009-06-23 20:02:00 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2009-06-30 01:49:52 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include <cassert>
|
2009-06-23 20:02:00 +00:00
|
|
|
|
2009-06-23 18:58:00 +00:00
|
|
|
namespace llvm {
|
|
|
|
class MCSymbol;
|
|
|
|
|
2009-06-23 23:31:52 +00:00
|
|
|
/// MCValue - This represents an "assembler immediate". In its most general
|
|
|
|
/// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports
|
2009-06-23 18:58:00 +00:00
|
|
|
/// relocations of this general form, but we need to represent this anyway.
|
2009-06-23 23:31:52 +00:00
|
|
|
///
|
2009-06-30 01:49:52 +00:00
|
|
|
/// In the general form, SymbolB can only be defined if SymbolA is, and both
|
2009-06-30 22:49:27 +00:00
|
|
|
/// must be in the same (non-external) section. The latter constraint is not
|
|
|
|
/// enforced, since a symbol's section may not be known at construction.
|
2009-06-30 01:49:52 +00:00
|
|
|
///
|
2009-06-23 23:31:52 +00:00
|
|
|
/// Note that this class must remain a simple POD value class, because we need
|
|
|
|
/// it to live in unions etc.
|
|
|
|
class MCValue {
|
2009-06-23 18:58:00 +00:00
|
|
|
MCSymbol *SymA, *SymB;
|
|
|
|
int64_t Cst;
|
|
|
|
public:
|
|
|
|
|
2009-06-29 19:51:00 +00:00
|
|
|
int64_t getConstant() const { return Cst; }
|
2009-06-23 18:58:00 +00:00
|
|
|
MCSymbol *getSymA() const { return SymA; }
|
|
|
|
MCSymbol *getSymB() const { return SymB; }
|
2009-06-29 19:51:00 +00:00
|
|
|
|
2009-07-01 06:48:00 +00:00
|
|
|
/// isAbsolute - Is this an absolute (as opposed to relocatable) value.
|
|
|
|
bool isAbsolute() const { return !SymA && !SymB; }
|
2009-06-30 01:49:52 +00:00
|
|
|
|
|
|
|
/// getAssociatedSection - For relocatable values, return the section the
|
|
|
|
/// value is associated with.
|
|
|
|
///
|
|
|
|
/// @result - The value's associated section, or null for external or constant
|
|
|
|
/// values.
|
|
|
|
MCSection *getAssociatedSection() const {
|
|
|
|
return SymA ? SymA->getSection() : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-23 23:31:52 +00:00
|
|
|
static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) {
|
|
|
|
MCValue R;
|
2009-06-30 22:49:27 +00:00
|
|
|
assert((!SymB || SymA) && "Invalid relocatable MCValue!");
|
2009-06-23 18:58:00 +00:00
|
|
|
R.Cst = Val;
|
|
|
|
R.SymA = SymA;
|
|
|
|
R.SymB = SymB;
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2009-06-23 23:31:52 +00:00
|
|
|
static MCValue get(int64_t Val) {
|
|
|
|
MCValue R;
|
2009-06-23 18:58:00 +00:00
|
|
|
R.Cst = Val;
|
|
|
|
R.SymA = 0;
|
|
|
|
R.SymB = 0;
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|