blob: aa885e6399379fc7887bfa17fe1f7659ff82a70d [file] [log] [blame]
Chris Lattner27aa7d22009-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"
18
19namespace llvm {
Daniel Dunbar475839e2009-06-29 20:37:27 +000020class AsmExpr;
Chris Lattnerc69485e2009-06-24 04:31:49 +000021class MCContext;
Chris Lattner29dfe7c2009-06-23 18:41:30 +000022class MCInst;
Chris Lattnercbc23f72009-06-24 00:52:40 +000023class MCStreamer;
Chris Lattner2cf5f142009-06-22 01:29:09 +000024
Chris Lattner27aa7d22009-06-21 20:16:42 +000025class AsmParser {
26 AsmLexer Lexer;
Chris Lattnerc69485e2009-06-24 04:31:49 +000027 MCContext &Ctx;
Chris Lattnercbc23f72009-06-24 00:52:40 +000028 MCStreamer &Out;
29
Chris Lattner2cf5f142009-06-22 01:29:09 +000030 struct X86Operand;
Chris Lattner27aa7d22009-06-21 20:16:42 +000031
32public:
Chris Lattnerc69485e2009-06-24 04:31:49 +000033 AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
34 : Lexer(SM), Ctx(ctx), Out(OutStr) {}
Chris Lattner27aa7d22009-06-21 20:16:42 +000035 ~AsmParser() {}
36
37 bool Run();
38
Chris Lattnerb0789ed2009-06-21 20:54:55 +000039private:
40 bool ParseStatement();
41
Chris Lattner14ee48a2009-06-21 21:22:11 +000042 bool Error(SMLoc L, const char *Msg);
43 bool TokError(const char *Msg);
Chris Lattner2cf5f142009-06-22 01:29:09 +000044
45 void EatToEndOfStatement();
46
Daniel Dunbar8f780cd2009-06-25 21:56:11 +000047 bool ParseAssignment(const char *Name, bool IsDotSet);
Daniel Dunbar475839e2009-06-29 20:37:27 +000048
49 /// ParseExpression - Parse a general assembly expression.
50 ///
51 /// @param Res - The resulting expression. The pointer value is null on error.
52 /// @result - False on success.
53 bool ParseExpression(AsmExpr *&Res);
54
55 /// ParseAbsoluteExpr - Parse an expression which must evaluate to an absolute
56 /// value.
57 ///
58 /// @param Res - The value of the absolute expression. The result is undefined
59 /// on error.
60 /// @result - False on success.
61 bool ParseAbsoluteExpression(int64_t &Res);
62
63 bool ParsePrimaryExpr(AsmExpr *&Res);
64 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
65 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattner29dfe7c2009-06-23 18:41:30 +000066
67 // X86 specific.
68 bool ParseX86InstOperands(MCInst &Inst);
69 bool ParseX86Operand(X86Operand &Op);
70 bool ParseX86MemOperand(X86Operand &Op);
Chris Lattner9a023f72009-06-24 04:43:34 +000071
72 // Directive Parsing.
Chris Lattner529fb542009-06-24 05:13:15 +000073 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
74 bool ParseDirectiveSectionSwitch(const char *Section,
75 const char *Directives = 0);
Daniel Dunbara0d14262009-06-24 23:30:00 +000076 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
77 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
78 bool ParseDirectiveFill(); // ".fill"
79 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbar8f780cd2009-06-25 21:56:11 +000080 bool ParseDirectiveSet(); // ".set"
Daniel Dunbarc238b582009-06-25 22:44:51 +000081 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbarc29dfa72009-06-29 23:46:59 +000082 // ".align{,32}", ".p2align{,w,l}"
83 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Chris Lattner9a023f72009-06-24 04:43:34 +000084
Chris Lattner27aa7d22009-06-21 20:16:42 +000085};
86
87} // end namespace llvm
88
89#endif