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/MCSectionMachO.h"
22 #include "llvm/MC/MCStreamer.h"
31 class TargetAsmParser;
34 class AsmParser : public MCAsmParser {
39 TargetAsmParser *TargetParser;
42 std::vector<AsmCond> TheCondStack;
44 // FIXME: Figure out where this should leave, the code is a copy of that which
45 // is also used by TargetLoweringObjectFile.
46 mutable void *SectionUniquingMap;
49 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
50 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0),
51 SectionUniquingMap(0) {}
57 TargetAsmParser &getTargetParser() const { return *TargetParser; }
58 void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
60 /// @name MCAsmParser Interface
63 virtual MCAsmLexer &getLexer() { return Lexer; }
65 virtual void Warning(SMLoc L, const Twine &Meg);
67 virtual bool Error(SMLoc L, const Twine &Msg);
69 virtual bool ParseExpression(const MCExpr *&Res);
71 virtual bool ParseAbsoluteExpression(int64_t &Res);
73 virtual bool ParseRelocatableExpression(MCValue &Res);
78 MCSymbol *CreateSymbol(StringRef Name);
80 // FIXME: See comment on SectionUniquingMap.
81 const MCSection *getMachOSection(const StringRef &Segment,
82 const StringRef &Section,
83 unsigned TypeAndAttributes,
85 SectionKind Kind) const;
87 bool ParseStatement();
89 bool TokError(const char *Msg);
91 bool ParseConditionalAssemblyDirectives(StringRef Directive,
93 void EatToEndOfStatement();
95 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
97 /// ParseParenRelocatableExpression - Parse an expression which must be
98 /// relocatable, assuming that an initial '(' has already been consumed.
100 /// @param Res - The relocatable expression value. The result is undefined on
102 /// @result - False on success.
104 /// @see ParseRelocatableExpression, ParseParenExpr.
105 bool ParseParenRelocatableExpression(MCValue &Res);
107 bool ParsePrimaryExpr(const MCExpr *&Res);
108 bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);
109 bool ParseParenExpr(const MCExpr *&Res);
111 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
112 /// and set \arg Res to the identifier contents.
113 bool ParseIdentifier(StringRef &Res);
115 // Directive Parsing.
116 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
117 bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
118 unsigned TAA = 0, unsigned ImplicitAlign = 0,
119 unsigned StubSize = 0);
120 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
121 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
122 bool ParseDirectiveFill(); // ".fill"
123 bool ParseDirectiveSpace(); // ".space"
124 bool ParseDirectiveSet(); // ".set"
125 bool ParseDirectiveOrg(); // ".org"
126 // ".align{,32}", ".p2align{,w,l}"
127 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
129 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
130 /// accepts a single symbol (which should be a label or an external).
131 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
132 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
133 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
135 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
136 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
138 // Darwin specific ".subsections_via_symbols"
139 bool ParseDirectiveDarwinSubsectionsViaSymbols();
140 // Darwin specific .dump and .load
141 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
143 bool ParseDirectiveAbort(); // ".abort"
144 bool ParseDirectiveInclude(); // ".include"
146 bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
147 bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
148 bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
149 bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
151 bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
152 bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
153 bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
155 /// ParseEscapedString - Parse the current token as a string which may include
156 /// escaped characters and return the string contents.
157 bool ParseEscapedString(std::string &Data);
160 } // end namespace llvm