MC: Improve expression parsing and implement evaluation of absolute expressions
[oota-llvm.git] / tools / llvm-mc / AsmParser.h
1 //===- 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
19 namespace llvm {
20 class AsmExpr;
21 class MCContext;
22 class MCInst;
23 class MCStreamer;
24   
25 class AsmParser {
26   AsmLexer Lexer;
27   MCContext &Ctx;
28   MCStreamer &Out;
29   
30   struct X86Operand;
31   
32 public:
33   AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
34     : Lexer(SM), Ctx(ctx), Out(OutStr) {}
35   ~AsmParser() {}
36   
37   bool Run();
38   
39 private:
40   bool ParseStatement();
41   
42   bool Error(SMLoc L, const char *Msg);
43   bool TokError(const char *Msg);
44   
45   void EatToEndOfStatement();
46   
47   bool ParseAssignment(const char *Name, bool IsDotSet);
48
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);
66   
67   // X86 specific.
68   bool ParseX86InstOperands(MCInst &Inst);
69   bool ParseX86Operand(X86Operand &Op);
70   bool ParseX86MemOperand(X86Operand &Op);
71   
72   // Directive Parsing.
73   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
74   bool ParseDirectiveSectionSwitch(const char *Section,
75                                    const char *Directives = 0);
76   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
77   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
78   bool ParseDirectiveFill(); // ".fill"
79   bool ParseDirectiveSpace(); // ".space"
80   bool ParseDirectiveSet(); // ".set"
81   bool ParseDirectiveOrg(); // ".org"
82   
83 };
84
85 } // end namespace llvm
86
87 #endif