llvm-mc: Evaluation for relocatable 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 #include "llvm/MC/MCStreamer.h"
19
20 namespace llvm {
21 class AsmExpr;
22 class MCContext;
23 class MCInst;
24 class MCStreamer;
25 class MCValue;
26
27 class AsmParser {
28   AsmLexer Lexer;
29   MCContext &Ctx;
30   MCStreamer &Out;
31   
32   struct X86Operand;
33   
34 public:
35   AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
36     : Lexer(SM), Ctx(ctx), Out(OutStr) {}
37   ~AsmParser() {}
38   
39   bool Run();
40   
41 private:
42   bool ParseStatement();
43
44   void Warning(SMLoc L, const char *Msg);
45   bool Error(SMLoc L, const char *Msg);
46   bool TokError(const char *Msg);
47   
48   void EatToEndOfStatement();
49   
50   bool ParseAssignment(const char *Name, bool IsDotSet);
51
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);
57
58   /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
59   /// absolute value.
60   ///
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
66   /// 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
74   bool ParsePrimaryExpr(AsmExpr *&Res);
75   bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
76   bool ParseParenExpr(AsmExpr *&Res);
77   
78   // X86 specific.
79   bool ParseX86InstOperands(MCInst &Inst);
80   bool ParseX86Operand(X86Operand &Op);
81   bool ParseX86MemOperand(X86Operand &Op);
82   
83   // Directive Parsing.
84   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
85   bool ParseDirectiveSectionSwitch(const char *Section,
86                                    const char *Directives = 0);
87   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
88   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
89   bool ParseDirectiveFill(); // ".fill"
90   bool ParseDirectiveSpace(); // ".space"
91   bool ParseDirectiveSet(); // ".set"
92   bool ParseDirectiveOrg(); // ".org"
93   // ".align{,32}", ".p2align{,w,l}"
94   bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
95
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);
99   
100 };
101
102 } // end namespace llvm
103
104 #endif