2009-06-23 22:01:43 +00:00
|
|
|
//===- MCSymbol.h - Machine Code Symbols ------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-01 06:21:53 +00:00
|
|
|
//
|
|
|
|
// This file contains the declaration of the MCSymbol class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-23 22:01:43 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCSYMBOL_H
|
|
|
|
#define LLVM_MC_MCSYMBOL_H
|
|
|
|
|
2009-07-27 21:22:30 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2009-06-23 22:01:43 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-10-16 01:33:57 +00:00
|
|
|
class MCExpr;
|
2009-06-30 01:49:52 +00:00
|
|
|
class MCSection;
|
2009-07-01 06:21:53 +00:00
|
|
|
class MCContext;
|
2009-08-14 03:41:23 +00:00
|
|
|
class raw_ostream;
|
2009-07-01 06:21:53 +00:00
|
|
|
|
|
|
|
/// MCSymbol - Instances of this class represent a symbol name in the MC file,
|
2010-01-17 19:23:46 +00:00
|
|
|
/// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
|
|
|
|
/// should only be constructed with valid names for the object file.
|
2009-07-01 06:21:53 +00:00
|
|
|
///
|
|
|
|
/// If the symbol is defined/emitted into the current translation unit, the
|
|
|
|
/// Section member is set to indicate what section it lives in. Otherwise, if
|
2010-03-18 00:59:02 +00:00
|
|
|
/// it is a reference to an external entity, it has a null section.
|
2009-06-23 22:01:43 +00:00
|
|
|
class MCSymbol {
|
2009-08-22 07:22:36 +00:00
|
|
|
// Special sentinal value for the absolute pseudo section.
|
|
|
|
//
|
|
|
|
// FIXME: Use a PointerInt wrapper for this?
|
|
|
|
static const MCSection *AbsolutePseudoSection;
|
|
|
|
|
2010-03-15 06:15:35 +00:00
|
|
|
/// Name - The name of the symbol. The referred-to string data is actually
|
|
|
|
/// held by the StringMap that lives in MCContext.
|
|
|
|
StringRef Name;
|
2009-08-22 07:22:36 +00:00
|
|
|
|
|
|
|
/// Section - The section the symbol is defined in. This is null for
|
|
|
|
/// undefined symbols, and the special AbsolutePseudoSection value for
|
|
|
|
/// absolute symbols.
|
2009-08-17 05:49:08 +00:00
|
|
|
const MCSection *Section;
|
2009-08-22 11:41:10 +00:00
|
|
|
|
2009-10-16 01:33:57 +00:00
|
|
|
/// Value - If non-null, the value for a variable symbol.
|
|
|
|
const MCExpr *Value;
|
|
|
|
|
2009-07-01 06:21:53 +00:00
|
|
|
/// IsTemporary - True if this is an assembler temporary label, which
|
|
|
|
/// typically does not survive in the .o file's symbol table. Usually
|
|
|
|
/// "Lfoo" or ".foo".
|
2009-06-23 22:01:43 +00:00
|
|
|
unsigned IsTemporary : 1;
|
2010-03-18 00:59:02 +00:00
|
|
|
|
2010-11-15 14:40:36 +00:00
|
|
|
/// IsUsed - True if this symbol has been used.
|
|
|
|
mutable unsigned IsUsed : 1;
|
2010-05-17 17:46:23 +00:00
|
|
|
|
2009-07-01 06:21:53 +00:00
|
|
|
private: // MCContext creates and uniques these.
|
|
|
|
friend class MCContext;
|
2010-03-15 06:15:35 +00:00
|
|
|
MCSymbol(StringRef name, bool isTemporary)
|
2010-05-17 17:46:23 +00:00
|
|
|
: Name(name), Section(0), Value(0),
|
2010-11-15 14:40:36 +00:00
|
|
|
IsTemporary(isTemporary), IsUsed(false) {}
|
2009-10-16 01:33:57 +00:00
|
|
|
|
2009-07-01 06:23:14 +00:00
|
|
|
MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const MCSymbol&); // DO NOT IMPLEMENT
|
2009-07-01 06:21:53 +00:00
|
|
|
public:
|
2009-08-22 07:22:36 +00:00
|
|
|
/// getName - Get the symbol name.
|
2010-03-15 06:15:35 +00:00
|
|
|
StringRef getName() const { return Name; }
|
2009-06-24 01:03:06 +00:00
|
|
|
|
2010-05-17 17:46:23 +00:00
|
|
|
/// @name Accessors
|
2009-08-22 07:22:36 +00:00
|
|
|
/// @{
|
2009-06-29 23:43:14 +00:00
|
|
|
|
2009-08-26 22:13:22 +00:00
|
|
|
/// isTemporary - Check if this is an assembler temporary symbol.
|
2010-05-17 17:46:23 +00:00
|
|
|
bool isTemporary() const { return IsTemporary; }
|
|
|
|
|
2010-11-15 14:40:36 +00:00
|
|
|
/// isUsed - Check if this is used.
|
|
|
|
bool isUsed() const { return IsUsed; }
|
|
|
|
void setUsed(bool Value) const { IsUsed = Value; }
|
2009-08-26 22:13:22 +00:00
|
|
|
|
2009-10-16 01:33:57 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Associated Sections
|
|
|
|
/// @{
|
|
|
|
|
2009-08-26 00:10:55 +00:00
|
|
|
/// isDefined - Check if this symbol is defined (i.e., it has an address).
|
|
|
|
///
|
|
|
|
/// Defined symbols are either absolute or in some section.
|
|
|
|
bool isDefined() const {
|
|
|
|
return Section != 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 00:59:02 +00:00
|
|
|
/// isInSection - Check if this symbol is defined in some section (i.e., it
|
|
|
|
/// is defined but not absolute).
|
|
|
|
bool isInSection() const {
|
|
|
|
return isDefined() && !isAbsolute();
|
|
|
|
}
|
|
|
|
|
2009-08-22 07:22:36 +00:00
|
|
|
/// isUndefined - Check if this symbol undefined (i.e., implicitly defined).
|
|
|
|
bool isUndefined() const {
|
2009-08-26 00:10:55 +00:00
|
|
|
return !isDefined();
|
2009-08-22 07:22:36 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 16:03:48 +00:00
|
|
|
/// isAbsolute - Check if this is an absolute symbol.
|
2009-08-22 07:22:36 +00:00
|
|
|
bool isAbsolute() const {
|
|
|
|
return Section == AbsolutePseudoSection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSection - Get the section associated with a defined, non-absolute
|
|
|
|
/// symbol.
|
|
|
|
const MCSection &getSection() const {
|
2010-03-18 00:59:02 +00:00
|
|
|
assert(isInSection() && "Invalid accessor!");
|
2009-08-22 07:22:36 +00:00
|
|
|
return *Section;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setSection - Mark the symbol as defined in the section \arg S.
|
|
|
|
void setSection(const MCSection &S) { Section = &S; }
|
|
|
|
|
|
|
|
/// setUndefined - Mark the symbol as undefined.
|
|
|
|
void setUndefined() {
|
|
|
|
Section = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setAbsolute - Mark the symbol as absolute.
|
|
|
|
void setAbsolute() { Section = AbsolutePseudoSection; }
|
|
|
|
|
2009-10-16 01:33:57 +00:00
|
|
|
/// @}
|
|
|
|
/// @name Variable Symbols
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/// isVariable - Check if this is a variable symbol.
|
|
|
|
bool isVariable() const {
|
|
|
|
return Value != 0;
|
|
|
|
}
|
|
|
|
|
2010-05-05 17:41:00 +00:00
|
|
|
/// getValue() - Get the value for variable symbols.
|
|
|
|
const MCExpr *getVariableValue() const {
|
|
|
|
assert(isVariable() && "Invalid accessor!");
|
2010-11-15 14:40:36 +00:00
|
|
|
IsUsed = true;
|
2010-05-05 17:41:00 +00:00
|
|
|
return Value;
|
|
|
|
}
|
2009-10-16 01:33:57 +00:00
|
|
|
|
2010-05-05 19:00:56 +00:00
|
|
|
void setVariableValue(const MCExpr *Value);
|
2009-10-16 01:33:57 +00:00
|
|
|
|
2009-08-22 07:22:36 +00:00
|
|
|
/// @}
|
2009-08-14 03:41:23 +00:00
|
|
|
|
|
|
|
/// print - Print the value to the stream \arg OS.
|
2010-01-17 21:43:43 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2009-08-14 03:41:23 +00:00
|
|
|
|
|
|
|
/// dump - Print the value to stderr.
|
|
|
|
void dump() const;
|
2009-06-23 22:01:43 +00:00
|
|
|
};
|
|
|
|
|
2010-01-17 21:43:43 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
|
|
|
|
Sym.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2009-06-23 22:01:43 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|