[llvm-commits] [llvm] r74057 - in /llvm/trunk: include/llvm/MC/MCContext.h lib/MC/MCAsmStreamer.cpp lib/MC/MCContext.cpp tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h tools/llvm-mc/llvm-mc.cpp
Chris Lattner
sabre at nondot.org
Tue Jun 23 21:31:50 PDT 2009
Author: lattner
Date: Tue Jun 23 23:31:49 2009
New Revision: 74057
URL: http://llvm.org/viewvc/llvm-project?rev=74057&view=rev
Log:
add trivial support for passing label definitions through the MCStreamer.
This is suboptimal in several aspects, see the commented out assertion.
I need to talk to Daniel about this.
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/tools/llvm-mc/AsmParser.cpp
llvm/trunk/tools/llvm-mc/AsmParser.h
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Jun 23 23:31:49 2009
@@ -56,6 +56,13 @@
/// @param Name - The symbol name, which must be unique across all symbols.
MCSymbol *CreateSymbol(MCAtom *Atom, const char *Name);
+ /// GetOrCreateSymbol - Lookup the symbol inside with the specified
+ /// @param Name. If it exists, return it. If not, create a forward
+ /// reference and return it.
+ ///
+ /// @param Name - The symbol name, which must be unique across all symbols.
+ MCSymbol *GetOrCreateSymbol(const char *Name);
+
/// CreateTemporarySymbol - Create a new temporary symbol inside @param Atom
/// with the specified @param Name.
///
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Jun 23 23:31:49 2009
@@ -84,8 +84,8 @@
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
// FIXME: We need to enforce that we aren't printing atoms which are more
// complicated than the assembler understands.
- assert(Symbol->getAtom()->getSection() == CurSection &&
- "The label for a symbol must match its section!");
+ //assert(Symbol->getAtom()->getSection() == CurSection &&
+ // "The label for a symbol must match its section!");
OS << Symbol->getName() << ":\n";
}
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue Jun 23 23:31:49 2009
@@ -44,6 +44,20 @@
return Entry = new (*this) MCSymbol(Atom, Name, false);
}
+/// GetOrCreateSymbol - Lookup the symbol inside with the specified
+/// @param Name. If it exists, return it. If not, create a forward
+/// reference and return it.
+///
+/// @param Name - The symbol name, which must be unique across all symbols.
+MCSymbol *MCContext::GetOrCreateSymbol(const char *Name) {
+ MCSymbol *&Entry = Symbols[Name];
+ if (Entry) return Entry;
+
+ // FIXME: is a null atom the right way to make a forward ref?
+ return Entry = new (*this) MCSymbol(0, Name, false);
+}
+
+
MCSymbol *MCContext::CreateTemporarySymbol(MCAtom *Atom, const char *Name) {
// If unnamed, just create a symbol.
if (Name[0] == '\0')
Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jun 23 23:31:49 2009
@@ -185,6 +185,12 @@
if (Lexer.Lex() == asmtok::Colon) {
// identifier ':' -> Label.
Lexer.Lex();
+
+ // Since we saw a label, create a symbol and emit it.
+ // 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(Ctx.GetOrCreateSymbol(IDVal));
+
return ParseStatement();
}
Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jun 23 23:31:49 2009
@@ -17,17 +17,20 @@
#include "AsmLexer.h"
namespace llvm {
+class MCContext;
class MCInst;
class MCStreamer;
class AsmParser {
AsmLexer Lexer;
+ MCContext &Ctx;
MCStreamer &Out;
struct X86Operand;
public:
- AsmParser(SourceMgr &SM, MCStreamer &OutStr) : Lexer(SM), Out(OutStr) {}
+ AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
+ : Lexer(SM), Ctx(ctx), Out(OutStr) {}
~AsmParser() {}
bool Run();
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=74057&r1=74056&r2=74057&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Jun 23 23:31:49 2009
@@ -139,10 +139,9 @@
// it later.
SrcMgr.setIncludeDirs(IncludeDirs);
- // FIXME: don't leak streamer, own.
MCContext Ctx;
OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, outs()));
- AsmParser Parser(SrcMgr, *Str.get());
+ AsmParser Parser(SrcMgr, Ctx, *Str.get());
return Parser.Run();
}
More information about the llvm-commits
mailing list