mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 00:24:26 +00:00
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:
@ -123,9 +123,12 @@ void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
|
|||||||
OS << " = ";
|
OS << " = ";
|
||||||
Value->print(OS, &MAI);
|
Value->print(OS, &MAI);
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
|
|
||||||
|
// FIXME: Lift context changes into super class.
|
||||||
|
Symbol->setValue(Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
|
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
|
||||||
SymbolAttr Attribute) {
|
SymbolAttr Attribute) {
|
||||||
switch (Attribute) {
|
switch (Attribute) {
|
||||||
case Global: OS << ".globl"; break;
|
case Global: OS << ".globl"; break;
|
||||||
|
@ -12,21 +12,21 @@ a:
|
|||||||
.long 0
|
.long 0
|
||||||
|
|
||||||
.text
|
.text
|
||||||
foo:
|
foo:
|
||||||
// CHECK: addl $24, a$b(%eax)
|
// CHECK: addl $24, a$b(%eax)
|
||||||
addl $24, "a$b"(%eax)
|
addl $24, "a$b"(%eax)
|
||||||
// CHECK: addl $24, a$b+10(%eax)
|
// CHECK: addl $24, a$b+10(%eax)
|
||||||
addl $24, ("a$b" + 10)(%eax)
|
addl $24, ("a$b" + 10)(%eax)
|
||||||
|
|
||||||
// CHECK: b$c = 10
|
// CHECK: b$c = 10
|
||||||
"b$c" = 10
|
"b$c" = 10
|
||||||
// CHECK: addl $b$c, %eax
|
// CHECK: addl $10, %eax
|
||||||
addl "b$c", %eax
|
addl "b$c", %eax
|
||||||
|
|
||||||
// CHECK: "a 0" = 11
|
// CHECK: "a 0" = 11
|
||||||
.set "a 0", 11
|
.set "a 0", 11
|
||||||
|
|
||||||
// CHECK: .long "a 0"
|
// CHECK: .long 11
|
||||||
.long "a 0"
|
.long "a 0"
|
||||||
|
|
||||||
// XXCHCK: .section "a 1,a 2"
|
// XXCHCK: .section "a 1,a 2"
|
||||||
@ -48,12 +48,12 @@ foo:
|
|||||||
.lcomm "a 7", 1
|
.lcomm "a 7", 1
|
||||||
|
|
||||||
// FIXME: We don't bother to support .lsym.
|
// FIXME: We don't bother to support .lsym.
|
||||||
|
|
||||||
// CHECX: .lsym "a 8",1
|
// CHECX: .lsym "a 8",1
|
||||||
// .lsym "a 8", 1
|
// .lsym "a 8", 1
|
||||||
|
|
||||||
// CHECK: "a 9" = a-b
|
// CHECK: "a 9" = a-b
|
||||||
.set "a 9", a - b
|
.set "a 9", a - b
|
||||||
|
|
||||||
// CHECK: .long "a 9"
|
// CHECK: .long "a 9"
|
||||||
.long "a 9"
|
.long "a 9"
|
||||||
|
15
test/MC/AsmParser/variables.s
Normal file
15
test/MC/AsmParser/variables.s
Normal 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
|
@ -21,6 +21,7 @@
|
|||||||
#include "llvm/MC/MCSectionMachO.h"
|
#include "llvm/MC/MCSectionMachO.h"
|
||||||
#include "llvm/MC/MCStreamer.h"
|
#include "llvm/MC/MCStreamer.h"
|
||||||
#include "llvm/MC/MCSymbol.h"
|
#include "llvm/MC/MCSymbol.h"
|
||||||
|
#include "llvm/MC/MCValue.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Target/TargetAsmParser.h"
|
#include "llvm/Target/TargetAsmParser.h"
|
||||||
@ -220,12 +221,22 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res) {
|
|||||||
Res = MCUnaryExpr::CreateLNot(Res, getContext());
|
Res = MCUnaryExpr::CreateLNot(Res, getContext());
|
||||||
return false;
|
return false;
|
||||||
case AsmToken::String:
|
case AsmToken::String:
|
||||||
case AsmToken::Identifier:
|
case AsmToken::Identifier: {
|
||||||
// This is a label, this should be parsed as part of an expression, to
|
// This is a symbol reference.
|
||||||
// handle things like LFOO+4.
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
||||||
Res = MCSymbolRefExpr::Create(Lexer.getTok().getIdentifier(), getContext());
|
|
||||||
Lexer.Lex(); // Eat identifier.
|
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;
|
return false;
|
||||||
|
}
|
||||||
case AsmToken::Integer:
|
case AsmToken::Integer:
|
||||||
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
|
Res = MCConstantExpr::Create(Lexer.getTok().getIntVal(), getContext());
|
||||||
Lexer.Lex(); // Eat token.
|
Lexer.Lex(); // Eat token.
|
||||||
|
Reference in New Issue
Block a user