summaryrefslogtreecommitdiffstats
path: root/include/llvm/MC
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/MC')
-rw-r--r--include/llvm/MC/MCAsmInfo.h124
-rw-r--r--include/llvm/MC/MCDirectives.h44
-rw-r--r--include/llvm/MC/MCExpr.h7
-rw-r--r--include/llvm/MC/MCParser/AsmCond.h40
-rw-r--r--include/llvm/MC/MCParser/AsmLexer.h72
-rw-r--r--include/llvm/MC/MCParser/AsmParser.h178
-rw-r--r--include/llvm/MC/MCParser/MCAsmLexer.h (renamed from include/llvm/MC/MCAsmLexer.h)33
-rw-r--r--include/llvm/MC/MCParser/MCAsmParser.h (renamed from include/llvm/MC/MCAsmParser.h)15
-rw-r--r--include/llvm/MC/MCParser/MCParsedAsmOperand.h (renamed from include/llvm/MC/MCParsedAsmOperand.h)0
-rw-r--r--include/llvm/MC/MCSectionELF.h5
-rw-r--r--include/llvm/MC/MCStreamer.h91
-rw-r--r--include/llvm/MC/MCSymbol.h17
-rw-r--r--include/llvm/MC/MCValue.h1
-rw-r--r--include/llvm/MC/SectionKind.h23
14 files changed, 530 insertions, 120 deletions
diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h
index fb69630..5e31dfe 100644
--- a/include/llvm/MC/MCAsmInfo.h
+++ b/include/llvm/MC/MCAsmInfo.h
@@ -16,9 +16,13 @@
#ifndef LLVM_TARGET_ASM_INFO_H
#define LLVM_TARGET_ASM_INFO_H
+#include "llvm/MC/MCDirectives.h"
#include <cassert>
namespace llvm {
+ class MCSection;
+ class MCContext;
+
/// MCAsmInfo - This class is intended to be used as a base class for asm
/// properties and features specific to the target.
namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
@@ -29,15 +33,20 @@ namespace llvm {
// Properties to be set by the target writer, used to configure asm printer.
//
- /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
- /// section on this target. Null if this target doesn't support zerofill.
- const char *ZeroFillDirective; // Default is null.
-
- /// NonexecutableStackDirective - Directive for declaring to the
- /// linker and beyond that the emitted code does not require stack
- /// memory to be executable.
- const char *NonexecutableStackDirective; // Default is null.
-
+ /// HasSubsectionsViaSymbols - True if this target has the MachO
+ /// .subsections_via_symbols directive.
+ bool HasSubsectionsViaSymbols; // Default is false.
+
+ /// HasMachoZeroFillDirective - True if this is a MachO target that supports
+ /// the macho-specific .zerofill directive for emitting BSS Symbols.
+ bool HasMachoZeroFillDirective; // Default is false.
+
+ /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
+ /// emit a ".reference .constructors_used" or ".reference .destructors_used"
+ /// directive after the a static ctor/dtor list. This directive is only
+ /// emitted in Static relocation model.
+ bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
+
/// NeedsSet - True if target asm treats expressions in data directives
/// as linktime-relocatable. For assembly-time computation, we need to
/// use a .set. Thus:
@@ -107,7 +116,6 @@ namespace llvm {
/// "\t.zero\t" and "\t.space\t". If this is set to null, the
/// Data*bitsDirective's will be used to emit zero bytes.
const char *ZeroDirective; // Defaults to "\t.zero\t"
- const char *ZeroDirectiveSuffix; // Defaults to ""
/// AsciiDirective - This directive allows emission of an ascii string with
/// the standard C escape characters embedded into it.
@@ -183,15 +191,10 @@ namespace llvm {
/// the assembler to set the value of a variable to some expression.
const char *SetDirective; // Defaults to null.
- /// LCOMMDirective - This is the name of a directive (if supported) that can
- /// be used to efficiently declare a local (internal) block of zero
- /// initialized data in the .bss/.data section. The syntax expected is:
- /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
- /// @endverbatim
- const char *LCOMMDirective; // Defaults to null.
+ /// HasLCOMMDirective - This is true if the target supports the .lcomm
+ /// directive.
+ bool HasLCOMMDirective; // Defaults to false.
- const char *COMMDirective; // Defaults to "\t.comm\t".
-
/// COMMDirectiveTakesAlignment - True if COMMDirective take a third
/// argument that specifies the alignment of the declaration.
bool COMMDirectiveTakesAlignment; // Defaults to true.
@@ -204,10 +207,9 @@ namespace llvm {
/// .file directive, this is true for ELF targets.
bool HasSingleParameterDotFile; // Defaults to true.
- /// UsedDirective - This directive, if non-null, is used to declare a global
- /// as being used somehow that the assembler can't see. This prevents dead
- /// code elimination on some targets.
- const char *UsedDirective; // Defaults to NULL.
+ /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
+ /// directive.
+ bool HasNoDeadStrip; // Defaults to false.
/// WeakRefDirective - This directive, if non-null, is used to declare a
/// global as being a weak undefined symbol.
@@ -216,14 +218,18 @@ namespace llvm {
/// WeakDefDirective - This directive, if non-null, is used to declare a
/// global as being a weak defined symbol.
const char *WeakDefDirective; // Defaults to NULL.
+
+ /// LinkOnceDirective - This directive, if non-null is used to declare a
+ /// global as being a weak defined symbol. This is used on cygwin/mingw.
+ const char *LinkOnceDirective; // Defaults to NULL.
- /// HiddenDirective - This directive, if non-null, is used to declare a
- /// global or function as having hidden visibility.
- const char *HiddenDirective; // Defaults to "\t.hidden\t".
+ /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
+ /// declare a symbol as having hidden visibility.
+ MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
- /// ProtectedDirective - This directive, if non-null, is used to declare a
- /// global or function as having protected visibility.
- const char *ProtectedDirective; // Defaults to "\t.protected\t".
+ /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
+ /// to declare a symbol as having protected visibility.
+ MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
//===--- Dwarf Emission Directives -----------------------------------===//
@@ -279,14 +285,12 @@ namespace llvm {
explicit MCAsmInfo();
virtual ~MCAsmInfo();
- /// getSLEB128Size - Compute the number of bytes required for a signed
- /// leb128 value.
+ // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
static unsigned getSLEB128Size(int Value);
-
- /// getULEB128Size - Compute the number of bytes required for an unsigned
- /// leb128 value.
static unsigned getULEB128Size(unsigned Value);
+ bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
+
// Data directive accessors.
//
const char *getData8bitsDirective(unsigned AS = 0) const {
@@ -302,6 +306,12 @@ namespace llvm {
return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
}
+ /// getNonexecutableStackSection - Targets can implement this method to
+ /// specify a section to switch to if the translation unit doesn't have any
+ /// trampolines that require an executable stack.
+ virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
+ return 0;
+ }
bool usesSunStyleELFSectionSwitchSyntax() const {
return SunStyleELFSectionSwitchSyntax;
@@ -313,11 +323,9 @@ namespace llvm {
// Accessors.
//
- const char *getZeroFillDirective() const {
- return ZeroFillDirective;
- }
- const char *getNonexecutableStackDirective() const {
- return NonexecutableStackDirective;
+ bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
+ bool hasStaticCtorDtorReferenceInStaticMode() const {
+ return HasStaticCtorDtorReferenceInStaticMode;
}
bool needsSet() const {
return NeedsSet;
@@ -364,9 +372,6 @@ namespace llvm {
const char *getZeroDirective() const {
return ZeroDirective;
}
- const char *getZeroDirectiveSuffix() const {
- return ZeroDirectiveSuffix;
- }
const char *getAsciiDirective() const {
return AsciiDirective;
}
@@ -394,35 +399,20 @@ namespace llvm {
const char *getSetDirective() const {
return SetDirective;
}
- const char *getLCOMMDirective() const {
- return LCOMMDirective;
- }
- const char *getCOMMDirective() const {
- return COMMDirective;
- }
+ bool hasLCOMMDirective() const { return HasLCOMMDirective; }
bool getCOMMDirectiveTakesAlignment() const {
return COMMDirectiveTakesAlignment;
}
- bool hasDotTypeDotSizeDirective() const {
- return HasDotTypeDotSizeDirective;
- }
- bool hasSingleParameterDotFile() const {
- return HasSingleParameterDotFile;
- }
- const char *getUsedDirective() const {
- return UsedDirective;
- }
- const char *getWeakRefDirective() const {
- return WeakRefDirective;
- }
- const char *getWeakDefDirective() const {
- return WeakDefDirective;
- }
- const char *getHiddenDirective() const {
- return HiddenDirective;
- }
- const char *getProtectedDirective() const {
- return ProtectedDirective;
+ bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
+ bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
+ bool hasNoDeadStrip() const { return HasNoDeadStrip; }
+ const char *getWeakRefDirective() const { return WeakRefDirective; }
+ const char *getWeakDefDirective() const { return WeakDefDirective; }
+ const char *getLinkOnceDirective() const { return LinkOnceDirective; }
+
+ MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
+ MCSymbolAttr getProtectedVisibilityAttr() const {
+ return ProtectedVisibilityAttr;
}
bool isAbsoluteDebugSectionOffsets() const {
return AbsoluteDebugSectionOffsets;
diff --git a/include/llvm/MC/MCDirectives.h b/include/llvm/MC/MCDirectives.h
new file mode 100644
index 0000000..57ce75d
--- /dev/null
+++ b/include/llvm/MC/MCDirectives.h
@@ -0,0 +1,44 @@
+//===- MCDirectives.h - Enums for directives on various targets -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines various enums that represent target-specific directives.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_MC_MCDIRECTIVES_H
+#define LLVM_MC_MCDIRECTIVES_H
+
+namespace llvm {
+
+enum MCSymbolAttr {
+ MCSA_Invalid = 0, /// Not a valid directive.
+
+ // Various directives in alphabetical order.
+ MCSA_Global, /// .globl
+ MCSA_Hidden, /// .hidden (ELF)
+ MCSA_IndirectSymbol, /// .indirect_symbol (MachO)
+ MCSA_Internal, /// .internal (ELF)
+ MCSA_LazyReference, /// .lazy_reference (MachO)
+ MCSA_Local, /// .local (ELF)
+ MCSA_NoDeadStrip, /// .no_dead_strip (MachO)
+ MCSA_PrivateExtern, /// .private_extern (MachO)
+ MCSA_Protected, /// .protected (ELF)
+ MCSA_Reference, /// .reference (MachO)
+ MCSA_Weak, /// .weak
+ MCSA_WeakDefinition, /// .weak_definition (MachO)
+ MCSA_WeakReference /// .weak_reference (MachO)
+};
+
+enum MCAssemblerFlag {
+ MCAF_SubsectionsViaSymbols /// .subsections_via_symbols (MachO)
+};
+
+} // end namespace llvm
+
+#endif
diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h
index 13d40ec..73d5f8e 100644
--- a/include/llvm/MC/MCExpr.h
+++ b/include/llvm/MC/MCExpr.h
@@ -51,7 +51,7 @@ public:
/// @name Utility Methods
/// @{
- void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
+ void print(raw_ostream &OS) const;
void dump() const;
/// @}
@@ -75,6 +75,11 @@ public:
static bool classof(const MCExpr *) { return true; }
};
+
+inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
+ E.print(OS);
+ return OS;
+}
//// MCConstantExpr - Represent a constant integer expression.
class MCConstantExpr : public MCExpr {
diff --git a/include/llvm/MC/MCParser/AsmCond.h b/include/llvm/MC/MCParser/AsmCond.h
new file mode 100644
index 0000000..92a115e
--- /dev/null
+++ b/include/llvm/MC/MCParser/AsmCond.h
@@ -0,0 +1,40 @@
+//===- AsmCond.h - Assembly file conditional assembly ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ASMCOND_H
+#define ASMCOND_H
+
+namespace llvm {
+
+/// AsmCond - Class to support conditional assembly
+///
+/// The conditional assembly feature (.if, .else, .elseif and .endif) is
+/// implemented with AsmCond that tells us what we are in the middle of
+/// processing. Ignore can be either true or false. When true we are ignoring
+/// the block of code in the middle of a conditional.
+
+class AsmCond {
+public:
+ enum ConditionalAssemblyType {
+ NoCond, // no conditional is being processed
+ IfCond, // inside if conditional
+ ElseIfCond, // inside elseif conditional
+ ElseCond // inside else conditional
+ };
+
+ ConditionalAssemblyType TheCond;
+ bool CondMet;
+ bool Ignore;
+
+ AsmCond() : TheCond(NoCond), CondMet(false), Ignore(false) {}
+};
+
+} // end namespace llvm
+
+#endif
diff --git a/include/llvm/MC/MCParser/AsmLexer.h b/include/llvm/MC/MCParser/AsmLexer.h
new file mode 100644
index 0000000..cf6eefb
--- /dev/null
+++ b/include/llvm/MC/MCParser/AsmLexer.h
@@ -0,0 +1,72 @@
+//===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class declares the lexer for assembly files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ASMLEXER_H
+#define ASMLEXER_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCParser/MCAsmLexer.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/System/DataTypes.h"
+#include <string>
+#include <cassert>
+
+namespace llvm {
+class MemoryBuffer;
+class SMLoc;
+class MCAsmInfo;
+
+/// AsmLexer - Lexer class for assembly files.
+class AsmLexer : public MCAsmLexer {
+ const MCAsmInfo &MAI;
+
+ const char *CurPtr;
+ const MemoryBuffer *CurBuf;
+
+ const char *TokStart;
+
+ void operator=(const AsmLexer&); // DO NOT IMPLEMENT
+ AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
+
+protected:
+ /// LexToken - Read the next token and return its code.
+ virtual AsmToken LexToken();
+
+public:
+ AsmLexer(const MCAsmInfo &MAI);
+ ~AsmLexer();
+
+ void setBuffer(const MemoryBuffer *buf, const char *ptr = NULL);
+
+ SMLoc getLoc() const;
+
+ StringRef LexUntilEndOfStatement();
+
+ bool isAtStartOfComment(char Char);
+
+ const MCAsmInfo &getMAI() const { return MAI; }
+
+private:
+ int getNextChar();
+ AsmToken ReturnError(const char *Loc, const std::string &Msg);
+
+ AsmToken LexIdentifier();
+ AsmToken LexSlash();
+ AsmToken LexLineComment();
+ AsmToken LexDigit();
+ AsmToken LexQuote();
+};
+
+} // end namespace llvm
+
+#endif
diff --git a/include/llvm/MC/MCParser/AsmParser.h b/include/llvm/MC/MCParser/AsmParser.h
new file mode 100644
index 0000000..f82584c
--- /dev/null
+++ b/include/llvm/MC/MCParser/AsmParser.h
@@ -0,0 +1,178 @@
+//===- AsmParser.h - Parser for Assembly Files ------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class declares the parser for assembly files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ASMPARSER_H
+#define ASMPARSER_H
+
+#include <vector>
+#include "llvm/MC/MCParser/AsmLexer.h"
+#include "llvm/MC/MCParser/AsmCond.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/MC/MCSectionMachO.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/ADT/StringMap.h"
+
+namespace llvm {
+class AsmCond;
+class AsmToken;
+class MCContext;
+class MCExpr;
+class MCInst;
+class MCStreamer;
+class MCAsmInfo;
+class MCValue;
+class SourceMgr;
+class TargetAsmParser;
+class Twine;
+
+class AsmParser : public MCAsmParser {
+private:
+ AsmLexer Lexer;
+ MCContext &Ctx;
+ MCStreamer &Out;
+ SourceMgr &SrcMgr;
+ TargetAsmParser *TargetParser;
+
+ /// This is the current buffer index we're lexing from as managed by the
+ /// SourceMgr object.
+ int CurBuffer;
+
+ AsmCond TheCondState;
+ std::vector<AsmCond> TheCondStack;
+
+ // FIXME: Figure out where this should leave, the code is a copy of that which
+ // is also used by TargetLoweringObjectFile.
+ mutable void *SectionUniquingMap;
+
+ /// DirectiveMap - This is a table handlers for directives. Each handler is
+ /// invoked after the directive identifier is read and is responsible for
+ /// parsing and validating the rest of the directive. The handler is passed
+ /// in the directive name and the location of the directive keyword.
+ StringMap<bool(AsmParser::*)(StringRef, SMLoc)> DirectiveMap;
+public:
+ AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
+ const MCAsmInfo &_MAI);
+ ~AsmParser();
+
+ bool Run();
+
+
+ void AddDirectiveHandler(StringRef Directive,
+ bool (AsmParser::*Handler)(StringRef, SMLoc)) {
+ DirectiveMap[Directive] = Handler;
+ }
+public:
+ TargetAsmParser &getTargetParser() const { return *TargetParser; }
+ void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
+
+ /// @name MCAsmParser Interface
+ /// {
+
+ virtual MCAsmLexer &getLexer() { return Lexer; }
+ virtual MCContext &getContext() { return Ctx; }
+ virtual MCStreamer &getStreamer() { return Out; }
+
+ virtual void Warning(SMLoc L, const Twine &Meg);
+ virtual bool Error(SMLoc L, const Twine &Msg);
+
+ const AsmToken &Lex();
+
+ bool ParseExpression(const MCExpr *&Res);
+ virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc);
+ virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
+ virtual bool ParseAbsoluteExpression(int64_t &Res);
+
+ /// }
+
+private:
+ MCSymbol *CreateSymbol(StringRef Name);
+
+ // FIXME: See comment on SectionUniquingMap.
+ const MCSection *getMachOSection(const StringRef &Segment,
+ const StringRef &Section,
+ unsigned TypeAndAttributes,
+ unsigned Reserved2,
+ SectionKind Kind) const;
+
+ bool ParseStatement();
+
+ bool TokError(const char *Msg);
+
+ void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
+
+ /// EnterIncludeFile - Enter the specified file. This returns true on failure.
+ bool EnterIncludeFile(const std::string &Filename);
+
+ bool ParseConditionalAssemblyDirectives(StringRef Directive,
+ SMLoc DirectiveLoc);
+ void EatToEndOfStatement();
+
+ bool ParseAssignment(const StringRef &Name);
+
+ bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
+ bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
+ bool ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc);
+
+ /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
+ /// and set \arg Res to the identifier contents.
+ bool ParseIdentifier(StringRef &Res);
+
+ // Directive Parsing.
+ bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
+ bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
+ unsigned TAA = 0, unsigned ImplicitAlign = 0,
+ unsigned StubSize = 0);
+ bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
+ bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
+ bool ParseDirectiveFill(); // ".fill"
+ bool ParseDirectiveSpace(); // ".space"
+ bool ParseDirectiveSet(); // ".set"
+ bool ParseDirectiveOrg(); // ".org"
+ // ".align{,32}", ".p2align{,w,l}"
+ bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
+
+ /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
+ /// accepts a single symbol (which should be a label or an external).
+ bool ParseDirectiveSymbolAttribute(MCSymbolAttr Attr);
+ bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
+ bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
+
+ bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
+ bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
+
+ // Darwin specific ".subsections_via_symbols"
+ bool ParseDirectiveDarwinSubsectionsViaSymbols();
+ // Darwin specific .dump and .load
+ bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
+
+ bool ParseDirectiveAbort(); // ".abort"
+ bool ParseDirectiveInclude(); // ".include"
+
+ bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
+ bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
+ bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
+ bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
+
+ bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); // ".file"
+ bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc); // ".line"
+ bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc"
+
+ /// ParseEscapedString - Parse the current token as a string which may include
+ /// escaped characters and return the string contents.
+ bool ParseEscapedString(std::string &Data);
+};
+
+} // end namespace llvm
+
+#endif
diff --git a/include/llvm/MC/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h
index e9a6e3f..043c363 100644
--- a/include/llvm/MC/MCAsmLexer.h
+++ b/include/llvm/MC/MCParser/MCAsmLexer.h
@@ -12,11 +12,11 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/System/DataTypes.h"
+#include "llvm/Support/SMLoc.h"
namespace llvm {
class MCAsmLexer;
class MCInst;
-class SMLoc;
class Target;
/// AsmToken - Target independent representation for an assembler token.
@@ -33,6 +33,9 @@ public:
// Integer values.
Integer,
+ // Register values (stored in IntVal). Only used by TargetAsmLexer.
+ Register,
+
// No-value.
EndOfStatement,
Colon,
@@ -96,6 +99,13 @@ public:
assert(Kind == Integer && "This token isn't an integer!");
return IntVal;
}
+
+ /// getRegVal - Get the register number for the current token, which should
+ /// be a register.
+ unsigned getRegVal() const {
+ assert(Kind == Register && "This token isn't a register!");
+ return static_cast<unsigned>(IntVal);
+ }
};
/// MCAsmLexer - Generic assembler lexer interface, for use by target specific
@@ -103,6 +113,10 @@ public:
class MCAsmLexer {
/// The current token, stored in the base class for faster access.
AsmToken CurTok;
+
+ /// The location and description of the current error
+ SMLoc ErrLoc;
+ std::string Err;
MCAsmLexer(const MCAsmLexer &); // DO NOT IMPLEMENT
void operator=(const MCAsmLexer &); // DO NOT IMPLEMENT
@@ -110,7 +124,12 @@ protected: // Can only create subclasses.
MCAsmLexer();
virtual AsmToken LexToken() = 0;
-
+
+ void SetError(const SMLoc &errLoc, const std::string &err) {
+ ErrLoc = errLoc;
+ Err = err;
+ }
+
public:
virtual ~MCAsmLexer();
@@ -126,6 +145,16 @@ public:
const AsmToken &getTok() {
return CurTok;
}
+
+ /// getErrLoc - Get the current error location
+ const SMLoc &getErrLoc() {
+ return ErrLoc;
+ }
+
+ /// getErr - Get the current error string
+ const std::string &getErr() {
+ return Err;
+ }
/// getKind - Get the kind of current token.
AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
diff --git a/include/llvm/MC/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h
index d530093..843c692 100644
--- a/include/llvm/MC/MCAsmParser.h
+++ b/include/llvm/MC/MCParser/MCAsmParser.h
@@ -13,6 +13,7 @@
#include "llvm/System/DataTypes.h"
namespace llvm {
+class AsmToken;
class MCAsmLexer;
class MCContext;
class MCExpr;
@@ -50,20 +51,28 @@ public:
/// clients.
virtual bool Error(SMLoc L, const Twine &Msg) = 0;
+ /// Lex - Get the next AsmToken in the stream, possibly handling file
+ /// inclusion first.
+ virtual const AsmToken &Lex() = 0;
+
+ /// getTok - Get the current AsmToken from the stream.
+ const AsmToken &getTok();
+
/// ParseExpression - Parse an arbitrary expression.
///
/// @param Res - The value of the expression. The result is undefined
/// on error.
/// @result - False on success.
- virtual bool ParseExpression(const MCExpr *&Res) = 0;
-
+ virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
+ bool ParseExpression(const MCExpr *&Res);
+
/// ParseParenExpression - Parse an arbitrary expression, assuming that an
/// initial '(' has already been consumed.
///
/// @param Res - The value of the expression. The result is undefined
/// on error.
/// @result - False on success.
- virtual bool ParseParenExpression(const MCExpr *&Res) = 0;
+ virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
/// ParseAbsoluteExpression - Parse an expression which must evaluate to an
/// absolute value.
diff --git a/include/llvm/MC/MCParsedAsmOperand.h b/include/llvm/MC/MCParser/MCParsedAsmOperand.h
index 7c2f5be..7c2f5be 100644
--- a/include/llvm/MC/MCParsedAsmOperand.h
+++ b/include/llvm/MC/MCParser/MCParsedAsmOperand.h
diff --git a/include/llvm/MC/MCSectionELF.h b/include/llvm/MC/MCSectionELF.h
index 4ec745f..2dccf5c 100644
--- a/include/llvm/MC/MCSectionELF.h
+++ b/include/llvm/MC/MCSectionELF.h
@@ -31,7 +31,7 @@ class MCSectionELF : public MCSection {
unsigned Flags;
/// IsExplicit - Indicates that this section comes from globals with an
- /// explicit section specfied.
+ /// explicit section specified.
bool IsExplicit;
protected:
@@ -47,8 +47,7 @@ public:
/// ShouldOmitSectionDirective - Decides whether a '.section' directive
/// should be printed before the section name
- bool ShouldOmitSectionDirective(const char *Name,
- const MCAsmInfo &MAI) const;
+ bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
/// ShouldPrintSectionType - Only prints the section type if supported
bool ShouldPrintSectionType(unsigned Ty) const;
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index 5febed7..2bcb594 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -15,6 +15,7 @@
#define LLVM_MC_MCSTREAMER_H
#include "llvm/System/DataTypes.h"
+#include "llvm/MC/MCDirectives.h"
namespace llvm {
class MCAsmInfo;
@@ -26,7 +27,9 @@ namespace llvm {
class MCSection;
class MCSymbol;
class StringRef;
+ class Twine;
class raw_ostream;
+ class formatted_raw_ostream;
/// MCStreamer - Streaming machine code generation interface. This interface
/// is intended to provide a programatic interface that is very similar to the
@@ -38,30 +41,6 @@ namespace llvm {
/// a .s file, and implementations that write out .o files of various formats.
///
class MCStreamer {
- public:
- enum SymbolAttr {
- Global, /// .globl
- Hidden, /// .hidden (ELF)
- IndirectSymbol, /// .indirect_symbol (Apple)
- Internal, /// .internal (ELF)
- LazyReference, /// .lazy_reference (Apple)
- NoDeadStrip, /// .no_dead_strip (Apple)
- PrivateExtern, /// .private_extern (Apple)
- Protected, /// .protected (ELF)
- Reference, /// .reference (Apple)
- Weak, /// .weak
- WeakDefinition, /// .weak_definition (Apple)
- WeakReference, /// .weak_reference (Apple)
-
- SymbolAttrFirst = Global,
- SymbolAttrLast = WeakReference
- };
-
- enum AssemblerFlag {
- SubsectionsViaSymbols /// .subsections_via_symbols (Apple)
- };
-
- private:
MCContext &Context;
MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
@@ -79,6 +58,28 @@ namespace llvm {
MCContext &getContext() const { return Context; }
+ /// @name Assembly File Formatting.
+ /// @{
+
+ /// AddComment - Add a comment that can be emitted to the generated .s
+ /// file if applicable as a QoI issue to make the output of the compiler
+ /// more readable. This only affects the MCAsmStreamer, and only when
+ /// verbose assembly output is enabled.
+ ///
+ /// If the comment includes embedded \n's, they will each get the comment
+ /// prefix as appropriate. The added comment should not end with a \n.
+ virtual void AddComment(const Twine &T) {}
+
+ /// GetCommentOS - Return a raw_ostream that comments can be written to.
+ /// Unlike AddComment, you are required to terminate comments with \n if you
+ /// use this method.
+ virtual raw_ostream &GetCommentOS();
+
+ /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
+ virtual void AddBlankLine() {}
+
+ /// @}
+
/// @name Symbol & Section Management
/// @{
@@ -103,7 +104,7 @@ namespace llvm {
virtual void EmitLabel(MCSymbol *Symbol) = 0;
/// EmitAssemblerFlag - Note in the output the specified @param Flag
- virtual void EmitAssemblerFlag(AssemblerFlag Flag) = 0;
+ virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) = 0;
/// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
///
@@ -120,7 +121,7 @@ namespace llvm {
/// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
virtual void EmitSymbolAttribute(MCSymbol *Symbol,
- SymbolAttr Attribute) = 0;
+ MCSymbolAttr Attribute) = 0;
/// EmitSymbolDesc - Set the @param DescValue for the @param Symbol.
///
@@ -128,15 +129,21 @@ namespace llvm {
/// @param DescValue - The value to set into the n_desc field.
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
- /// EmitCommonSymbol - Emit a common or local common symbol.
+ /// EmitCommonSymbol - Emit a common symbol.
///
/// @param Symbol - The common symbol to emit.
/// @param Size - The size of the common symbol.
/// @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,
+ /// non-zero. This must be a power of 2.
+ virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) = 0;
+ /// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
+ ///
+ /// @param Symbol - The common symbol to emit.
+ /// @param Size - The size of the common symbol.
+ virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) = 0;
+
/// EmitZerofill - Emit a the zerofill section and an option symbol.
///
/// @param Section - The zerofill section to create and or to put the symbol
@@ -155,7 +162,7 @@ namespace llvm {
///
/// This is used to implement assembler directives such as .byte, .ascii,
/// etc.
- virtual void EmitBytes(StringRef Data) = 0;
+ virtual void EmitBytes(StringRef Data, unsigned AddrSpace) = 0;
/// EmitValue - Emit the expression @param Value into the output as a native
/// integer of the given @param Size bytes.
@@ -166,8 +173,25 @@ namespace llvm {
/// @param Value - The value to emit.
/// @param Size - The size of the integer (in bytes) to emit. This must
/// match a native machine width.
- virtual void EmitValue(const MCExpr *Value, unsigned Size) = 0;
+ virtual void EmitValue(const MCExpr *Value, unsigned Size,
+ unsigned AddrSpace) = 0;
+ /// EmitIntValue - Special case of EmitValue that avoids the client having
+ /// to pass in a MCExpr for constant integers.
+ virtual void EmitIntValue(uint64_t Value, unsigned Size,unsigned AddrSpace);
+
+ /// EmitFill - Emit NumBytes bytes worth of the value specified by
+ /// FillValue. This implements directives such as '.space'.
+ virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
+ unsigned AddrSpace);
+
+ /// EmitZeros - Emit NumBytes worth of zeros. This is a convenience
+ /// function that just wraps EmitFill.
+ void EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
+ EmitFill(NumBytes, 0, AddrSpace);
+ }
+
+
/// EmitValueToAlignment - Emit some number of copies of @param Value until
/// the byte alignment @param ByteAlignment is reached.
///
@@ -217,8 +241,9 @@ namespace llvm {
/// createAsmStreamer - Create a machine code streamer which will print out
/// assembly for the native target, suitable for compiling with a native
/// assembler.
- MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS,
- const MCAsmInfo &MAI,
+ MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
+ const MCAsmInfo &MAI, bool isLittleEndian,
+ bool isVerboseAsm,
MCInstPrinter *InstPrint = 0,
MCCodeEmitter *CE = 0);
diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h
index eb59453..e770604 100644
--- a/include/llvm/MC/MCSymbol.h
+++ b/include/llvm/MC/MCSymbol.h
@@ -19,14 +19,14 @@
#include "llvm/System/DataTypes.h"
namespace llvm {
- class MCAsmInfo;
class MCExpr;
class MCSection;
class MCContext;
class raw_ostream;
/// MCSymbol - Instances of this class represent a symbol name in the MC file,
- /// and MCSymbols are created and unique'd by the MCContext class.
+ /// and MCSymbols are created and unique'd by the MCContext class. MCSymbols
+ /// should only be constructed with valid names for the object file.
///
/// If the symbol is defined/emitted into the current translation unit, the
/// Section member is set to indicate what section it lives in. Otherwise, if
@@ -53,7 +53,7 @@ namespace llvm {
/// typically does not survive in the .o file's symbol table. Usually
/// "Lfoo" or ".foo".
unsigned IsTemporary : 1;
-
+
private: // MCContext creates and uniques these.
friend class MCContext;
MCSymbol(StringRef _Name, bool _IsTemporary)
@@ -132,17 +132,16 @@ namespace llvm {
/// @}
/// print - Print the value to the stream \arg OS.
- void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
+ void print(raw_ostream &OS) const;
/// dump - Print the value to stderr.
void dump() const;
-
- /// printMangledName - Print the specified string in mangled form if it uses
- /// any unusual characters.
- static void printMangledName(StringRef Str, raw_ostream &OS,
- const MCAsmInfo *MAI);
};
+ inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
+ Sym.print(OS);
+ return OS;
+ }
} // end namespace llvm
#endif
diff --git a/include/llvm/MC/MCValue.h b/include/llvm/MC/MCValue.h
index 4f5ab31..8aa73f3 100644
--- a/include/llvm/MC/MCValue.h
+++ b/include/llvm/MC/MCValue.h
@@ -20,6 +20,7 @@
namespace llvm {
class MCSymbol;
+class MCAsmInfo;
class raw_ostream;
/// MCValue - This represents an "assembler immediate". In its most general
diff --git a/include/llvm/MC/SectionKind.h b/include/llvm/MC/SectionKind.h
index 945cff7..c9557f2 100644
--- a/include/llvm/MC/SectionKind.h
+++ b/include/llvm/MC/SectionKind.h
@@ -87,6 +87,18 @@ class SectionKind {
/// BSS - Zero initialized writeable data.
BSS,
+
+ /// BSSLocal - This is BSS (zero initialized and writable) data
+ /// which has local linkage.
+ BSSLocal,
+
+ /// BSSExtern - This is BSS data with normal external linkage.
+ BSSExtern,
+
+ /// Common - Data with common linkage. These represent tentative
+ /// definitions, which always have a zero initializer and are never
+ /// marked 'constant'.
+ Common,
/// DataRel - This is the most general form of data that is written
/// to by the program, it can have random relocations to arbitrary
@@ -158,10 +170,14 @@ public:
bool isThreadData() const { return K == ThreadData; }
bool isGlobalWriteableData() const {
- return isBSS() || isDataRel() || isReadOnlyWithRel();
+ return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
}
- bool isBSS() const { return K == BSS; }
+ bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
+ bool isBSSLocal() const { return K == BSSLocal; }
+ bool isBSSExtern() const { return K == BSSExtern; }
+
+ bool isCommon() const { return K == Common; }
bool isDataRel() const {
return K == DataRel || K == DataRelLocal || K == DataNoRel;
@@ -207,6 +223,9 @@ public:
static SectionKind getThreadBSS() { return get(ThreadBSS); }
static SectionKind getThreadData() { return get(ThreadData); }
static SectionKind getBSS() { return get(BSS); }
+ static SectionKind getBSSLocal() { return get(BSSLocal); }
+ static SectionKind getBSSExtern() { return get(BSSExtern); }
+ static SectionKind getCommon() { return get(Common); }
static SectionKind getDataRel() { return get(DataRel); }
static SectionKind getDataRelLocal() { return get(DataRelLocal); }
static SectionKind getDataNoRel() { return get(DataNoRel); }
OpenPOWER on IntegriCloud