summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-10-16 01:34:54 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-10-16 01:34:54 +0000
commitd20cda028a11e50d94f8279a2a968a27d8483d55 (patch)
tree245b09ba888e895f8da46f90d1d8d25d04de66c5 /llvm/tools
parent17b9027b5c22dc6cde1a7c3c0ce20a830dfd8b67 (diff)
downloadbcm5719-llvm-d20cda028a11e50d94f8279a2a968a27d8483d55.tar.gz
bcm5719-llvm-d20cda028a11e50d94f8279a2a968a27d8483d55.zip
MC: When parsing a variable reference, substitute absolute variables immediately
since they are allowed to be redefined. llvm-svn: 84230
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-mc/AsmParser.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/tools/llvm-mc/AsmParser.cpp b/llvm/tools/llvm-mc/AsmParser.cpp
index aae27f5d764..7174fa8ee8e 100644
--- a/llvm/tools/llvm-mc/AsmParser.cpp
+++ b/llvm/tools/llvm-mc/AsmParser.cpp
@@ -21,6 +21,7 @@
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCValue.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetAsmParser.h"
@@ -220,12 +221,22 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) {
Res = MCUnaryExpr::CreateLNot(Res, getContext());
return false;
case AsmToken::String:
- case AsmToken::Identifier:
- // This is a label, this should be parsed as part of an expression, to
- // handle things like LFOO+4.
- Res = MCSymbolRefExpr::Create(Lexer.getTok().getIdentifier(), getContext());
+ case AsmToken::Identifier: {
+ // This is a symbol reference.
+ MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
Lexer.Lex(); // Eat identifier.
+
+ // If this is an absolute variable reference, substitute it now to preserve
+ // semantics in the face of reassignment.
+ if (Sym->getValue() && isa<MCConstantExpr>(Sym->getValue())) {
+ Res = Sym->getValue();
+ return false;
+ }
+
+ // Otherwise create a symbol ref.
+ Res = MCSymbolRefExpr::Create(Sym, getContext());
return false;
+ }
case AsmToken::Integer:
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
Lexer.Lex(); // Eat token.
OpenPOWER on IntegriCloud