add llvm-mc support for parsing the .lcomm directive, patch by Kevin Enderby!
[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 public:
29   struct X86Operand;
30
31 private:  
32   AsmLexer Lexer;
33   MCContext &Ctx;
34   MCStreamer &Out;
35   
36 public:
37   AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
38     : Lexer(SM), Ctx(ctx), Out(OutStr) {}
39   ~AsmParser() {}
40   
41   bool Run();
42   
43 private:
44   bool ParseStatement();
45
46   void Warning(SMLoc L, const char *Msg);
47   bool Error(SMLoc L, const char *Msg);
48   bool TokError(const char *Msg);
49   
50   void EatToEndOfStatement();
51   
52   bool ParseAssignment(const char *Name, bool IsDotSet);
53
54   /// ParseExpression - Parse a general assembly expression.
55   ///
56   /// @param Res - The resulting expression. The pointer value is null on error.
57   /// @result - False on success.
58   bool ParseExpression(AsmExpr *&Res);
59
60   /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
61   /// absolute value.
62   ///
63   /// @param Res - The value of the absolute expression. The result is undefined
64   /// on error.
65   /// @result - False on success.
66   bool ParseAbsoluteExpression(int64_t &Res);
67
68   /// ParseRelocatableExpression - Parse an expression which must be
69   /// relocatable.
70   ///
71   /// @param Res - The relocatable expression value. The result is undefined on
72   /// error.  
73   /// @result - False on success.
74   bool ParseRelocatableExpression(MCValue &Res);
75
76   /// ParseParenRelocatableExpression - Parse an expression which must be
77   /// relocatable, assuming that an initial '(' has already been consumed.
78   ///
79   /// @param Res - The relocatable expression value. The result is undefined on
80   /// error.  
81   /// @result - False on success.
82   ///
83   /// @see ParseRelocatableExpression, ParseParenExpr.
84   bool ParseParenRelocatableExpression(MCValue &Res);
85
86   bool ParsePrimaryExpr(AsmExpr *&Res);
87   bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
88   bool ParseParenExpr(AsmExpr *&Res);
89   
90   // X86 specific.
91   bool ParseX86InstOperands(const char *InstName, MCInst &Inst);
92   bool ParseX86Operand(X86Operand &Op);
93   bool ParseX86MemOperand(X86Operand &Op);
94   bool ParseX86Register(X86Operand &Op);
95   
96   // Directive Parsing.
97   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
98   bool ParseDirectiveSectionSwitch(const char *Section,
99                                    const char *Directives = 0);
100   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
101   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
102   bool ParseDirectiveFill(); // ".fill"
103   bool ParseDirectiveSpace(); // ".space"
104   bool ParseDirectiveSet(); // ".set"
105   bool ParseDirectiveOrg(); // ".org"
106   // ".align{,32}", ".p2align{,w,l}"
107   bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
108
109   /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
110   /// accepts a single symbol (which should be a label or an external).
111   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
112
113   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
114   
115 };
116
117 } // end namespace llvm
118
119 #endif