blob: dd6033847b43a12efe4fe29593b09b80a4ead6cb [file] [log] [blame]
Chris Lattner27aa7d22009-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 Dunbara3af3702009-07-20 18:55:04 +000018#include "llvm/MC/MCAsmParser.h"
Daniel Dunbard7b267b2009-06-30 00:33:19 +000019#include "llvm/MC/MCStreamer.h"
Chris Lattner27aa7d22009-06-21 20:16:42 +000020
21namespace llvm {
Daniel Dunbar475839e2009-06-29 20:37:27 +000022class AsmExpr;
Chris Lattnerc69485e2009-06-24 04:31:49 +000023class MCContext;
Chris Lattner29dfe7c2009-06-23 18:41:30 +000024class MCInst;
Chris Lattnercbc23f72009-06-24 00:52:40 +000025class MCStreamer;
Daniel Dunbar15d17072009-06-30 01:49:52 +000026class MCValue;
Daniel Dunbardbd692a2009-07-20 20:01:54 +000027class TargetAsmParser;
Daniel Dunbarf9507ff2009-07-27 23:20:52 +000028class Twine;
Daniel Dunbar15d17072009-06-30 01:49:52 +000029
Daniel Dunbara3af3702009-07-20 18:55:04 +000030class AsmParser : MCAsmParser {
Daniel Dunbard9627e12009-06-30 23:38:38 +000031public:
32 struct X86Operand;
33
34private:
Chris Lattner27aa7d22009-06-21 20:16:42 +000035 AsmLexer Lexer;
Chris Lattnerc69485e2009-06-24 04:31:49 +000036 MCContext &Ctx;
Chris Lattnercbc23f72009-06-24 00:52:40 +000037 MCStreamer &Out;
Daniel Dunbara3af3702009-07-20 18:55:04 +000038 TargetAsmParser &TargetParser;
Chris Lattnercbc23f72009-06-24 00:52:40 +000039
Chris Lattner27aa7d22009-06-21 20:16:42 +000040public:
Daniel Dunbara3af3702009-07-20 18:55:04 +000041 AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
42 TargetAsmParser &_TargetParser)
43 : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {}
Chris Lattner27aa7d22009-06-21 20:16:42 +000044 ~AsmParser() {}
45
46 bool Run();
47
Daniel Dunbara3af3702009-07-20 18:55:04 +000048public:
49 TargetAsmParser &getTargetParser() const { return TargetParser; }
50
Daniel Dunbardbd692a2009-07-20 20:01:54 +000051 virtual MCAsmLexer &getLexer() { return Lexer; }
52
Chris Lattnerb0789ed2009-06-21 20:54:55 +000053private:
54 bool ParseStatement();
Daniel Dunbar3fb76832009-06-30 00:49:23 +000055
Daniel Dunbarf9507ff2009-07-27 23:20:52 +000056 void Warning(SMLoc L, const Twine &Msg);
57 bool Error(SMLoc L, const Twine &Msg);
Chris Lattner14ee48a2009-06-21 21:22:11 +000058 bool TokError(const char *Msg);
Chris Lattner2cf5f142009-06-22 01:29:09 +000059
60 void EatToEndOfStatement();
61
Daniel Dunbar9a7e2cc2009-07-27 21:49:56 +000062 bool ParseAssignment(const StringRef &Name, bool IsDotSet);
Daniel Dunbar475839e2009-06-29 20:37:27 +000063
64 /// ParseExpression - Parse a general assembly expression.
65 ///
66 /// @param Res - The resulting expression. The pointer value is null on error.
67 /// @result - False on success.
68 bool ParseExpression(AsmExpr *&Res);
Daniel Dunbar15d17072009-06-30 01:49:52 +000069
70 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
71 /// absolute value.
Daniel Dunbar475839e2009-06-29 20:37:27 +000072 ///
73 /// @param Res - The value of the absolute expression. The result is undefined
74 /// on error.
75 /// @result - False on success.
76 bool ParseAbsoluteExpression(int64_t &Res);
77
Daniel Dunbar15d17072009-06-30 01:49:52 +000078 /// ParseRelocatableExpression - Parse an expression which must be
79 /// relocatable.
80 ///
81 /// @param Res - The relocatable expression value. The result is undefined on
82 /// error.
83 /// @result - False on success.
84 bool ParseRelocatableExpression(MCValue &Res);
85
Daniel Dunbar2c3f00c2009-07-02 02:09:07 +000086 /// ParseParenRelocatableExpression - Parse an expression which must be
87 /// relocatable, assuming that an initial '(' has already been consumed.
88 ///
89 /// @param Res - The relocatable expression value. The result is undefined on
90 /// error.
91 /// @result - False on success.
92 ///
93 /// @see ParseRelocatableExpression, ParseParenExpr.
94 bool ParseParenRelocatableExpression(MCValue &Res);
95
Daniel Dunbar475839e2009-06-29 20:37:27 +000096 bool ParsePrimaryExpr(AsmExpr *&Res);
97 bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
98 bool ParseParenExpr(AsmExpr *&Res);
Chris Lattner29dfe7c2009-06-23 18:41:30 +000099
100 // X86 specific.
Daniel Dunbar9a7e2cc2009-07-27 21:49:56 +0000101 bool ParseX86InstOperands(const StringRef &InstName, MCInst &Inst);
Chris Lattner29dfe7c2009-06-23 18:41:30 +0000102 bool ParseX86Operand(X86Operand &Op);
103 bool ParseX86MemOperand(X86Operand &Op);
Daniel Dunbar46b6c522009-07-02 01:58:24 +0000104 bool ParseX86Register(X86Operand &Op);
Chris Lattner9a023f72009-06-24 04:43:34 +0000105
106 // Directive Parsing.
Chris Lattner529fb542009-06-24 05:13:15 +0000107 bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
108 bool ParseDirectiveSectionSwitch(const char *Section,
109 const char *Directives = 0);
Daniel Dunbara0d14262009-06-24 23:30:00 +0000110 bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
111 bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
112 bool ParseDirectiveFill(); // ".fill"
113 bool ParseDirectiveSpace(); // ".space"
Daniel Dunbar8f780cd2009-06-25 21:56:11 +0000114 bool ParseDirectiveSet(); // ".set"
Daniel Dunbarc238b582009-06-25 22:44:51 +0000115 bool ParseDirectiveOrg(); // ".org"
Daniel Dunbarc29dfa72009-06-29 23:46:59 +0000116 // ".align{,32}", ".p2align{,w,l}"
117 bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
Daniel Dunbard7b267b2009-06-30 00:33:19 +0000118
119 /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
120 /// accepts a single symbol (which should be a label or an external).
121 bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
Kevin Enderby95cf30c2009-07-14 18:17:10 +0000122 bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
Kevin Enderby71148242009-07-14 21:35:03 +0000123 bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
Chris Lattner4e4db7a2009-07-07 20:30:46 +0000124
Chris Lattner1fc3d752009-07-09 17:25:12 +0000125 bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
Chris Lattner9be3fee2009-07-10 22:20:30 +0000126 bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
Kevin Enderbya5c78322009-07-13 21:03:15 +0000127
128 // Darwin specific ".subsections_via_symbols"
129 bool ParseDirectiveDarwinSubsectionsViaSymbols();
Kevin Enderby6e68cd92009-07-15 15:30:11 +0000130 // Darwin specific .dump and .load
Kevin Enderby5026ae42009-07-20 20:25:37 +0000131 bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
Kevin Enderby5f1f0b82009-07-13 23:15:14 +0000132
133 bool ParseDirectiveAbort(); // ".abort"
Kevin Enderby1f049b22009-07-14 23:21:55 +0000134 bool ParseDirectiveInclude(); // ".include"
Chris Lattner27aa7d22009-06-21 20:16:42 +0000135};
136
137} // end namespace llvm
138
139#endif