blob: e59e85ceb57e61ce88848e98b0550f42392f6ef1 [file] [log] [blame]
Chris Lattner3b4bfbd2009-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 Dunbar4b0f4ef2009-07-20 18:55:04 +000018#include "llvm/MC/MCAsmParser.h"
Daniel Dunbar05111ab2009-06-30 00:33:19 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000020
21namespace llvm {
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000022class AsmExpr;
Chris Lattnere462e4e2009-06-24 04:31:49 +000023class MCContext;
Chris Lattnere6c561b2009-06-23 18:41:30 +000024class MCInst;
Chris Lattner7a3716d2009-06-24 00:52:40 +000025class MCStreamer;
Daniel Dunbarc6c054e2009-06-30 01:49:52 +000026class MCValue;
Daniel Dunbar78929e52009-07-20 20:01:54 +000027class TargetAsmParser;
Daniel Dunbarbc9c6472009-07-27 23:20:52 +000028class Twine;
Daniel Dunbarc6c054e2009-06-30 01:49:52 +000029
Daniel Dunbard80432a2009-07-28 20:47:52 +000030class AsmParser : public MCAsmParser {
Daniel Dunbard1d1e832009-06-30 23:38:38 +000031public:
32 struct X86Operand;
33
34private:
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000035 AsmLexer Lexer;
Chris Lattnere462e4e2009-06-24 04:31:49 +000036 MCContext &Ctx;
Chris Lattner7a3716d2009-06-24 00:52:40 +000037 MCStreamer &Out;
Daniel Dunbard80432a2009-07-28 20:47:52 +000038 TargetAsmParser *TargetParser;
Chris Lattner7a3716d2009-06-24 00:52:40 +000039
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000040public:
Daniel Dunbard80432a2009-07-28 20:47:52 +000041 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
42 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000043 ~AsmParser() {}
Daniel Dunbard80432a2009-07-28 20:47:52 +000044
Chris Lattner3b4bfbd2009-06-21 20:16:42 +000045 bool Run();
46
Daniel Dunbar4b0f4ef2009-07-20 18:55:04 +000047public:
Daniel Dunbard80432a2009-07-28 20:47:52 +000048 TargetAsmParser &getTargetParser() const { return *TargetParser; }
49 void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
Daniel Dunbar4b0f4ef2009-07-20 18:55:04 +000050
Daniel Dunbar665481f2009-07-28 22:22:31 +000051 /// @name MCAsmParser Interface
52 /// {
53
Daniel Dunbar78929e52009-07-20 20:01:54 +000054 virtual MCAsmLexer &getLexer() { return Lexer; }
55
Daniel Dunbar665481f2009-07-28 22:22:31 +000056 virtual void Warning(SMLoc L, const Twine &Meg);
57
58 virtual bool Error(SMLoc L, const Twine &Msg);
59
60 virtual bool ParseExpression(AsmExpr *&Res);
61
62 virtual bool ParseAbsoluteExpression(int64_t &Res);
63
64 virtual bool ParseRelocatableExpression(MCValue &Res);
65
66 /// }
67
Chris Lattnercfd2e3b2009-06-21 20:54:55 +000068private:
69 bool ParseStatement();
Daniel Dunbarb5aec992009-06-30 00:49:23 +000070
Chris Lattnerf6611852009-06-21 21:22:11 +000071 bool TokError(const char *Msg);
Chris Lattnere883aa62009-06-22 01:29:09 +000072
73 void EatToEndOfStatement();
74
Daniel Dunbar9a7b61d2009-07-27 21:49:56 +000075 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000076
Daniel Dunbar5ebef272009-07-02 02:09:07 +000077 /// ParseParenRelocatableExpression - Parse an expression which must be
78 /// relocatable, assuming that an initial '(' has already been consumed.
79 ///
80 /// @param Res - The relocatable expression value. The result is undefined on
81 /// error.
82 /// @result - False on success.
83 ///
84 /// @see ParseRelocatableExpression, ParseParenExpr.
85 bool ParseParenRelocatableExpression(MCValue &Res);
86
Daniel Dunbarc3b8a4b2009-06-29 20:37:27 +000087 bool ParsePrimaryExpr(AsmExpr *&Res);
88 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
89 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattnere6c561b2009-06-23 18:41:30 +000090
91 // X86 specific.
Daniel Dunbar9a7b61d2009-07-27 21:49:56 +000092 bool ParseX86InstOperands(const StringRef &InstName, MCInst &Inst);
Chris Lattnere6c561b2009-06-23 18:41:30 +000093 bool ParseX86Operand(X86Operand &Op);
94 bool ParseX86MemOperand(X86Operand &Op);
Daniel Dunbarb336eac2009-07-02 01:58:24 +000095 bool ParseX86Register(X86Operand &Op);
Chris Lattnerec6cf312009-06-24 04:43:34 +000096
97 // Directive Parsing.
Chris Lattner4686d2f2009-06-24 05:13:15 +000098 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
99 bool ParseDirectiveSectionSwitch(const char *Section,
100 const char *Directives = 0);
Daniel Dunbara0527a92009-06-24 23:30:00 +0000101 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
102 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
103 bool ParseDirectiveFill(); // ".fill"
104 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbarfca5d342009-06-25 21:56:11 +0000105 bool ParseDirectiveSet(); // ".set"
Daniel Dunbar0a2a15c2009-06-25 22:44:51 +0000106 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbar631e12c2009-06-29 23:46:59 +0000107 // ".align{,32}", ".p2align{,w,l}"
108 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbar05111ab2009-06-30 00:33:19 +0000109
110 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
111 /// accepts a single symbol (which should be a label or an external).
112 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Kevin Enderby8ae702b2009-07-14 18:17:10 +0000113 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
Kevin Enderbyd7895a12009-07-14 21:35:03 +0000114 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
Chris Lattnere29dbe32009-07-07 20:30:46 +0000115
Chris Lattner18359222009-07-09 17:25:12 +0000116 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
Chris Lattner349007a2009-07-10 22:20:30 +0000117 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
Kevin Enderby3694db22009-07-13 21:03:15 +0000118
119 // Darwin specific ".subsections_via_symbols"
120 bool ParseDirectiveDarwinSubsectionsViaSymbols();
Kevin Enderby7495f5b2009-07-15 15:30:11 +0000121 // Darwin specific .dump and .load
Kevin Enderby76022e42009-07-20 20:25:37 +0000122 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
Kevin Enderby58773c72009-07-13 23:15:14 +0000123
124 bool ParseDirectiveAbort(); // ".abort"
Kevin Enderbyf7f70012009-07-14 23:21:55 +0000125 bool ParseDirectiveInclude(); // ".include"
Chris Lattner3b4bfbd2009-06-21 20:16:42 +0000126};
127
128} // end namespace llvm
129
130#endif