summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/MC/MCStreamer.h45
-rw-r--r--lib/MC/MCAsmStreamer.cpp22
-rw-r--r--lib/MC/MCMachOStreamer.cpp20
-rw-r--r--lib/MC/MCNullStreamer.cpp6
-rw-r--r--test/MC/AsmParser/directive_lsym.s5
-rw-r--r--tools/llvm-mc/AsmParser.cpp21
6 files changed, 48 insertions, 71 deletions
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index 626b34d609..8ca51219e1 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -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.
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp
index fa7c7cf09a..e5899fc899 100644
--- a/lib/MC/MCAsmStreamer.cpp
+++ b/lib/MC/MCAsmStreamer.cpp
@@ -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';
}
diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp
index 4ac0917bb0..41c82b3d42 100644
--- a/lib/MC/MCMachOStreamer.cpp
+++ b/lib/MC/MCMachOStreamer.cpp
@@ -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);
diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp
index fa2aec392d..d4ca3d922b 100644
--- a/lib/MC/MCNullStreamer.cpp
+++ b/lib/MC/MCNullStreamer.cpp
@@ -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) {}
diff --git a/test/MC/AsmParser/directive_lsym.s b/test/MC/AsmParser/directive_lsym.s
index 3d5403e975..7b70cac3d1 100644
--- a/test/MC/AsmParser/directive_lsym.s
+++ b/test/MC/AsmParser/directive_lsym.s
@@ -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
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp
index 74512ca935..032b25eeb6 100644
--- a/tools/llvm-mc/AsmParser.cpp
+++ b/tools/llvm-mc/AsmParser.cpp
@@ -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