1 //===- AsmParser.h - Parser for Assembly Files ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class declares the parser for assembly files.
12 //===----------------------------------------------------------------------===//
20 #include "llvm/MC/MCAsmParser.h"
21 #include "llvm/MC/MCStreamer.h"
30 class TargetAsmParser;
33 class AsmParser : public MCAsmParser {
38 TargetAsmParser *TargetParser;
41 std::vector<AsmCond> TheCondStack;
44 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
45 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
51 TargetAsmParser &getTargetParser() const { return *TargetParser; }
52 void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
54 /// @name MCAsmParser Interface
57 virtual MCAsmLexer &getLexer() { return Lexer; }
59 virtual void Warning(SMLoc L, const Twine &Meg);
61 virtual bool Error(SMLoc L, const Twine &Msg);
63 virtual bool ParseExpression(AsmExpr *&Res);
65 virtual bool ParseAbsoluteExpression(int64_t &Res);
67 virtual bool ParseRelocatableExpression(MCValue &Res);
72 bool ParseStatement();
74 bool TokError(const char *Msg);
76 bool ParseConditionalAssemblyDirectives(StringRef Directive,
78 void EatToEndOfStatement();
80 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
82 /// ParseParenRelocatableExpression - Parse an expression which must be
83 /// relocatable, assuming that an initial '(' has already been consumed.
85 /// @param Res - The relocatable expression value. The result is undefined on
87 /// @result - False on success.
89 /// @see ParseRelocatableExpression, ParseParenExpr.
90 bool ParseParenRelocatableExpression(MCValue &Res);
92 bool ParsePrimaryExpr(AsmExpr *&Res);
93 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
94 bool ParseParenExpr(AsmExpr *&Res);
96 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
97 /// and set \arg Res to the identifier contents.
98 bool ParseIdentifier(StringRef &Res);
100 // Directive Parsing.
101 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
102 bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
103 unsigned TAA, unsigned StubSize = 0);
104 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
105 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
106 bool ParseDirectiveFill(); // ".fill"
107 bool ParseDirectiveSpace(); // ".space"
108 bool ParseDirectiveSet(); // ".set"
109 bool ParseDirectiveOrg(); // ".org"
110 // ".align{,32}", ".p2align{,w,l}"
111 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
113 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
114 /// accepts a single symbol (which should be a label or an external).
115 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
116 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
117 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
119 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
120 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
122 // Darwin specific ".subsections_via_symbols"
123 bool ParseDirectiveDarwinSubsectionsViaSymbols();
124 // Darwin specific .dump and .load
125 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
127 bool ParseDirectiveAbort(); // ".abort"
128 bool ParseDirectiveInclude(); // ".include"
130 bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
131 bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
132 bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
133 bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
135 bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
136 bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
137 bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
139 /// ParseEscapedString - Parse the current token as a string which may include
140 /// escaped characters and return the string contents.
141 bool ParseEscapedString(std::string &Data);
144 } // end namespace llvm