blob: 3a812c3e05d709b9b2ad70d9cab2c9c9ff0dcac9 [file] [log] [blame]
Chris Lattner3b4bfbd2009-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 Dunbar05111ab2009-06-30 00:33:19 +000018#include "llvm/MC/MCStreamer.h"
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000019
20namespace llvm {
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000021class AsmExpr;
Chris Lattnere462e4e2009-06-24 04:31:49 +000022class MCContext;
Chris Lattnere6c561b2009-06-23 18:41:30 +000023class MCInst;
Chris Lattner7a3716d2009-06-24 00:52:40 +000024class MCStreamer;
Daniel Dunbarc6c054e2009-06-30 01:49:52 +000025class MCValue;
26
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000027class AsmParser {
28 AsmLexer Lexer;
Chris Lattnere462e4e2009-06-24 04:31:49 +000029 MCContext &Ctx;
Chris Lattner7a3716d2009-06-24 00:52:40 +000030 MCStreamer &Out;
31
Chris Lattnere883aa62009-06-22 01:29:09 +000032 struct X86Operand;
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000033
34public:
Chris Lattnere462e4e2009-06-24 04:31:49 +000035 AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
36 : Lexer(SM), Ctx(ctx), Out(OutStr) {}
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000037 ~AsmParser() {}
38
39 bool Run();
40
Chris Lattnercfd2e3b2009-06-21 20:54:55 +000041private:
42 bool ParseStatement();
Daniel Dunbarb5aec992009-06-30 00:49:23 +000043
44 void Warning(SMLoc L, const char *Msg);
Chris Lattnerf6611852009-06-21 21:22:11 +000045 bool Error(SMLoc L, const char *Msg);
46 bool TokError(const char *Msg);
Chris Lattnere883aa62009-06-22 01:29:09 +000047
48 void EatToEndOfStatement();
49
Daniel Dunbarfca5d342009-06-25 21:56:11 +000050 bool ParseAssignment(const char *Name, bool IsDotSet);
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000051
52 /// ParseExpression - Parse a general assembly expression.
53 ///
54 /// @param Res - The resulting expression. The pointer value is null on error.
55 /// @result - False on success.
56 bool ParseExpression(AsmExpr *&Res);
Daniel Dunbarc6c054e2009-06-30 01:49:52 +000057
58 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
59 /// absolute value.
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000060 ///
61 /// @param Res - The value of the absolute expression. The result is undefined
62 /// on error.
63 /// @result - False on success.
64 bool ParseAbsoluteExpression(int64_t &Res);
65
Daniel Dunbarc6c054e2009-06-30 01:49:52 +000066 /// ParseRelocatableExpression - Parse an expression which must be
67 /// relocatable.
68 ///
69 /// @param Res - The relocatable expression value. The result is undefined on
70 /// error.
71 /// @result - False on success.
72 bool ParseRelocatableExpression(MCValue &Res);
73
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000074 bool ParsePrimaryExpr(AsmExpr *&Res);
75 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
76 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattnere6c561b2009-06-23 18:41:30 +000077
78 // X86 specific.
79 bool ParseX86InstOperands(MCInst &Inst);
80 bool ParseX86Operand(X86Operand &Op);
81 bool ParseX86MemOperand(X86Operand &Op);
Chris Lattnerec6cf312009-06-24 04:43:34 +000082
83 // Directive Parsing.
Chris Lattner4686d2f2009-06-24 05:13:15 +000084 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
85 bool ParseDirectiveSectionSwitch(const char *Section,
86 const char *Directives = 0);
Daniel Dunbara0527a92009-06-24 23:30:00 +000087 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
88 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
89 bool ParseDirectiveFill(); // ".fill"
90 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbarfca5d342009-06-25 21:56:11 +000091 bool ParseDirectiveSet(); // ".set"
Daniel Dunbar0a2a15c2009-06-25 22:44:51 +000092 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbar631e12c2009-06-29 23:46:59 +000093 // ".align{,32}", ".p2align{,w,l}"
94 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbar05111ab2009-06-30 00:33:19 +000095
96 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
97 /// accepts a single symbol (which should be a label or an external).
98 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Chris Lattnerec6cf312009-06-24 04:43:34 +000099
Chris Lattner3b4bfbd2009-06-21 20:16:42 +0000100};
101
102} // end namespace llvm
103
104#endif