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 | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 21 | class AsmExpr; |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 22 | class MCContext; |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 23 | class MCInst; |
Chris Lattner | cbc23f7 | 2009-06-24 00:52:40 +0000 | [diff] [blame] | 24 | class MCStreamer; |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 25 | class MCValue; |
| 26 | |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 27 | class AsmParser { |
Daniel Dunbar | d9627e1 | 2009-06-30 23:38:38 +0000 | [diff] [blame] | 28 | public: |
| 29 | struct X86Operand; |
| 30 | |
| 31 | private: |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 32 | AsmLexer Lexer; |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 33 | MCContext &Ctx; |
Chris Lattner | cbc23f7 | 2009-06-24 00:52:40 +0000 | [diff] [blame] | 34 | MCStreamer &Out; |
| 35 | |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 36 | public: |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 37 | AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr) |
| 38 | : Lexer(SM), Ctx(ctx), Out(OutStr) {} |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 39 | ~AsmParser() {} |
| 40 | |
| 41 | bool Run(); |
| 42 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 43 | private: |
| 44 | bool ParseStatement(); |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 45 | |
| 46 | void Warning(SMLoc L, const char *Msg); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 47 | bool Error(SMLoc L, const char *Msg); |
| 48 | bool TokError(const char *Msg); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 49 | |
| 50 | void EatToEndOfStatement(); |
| 51 | |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 52 | bool ParseAssignment(const char *Name, bool IsDotSet); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 53 | |
| 54 | /// ParseExpression - Parse a general assembly expression. |
| 55 | /// |
| 56 | /// @param Res - The resulting expression. The pointer value is null on error. |
| 57 | /// @result - False on success. |
| 58 | bool ParseExpression(AsmExpr *&Res); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 59 | |
| 60 | /// ParseAbsoluteExpression - Parse an expression which must evaluate to an |
| 61 | /// absolute value. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 62 | /// |
| 63 | /// @param Res - The value of the absolute expression. The result is undefined |
| 64 | /// on error. |
| 65 | /// @result - False on success. |
| 66 | bool ParseAbsoluteExpression(int64_t &Res); |
| 67 | |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 68 | /// ParseRelocatableExpression - Parse an expression which must be |
| 69 | /// relocatable. |
| 70 | /// |
| 71 | /// @param Res - The relocatable expression value. The result is undefined on |
| 72 | /// error. |
| 73 | /// @result - False on success. |
| 74 | bool ParseRelocatableExpression(MCValue &Res); |
| 75 | |
Daniel Dunbar | 2c3f00c | 2009-07-02 02:09:07 +0000 | [diff] [blame] | 76 | /// ParseParenRelocatableExpression - Parse an expression which must be |
| 77 | /// relocatable, assuming that an initial '(' has already been consumed. |
| 78 | /// |
| 79 | /// @param Res - The relocatable expression value. The result is undefined on |
| 80 | /// error. |
| 81 | /// @result - False on success. |
| 82 | /// |
| 83 | /// @see ParseRelocatableExpression, ParseParenExpr. |
| 84 | bool ParseParenRelocatableExpression(MCValue &Res); |
| 85 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 86 | bool ParsePrimaryExpr(AsmExpr *&Res); |
| 87 | bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res); |
| 88 | bool ParseParenExpr(AsmExpr *&Res); |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 89 | |
| 90 | // X86 specific. |
Daniel Dunbar | d9627e1 | 2009-06-30 23:38:38 +0000 | [diff] [blame] | 91 | bool ParseX86InstOperands(const char *InstName, MCInst &Inst); |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 92 | bool ParseX86Operand(X86Operand &Op); |
| 93 | bool ParseX86MemOperand(X86Operand &Op); |
Daniel Dunbar | 46b6c52 | 2009-07-02 01:58:24 +0000 | [diff] [blame] | 94 | bool ParseX86Register(X86Operand &Op); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 95 | |
| 96 | // Directive Parsing. |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 97 | bool ParseDirectiveDarwinSection(); // Darwin specific ".section". |
| 98 | bool ParseDirectiveSectionSwitch(const char *Section, |
| 99 | const char *Directives = 0); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 100 | bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz" |
| 101 | bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ... |
| 102 | bool ParseDirectiveFill(); // ".fill" |
| 103 | bool ParseDirectiveSpace(); // ".space" |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 104 | bool ParseDirectiveSet(); // ".set" |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 105 | bool ParseDirectiveOrg(); // ".org" |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 106 | // ".align{,32}", ".p2align{,w,l}" |
| 107 | bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize); |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 108 | |
| 109 | /// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which |
| 110 | /// accepts a single symbol (which should be a label or an external). |
| 111 | bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 113 | bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm" |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 114 | bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill" |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame^] | 115 | |
| 116 | // Darwin specific ".subsections_via_symbols" |
| 117 | bool ParseDirectiveDarwinSubsectionsViaSymbols(); |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } // end namespace llvm |
| 121 | |
| 122 | #endif |