avoid copying MCAsmInfo by value, add an (extremely low prio) fixme.
[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/MCSectionMachO.h"
22 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/MC/MCAsmInfo.h"
24
25 namespace llvm {
26 class AsmCond;
27 class MCContext;
28 class MCExpr;
29 class MCInst;
30 class MCStreamer;
31 class MCAsmInfo;
32 class MCValue;
33 class TargetAsmParser;
34 class Twine;
35
36 class AsmParser : public MCAsmParser {
37 private:  
38   AsmLexer Lexer;
39   MCContext &Ctx;
40   MCStreamer &Out;
41   TargetAsmParser *TargetParser;
42
43   AsmCond TheCondState;
44   std::vector<AsmCond> TheCondStack;
45
46   // FIXME: Figure out where this should leave, the code is a copy of that which
47   // is also used by TargetLoweringObjectFile.
48   mutable void *SectionUniquingMap;
49
50 public:
51   AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
52             const MCAsmInfo &_MAI)
53     : Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0),
54       SectionUniquingMap(0) {}
55   ~AsmParser();
56
57   bool Run();
58   
59 public:
60   TargetAsmParser &getTargetParser() const { return *TargetParser; }
61   void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
62
63   /// @name MCAsmParser Interface
64   /// {
65
66   virtual MCAsmLexer &getLexer() { return Lexer; }
67
68   virtual MCContext &getContext() { return Ctx; }
69
70   virtual MCStreamer &getStreamer() { return Out; }
71
72   virtual void Warning(SMLoc L, const Twine &Meg);
73
74   virtual bool Error(SMLoc L, const Twine &Msg);
75
76   virtual bool ParseExpression(const MCExpr *&Res);
77
78   virtual bool ParseParenExpression(const MCExpr *&Res);
79
80   virtual bool ParseAbsoluteExpression(int64_t &Res);
81
82   /// }
83
84 private:
85   MCSymbol *CreateSymbol(StringRef Name);
86
87   // FIXME: See comment on SectionUniquingMap.
88   const MCSection *getMachOSection(const StringRef &Segment,
89                                    const StringRef &Section,
90                                    unsigned TypeAndAttributes,
91                                    unsigned Reserved2,
92                                    SectionKind Kind) const;
93
94   bool ParseStatement();
95
96   bool TokError(const char *Msg);
97   
98   bool ParseConditionalAssemblyDirectives(StringRef Directive,
99                                           SMLoc DirectiveLoc);
100   void EatToEndOfStatement();
101   
102   bool ParseAssignment(const StringRef &Name);
103
104   bool ParsePrimaryExpr(const MCExpr *&Res);
105   bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);
106   bool ParseParenExpr(const MCExpr *&Res);
107
108   /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
109   /// and set \arg Res to the identifier contents.
110   bool ParseIdentifier(StringRef &Res);
111   
112   // Directive Parsing.
113   bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
114   bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
115                                    unsigned TAA = 0, unsigned ImplicitAlign = 0,
116                                    unsigned StubSize = 0);
117   bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
118   bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
119   bool ParseDirectiveFill(); // ".fill"
120   bool ParseDirectiveSpace(); // ".space"
121   bool ParseDirectiveSet(); // ".set"
122   bool ParseDirectiveOrg(); // ".org"
123   // ".align{,32}", ".p2align{,w,l}"
124   bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
125
126   /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
127   /// accepts a single symbol (which should be a label or an external).
128   bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
129   bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
130   bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
131
132   bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
133   bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
134
135   // Darwin specific ".subsections_via_symbols"
136   bool ParseDirectiveDarwinSubsectionsViaSymbols();
137   // Darwin specific .dump and .load
138   bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
139
140   bool ParseDirectiveAbort(); // ".abort"
141   bool ParseDirectiveInclude(); // ".include"
142
143   bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
144   bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
145   bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
146   bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
147
148   bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
149   bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
150   bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
151
152   /// ParseEscapedString - Parse the current token as a string which may include
153   /// escaped characters and return the string contents.
154   bool ParseEscapedString(std::string &Data);
155 };
156
157 } // end namespace llvm
158
159 #endif