Update CMakeLists
[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 : public MCAsmParser {
31 private:  
32   AsmLexer Lexer;
33   MCContext &Ctx;
34   MCStreamer &Out;
35   TargetAsmParser *TargetParser;
36   
37 public:
38   AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
39     : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
40   ~AsmParser() {}
41
42   bool Run();
43   
44 public:
45   TargetAsmParser &getTargetParser() const { return *TargetParser; }
46   void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
47
48   /// @name MCAsmParser Interface
49   /// {
50
51   virtual MCAsmLexer &getLexer() { return Lexer; }
52
53   virtual void Warning(SMLoc L, const Twine &Meg);
54
55   virtual bool Error(SMLoc L, const Twine &Msg);
56
57   virtual bool ParseExpression(AsmExpr *&Res);
58
59   virtual bool ParseAbsoluteExpression(int64_t &Res);
60
61   virtual bool ParseRelocatableExpression(MCValue &Res);
62
63   /// }
64
65 private:
66   bool ParseStatement();
67
68   bool TokError(const char *Msg);
69   
70   void EatToEndOfStatement();
71   
72   bool ParseAssignment(const StringRef &Name, bool IsDotSet);
73
74   /// ParseParenRelocatableExpression - Parse an expression which must be
75   /// relocatable, assuming that an initial '(' has already been consumed.
76   ///
77   /// @param Res - The relocatable expression value. The result is undefined on
78   /// error.  
79   /// @result - False on success.
80   ///
81   /// @see ParseRelocatableExpression, ParseParenExpr.
82   bool ParseParenRelocatableExpression(MCValue &Res);
83
84   bool ParsePrimaryExpr(AsmExpr *&Res);
85   bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
86   bool ParseParenExpr(AsmExpr *&Res);
87   
88   // Directive Parsing.
89   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
90   bool ParseDirectiveSectionSwitch(const char *Section,
91                                    const char *Directives = 0);
92   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
93   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
94   bool ParseDirectiveFill(); // ".fill"
95   bool ParseDirectiveSpace(); // ".space"
96   bool ParseDirectiveSet(); // ".set"
97   bool ParseDirectiveOrg(); // ".org"
98   // ".align{,32}", ".p2align{,w,l}"
99   bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
100
101   /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
102   /// accepts a single symbol (which should be a label or an external).
103   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
104   bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
105   bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
106
107   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
108   bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
109
110   // Darwin specific ".subsections_via_symbols"
111   bool ParseDirectiveDarwinSubsectionsViaSymbols();
112   // Darwin specific .dump and .load
113   bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
114
115   bool ParseDirectiveAbort(); // ".abort"
116   bool ParseDirectiveInclude(); // ".include"
117 };
118
119 } // end namespace llvm
120
121 #endif