blob: 7a4c8322e5ca4769795f1b87cd8b4d1b487fdad5 [file] [log] [blame]
Chris Lattnerb0133452009-06-21 20:16:42 +00001//===- 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"
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000018#include "llvm/MC/MCAsmParser.h"
Daniel Dunbara5508c82009-06-30 00:33:19 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattnerb0133452009-06-21 20:16:42 +000020
21namespace llvm {
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000022class AsmExpr;
Chris Lattner3f5738d2009-06-24 04:31:49 +000023class MCContext;
Chris Lattner3417d712009-06-23 18:41:30 +000024class MCInst;
Chris Lattner92ffdd12009-06-24 00:52:40 +000025class MCStreamer;
Daniel Dunbarbd4bf3d2009-06-30 01:49:52 +000026class MCValue;
Daniel Dunbar2b11c7d2009-07-20 20:01:54 +000027class TargetAsmParser;
Daniel Dunbareb6bb322009-07-27 23:20:52 +000028class Twine;
Daniel Dunbarbd4bf3d2009-06-30 01:49:52 +000029
Daniel Dunbarf59ee962009-07-28 20:47:52 +000030class AsmParser : public MCAsmParser {
Daniel Dunbard0a08e02009-06-30 23:38:38 +000031private:
Chris Lattnerb0133452009-06-21 20:16:42 +000032 AsmLexer Lexer;
Chris Lattner3f5738d2009-06-24 04:31:49 +000033 MCContext &Ctx;
Chris Lattner92ffdd12009-06-24 00:52:40 +000034 MCStreamer &Out;
Daniel Dunbarf59ee962009-07-28 20:47:52 +000035 TargetAsmParser *TargetParser;
Chris Lattner92ffdd12009-06-24 00:52:40 +000036
Chris Lattnerb0133452009-06-21 20:16:42 +000037public:
Daniel Dunbarf59ee962009-07-28 20:47:52 +000038 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
39 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
Chris Lattnerb0133452009-06-21 20:16:42 +000040 ~AsmParser() {}
Daniel Dunbarf59ee962009-07-28 20:47:52 +000041
Chris Lattnerb0133452009-06-21 20:16:42 +000042 bool Run();
43
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000044public:
Daniel Dunbarf59ee962009-07-28 20:47:52 +000045 TargetAsmParser &getTargetParser() const { return *TargetParser; }
46 void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
Daniel Dunbar3c2a8932009-07-20 18:55:04 +000047
Daniel Dunbarc43267a2009-07-28 22:22:31 +000048 /// @name MCAsmParser Interface
49 /// {
50
Daniel Dunbar2b11c7d2009-07-20 20:01:54 +000051 virtual MCAsmLexer &getLexer() { return Lexer; }
52
Daniel Dunbarc43267a2009-07-28 22:22:31 +000053 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
Chris Lattner36e02122009-06-21 20:54:55 +000065private:
66 bool ParseStatement();
Daniel Dunbarc9dc78a2009-06-30 00:49:23 +000067
Chris Lattner2adc9e72009-06-21 21:22:11 +000068 bool TokError(const char *Msg);
Chris Lattnere5074c42009-06-22 01:29:09 +000069
70 void EatToEndOfStatement();
71
Daniel Dunbar52d03b22009-07-27 21:49:56 +000072 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000073
Daniel Dunbar9bff6532009-07-02 02:09:07 +000074 /// 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
Daniel Dunbar7e8d6c72009-06-29 20:37:27 +000084 bool ParsePrimaryExpr(AsmExpr *&Res);
85 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
86 bool ParseParenExpr(AsmExpr *&Res);
Daniel Dunbarc54ecb32009-08-01 00:48:30 +000087
88 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
89 /// and set \arg Res to the identifier contents.
90 bool ParseIdentifier(StringRef &Res);
Chris Lattner3417d712009-06-23 18:41:30 +000091
Chris Lattnerbedf6c22009-06-24 04:43:34 +000092 // Directive Parsing.
Chris Lattnerf7ebca42009-06-24 05:13:15 +000093 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
94 bool ParseDirectiveSectionSwitch(const char *Section,
95 const char *Directives = 0);
Daniel Dunbara10e5192009-06-24 23:30:00 +000096 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
97 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
98 bool ParseDirectiveFill(); // ".fill"
99 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbar2d2ee152009-06-25 21:56:11 +0000100 bool ParseDirectiveSet(); // ".set"
Daniel Dunbar4a5a5612009-06-25 22:44:51 +0000101 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbarcc566a712009-06-29 23:46:59 +0000102 // ".align{,32}", ".p2align{,w,l}"
103 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbara5508c82009-06-30 00:33:19 +0000104
105 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
106 /// accepts a single symbol (which should be a label or an external).
107 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Kevin Enderby4c21caa2009-07-14 18:17:10 +0000108 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
Kevin Enderbycbe475d2009-07-14 21:35:03 +0000109 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
Chris Lattnera1e11f52009-07-07 20:30:46 +0000110
Chris Lattner28ad7542009-07-09 17:25:12 +0000111 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
Chris Lattner07cadaf2009-07-10 22:20:30 +0000112 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
Kevin Enderbyc9d93ef2009-07-13 21:03:15 +0000113
114 // Darwin specific ".subsections_via_symbols"
115 bool ParseDirectiveDarwinSubsectionsViaSymbols();
Kevin Enderby09ea5702009-07-15 15:30:11 +0000116 // Darwin specific .dump and .load
Kevin Enderbyee551352009-07-20 20:25:37 +0000117 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
Kevin Enderby56523ce2009-07-13 23:15:14 +0000118
119 bool ParseDirectiveAbort(); // ".abort"
Kevin Enderbyd1ea5392009-07-14 23:21:55 +0000120 bool ParseDirectiveInclude(); // ".include"
Chris Lattnerb0133452009-06-21 20:16:42 +0000121};
122
123} // end namespace llvm
124
125#endif