diff options
Diffstat (limited to 'tools/llvm-mc/AsmParser.h')
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 162 |
1 files changed, 104 insertions, 58 deletions
diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index 333b284eac91..171dfcd4aa9b 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -14,89 +14,110 @@ #ifndef ASMPARSER_H #define ASMPARSER_H +#include <vector> #include "AsmLexer.h" +#include "AsmCond.h" +#include "llvm/MC/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 AsmExpr; +class AsmCond; class MCContext; +class MCExpr; class MCInst; class MCStreamer; +class MCAsmInfo; class MCValue; +class TargetAsmParser; +class Twine; -class AsmParser { -public: - struct X86Operand; - +class AsmParser : public MCAsmParser { private: AsmLexer Lexer; MCContext &Ctx; MCStreamer &Out; - + TargetAsmParser *TargetParser; + + 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 &OutStr) - : Lexer(SM), Ctx(ctx), Out(OutStr) {} - ~AsmParser() {} - + 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); + + virtual bool ParseExpression(const MCExpr *&Res); + virtual bool ParseParenExpression(const MCExpr *&Res); + 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(); - void Warning(SMLoc L, const char *Msg); - bool Error(SMLoc L, const char *Msg); bool TokError(const char *Msg); + bool ParseConditionalAssemblyDirectives(StringRef Directive, + SMLoc DirectiveLoc); void EatToEndOfStatement(); - bool ParseAssignment(const char *Name, bool IsDotSet); - - /// ParseExpression - Parse a general assembly expression. - /// - /// @param Res - The resulting expression. The pointer value is null on error. - /// @result - False on success. - bool ParseExpression(AsmExpr *&Res); - - /// ParseAbsoluteExpression - Parse an expression which must evaluate to an - /// absolute value. - /// - /// @param Res - The value of the absolute expression. The result is undefined - /// on error. - /// @result - False on success. - bool ParseAbsoluteExpression(int64_t &Res); - - /// ParseRelocatableExpression - Parse an expression which must be - /// relocatable. - /// - /// @param Res - The relocatable expression value. The result is undefined on - /// error. - /// @result - False on success. - bool ParseRelocatableExpression(MCValue &Res); - - /// ParseParenRelocatableExpression - Parse an expression which must be - /// relocatable, assuming that an initial '(' has already been consumed. - /// - /// @param Res - The relocatable expression value. The result is undefined on - /// error. - /// @result - False on success. - /// - /// @see ParseRelocatableExpression, ParseParenExpr. - bool ParseParenRelocatableExpression(MCValue &Res); - - bool ParsePrimaryExpr(AsmExpr *&Res); - bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res); - bool ParseParenExpr(AsmExpr *&Res); - - // X86 specific. - bool ParseX86InstOperands(const char *InstName, MCInst &Inst); - bool ParseX86Operand(X86Operand &Op); - bool ParseX86MemOperand(X86Operand &Op); - bool ParseX86Register(X86Operand &Op); + bool ParseAssignment(const StringRef &Name); + + bool ParsePrimaryExpr(const MCExpr *&Res); + bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res); + bool ParseParenExpr(const MCExpr *&Res); + + /// 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 *Section, - const char *Directives = 0); + 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" @@ -109,7 +130,32 @@ private: /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which /// accepts a single symbol (which should be a label or an external). bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr 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 |