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