llvm-mc: Simplify EmitAssignment ('.set' is identical to '=').

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80577 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-08-31 08:09:09 +00:00
parent 883f920acb
commit e2ace509fc
9 changed files with 18 additions and 41 deletions

View File

@ -116,11 +116,7 @@ namespace llvm {
///
/// @param Symbol - The symbol being assigned to.
/// @param Value - The value for the symbol.
/// @param MakeAbsolute - If true, then the symbol should be given the
/// absolute value of @param Value, even if @param Value would be
/// relocatable expression. This corresponds to the ".set" directive.
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
bool MakeAbsolute = false) = 0;
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value) = 0;
/// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
virtual void EmitSymbolAttribute(MCSymbol *Symbol,

View File

@ -47,8 +47,7 @@ public:
virtual void EmitAssemblerFlag(AssemblerFlag Flag);
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
bool MakeAbsolute = false);
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value);
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
@ -126,26 +125,12 @@ void MCAsmStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
OS << '\n';
}
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
bool MakeAbsolute) {
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {
// Only absolute symbols can be redefined.
assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
"Cannot define a symbol twice!");
if (MakeAbsolute) {
OS << ".set " << Symbol << ", " << Value << '\n';
// HACK: If the value isn't already absolute, set the symbol value to
// itself, we want to use the .set absolute value, not the actual
// expression.
if (!Value.isAbsolute())
getContext().SetSymbolValue(Symbol, MCValue::get(Symbol));
else
getContext().SetSymbolValue(Symbol, Value);
} else {
OS << Symbol << " = " << Value << '\n';
getContext().SetSymbolValue(Symbol, Value);
}
OS << Symbol << " = " << Value << '\n';
}
void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,

View File

@ -129,8 +129,7 @@ public:
virtual void EmitAssemblerFlag(AssemblerFlag Flag);
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
bool MakeAbsolute = false);
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value);
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute);
@ -201,9 +200,7 @@ void MCMachOStreamer::EmitAssemblerFlag(AssemblerFlag Flag) {
assert(0 && "invalid assembler flag!");
}
void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol,
const MCValue &Value,
bool MakeAbsolute) {
void MCMachOStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {
// Only absolute symbols can be redefined.
assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
"Cannot define a symbol twice!");

View File

@ -34,8 +34,7 @@ namespace {
virtual void EmitAssemblerFlag(AssemblerFlag Flag) {}
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
bool MakeAbsolute = false) {}
virtual void EmitAssignment(MCSymbol *Symbol, const MCValue &Value) {}
virtual void EmitSymbolAttribute(MCSymbol *Symbol, SymbolAttr Attribute) {}

View File

@ -2,7 +2,7 @@
# CHECK: TESTA:
# CHECK: TEST0:
# CHECK: .set a, 0
# CHECK: a = 0
# CHECK: TESTB:
TESTA:
.include "directive_set.s"

View File

@ -1,7 +1,7 @@
# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
# CHECK: TEST0:
# CHECK: .set a, 0
# CHECK: a = 0
TEST0:
.set a, 0

View File

@ -23,10 +23,10 @@ foo:
// CHECK: addl $"b$c", %eax
addl "b$c", %eax
// CHECK: set "a 0", 11
// CHECK: "a 0" = 11
.set "a 0", 11
// CHECK: .long 11
// CHECK: .long "a 0"
.long "a 0"
// XXCHCK: .section "a 1,a 2"
@ -44,7 +44,7 @@ foo:
// CHECK: .comm "a 6",1
.comm "a 6", 1
// CHECK: .zerofill __DATA,__bss,"a 7",1
// CHECK: .zerofill __DATA,__bss,"a 7",1,0
.lcomm "a 7", 1
// FIXME: We don't bother to support .lsym.
@ -52,7 +52,7 @@ foo:
// CHECX: .lsym "a 8",1
// .lsym "a 8", 1
// CHECK: set "a 9", a - b
// CHECK: "a 9" = a - b
.set "a 9", a - b
// CHECK: .long "a 9"

View File

@ -431,7 +431,7 @@ bool AsmParser::ParseStatement() {
// identifier '=' ... -> assignment statement
Lexer.Lex();
return ParseAssignment(IDVal, false);
return ParseAssignment(IDVal);
default: // Normal instruction or directive.
break;
@ -708,7 +708,7 @@ bool AsmParser::ParseStatement() {
return false;
}
bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) {
bool AsmParser::ParseAssignment(const StringRef &Name) {
// FIXME: Use better location, we should use proper tokens.
SMLoc EqualLoc = Lexer.getLoc();
@ -737,7 +737,7 @@ bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) {
return Error(EqualLoc, "symbol has already been defined");
// Do the assignment.
Out.EmitAssignment(Sym, Value, IsDotSet);
Out.EmitAssignment(Sym, Value);
return false;
}
@ -769,7 +769,7 @@ bool AsmParser::ParseDirectiveSet() {
return TokError("unexpected token in '.set'");
Lexer.Lex();
return ParseAssignment(Name, true);
return ParseAssignment(Name);
}
/// ParseDirectiveSection:

View File

@ -94,7 +94,7 @@ private:
SMLoc DirectiveLoc);
void EatToEndOfStatement();
bool ParseAssignment(const StringRef &Name, bool IsDotSet);
bool ParseAssignment(const StringRef &Name);
bool ParsePrimaryExpr(const MCExpr *&Res);
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);