[llvm-commits] [llvm] r84228 - in /llvm/trunk: include/llvm/MC/MCContext.h lib/MC/MCContext.cpp lib/MC/MCExpr.cpp
Daniel Dunbar
daniel at zuster.org
Thu Oct 15 18:33:11 PDT 2009
Author: ddunbar
Date: Thu Oct 15 20:33:11 2009
New Revision: 84228
URL: http://llvm.org/viewvc/llvm-project?rev=84228&view=rev
Log:
MC: Switch MCContext value table to storing MCExprs.
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCExpr.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=84228&r1=84227&r2=84228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Oct 15 20:33:11 2009
@@ -15,7 +15,7 @@
#include "llvm/Support/Allocator.h"
namespace llvm {
- class MCValue;
+ class MCExpr;
class MCSection;
class MCSymbol;
class StringRef;
@@ -36,7 +36,7 @@
/// SymbolValues - Bindings of symbols to values.
//
// FIXME: Is there a good reason to not just put this in the MCSymbol?
- DenseMap<const MCSymbol*, MCValue> SymbolValues;
+ DenseMap<const MCSymbol*, const MCExpr*> SymbolValues;
/// Allocator - Allocator object used for creating machine code objects.
///
@@ -63,7 +63,7 @@
/// @param IsTemporary - Whether this symbol is an assembler temporary,
/// which should not survive into the symbol table for the translation unit.
MCSymbol *GetOrCreateSymbol(const StringRef &Name);
-
+
/// CreateTemporarySymbol - Create a new temporary symbol with the specified
/// @param Name.
///
@@ -79,22 +79,30 @@
/// @name Symbol Value Table
/// @{
- /// ClearSymbolValue - Erase a value binding for @arg Symbol, if one exists.
- void ClearSymbolValue(const MCSymbol *Symbol);
+ /// ClearSymbolValue - Erase the variable binding for @arg Symbol, if one
+ /// exists.
+ void ClearSymbolValue(const MCSymbol *Symbol) {
+ SymbolValues.erase(Symbol);
+ }
- /// SetSymbolValue - Set the value binding for @arg Symbol to @arg Value.
- void SetSymbolValue(const MCSymbol *Symbol, const MCValue &Value);
+ /// SetSymbolValue - Set the variable binding for @arg Symbol to @arg Value.
+ void SetSymbolValue(const MCSymbol *Symbol, const MCExpr *Value) {
+ assert(Value && "Invalid variable assignment!");
+ SymbolValues.insert(std::make_pair(Symbol, Value));
+ }
- /// GetSymbolValue - Return the current value for @arg Symbol, or null if
- /// none exists.
- const MCValue *GetSymbolValue(const MCSymbol *Symbol) const;
+ /// GetSymbolValue - Return the current variable value for @arg Symbol, or
+ /// null if @arg Symbol is not a variable.
+ const MCExpr *GetSymbolValue(const MCSymbol *Symbol) const {
+ return SymbolValues.lookup(Symbol);
+ }
/// @}
void *Allocate(unsigned Size, unsigned Align = 8) {
return Allocator.Allocate(Size, Align);
}
- void Deallocate(void *Ptr) {
+ void Deallocate(void *Ptr) {
}
};
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=84228&r1=84227&r2=84228&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Oct 15 20:33:11 2009
@@ -52,20 +52,3 @@
MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
return Symbols.lookup(Name);
}
-
-void MCContext::ClearSymbolValue(const MCSymbol *Sym) {
- SymbolValues.erase(Sym);
-}
-
-void MCContext::SetSymbolValue(const MCSymbol *Sym, const MCValue &Value) {
- SymbolValues[Sym] = Value;
-}
-
-const MCValue *MCContext::GetSymbolValue(const MCSymbol *Sym) const {
- DenseMap<const MCSymbol*, MCValue>::iterator it = SymbolValues.find(Sym);
-
- if (it == SymbolValues.end())
- return 0;
-
- return &it->second;
-}
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=84228&r1=84227&r2=84228&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Thu Oct 15 20:33:11 2009
@@ -181,10 +181,9 @@
case SymbolRef: {
const MCSymbol &Sym = cast<MCSymbolRefExpr>(this)->getSymbol();
- if (const MCValue *Value = Ctx.GetSymbolValue(&Sym))
- Res = *Value;
- else
- Res = MCValue::get(&Sym, 0, 0);
+ if (const MCExpr *Value = Ctx.GetSymbolValue(&Sym))
+ return Value->EvaluateAsRelocatable(Ctx, Res);
+ Res = MCValue::get(&Sym, 0, 0);
return true;
}
More information about the llvm-commits
mailing list