blob: b99675850809c80eb79b06acd7686bf266b8d812 [file] [log] [blame]
Chris Lattnerb0133452009-06-21 20:16:42 +00001//===- AsmParser.h - Parser for Assembly Files ------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class declares the parser for assembly files.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef ASMPARSER_H
15#define ASMPARSER_H
16
17#include "AsmLexer.h"
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000018#include "llvm/MC/MCAsmParser.h"
Daniel Dunbara5508c82009-06-30 00:33:19 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattnerb0133452009-06-21 20:16:42 +000020
21namespace llvm {
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000022class AsmExpr;
Chris Lattner3f5738d2009-06-24 04:31:49 +000023class MCContext;
Chris Lattner3417d712009-06-23 18:41:30 +000024class MCInst;
Chris Lattner92ffdd12009-06-24 00:52:40 +000025class MCStreamer;
Daniel Dunbarbd4bf3d2009-06-30 01:49:52 +000026class MCValue;
27
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000028class AsmParser : MCAsmParser {
Daniel Dunbard0a08e02009-06-30 23:38:38 +000029public:
30 struct X86Operand;
31
32private:
Chris Lattnerb0133452009-06-21 20:16:42 +000033 AsmLexer Lexer;
Chris Lattner3f5738d2009-06-24 04:31:49 +000034 MCContext &Ctx;
Chris Lattner92ffdd12009-06-24 00:52:40 +000035 MCStreamer &Out;
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000036 TargetAsmParser &TargetParser;
Chris Lattner92ffdd12009-06-24 00:52:40 +000037
Chris Lattnerb0133452009-06-21 20:16:42 +000038public:
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000039 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
40 TargetAsmParser &_TargetParser)
41 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
Chris Lattnerb0133452009-06-21 20:16:42 +000042 ~AsmParser() {}
43
44 bool Run();
45
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000046public:
47 TargetAsmParser &getTargetParser() const { return TargetParser; }
48
Chris Lattner36e02122009-06-21 20:54:55 +000049private:
50 bool ParseStatement();
Daniel Dunbarc9dc78a2009-06-30 00:49:23 +000051
52 void Warning(SMLoc L, const char *Msg);
Chris Lattner2adc9e72009-06-21 21:22:11 +000053 bool Error(SMLoc L, const char *Msg);
54 bool TokError(const char *Msg);
Chris Lattnere5074c42009-06-22 01:29:09 +000055
56 void EatToEndOfStatement();
57
Daniel Dunbar2d2ee152009-06-25 21:56:11 +000058 bool ParseAssignment(const char *Name, bool IsDotSet);
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000059
60 /// ParseExpression - Parse a general assembly expression.
61 ///
62 /// @param Res - The resulting expression. The pointer value is null on error.
63 /// @result - False on success.
64 bool ParseExpression(AsmExpr *&Res);
Daniel Dunbarbd4bf3d2009-06-30 01:49:52 +000065
66 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
67 /// absolute value.
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000068 ///
69 /// @param Res - The value of the absolute expression. The result is undefined
70 /// on error.
71 /// @result - False on success.
72 bool ParseAbsoluteExpression(int64_t &Res);
73
Daniel Dunbarbd4bf3d2009-06-30 01:49:52 +000074 /// ParseRelocatableExpression - Parse an expression which must be
75 /// relocatable.
76 ///
77 /// @param Res - The relocatable expression value. The result is undefined on
78 /// error.
79 /// @result - False on success.
80 bool ParseRelocatableExpression(MCValue &Res);
81
Daniel Dunbar9bff6532009-07-02 02:09:07 +000082 /// ParseParenRelocatableExpression - Parse an expression which must be
83 /// relocatable, assuming that an initial '(' has already been consumed.
84 ///
85 /// @param Res - The relocatable expression value. The result is undefined on
86 /// error.
87 /// @result - False on success.
88 ///
89 /// @see ParseRelocatableExpression, ParseParenExpr.
90 bool ParseParenRelocatableExpression(MCValue &Res);
91
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000092 bool ParsePrimaryExpr(AsmExpr *&Res);
93 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
94 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattner3417d712009-06-23 18:41:30 +000095
96 // X86 specific.
Daniel Dunbard0a08e02009-06-30 23:38:38 +000097 bool ParseX86InstOperands(const char *InstName, MCInst &Inst);
Chris Lattner3417d712009-06-23 18:41:30 +000098 bool ParseX86Operand(X86Operand &Op);
99 bool ParseX86MemOperand(X86Operand &Op);
Daniel Dunbar36a20072009-07-02 01:58:24 +0000100 bool ParseX86Register(X86Operand &Op);
Chris Lattnerbedf6c22009-06-24 04:43:34 +0000101
102 // Directive Parsing.
Chris Lattnerf7ebca42009-06-24 05:13:15 +0000103 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
104 bool ParseDirectiveSectionSwitch(const char *Section,
105 const char *Directives = 0);
Daniel Dunbara10e5192009-06-24 23:30:00 +0000106 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
107 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
108 bool ParseDirectiveFill(); // ".fill"
109 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbar2d2ee152009-06-25 21:56:11 +0000110 bool ParseDirectiveSet(); // ".set"
Daniel Dunbar4a5a5612009-06-25 22:44:51 +0000111 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbarcc566a712009-06-29 23:46:59 +0000112 // ".align{,32}", ".p2align{,w,l}"
113 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbara5508c82009-06-30 00:33:19 +0000114
115 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
116 /// accepts a single symbol (which should be a label or an external).
117 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Kevin Enderby4c21caa2009-07-14 18:17:10 +0000118 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
Kevin Enderbycbe475d2009-07-14 21:35:03 +0000119 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
Chris Lattnera1e11f52009-07-07 20:30:46 +0000120
Chris Lattner28ad7542009-07-09 17:25:12 +0000121 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
Chris Lattner07cadaf2009-07-10 22:20:30 +0000122 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
Kevin Enderbyc9d93ef2009-07-13 21:03:15 +0000123
124 // Darwin specific ".subsections_via_symbols"
125 bool ParseDirectiveDarwinSubsectionsViaSymbols();
Kevin Enderby09ea5702009-07-15 15:30:11 +0000126 // Darwin specific .dump and .load
127 bool ParseDirectiveDarwinDumpOrLoad(bool IsDump);
Kevin Enderby56523ce2009-07-13 23:15:14 +0000128
129 bool ParseDirectiveAbort(); // ".abort"
Kevin Enderbyd1ea5392009-07-14 23:21:55 +0000130 bool ParseDirectiveInclude(); // ".include"
Chris Lattnerb0133452009-06-21 20:16:42 +0000131};
132
133} // end namespace llvm
134
135#endif