blob: 8cd40eb4d4f1a3413cd5838b7b1fddf677e14bfd [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"
Daniel Dunbard7b267b2009-06-30 00:33:19 +000018#include "llvm/MC/MCStreamer.h"
Chris Lattner27aa7d22009-06-21 20:16:42 +000019
20namespace llvm {
Daniel Dunbar475839e2009-06-29 20:37:27 +000021class AsmExpr;
Chris Lattnerc69485e2009-06-24 04:31:49 +000022class MCContext;
Chris Lattner29dfe7c2009-06-23 18:41:30 +000023class MCInst;
Chris Lattnercbc23f72009-06-24 00:52:40 +000024class MCStreamer;
Chris Lattner2cf5f142009-06-22 01:29:09 +000025
Chris Lattner27aa7d22009-06-21 20:16:42 +000026class AsmParser {
27 AsmLexer Lexer;
Chris Lattnerc69485e2009-06-24 04:31:49 +000028 MCContext &Ctx;
Chris Lattnercbc23f72009-06-24 00:52:40 +000029 MCStreamer &Out;
30
Chris Lattner2cf5f142009-06-22 01:29:09 +000031 struct X86Operand;
Chris Lattner27aa7d22009-06-21 20:16:42 +000032
33public:
Chris Lattnerc69485e2009-06-24 04:31:49 +000034 AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
35 : Lexer(SM), Ctx(ctx), Out(OutStr) {}
Chris Lattner27aa7d22009-06-21 20:16:42 +000036 ~AsmParser() {}
37
38 bool Run();
39
Chris Lattnerb0789ed2009-06-21 20:54:55 +000040private:
41 bool ParseStatement();
Daniel Dunbar3fb76832009-06-30 00:49:23 +000042
43 void Warning(SMLoc L, const char *Msg);
Chris Lattner14ee48a2009-06-21 21:22:11 +000044 bool Error(SMLoc L, const char *Msg);
45 bool TokError(const char *Msg);
Chris Lattner2cf5f142009-06-22 01:29:09 +000046
47 void EatToEndOfStatement();
48
Daniel Dunbar8f780cd2009-06-25 21:56:11 +000049 bool ParseAssignment(const char *Name, bool IsDotSet);
Daniel Dunbar475839e2009-06-29 20:37:27 +000050
51 /// ParseExpression - Parse a general assembly expression.
52 ///
53 /// @param Res - The resulting expression. The pointer value is null on error.
54 /// @result - False on success.
55 bool ParseExpression(AsmExpr *&Res);
56
57 /// ParseAbsoluteExpr - Parse an expression which must evaluate to an absolute
58 /// value.
59 ///
60 /// @param Res - The value of the absolute expression. The result is undefined
61 /// on error.
62 /// @result - False on success.
63 bool ParseAbsoluteExpression(int64_t &Res);
64
65 bool ParsePrimaryExpr(AsmExpr *&Res);
66 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
67 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattner29dfe7c2009-06-23 18:41:30 +000068
69 // X86 specific.
70 bool ParseX86InstOperands(MCInst &Inst);
71 bool ParseX86Operand(X86Operand &Op);
72 bool ParseX86MemOperand(X86Operand &Op);
Chris Lattner9a023f72009-06-24 04:43:34 +000073
74 // Directive Parsing.
Chris Lattner529fb542009-06-24 05:13:15 +000075 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
76 bool ParseDirectiveSectionSwitch(const char *Section,
77 const char *Directives = 0);
Daniel Dunbara0d14262009-06-24 23:30:00 +000078 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
79 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
80 bool ParseDirectiveFill(); // ".fill"
81 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbar8f780cd2009-06-25 21:56:11 +000082 bool ParseDirectiveSet(); // ".set"
Daniel Dunbarc238b582009-06-25 22:44:51 +000083 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbarc29dfa72009-06-29 23:46:59 +000084 // ".align{,32}", ".p2align{,w,l}"
85 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbard7b267b2009-06-30 00:33:19 +000086
87 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
88 /// accepts a single symbol (which should be a label or an external).
89 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Chris Lattner9a023f72009-06-24 04:43:34 +000090
Chris Lattner27aa7d22009-06-21 20:16:42 +000091};
92
93} // end namespace llvm
94
95#endif