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-10-26 01:35:46 +00:00
|
|
|
#include "llvm/System/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 {
|
2010-01-17 21:43:43 +00:00
|
|
|
class MCAsmInfo;
|
2010-03-18 00:59:10 +00:00
|
|
|
class MCSymbol;
|
|
|
|
class MCSymbolRefExpr;
|
2009-08-14 03:11:09 +00:00
|
|
|
class raw_ostream;
|
2009-06-23 18:58:00 +00:00
|
|
|
|
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 {
|
2010-03-18 00:59:10 +00:00
|
|
|
const MCSymbolRefExpr *SymA, *SymB;
|
2009-06-23 18:58:00 +00:00
|
|
|
int64_t Cst;
|
|
|
|
public:
|
|
|
|
|
2009-06-29 19:51:00 +00:00
|
|
|
int64_t getConstant() const { return Cst; }
|
2010-03-18 00:59:10 +00:00
|
|
|
const MCSymbolRefExpr *getSymA() const { return SymA; }
|
|
|
|
const MCSymbolRefExpr *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.
|
2009-08-22 07:22:36 +00:00
|
|
|
//
|
|
|
|
// FIXME: Switch to a tagged section, so this can return the tagged section
|
|
|
|
// value.
|
|
|
|
const MCSection *getAssociatedSection() const;
|
2009-06-30 01:49:52 +00:00
|
|
|
|
2009-08-14 03:11:09 +00:00
|
|
|
/// print - Print the value to the stream \arg OS.
|
2009-09-03 05:46:51 +00:00
|
|
|
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
|
2010-03-18 00:59:10 +00:00
|
|
|
|
2009-08-14 03:11:09 +00:00
|
|
|
/// dump - Print the value to stderr.
|
|
|
|
void dump() const;
|
|
|
|
|
2010-03-18 00:59:10 +00:00
|
|
|
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=0,
|
2009-08-26 09:16:46 +00:00
|
|
|
int64_t Val = 0) {
|
2009-06-23 23:31:52 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-03-18 00:59:10 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2010-03-18 00:59:10 +00:00
|
|
|
|
2009-06-23 18:58:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|