1 //===- AsmParser.h - Parser for Assembly Files ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class declares the parser for assembly files.
12 //===----------------------------------------------------------------------===//
20 #include "llvm/MC/MCAsmParser.h"
21 #include "llvm/MC/MCSectionMachO.h"
22 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/MC/MCAsmInfo.h"
33 class TargetAsmParser
;
36 class AsmParser
: public MCAsmParser
{
41 TargetAsmParser
*TargetParser
;
44 std::vector
<AsmCond
> TheCondStack
;
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
;
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) {}
60 TargetAsmParser
&getTargetParser() const { return *TargetParser
; }
61 void setTargetParser(TargetAsmParser
&P
) { TargetParser
= &P
; }
63 /// @name MCAsmParser Interface
66 virtual MCAsmLexer
&getLexer() { return Lexer
; }
68 virtual MCContext
&getContext() { return Ctx
; }
70 virtual MCStreamer
&getStreamer() { return Out
; }
72 virtual void Warning(SMLoc L
, const Twine
&Meg
);
74 virtual bool Error(SMLoc L
, const Twine
&Msg
);
76 virtual bool ParseExpression(const MCExpr
*&Res
);
78 virtual bool ParseParenExpression(const MCExpr
*&Res
);
80 virtual bool ParseAbsoluteExpression(int64_t &Res
);
85 MCSymbol
*CreateSymbol(StringRef Name
);
87 // FIXME: See comment on SectionUniquingMap.
88 const MCSection
*getMachOSection(const StringRef
&Segment
,
89 const StringRef
&Section
,
90 unsigned TypeAndAttributes
,
92 SectionKind Kind
) const;
94 bool ParseStatement();
96 bool TokError(const char *Msg
);
98 bool ParseConditionalAssemblyDirectives(StringRef Directive
,
100 void EatToEndOfStatement();
102 bool ParseAssignment(const StringRef
&Name
);
104 bool ParsePrimaryExpr(const MCExpr
*&Res
);
105 bool ParseBinOpRHS(unsigned Precedence
, const MCExpr
*&Res
);
106 bool ParseParenExpr(const MCExpr
*&Res
);
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
);
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
);
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"
132 bool ParseDirectiveComm(bool IsLocal
); // ".comm" and ".lcomm"
133 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
135 // Darwin specific ".subsections_via_symbols"
136 bool ParseDirectiveDarwinSubsectionsViaSymbols();
137 // Darwin specific .dump and .load
138 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc
, bool IsDump
);
140 bool ParseDirectiveAbort(); // ".abort"
141 bool ParseDirectiveInclude(); // ".include"
143 bool ParseDirectiveIf(SMLoc DirectiveLoc
); // ".if"
144 bool ParseDirectiveElseIf(SMLoc DirectiveLoc
); // ".elseif"
145 bool ParseDirectiveElse(SMLoc DirectiveLoc
); // ".else"
146 bool ParseDirectiveEndIf(SMLoc DirectiveLoc
); // .endif
148 bool ParseDirectiveFile(SMLoc DirectiveLoc
); // ".file"
149 bool ParseDirectiveLine(SMLoc DirectiveLoc
); // ".line"
150 bool ParseDirectiveLoc(SMLoc DirectiveLoc
); // ".loc"
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
);
157 } // end namespace llvm