llvm-mc: Implement .abort fully in the front end
[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/MCAsmParser.h"
19 #include "llvm/MC/MCStreamer.h"
20
21 namespace llvm {
22 class AsmExpr;
23 class MCContext;
24 class MCInst;
25 class MCStreamer;
26 class MCValue;
27 class TargetAsmParser;
28 class Twine;
29
30 class AsmParser : MCAsmParser {
31 public:
32   struct X86Operand;
33
34 private:  
35   AsmLexer Lexer;
36   MCContext &Ctx;
37   MCStreamer &Out;
38   TargetAsmParser &TargetParser;
39   
40 public:
41   AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, 
42             TargetAsmParser &_TargetParser)
43     : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
44   ~AsmParser() {}
45   
46   bool Run();
47   
48 public:
49   TargetAsmParser &getTargetParser() const { return TargetParser; }
50
51   virtual MCAsmLexer &getLexer() { return Lexer; }
52
53 private:
54   bool ParseStatement();
55
56   void Warning(SMLoc L, const Twine &Msg);
57   bool Error(SMLoc L, const Twine &Msg);
58   bool TokError(const char *Msg);
59   
60   void EatToEndOfStatement();
61   
62   bool ParseAssignment(const StringRef &Name, bool IsDotSet);
63
64   /// ParseExpression - Parse a general assembly expression.
65   ///
66   /// @param Res - The resulting expression. The pointer value is null on error.
67   /// @result - False on success.
68   bool ParseExpression(AsmExpr *&Res);
69
70   /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
71   /// absolute value.
72   ///
73   /// @param Res - The value of the absolute expression. The result is undefined
74   /// on error.
75   /// @result - False on success.
76   bool ParseAbsoluteExpression(int64_t &Res);
77
78   /// ParseRelocatableExpression - Parse an expression which must be
79   /// relocatable.
80   ///
81   /// @param Res - The relocatable expression value. The result is undefined on
82   /// error.  
83   /// @result - False on success.
84   bool ParseRelocatableExpression(MCValue &Res);
85
86   /// ParseParenRelocatableExpression - Parse an expression which must be
87   /// relocatable, assuming that an initial '(' has already been consumed.
88   ///
89   /// @param Res - The relocatable expression value. The result is undefined on
90   /// error.  
91   /// @result - False on success.
92   ///
93   /// @see ParseRelocatableExpression, ParseParenExpr.
94   bool ParseParenRelocatableExpression(MCValue &Res);
95
96   bool ParsePrimaryExpr(AsmExpr *&Res);
97   bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
98   bool ParseParenExpr(AsmExpr *&Res);
99   
100   // X86 specific.
101   bool ParseX86InstOperands(const StringRef &InstName, MCInst &Inst);
102   bool ParseX86Operand(X86Operand &Op);
103   bool ParseX86MemOperand(X86Operand &Op);
104   bool ParseX86Register(X86Operand &Op);
105   
106   // Directive Parsing.
107   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
108   bool ParseDirectiveSectionSwitch(const char *Section,
109                                    const char *Directives = 0);
110   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
111   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
112   bool ParseDirectiveFill(); // ".fill"
113   bool ParseDirectiveSpace(); // ".space"
114   bool ParseDirectiveSet(); // ".set"
115   bool ParseDirectiveOrg(); // ".org"
116   // ".align{,32}", ".p2align{,w,l}"
117   bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
118
119   /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
120   /// accepts a single symbol (which should be a label or an external).
121   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
122   bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
123   bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
124
125   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
126   bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
127
128   // Darwin specific ".subsections_via_symbols"
129   bool ParseDirectiveDarwinSubsectionsViaSymbols();
130   // Darwin specific .dump and .load
131   bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
132
133   bool ParseDirectiveAbort(); // ".abort"
134   bool ParseDirectiveInclude(); // ".include"
135 };
136
137 } // end namespace llvm
138
139 #endif