mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
llvm-mc/Mach-O: Don't put assembler temporary labels in the symbol table.
- I moved section creation back into AsmParser. I think policy decisions like this should be pushed higher, not lower, when possible (in addition the assembler has flags which change this behavior, for example). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80162 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c33e696477
commit
959fd88334
@ -57,6 +57,8 @@ namespace llvm {
|
|||||||
/// reference and return it.
|
/// reference and return it.
|
||||||
///
|
///
|
||||||
/// @param Name - The symbol name, which must be unique across all symbols.
|
/// @param Name - The symbol name, which must be unique across all symbols.
|
||||||
|
/// @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);
|
MCSymbol *GetOrCreateSymbol(const StringRef &Name);
|
||||||
|
|
||||||
/// CreateTemporarySymbol - Create a new temporary symbol with the specified
|
/// CreateTemporarySymbol - Create a new temporary symbol with the specified
|
||||||
|
@ -63,6 +63,11 @@ namespace llvm {
|
|||||||
/// @name Symbol Type
|
/// @name Symbol Type
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/// isTemporary - Check if this is an assembler temporary symbol.
|
||||||
|
bool isTemporary() const {
|
||||||
|
return IsTemporary;
|
||||||
|
}
|
||||||
|
|
||||||
/// isDefined - Check if this symbol is defined (i.e., it has an address).
|
/// isDefined - Check if this symbol is defined (i.e., it has an address).
|
||||||
///
|
///
|
||||||
/// Defined symbols are either absolute or in some section.
|
/// Defined symbols are either absolute or in some section.
|
||||||
|
@ -557,6 +557,10 @@ public:
|
|||||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||||
MCSymbol &Symbol = it->getSymbol();
|
MCSymbol &Symbol = it->getSymbol();
|
||||||
|
|
||||||
|
// Ignore assembler temporaries.
|
||||||
|
if (it->getSymbol().isTemporary())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!it->isExternal() && !Symbol.isUndefined())
|
if (!it->isExternal() && !Symbol.isUndefined())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -589,6 +593,10 @@ public:
|
|||||||
ie = Asm.symbol_end(); it != ie; ++it) {
|
ie = Asm.symbol_end(); it != ie; ++it) {
|
||||||
MCSymbol &Symbol = it->getSymbol();
|
MCSymbol &Symbol = it->getSymbol();
|
||||||
|
|
||||||
|
// Ignore assembler temporaries.
|
||||||
|
if (it->getSymbol().isTemporary())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (it->isExternal() || Symbol.isUndefined())
|
if (it->isExternal() || Symbol.isUndefined())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
|
|||||||
return Entry = new (*this) MCSymbol(Name, false);
|
return Entry = new (*this) MCSymbol(Name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
|
MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
|
||||||
// If unnamed, just create a symbol.
|
// If unnamed, just create a symbol.
|
||||||
if (Name.empty())
|
if (Name.empty())
|
||||||
|
@ -13,8 +13,9 @@ sym_local_C:
|
|||||||
sym_globl_def_A:
|
sym_globl_def_A:
|
||||||
sym_globl_def_B:
|
sym_globl_def_B:
|
||||||
sym_globl_def_C:
|
sym_globl_def_C:
|
||||||
|
Lsym_asm_temp:
|
||||||
.long 0
|
.long 0
|
||||||
|
|
||||||
// CHECK: ('cputype', 7)
|
// CHECK: ('cputype', 7)
|
||||||
// CHECK: ('cpusubtype', 3)
|
// CHECK: ('cpusubtype', 3)
|
||||||
// CHECK: ('filetype', 1)
|
// CHECK: ('filetype', 1)
|
||||||
|
@ -129,6 +129,17 @@ bool AsmParser::ParseParenExpr(AsmExpr *&Res) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MCSymbol *AsmParser::CreateSymbol(StringRef Name) {
|
||||||
|
if (MCSymbol *S = Ctx.LookupSymbol(Name))
|
||||||
|
return S;
|
||||||
|
|
||||||
|
// If the label starts with L it is an assembler temporary label.
|
||||||
|
if (Name.startswith("L"))
|
||||||
|
return Ctx.CreateTemporarySymbol(Name);
|
||||||
|
|
||||||
|
return Ctx.CreateSymbol(Name);
|
||||||
|
}
|
||||||
|
|
||||||
/// ParsePrimaryExpr - Parse a primary expression and return it.
|
/// ParsePrimaryExpr - Parse a primary expression and return it.
|
||||||
/// primaryexpr ::= (parenexpr
|
/// primaryexpr ::= (parenexpr
|
||||||
/// primaryexpr ::= symbol
|
/// primaryexpr ::= symbol
|
||||||
@ -148,7 +159,7 @@ bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) {
|
|||||||
case AsmToken::Identifier: {
|
case AsmToken::Identifier: {
|
||||||
// This is a label, this should be parsed as part of an expression, to
|
// This is a label, this should be parsed as part of an expression, to
|
||||||
// handle things like LFOO+4.
|
// handle things like LFOO+4.
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getIdentifier());
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier());
|
||||||
|
|
||||||
Res = new AsmSymbolRefExpr(Sym);
|
Res = new AsmSymbolRefExpr(Sym);
|
||||||
Lexer.Lex(); // Eat identifier.
|
Lexer.Lex(); // Eat identifier.
|
||||||
@ -371,13 +382,11 @@ bool AsmParser::ParseStatement() {
|
|||||||
// FIXME: Diagnostics. Note the location of the definition as a label.
|
// FIXME: Diagnostics. Note the location of the definition as a label.
|
||||||
// FIXME: This doesn't diagnose assignment to a symbol which has been
|
// FIXME: This doesn't diagnose assignment to a symbol which has been
|
||||||
// implicitly marked as external.
|
// implicitly marked as external.
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(IDVal);
|
MCSymbol *Sym = CreateSymbol(IDVal);
|
||||||
if (!Sym->isUndefined())
|
if (!Sym->isUndefined())
|
||||||
return Error(IDLoc, "invalid symbol redefinition");
|
return Error(IDLoc, "invalid symbol redefinition");
|
||||||
|
|
||||||
// Since we saw a label, create a symbol and emit it.
|
// Emit the label.
|
||||||
// FIXME: If the label starts with L it is an assembler temporary label.
|
|
||||||
// Why does the client of this api need to know this?
|
|
||||||
Out.EmitLabel(Sym);
|
Out.EmitLabel(Sym);
|
||||||
|
|
||||||
return ParseStatement();
|
return ParseStatement();
|
||||||
@ -683,7 +692,7 @@ bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) {
|
|||||||
// FIXME: Diagnostics. Note the location of the definition as a label.
|
// FIXME: Diagnostics. Note the location of the definition as a label.
|
||||||
// FIXME: Handle '.'.
|
// FIXME: Handle '.'.
|
||||||
// FIXME: Diagnose assignment to protected identifier (e.g., register name).
|
// FIXME: Diagnose assignment to protected identifier (e.g., register name).
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
MCSymbol *Sym = CreateSymbol(Name);
|
||||||
if (!Sym->isUndefined() && !Sym->isAbsolute())
|
if (!Sym->isUndefined() && !Sym->isAbsolute())
|
||||||
return Error(EqualLoc, "symbol has already been defined");
|
return Error(EqualLoc, "symbol has already been defined");
|
||||||
|
|
||||||
@ -1110,7 +1119,7 @@ bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) {
|
|||||||
if (ParseIdentifier(Name))
|
if (ParseIdentifier(Name))
|
||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
MCSymbol *Sym = CreateSymbol(Name);
|
||||||
|
|
||||||
Out.EmitSymbolAttribute(Sym, Attr);
|
Out.EmitSymbolAttribute(Sym, Attr);
|
||||||
|
|
||||||
@ -1135,7 +1144,7 @@ bool AsmParser::ParseDirectiveDarwinSymbolDesc() {
|
|||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// Handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
MCSymbol *Sym = CreateSymbol(Name);
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.desc' directive");
|
return TokError("unexpected token in '.desc' directive");
|
||||||
@ -1166,7 +1175,7 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
|||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// Handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
MCSymbol *Sym = CreateSymbol(Name);
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in directive");
|
return TokError("unexpected token in directive");
|
||||||
@ -1258,7 +1267,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
|||||||
|
|
||||||
// handle the identifier as the key symbol.
|
// handle the identifier as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
SMLoc IDLoc = Lexer.getLoc();
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getTok().getString());
|
MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString());
|
||||||
Lexer.Lex();
|
Lexer.Lex();
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
@ -1363,7 +1372,7 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
|||||||
return TokError("expected identifier in directive");
|
return TokError("expected identifier in directive");
|
||||||
|
|
||||||
// Handle the identifier as the key symbol.
|
// Handle the identifier as the key symbol.
|
||||||
MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name);
|
MCSymbol *Sym = CreateSymbol(Name);
|
||||||
|
|
||||||
if (Lexer.isNot(AsmToken::Comma))
|
if (Lexer.isNot(AsmToken::Comma))
|
||||||
return TokError("unexpected token in '.lsym' directive");
|
return TokError("unexpected token in '.lsym' directive");
|
||||||
|
@ -69,6 +69,8 @@ public:
|
|||||||
/// }
|
/// }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
MCSymbol *CreateSymbol(StringRef Name);
|
||||||
|
|
||||||
bool ParseStatement();
|
bool ParseStatement();
|
||||||
|
|
||||||
bool TokError(const char *Msg);
|
bool TokError(const char *Msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user