mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-27 02:31:09 +00:00
llvm-mc: MCStreamer cleanups. - Remove EmitLocalSymbol, this is unsupported for now.
- Switch Emit{CommonSymbol,Zerofill} to take alignment in bytes (for consistency). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80484 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7a1e924b9a
commit
7092c7e1dc
@ -31,7 +31,7 @@ namespace llvm {
|
||||
/// MCStreamer - Streaming machine code generation interface. This interface
|
||||
/// is intended to provide a programatic interface that is very similar to the
|
||||
/// level that an assembler .s file provides. It has callbacks to emit bytes,
|
||||
/// "emit directives", etc. The implementation of this interface retains
|
||||
/// handle directives, etc. The implementation of this interface retains
|
||||
/// state to know what the current section is etc.
|
||||
///
|
||||
/// There are multiple implementations of this interface: one for writing out
|
||||
@ -73,6 +73,7 @@ namespace llvm {
|
||||
/// CurSection - This is the current section code is being emitted to, it is
|
||||
/// kept up to date by SwitchSection.
|
||||
const MCSection *CurSection;
|
||||
|
||||
public:
|
||||
virtual ~MCStreamer();
|
||||
|
||||
@ -80,17 +81,16 @@ namespace llvm {
|
||||
|
||||
/// @name Symbol & Section Management
|
||||
/// @{
|
||||
|
||||
/// getCurrentSection - Return the current seciton that the streamer is
|
||||
/// emitting code to.
|
||||
const MCSection *getCurrentSection() const { return CurSection; }
|
||||
|
||||
/// SwitchSection - Set the current section where code is being emitted to
|
||||
/// @param Section. This is required to update CurSection.
|
||||
///
|
||||
/// This corresponds to assembler directives like .section, .text, etc.
|
||||
virtual void SwitchSection(const MCSection *Section) = 0;
|
||||
|
||||
|
||||
/// getCurrentSection - Return the current seciton that the streamer is
|
||||
/// emitting code to.
|
||||
const MCSection *getCurrentSection() const { return CurSection; }
|
||||
|
||||
/// EmitLabel - Emit a label for @param Symbol into the current section.
|
||||
///
|
||||
@ -100,9 +100,6 @@ namespace llvm {
|
||||
/// @param Symbol - The symbol to emit. A given symbol should only be
|
||||
/// emitted as a label once, and symbols emitted as a label should never be
|
||||
/// used in an assignment.
|
||||
//
|
||||
// FIXME: What to do about the current section? Should we get rid of the
|
||||
// symbol section in the constructor and initialize it here?
|
||||
virtual void EmitLabel(MCSymbol *Symbol) = 0;
|
||||
|
||||
/// EmitAssemblerFlag - Note in the output the specified @param Flag
|
||||
@ -126,11 +123,6 @@ namespace llvm {
|
||||
bool MakeAbsolute = false) = 0;
|
||||
|
||||
/// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
|
||||
//
|
||||
// FIXME: This doesn't make much sense, could we just have attributes be on
|
||||
// the symbol and make the printer smart enough to add the right symbols?
|
||||
// This should work as long as the order of attributes in the file doesn't
|
||||
// matter.
|
||||
virtual void EmitSymbolAttribute(MCSymbol *Symbol,
|
||||
SymbolAttr Attribute) = 0;
|
||||
|
||||
@ -140,37 +132,30 @@ namespace llvm {
|
||||
/// @param DescValue - The value to set into the n_desc field.
|
||||
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
|
||||
|
||||
/// EmitLocalSymbol - Emit a local symbol of @param Value to @param Symbol.
|
||||
///
|
||||
/// @param Symbol - The local symbol being created.
|
||||
/// @param Value - The value for the symbol.
|
||||
virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) = 0;
|
||||
|
||||
/// EmitCommonSymbol - Emit a common or local common symbol of @param Size
|
||||
/// with the @param Pow2Alignment if non-zero.
|
||||
/// EmitCommonSymbol - Emit a common or local common symbol.
|
||||
///
|
||||
/// @param Symbol - The common symbol to emit.
|
||||
/// @param Size - The size of the common symbol.
|
||||
/// @param Pow2Alignment - The alignment of the common symbol if non-zero.
|
||||
/// @param ByteAlignment - The alignment of the symbol if
|
||||
/// non-zero. This must be a power of 2 on some targets.
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment) = 0;
|
||||
unsigned ByteAlignment) = 0;
|
||||
|
||||
/// EmitZerofill - Emit a the zerofill section and possiblity a symbol, if
|
||||
/// @param Symbol is non-NULL, for @param Size and with the @param
|
||||
/// Pow2Alignment if non-zero.
|
||||
/// EmitZerofill - Emit a the zerofill section and an option symbol.
|
||||
///
|
||||
/// @param Section - The zerofill section to create and or to put the symbol
|
||||
/// @param Symbol - The zerofill symbol to emit, if non-NULL.
|
||||
/// @param Size - The size of the zerofill symbol.
|
||||
/// @param Pow2Alignment - The alignment of the zerofill symbol if non-zero.
|
||||
/// @param ByteAlignment - The alignment of the zerofill symbol if
|
||||
/// non-zero. This must be a power of 2 on some targets.
|
||||
virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
|
||||
unsigned Size = 0,unsigned Pow2Alignment = 0) = 0;
|
||||
unsigned Size = 0,unsigned ByteAlignment = 0) = 0;
|
||||
|
||||
/// @}
|
||||
/// @name Generating Data
|
||||
/// @{
|
||||
|
||||
/// EmitBytes - Emit the bytes in @param Data into the output.
|
||||
/// EmitBytes - Emit the bytes in \arg Data into the output.
|
||||
///
|
||||
/// This is used to implement assembler directives such as .byte, .ascii,
|
||||
/// etc.
|
||||
|
@ -53,13 +53,11 @@ public:
|
||||
|
||||
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
|
||||
|
||||
virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value);
|
||||
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment);
|
||||
unsigned ByteAlignment);
|
||||
|
||||
virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
|
||||
unsigned Size = 0, unsigned Pow2Alignment = 0);
|
||||
unsigned Size = 0, unsigned ByteAlignment = 0);
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data);
|
||||
|
||||
@ -173,21 +171,17 @@ void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
|
||||
OS << ".desc" << ' ' << Symbol << ',' << DescValue << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) {
|
||||
OS << ".lsym" << ' ' << Symbol << ',' << Value << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment) {
|
||||
unsigned ByteAlignment) {
|
||||
OS << ".comm";
|
||||
OS << ' ' << Symbol << ',' << Size;
|
||||
if (Pow2Alignment != 0)
|
||||
OS << ',' << Pow2Alignment;
|
||||
if (ByteAlignment != 0)
|
||||
OS << ',' << Log2_32(ByteAlignment);
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
|
||||
unsigned Size, unsigned Pow2Alignment) {
|
||||
unsigned Size, unsigned ByteAlignment) {
|
||||
// Note: a .zerofill directive does not switch sections.
|
||||
OS << ".zerofill ";
|
||||
|
||||
@ -197,8 +191,8 @@ void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
|
||||
|
||||
if (Symbol != NULL) {
|
||||
OS << ',' << Symbol << ',' << Size;
|
||||
if (Pow2Alignment != 0)
|
||||
OS << ',' << Pow2Alignment;
|
||||
if (ByteAlignment != 0)
|
||||
OS << ',' << Log2_32(ByteAlignment);
|
||||
}
|
||||
OS << '\n';
|
||||
}
|
||||
|
@ -111,13 +111,11 @@ public:
|
||||
|
||||
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
|
||||
|
||||
virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value);
|
||||
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment);
|
||||
unsigned ByteAlignment);
|
||||
|
||||
virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
|
||||
unsigned Size = 0, unsigned Pow2Alignment = 0);
|
||||
unsigned Size = 0, unsigned ByteAlignment = 0);
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data);
|
||||
|
||||
@ -266,24 +264,18 @@ void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
|
||||
getSymbolData(*Symbol).setFlags(DescValue & SF_DescFlagsMask);
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) {
|
||||
// FIXME: Implement?
|
||||
llvm_report_error("unsupported '.lsym' directive");
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment) {
|
||||
unsigned ByteAlignment) {
|
||||
// FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
|
||||
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
|
||||
|
||||
MCSymbolData &SD = getSymbolData(*Symbol);
|
||||
SD.setExternal(true);
|
||||
SD.setCommon(Size, 1 << Pow2Alignment);
|
||||
SD.setCommon(Size, ByteAlignment);
|
||||
}
|
||||
|
||||
void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
|
||||
unsigned Size, unsigned Pow2Alignment) {
|
||||
unsigned ByteAlignment = 1 << Pow2Alignment;
|
||||
unsigned Size, unsigned ByteAlignment) {
|
||||
MCSectionData &SectData = getSectionData(*Section);
|
||||
|
||||
// The symbol may not be present, which only creates the section.
|
||||
@ -296,7 +288,7 @@ void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
|
||||
|
||||
MCSymbolData &SD = getSymbolData(*Symbol);
|
||||
|
||||
MCFragment *F = new MCZeroFillFragment(Size, 1 << Pow2Alignment, &SectData);
|
||||
MCFragment *F = new MCZeroFillFragment(Size, ByteAlignment, &SectData);
|
||||
SD.setFragment(F);
|
||||
|
||||
Symbol->setSection(*Section);
|
||||
|
@ -41,13 +41,11 @@ namespace {
|
||||
|
||||
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
|
||||
|
||||
virtual void EmitLocalSymbol(MCSymbol *Symbol, const MCValue &Value) {}
|
||||
|
||||
virtual void EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
|
||||
unsigned Pow2Alignment) {}
|
||||
unsigned ByteAlignment) {}
|
||||
|
||||
virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
|
||||
unsigned Size = 0, unsigned Pow2Alignment = 0) {}
|
||||
unsigned Size = 0, unsigned ByteAlignment = 0) {}
|
||||
|
||||
virtual void EmitBytes(const StringRef &Data) {}
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
|
||||
|
||||
# FIXME: This is currently unsupported. If it turns out no one uses it, we
|
||||
# should just rip it out.
|
||||
|
||||
# XFAIL: *
|
||||
|
||||
# CHECK: TEST0:
|
||||
# CHECK: .lsym bar,foo
|
||||
# CHECK: .lsym baz,3
|
||||
|
@ -1257,15 +1257,17 @@ bool AsmParser::ParseDirectiveComm(bool IsLocal) {
|
||||
if (!Sym->isUndefined())
|
||||
return Error(IDLoc, "invalid symbol redefinition");
|
||||
|
||||
// '.lcomm' is equivalent to '.zerofill'.
|
||||
// Create the Symbol as a common or local common with Size and Pow2Alignment
|
||||
if (IsLocal)
|
||||
if (IsLocal) {
|
||||
Out.EmitZerofill(getMachOSection("__DATA", "__bss",
|
||||
MCSectionMachO::S_ZEROFILL, 0,
|
||||
SectionKind()),
|
||||
Sym, Size, Pow2Alignment);
|
||||
else
|
||||
Out.EmitCommonSymbol(Sym, Size, Pow2Alignment);
|
||||
Sym, Size, 1 << Pow2Alignment);
|
||||
return false;
|
||||
}
|
||||
|
||||
Out.EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1355,7 +1357,7 @@ bool AsmParser::ParseDirectiveDarwinZerofill() {
|
||||
Out.EmitZerofill(getMachOSection(Segment, Section,
|
||||
MCSectionMachO::S_ZEROFILL, 0,
|
||||
SectionKind()),
|
||||
Sym, Size, Pow2Alignment);
|
||||
Sym, Size, 1 << Pow2Alignment);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1426,10 +1428,11 @@ bool AsmParser::ParseDirectiveDarwinLsym() {
|
||||
|
||||
Lexer.Lex();
|
||||
|
||||
// Create the Sym with the value of the Expr
|
||||
Out.EmitLocalSymbol(Sym, Expr);
|
||||
|
||||
return false;
|
||||
// We don't currently support this directive.
|
||||
//
|
||||
// FIXME: Diagnostic location!
|
||||
(void) Sym;
|
||||
return TokError("directive '.lsym' is unsupported");
|
||||
}
|
||||
|
||||
/// ParseDirectiveInclude
|
||||
|
Loading…
x
Reference in New Issue
Block a user