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 //===----------------------------------------------------------------------===//
18 #include "llvm/MC/MCAsmParser.h"
19 #include "llvm/MC/MCStreamer.h"
27 class TargetAsmParser;
30 class AsmParser : public MCAsmParser {
35 TargetAsmParser *TargetParser;
38 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
39 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
45 TargetAsmParser &getTargetParser() const { return *TargetParser; }
46 void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
48 /// @name MCAsmParser Interface
51 virtual MCAsmLexer &getLexer() { return Lexer; }
53 virtual void Warning(SMLoc L, const Twine &Meg);
55 virtual bool Error(SMLoc L, const Twine &Msg);
57 virtual bool ParseExpression(AsmExpr *&Res);
59 virtual bool ParseAbsoluteExpression(int64_t &Res);
61 virtual bool ParseRelocatableExpression(MCValue &Res);
66 bool ParseStatement();
68 bool TokError(const char *Msg);
70 void EatToEndOfStatement();
72 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
74 /// ParseParenRelocatableExpression - Parse an expression which must be
75 /// relocatable, assuming that an initial '(' has already been consumed.
77 /// @param Res - The relocatable expression value. The result is undefined on
79 /// @result - False on success.
81 /// @see ParseRelocatableExpression, ParseParenExpr.
82 bool ParseParenRelocatableExpression(MCValue &Res);
84 bool ParsePrimaryExpr(AsmExpr *&Res);
85 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
86 bool ParseParenExpr(AsmExpr *&Res);
89 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
90 bool ParseDirectiveSectionSwitch(const char *Section,
91 const char *Directives = 0);
92 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
93 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
94 bool ParseDirectiveFill(); // ".fill"
95 bool ParseDirectiveSpace(); // ".space"
96 bool ParseDirectiveSet(); // ".set"
97 bool ParseDirectiveOrg(); // ".org"
98 // ".align{,32}", ".p2align{,w,l}"
99 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
101 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
102 /// accepts a single symbol (which should be a label or an external).
103 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
104 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
105 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
107 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
108 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
110 // Darwin specific ".subsections_via_symbols"
111 bool ParseDirectiveDarwinSubsectionsViaSymbols();
112 // Darwin specific .dump and .load
113 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
115 bool ParseDirectiveAbort(); // ".abort"
116 bool ParseDirectiveInclude(); // ".include"
119 } // end namespace llvm