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 MCContext &getContext() { return Ctx; }
67 virtual void Warning(SMLoc L, const Twine &Meg);
69 virtual bool Error(SMLoc L, const Twine &Msg);
71 virtual bool ParseExpression(const MCExpr *&Res);
73 virtual bool ParseParenExpression(const MCExpr *&Res);
75 virtual bool ParseAbsoluteExpression(int64_t &Res);
80 MCSymbol *CreateSymbol(StringRef Name);
82 // FIXME: See comment on SectionUniquingMap.
83 const MCSection *getMachOSection(const StringRef &Segment,
84 const StringRef &Section,
85 unsigned TypeAndAttributes,
87 SectionKind Kind) const;
89 bool ParseStatement();
91 bool TokError(const char *Msg);
93 bool ParseConditionalAssemblyDirectives(StringRef Directive,
95 void EatToEndOfStatement();
97 bool ParseAssignment(const StringRef &Name);
99 bool ParsePrimaryExpr(const MCExpr *&Res);
100 bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);
101 bool ParseParenExpr(const MCExpr *&Res);
103 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
104 /// and set \arg Res to the identifier contents.
105 bool ParseIdentifier(StringRef &Res);
107 // Directive Parsing.
108 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
109 bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
110 unsigned TAA = 0, unsigned ImplicitAlign = 0,
111 unsigned StubSize = 0);
112 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
113 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
114 bool ParseDirectiveFill(); // ".fill"
115 bool ParseDirectiveSpace(); // ".space"
116 bool ParseDirectiveSet(); // ".set"
117 bool ParseDirectiveOrg(); // ".org"
118 // ".align{,32}", ".p2align{,w,l}"
119 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
121 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
122 /// accepts a single symbol (which should be a label or an external).
123 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
124 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
125 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
127 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
128 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
130 // Darwin specific ".subsections_via_symbols"
131 bool ParseDirectiveDarwinSubsectionsViaSymbols();
132 // Darwin specific .dump and .load
133 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
135 bool ParseDirectiveAbort(); // ".abort"
136 bool ParseDirectiveInclude(); // ".include"
138 bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
139 bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
140 bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
141 bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
143 bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
144 bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
145 bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
147 /// ParseEscapedString - Parse the current token as a string which may include
148 /// escaped characters and return the string contents.
149 bool ParseEscapedString(std::string &Data);
152 } // end namespace llvm