MC: When parsing a variable reference, substitute absolute variables immediately

since they are allowed to be redefined.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84230 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-10-16 01:34:54 +00:00
parent 7c3600de94
commit fffff915d5
4 changed files with 43 additions and 14 deletions

View File

@ -123,9 +123,12 @@ void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
OS << " = ";
Value->print(OS, &MAI);
OS << '\n';
// FIXME: Lift context changes into super class.
Symbol->setValue(Value);
}
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
SymbolAttr Attribute) {
switch (Attribute) {
case Global: OS << ".globl"; break;

View File

@ -12,21 +12,21 @@ a:
.long 0
.text
foo:
foo:
// CHECK: addl $24, a$b(%eax)
addl $24, "a$b"(%eax)
addl $24, "a$b"(%eax)
// CHECK: addl $24, a$b+10(%eax)
addl $24, ("a$b" + 10)(%eax)
// CHECK: b$c = 10
"b$c" = 10
// CHECK: addl $b$c, %eax
// CHECK: addl $10, %eax
addl "b$c", %eax
// CHECK: "a 0" = 11
.set "a 0", 11
// CHECK: .long "a 0"
// CHECK: .long 11
.long "a 0"
// XXCHCK: .section "a 1,a 2"
@ -48,12 +48,12 @@ foo:
.lcomm "a 7", 1
// FIXME: We don't bother to support .lsym.
// CHECX: .lsym "a 8",1
// .lsym "a 8", 1
// CHECK: "a 9" = a-b
.set "a 9", a - b
// CHECK: .long "a 9"
.long "a 9"

View File

@ -0,0 +1,15 @@
// RUN: llvm-mc %s
.data
t0_v0 = 1
t0_v1 = t0_v0
.if t0_v1 != 1
.abort "invalid value"
.endif
t1_v0 = 1
t1_v1 = t0_v0
t1_v0 = 2
.if t0_v1 != 1
.abort "invalid value"
.endif

View File

@ -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.