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 : MCAsmParser {
38 TargetAsmParser &TargetParser;
41 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
42 TargetAsmParser &_TargetParser)
43 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
49 TargetAsmParser &getTargetParser() const { return TargetParser; }
51 virtual MCAsmLexer &getLexer() { return Lexer; }
54 bool ParseStatement();
56 void Warning(SMLoc L, const Twine &Msg);
57 bool Error(SMLoc L, const Twine &Msg);
58 bool TokError(const char *Msg);
60 void EatToEndOfStatement();
62 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
64 /// ParseExpression - Parse a general assembly expression.
66 /// @param Res - The resulting expression. The pointer value is null on error.
67 /// @result - False on success.
68 bool ParseExpression(AsmExpr *&Res);
70 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
73 /// @param Res - The value of the absolute expression. The result is undefined
75 /// @result - False on success.
76 bool ParseAbsoluteExpression(int64_t &Res);
78 /// ParseRelocatableExpression - Parse an expression which must be
81 /// @param Res - The relocatable expression value. The result is undefined on
83 /// @result - False on success.
84 bool ParseRelocatableExpression(MCValue &Res);
86 /// ParseParenRelocatableExpression - Parse an expression which must be
87 /// relocatable, assuming that an initial '(' has already been consumed.
89 /// @param Res - The relocatable expression value. The result is undefined on
91 /// @result - False on success.
93 /// @see ParseRelocatableExpression, ParseParenExpr.
94 bool ParseParenRelocatableExpression(MCValue &Res);
96 bool ParsePrimaryExpr(AsmExpr *&Res);
97 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
98 bool ParseParenExpr(AsmExpr *&Res);
101 bool ParseX86InstOperands(const StringRef &InstName, MCInst &Inst);
102 bool ParseX86Operand(X86Operand &Op);
103 bool ParseX86MemOperand(X86Operand &Op);
104 bool ParseX86Register(X86Operand &Op);
106 // Directive Parsing.
107 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
108 bool ParseDirectiveSectionSwitch(const char *Section,
109 const char *Directives = 0);
110 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
111 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
112 bool ParseDirectiveFill(); // ".fill"
113 bool ParseDirectiveSpace(); // ".space"
114 bool ParseDirectiveSet(); // ".set"
115 bool ParseDirectiveOrg(); // ".org"
116 // ".align{,32}", ".p2align{,w,l}"
117 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
119 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
120 /// accepts a single symbol (which should be a label or an external).
121 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
122 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
123 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
125 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
126 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
128 // Darwin specific ".subsections_via_symbols"
129 bool ParseDirectiveDarwinSubsectionsViaSymbols();
130 // Darwin specific .dump and .load
131 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
133 bool ParseDirectiveAbort(); // ".abort"
134 bool ParseDirectiveInclude(); // ".include"
137 } // end namespace llvm