1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

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.

llvm-svn: 74057
This commit is contained in:
Chris Lattner 2009-06-24 04:31:49 +00:00
parent 38bf7cf4e2
commit 61a6509f6a
6 changed files with 34 additions and 5 deletions

View File

@ -56,6 +56,13 @@ namespace llvm {
/// @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.
///

View File

@ -84,8 +84,8 @@ void MCAsmStreamer::SwitchSection(MCSection *Section) {
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";
}

View File

@ -44,6 +44,20 @@ MCSymbol *MCContext::CreateSymbol(MCAtom *Atom, const char *Name) {
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')

View File

@ -185,6 +185,12 @@ bool AsmParser::ParseStatement() {
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();
}

View File

@ -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();

View File

@ -139,10 +139,9 @@ static int AssembleInput(const char *ProgName) {
// 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();
}