summaryrefslogtreecommitdiffstats
path: root/include/llvm/MC
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/MC')
-rw-r--r--include/llvm/MC/MCContext.h2
-rw-r--r--include/llvm/MC/MCInst.h18
-rw-r--r--include/llvm/MC/MCSection.h15
-rw-r--r--include/llvm/MC/MCStreamer.h16
-rw-r--r--include/llvm/MC/MCSymbol.h42
-rw-r--r--include/llvm/MC/MCValue.h24
6 files changed, 104 insertions, 13 deletions
diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h
index 13180e8..846e195 100644
--- a/include/llvm/MC/MCContext.h
+++ b/include/llvm/MC/MCContext.h
@@ -31,6 +31,8 @@ namespace llvm {
StringMap<MCSymbol*> Symbols;
/// SymbolValues - Bindings of symbols to values.
+ //
+ // FIXME: Is there a good reason to not just put this in the MCSymbol?
DenseMap<MCSymbol*, MCValue> SymbolValues;
/// Allocator - Allocator object used for creating machine code objects.
diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h
index 3108985..8b638d4 100644
--- a/include/llvm/MC/MCInst.h
+++ b/include/llvm/MC/MCInst.h
@@ -31,7 +31,7 @@ class MCOperand {
kRegister, ///< Register operand.
kImmediate, ///< Immediate operand.
kMBBLabel, ///< Basic block label.
- kMCValue
+ kMCValue ///< Relocatable immediate operand.
};
unsigned char Kind;
@@ -49,9 +49,11 @@ public:
MCOperand() : Kind(kInvalid) {}
MCOperand(const MCOperand &RHS) { *this = RHS; }
+ bool isValid() const { return Kind != kInvalid; }
bool isReg() const { return Kind == kRegister; }
bool isImm() const { return Kind == kImmediate; }
bool isMBBLabel() const { return Kind == kMBBLabel; }
+ bool isMCValue() const { return Kind == kMCValue; }
/// getReg - Returns the register number.
unsigned getReg() const {
@@ -82,6 +84,15 @@ public:
assert(isMBBLabel() && "Wrong accessor");
return MBBLabel.BlockNo;
}
+
+ const MCValue &getMCValue() const {
+ assert(isMCValue() && "This is not an MCValue");
+ return MCValueVal;
+ }
+ void setMCValue(const MCValue &Val) {
+ assert(isMCValue() && "This is not an MCValue");
+ MCValueVal = Val;
+ }
void MakeReg(unsigned Reg) {
Kind = kRegister;
@@ -96,6 +107,10 @@ public:
MBBLabel.FunctionNo = Fn;
MBBLabel.BlockNo = MBB;
}
+ void MakeMCValue(const MCValue &Val) {
+ Kind = kMCValue;
+ MCValueVal = Val;
+ }
};
@@ -119,7 +134,6 @@ public:
void addOperand(const MCOperand &Op) {
Operands.push_back(Op);
}
-
};
diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h
index 341f7f0..1b127b5 100644
--- a/include/llvm/MC/MCSection.h
+++ b/include/llvm/MC/MCSection.h
@@ -6,6 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
+// This file declares the MCSection class.
+//
+//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCSECTION_H
#define LLVM_MC_MCSECTION_H
@@ -14,11 +18,18 @@
namespace llvm {
+ /// MCSection - Instances of this class represent a uniqued identifier for a
+ /// section in the current translation unit. The MCContext class uniques and
+ /// creates these.
class MCSection {
std::string Name;
-
- public:
+ private:
+ friend class MCContext;
MCSection(const char *_Name) : Name(_Name) {}
+
+ MCSection(const MCSection&); // DO NOT IMPLEMENT
+ void operator=(const MCSection&); // DO NOT IMPLEMENT
+ public:
const std::string &getName() const { return Name; }
};
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index bb85d2d..54de8a3 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -6,6 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
+// This file declares the MCStreamer class.
+//
+//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCSTREAMER_H
#define LLVM_MC_MCSTREAMER_H
@@ -20,7 +24,15 @@ namespace llvm {
class MCSymbol;
class raw_ostream;
- /// MCStreamer - Streaming machine code generation interface.
+ /// MCStreamer - Streaming machine code generation interface. This interface
+ /// is intended to provide a programatic interface that is very similar to the
+ /// level that an assembler .s file provides. It has callbacks to emit bytes,
+ /// "emit directives", etc. The implementation of this interface retains
+ /// state to know what the current section is etc.
+ ///
+ /// There are multiple implementations of this interface: one for writing out
+ /// a .s file, and implementations that write out .o files of various formats.
+ ///
class MCStreamer {
public:
enum SymbolAttr {
@@ -135,7 +147,7 @@ namespace llvm {
/// This used to implement the .align assembler directive.
///
/// @param ByteAlignment - The alignment to reach. This must be a power of
- /// two.
+ /// two on some targets.
/// @param Value - The value to use when filling bytes.
/// @param Size - The size of the integer (in bytes) to emit for @param
/// Value. This must match a native machine width.
diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h
index 06f50ae..235e661 100644
--- a/include/llvm/MC/MCSymbol.h
+++ b/include/llvm/MC/MCSymbol.h
@@ -6,6 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+//
+// This file contains the declaration of the MCSymbol class.
+//
+//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCSYMBOL_H
#define LLVM_MC_MCSYMBOL_H
@@ -13,18 +17,48 @@
#include <string>
namespace llvm {
+ class MCSection;
+ class MCContext;
+
+ /// MCSymbol - Instances of this class represent a symbol name in the MC file,
+ /// and MCSymbols are created and unique'd by the MCContext class.
+ ///
+ /// 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
+ /// it is a reference to an external entity, it has a null section.
+ ///
class MCSymbol {
- MCSection *Section;
+ /// Name - The name of the symbol.
std::string Name;
+ /// Section - The section the symbol is defined in, or null if the symbol
+ /// has not been defined in the associated translation unit.
+ MCSection *Section;
+
+ /// 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".
unsigned IsTemporary : 1;
+
+ /// IsExternal - True if this symbol has been implicitly defined as an
+ /// external, for example by using it in an expression without ever emitting
+ /// it as a label. The @var Section for an external symbol is always null.
+ unsigned IsExternal : 1;
- public:
+ private: // MCContext creates and uniques these.
+ friend class MCContext;
MCSymbol(const char *_Name, bool _IsTemporary)
- : Section(0), Name(_Name), IsTemporary(_IsTemporary) {}
-
+ : Name(_Name), Section(0), IsTemporary(_IsTemporary), IsExternal(false) {}
+
+ MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT
+ void operator=(const MCSymbol&); // DO NOT IMPLEMENT
+ public:
+
MCSection *getSection() const { return Section; }
void setSection(MCSection *Value) { Section = Value; }
+ bool isExternal() const { return IsExternal; }
+ void setExternal(bool Value) { IsExternal = Value; }
+
const std::string &getName() const { return Name; }
};
diff --git a/include/llvm/MC/MCValue.h b/include/llvm/MC/MCValue.h
index 7df12da..d032f17 100644
--- a/include/llvm/MC/MCValue.h
+++ b/include/llvm/MC/MCValue.h
@@ -15,6 +15,8 @@
#define LLVM_MC_MCVALUE_H
#include "llvm/Support/DataTypes.h"
+#include "llvm/MC/MCSymbol.h"
+#include <cassert>
namespace llvm {
class MCSymbol;
@@ -23,6 +25,10 @@ class MCSymbol;
/// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports
/// relocations of this general form, but we need to represent this anyway.
///
+/// In the general form, SymbolB can only be defined if SymbolA is, and both
+/// 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.
+///
/// Note that this class must remain a simple POD value class, because we need
/// it to live in unions etc.
class MCValue {
@@ -30,13 +36,25 @@ class MCValue {
int64_t Cst;
public:
- int64_t getCst() const { return Cst; }
+ int64_t getConstant() const { return Cst; }
MCSymbol *getSymA() const { return SymA; }
MCSymbol *getSymB() const { return SymB; }
-
-
+
+ /// isAbsolute - Is this an absolute (as opposed to relocatable) value.
+ bool isAbsolute() const { return !SymA && !SymB; }
+
+ /// 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;
+ }
+
static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) {
MCValue R;
+ assert((!SymB || SymA) && "Invalid relocatable MCValue!");
R.Cst = Val;
R.SymA = SymA;
R.SymB = SymB;
OpenPOWER on IntegriCloud