Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 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 "AsmLexer.h" |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCAsmParser.h" |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 22 | class AsmExpr; |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 23 | class MCContext; |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 24 | class MCInst; |
Chris Lattner | cbc23f7 | 2009-06-24 00:52:40 +0000 | [diff] [blame] | 25 | class MCStreamer; |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 26 | class MCValue; |
Daniel Dunbar | dbd692a | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 27 | class TargetAsmParser; |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame^] | 28 | class Twine; |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 29 | |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 30 | class AsmParser : MCAsmParser { |
Daniel Dunbar | d9627e1 | 2009-06-30 23:38:38 +0000 | [diff] [blame] | 31 | public: |
| 32 | struct X86Operand; |
| 33 | |
| 34 | private: |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 35 | AsmLexer Lexer; |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 36 | MCContext &Ctx; |
Chris Lattner | cbc23f7 | 2009-06-24 00:52:40 +0000 | [diff] [blame] | 37 | MCStreamer &Out; |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 38 | TargetAsmParser &TargetParser; |
Chris Lattner | cbc23f7 | 2009-06-24 00:52:40 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 40 | public: |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 41 | AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, |
| 42 | TargetAsmParser &_TargetParser) |
| 43 | : Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(_TargetParser) {} |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 44 | ~AsmParser() {} |
| 45 | |
| 46 | bool Run(); |
| 47 | |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 48 | public: |
| 49 | TargetAsmParser &getTargetParser() const { return TargetParser; } |
| 50 | |
Daniel Dunbar | dbd692a | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 51 | virtual MCAsmLexer &getLexer() { return Lexer; } |
| 52 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 53 | private: |
| 54 | bool ParseStatement(); |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 55 | |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame^] | 56 | void Warning(SMLoc L, const Twine &Msg); |
| 57 | bool Error(SMLoc L, const Twine &Msg); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 58 | bool TokError(const char *Msg); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 59 | |
| 60 | void EatToEndOfStatement(); |
| 61 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 62 | bool ParseAssignment(const StringRef &Name, bool IsDotSet); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 63 | |
| 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 Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 69 | |
| 70 | /// ParseAbsoluteExpression - Parse an expression which must evaluate to an |
| 71 | /// absolute value. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 72 | /// |
| 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 Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 78 | /// 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 Dunbar | 2c3f00c | 2009-07-02 02:09:07 +0000 | [diff] [blame] | 86 | /// 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 Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 96 | bool ParsePrimaryExpr(AsmExpr *&Res); |
| 97 | bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res); |
| 98 | bool ParseParenExpr(AsmExpr *&Res); |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 99 | |
| 100 | // X86 specific. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 101 | bool ParseX86InstOperands(const StringRef &InstName, MCInst &Inst); |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 102 | bool ParseX86Operand(X86Operand &Op); |
| 103 | bool ParseX86MemOperand(X86Operand &Op); |
Daniel Dunbar | 46b6c52 | 2009-07-02 01:58:24 +0000 | [diff] [blame] | 104 | bool ParseX86Register(X86Operand &Op); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 105 | |
| 106 | // Directive Parsing. |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 107 | bool ParseDirectiveDarwinSection(); // Darwin specific ".section". |
| 108 | bool ParseDirectiveSectionSwitch(const char *Section, |
| 109 | const char *Directives = 0); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 110 | bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz" |
| 111 | bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ... |
| 112 | bool ParseDirectiveFill(); // ".fill" |
| 113 | bool ParseDirectiveSpace(); // ".space" |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 114 | bool ParseDirectiveSet(); // ".set" |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 115 | bool ParseDirectiveOrg(); // ".org" |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 116 | // ".align{,32}", ".p2align{,w,l}" |
| 117 | bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize); |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 118 | |
| 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 Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 122 | bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc" |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 123 | bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym" |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 124 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 125 | bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm" |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 126 | bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill" |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 127 | |
| 128 | // Darwin specific ".subsections_via_symbols" |
| 129 | bool ParseDirectiveDarwinSubsectionsViaSymbols(); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 130 | // Darwin specific .dump and .load |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 131 | bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump); |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 132 | |
| 133 | bool ParseDirectiveAbort(); // ".abort" |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 134 | bool ParseDirectiveInclude(); // ".include" |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // end namespace llvm |
| 138 | |
| 139 | #endif |