Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 1 | //===- AsmParser.cpp - Parser for Assembly Files --------------------------===// |
| 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 implements the parser for assembly files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "AsmParser.h" |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 15 | |
| 16 | #include "AsmExpr.h" |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInst.h" |
Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSectionMachO.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 23 | #include "llvm/Support/SourceMgr.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetAsmParser.h" |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 28 | void AsmParser::Warning(SMLoc L, const Twine &Msg) { |
| 29 | Lexer.PrintMessage(L, Msg.str(), "warning"); |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 32 | bool AsmParser::Error(SMLoc L, const Twine &Msg) { |
| 33 | Lexer.PrintMessage(L, Msg.str(), "error"); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
| 37 | bool AsmParser::TokError(const char *Msg) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 38 | Lexer.PrintMessage(Lexer.getLoc(), Msg, "error"); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 39 | return true; |
| 40 | } |
| 41 | |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 42 | bool AsmParser::Run() { |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 43 | // Prime the lexer. |
| 44 | Lexer.Lex(); |
| 45 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 46 | bool HadError = false; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 47 | |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 48 | AsmCond StartingCondState = TheCondState; |
| 49 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 50 | // While we have input, parse each statement. |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 51 | while (Lexer.isNot(AsmToken::Eof)) { |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 52 | // Handle conditional assembly here before calling ParseStatement() |
| 53 | if (Lexer.getKind() == AsmToken::Identifier) { |
| 54 | // If we have an identifier, handle it as the key symbol. |
| 55 | AsmToken ID = Lexer.getTok(); |
| 56 | SMLoc IDLoc = ID.getLoc(); |
| 57 | StringRef IDVal = ID.getString(); |
| 58 | |
| 59 | if (IDVal == ".if" || |
| 60 | IDVal == ".elseif" || |
| 61 | IDVal == ".else" || |
| 62 | IDVal == ".endif") { |
| 63 | if (!ParseConditionalAssemblyDirectives(IDVal, IDLoc)) |
| 64 | continue; |
| 65 | HadError = true; |
| 66 | EatToEndOfStatement(); |
| 67 | continue; |
| 68 | } |
| 69 | } |
| 70 | if (TheCondState.Ignore) { |
| 71 | EatToEndOfStatement(); |
| 72 | continue; |
| 73 | } |
| 74 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 75 | if (!ParseStatement()) continue; |
| 76 | |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 77 | // We had an error, remember it and recover by skipping to the next line. |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 78 | HadError = true; |
| 79 | EatToEndOfStatement(); |
| 80 | } |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 81 | |
| 82 | if (TheCondState.TheCond != StartingCondState.TheCond || |
| 83 | TheCondState.Ignore != StartingCondState.Ignore) |
| 84 | return TokError("unmatched .ifs or .elses"); |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 85 | |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 86 | if (!HadError) |
| 87 | Out.Finish(); |
| 88 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 89 | return HadError; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 92 | /// ParseConditionalAssemblyDirectives - parse the conditional assembly |
| 93 | /// directives |
| 94 | bool AsmParser::ParseConditionalAssemblyDirectives(StringRef Directive, |
| 95 | SMLoc DirectiveLoc) { |
| 96 | if (Directive == ".if") |
| 97 | return ParseDirectiveIf(DirectiveLoc); |
| 98 | if (Directive == ".elseif") |
| 99 | return ParseDirectiveElseIf(DirectiveLoc); |
| 100 | if (Directive == ".else") |
| 101 | return ParseDirectiveElse(DirectiveLoc); |
| 102 | if (Directive == ".endif") |
| 103 | return ParseDirectiveEndIf(DirectiveLoc); |
| 104 | return true; |
| 105 | } |
| 106 | |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 107 | /// EatToEndOfStatement - Throw away the rest of the line for testing purposes. |
| 108 | void AsmParser::EatToEndOfStatement() { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 109 | while (Lexer.isNot(AsmToken::EndOfStatement) && |
| 110 | Lexer.isNot(AsmToken::Eof)) |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 111 | Lexer.Lex(); |
| 112 | |
| 113 | // Eat EOL. |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 114 | if (Lexer.is(AsmToken::EndOfStatement)) |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 115 | Lexer.Lex(); |
| 116 | } |
| 117 | |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 119 | /// ParseParenExpr - Parse a paren expression and return it. |
| 120 | /// NOTE: This assumes the leading '(' has already been consumed. |
| 121 | /// |
| 122 | /// parenexpr ::= expr) |
| 123 | /// |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 124 | bool AsmParser::ParseParenExpr(AsmExpr *&Res) { |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 125 | if (ParseExpression(Res)) return true; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 126 | if (Lexer.isNot(AsmToken::RParen)) |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 127 | return TokError("expected ')' in parentheses expression"); |
| 128 | Lexer.Lex(); |
| 129 | return false; |
| 130 | } |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 131 | |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 132 | MCSymbol *AsmParser::CreateSymbol(StringRef Name) { |
| 133 | if (MCSymbol *S = Ctx.LookupSymbol(Name)) |
| 134 | return S; |
| 135 | |
| 136 | // If the label starts with L it is an assembler temporary label. |
| 137 | if (Name.startswith("L")) |
| 138 | return Ctx.CreateTemporarySymbol(Name); |
| 139 | |
| 140 | return Ctx.CreateSymbol(Name); |
| 141 | } |
| 142 | |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 143 | /// ParsePrimaryExpr - Parse a primary expression and return it. |
| 144 | /// primaryexpr ::= (parenexpr |
| 145 | /// primaryexpr ::= symbol |
| 146 | /// primaryexpr ::= number |
| 147 | /// primaryexpr ::= ~,+,- primaryexpr |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 148 | bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) { |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 149 | switch (Lexer.getKind()) { |
| 150 | default: |
| 151 | return TokError("unknown token in expression"); |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 152 | case AsmToken::Exclaim: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 153 | Lexer.Lex(); // Eat the operator. |
| 154 | if (ParsePrimaryExpr(Res)) |
| 155 | return true; |
| 156 | Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res); |
| 157 | return false; |
Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 158 | case AsmToken::String: |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 159 | case AsmToken::Identifier: { |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 160 | // This is a label, this should be parsed as part of an expression, to |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 161 | // handle things like LFOO+4. |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 162 | MCSymbol *Sym = CreateSymbol(Lexer.getTok().getIdentifier()); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 163 | |
| 164 | Res = new AsmSymbolRefExpr(Sym); |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 165 | Lexer.Lex(); // Eat identifier. |
| 166 | return false; |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 167 | } |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 168 | case AsmToken::Integer: |
Daniel Dunbar | 419aded | 2009-07-28 16:38:40 +0000 | [diff] [blame] | 169 | Res = new AsmConstantExpr(Lexer.getTok().getIntVal()); |
Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 170 | Lexer.Lex(); // Eat token. |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 171 | return false; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 172 | case AsmToken::LParen: |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 173 | Lexer.Lex(); // Eat the '('. |
| 174 | return ParseParenExpr(Res); |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 175 | case AsmToken::Minus: |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 176 | Lexer.Lex(); // Eat the operator. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 177 | if (ParsePrimaryExpr(Res)) |
| 178 | return true; |
| 179 | Res = new AsmUnaryExpr(AsmUnaryExpr::Minus, Res); |
| 180 | return false; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 181 | case AsmToken::Plus: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 182 | Lexer.Lex(); // Eat the operator. |
| 183 | if (ParsePrimaryExpr(Res)) |
| 184 | return true; |
| 185 | Res = new AsmUnaryExpr(AsmUnaryExpr::Plus, Res); |
| 186 | return false; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 187 | case AsmToken::Tilde: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 188 | Lexer.Lex(); // Eat the operator. |
| 189 | if (ParsePrimaryExpr(Res)) |
| 190 | return true; |
| 191 | Res = new AsmUnaryExpr(AsmUnaryExpr::Not, Res); |
| 192 | return false; |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 195 | |
| 196 | /// ParseExpression - Parse an expression and return it. |
| 197 | /// |
| 198 | /// expr ::= expr +,- expr -> lowest. |
| 199 | /// expr ::= expr |,^,&,! expr -> middle. |
| 200 | /// expr ::= expr *,/,%,<<,>> expr -> highest. |
| 201 | /// expr ::= primaryexpr |
| 202 | /// |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 203 | bool AsmParser::ParseExpression(AsmExpr *&Res) { |
| 204 | Res = 0; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 205 | return ParsePrimaryExpr(Res) || |
| 206 | ParseBinOpRHS(1, Res); |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 207 | } |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 208 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 209 | bool AsmParser::ParseAbsoluteExpression(int64_t &Res) { |
| 210 | AsmExpr *Expr; |
| 211 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 212 | SMLoc StartLoc = Lexer.getLoc(); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 213 | if (ParseExpression(Expr)) |
| 214 | return true; |
| 215 | |
| 216 | if (!Expr->EvaluateAsAbsolute(Ctx, Res)) |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 217 | return Error(StartLoc, "expected absolute expression"); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 218 | |
| 219 | return false; |
| 220 | } |
| 221 | |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 222 | bool AsmParser::ParseRelocatableExpression(MCValue &Res) { |
| 223 | AsmExpr *Expr; |
| 224 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 225 | SMLoc StartLoc = Lexer.getLoc(); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 226 | if (ParseExpression(Expr)) |
| 227 | return true; |
| 228 | |
| 229 | if (!Expr->EvaluateAsRelocatable(Ctx, Res)) |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 230 | return Error(StartLoc, "expected relocatable expression"); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 231 | |
| 232 | return false; |
| 233 | } |
| 234 | |
Daniel Dunbar | 2c3f00c | 2009-07-02 02:09:07 +0000 | [diff] [blame] | 235 | bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) { |
| 236 | AsmExpr *Expr; |
| 237 | |
| 238 | SMLoc StartLoc = Lexer.getLoc(); |
| 239 | if (ParseParenExpr(Expr)) |
| 240 | return true; |
| 241 | |
| 242 | if (!Expr->EvaluateAsRelocatable(Ctx, Res)) |
| 243 | return Error(StartLoc, "expected relocatable expression"); |
| 244 | |
| 245 | return false; |
| 246 | } |
| 247 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 248 | static unsigned getBinOpPrecedence(AsmToken::TokenKind K, |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 249 | AsmBinaryExpr::Opcode &Kind) { |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 250 | switch (K) { |
| 251 | default: return 0; // not a binop. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 252 | |
| 253 | // Lowest Precedence: &&, || |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 254 | case AsmToken::AmpAmp: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 255 | Kind = AsmBinaryExpr::LAnd; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 256 | return 1; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 257 | case AsmToken::PipePipe: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 258 | Kind = AsmBinaryExpr::LOr; |
| 259 | return 1; |
| 260 | |
| 261 | // Low Precedence: +, -, ==, !=, <>, <, <=, >, >= |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 262 | case AsmToken::Plus: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 263 | Kind = AsmBinaryExpr::Add; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 264 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 265 | case AsmToken::Minus: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 266 | Kind = AsmBinaryExpr::Sub; |
| 267 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 268 | case AsmToken::EqualEqual: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 269 | Kind = AsmBinaryExpr::EQ; |
| 270 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 271 | case AsmToken::ExclaimEqual: |
| 272 | case AsmToken::LessGreater: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 273 | Kind = AsmBinaryExpr::NE; |
| 274 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 275 | case AsmToken::Less: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 276 | Kind = AsmBinaryExpr::LT; |
| 277 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 278 | case AsmToken::LessEqual: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 279 | Kind = AsmBinaryExpr::LTE; |
| 280 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 281 | case AsmToken::Greater: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 282 | Kind = AsmBinaryExpr::GT; |
| 283 | return 2; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 284 | case AsmToken::GreaterEqual: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 285 | Kind = AsmBinaryExpr::GTE; |
| 286 | return 2; |
| 287 | |
| 288 | // Intermediate Precedence: |, &, ^ |
| 289 | // |
| 290 | // FIXME: gas seems to support '!' as an infix operator? |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 291 | case AsmToken::Pipe: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 292 | Kind = AsmBinaryExpr::Or; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 293 | return 3; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 294 | case AsmToken::Caret: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 295 | Kind = AsmBinaryExpr::Xor; |
| 296 | return 3; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 297 | case AsmToken::Amp: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 298 | Kind = AsmBinaryExpr::And; |
| 299 | return 3; |
| 300 | |
| 301 | // Highest Precedence: *, /, %, <<, >> |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 302 | case AsmToken::Star: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 303 | Kind = AsmBinaryExpr::Mul; |
| 304 | return 4; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 305 | case AsmToken::Slash: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 306 | Kind = AsmBinaryExpr::Div; |
| 307 | return 4; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 308 | case AsmToken::Percent: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 309 | Kind = AsmBinaryExpr::Mod; |
| 310 | return 4; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 311 | case AsmToken::LessLess: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 312 | Kind = AsmBinaryExpr::Shl; |
| 313 | return 4; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 314 | case AsmToken::GreaterGreater: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 315 | Kind = AsmBinaryExpr::Shr; |
| 316 | return 4; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'. |
| 322 | /// Res contains the LHS of the expression on input. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 323 | bool AsmParser::ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res) { |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 324 | while (1) { |
Daniel Dunbar | 5133063 | 2009-06-29 21:14:21 +0000 | [diff] [blame] | 325 | AsmBinaryExpr::Opcode Kind = AsmBinaryExpr::Add; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 326 | unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 327 | |
| 328 | // If the next token is lower precedence than we are allowed to eat, return |
| 329 | // successfully with what we ate already. |
| 330 | if (TokPrec < Precedence) |
| 331 | return false; |
| 332 | |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 333 | Lexer.Lex(); |
| 334 | |
| 335 | // Eat the next primary expression. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 336 | AsmExpr *RHS; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 337 | if (ParsePrimaryExpr(RHS)) return true; |
| 338 | |
| 339 | // If BinOp binds less tightly with RHS than the operator after RHS, let |
| 340 | // the pending operator take RHS as its LHS. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 341 | AsmBinaryExpr::Opcode Dummy; |
| 342 | unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 343 | if (TokPrec < NextTokPrec) { |
| 344 | if (ParseBinOpRHS(Precedence+1, RHS)) return true; |
| 345 | } |
| 346 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 347 | // Merge LHS and RHS according to operator. |
| 348 | Res = new AsmBinaryExpr(Kind, Res, RHS); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 352 | |
| 353 | |
| 354 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 355 | /// ParseStatement: |
| 356 | /// ::= EndOfStatement |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 357 | /// ::= Label* Directive ...Operands... EndOfStatement |
| 358 | /// ::= Label* Identifier OperandList* EndOfStatement |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 359 | bool AsmParser::ParseStatement() { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 360 | if (Lexer.is(AsmToken::EndOfStatement)) { |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 361 | Lexer.Lex(); |
| 362 | return false; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 363 | } |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 364 | |
| 365 | // Statements always start with an identifier. |
Daniel Dunbar | 419aded | 2009-07-28 16:38:40 +0000 | [diff] [blame] | 366 | AsmToken ID = Lexer.getTok(); |
| 367 | SMLoc IDLoc = ID.getLoc(); |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 368 | StringRef IDVal; |
| 369 | if (ParseIdentifier(IDVal)) |
| 370 | return TokError("unexpected token at start of statement"); |
| 371 | |
| 372 | // FIXME: Recurse on local labels? |
| 373 | |
| 374 | // See what kind of statement we have. |
| 375 | switch (Lexer.getKind()) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 376 | case AsmToken::Colon: { |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 377 | // identifier ':' -> Label. |
| 378 | Lexer.Lex(); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 379 | |
| 380 | // Diagnose attempt to use a variable as a label. |
| 381 | // |
| 382 | // FIXME: Diagnostics. Note the location of the definition as a label. |
| 383 | // FIXME: This doesn't diagnose assignment to a symbol which has been |
| 384 | // implicitly marked as external. |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 385 | MCSymbol *Sym = CreateSymbol(IDVal); |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 386 | if (!Sym->isUndefined()) |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 387 | return Error(IDLoc, "invalid symbol redefinition"); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 388 | |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 389 | // Emit the label. |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 390 | Out.EmitLabel(Sym); |
| 391 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 392 | return ParseStatement(); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 393 | } |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 394 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 395 | case AsmToken::Equal: |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 396 | // identifier '=' ... -> assignment statement |
| 397 | Lexer.Lex(); |
| 398 | |
| 399 | return ParseAssignment(IDVal, false); |
| 400 | |
| 401 | default: // Normal instruction or directive. |
| 402 | break; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // Otherwise, we have a normal instruction or directive. |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 406 | if (IDVal[0] == '.') { |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 407 | // FIXME: This should be driven based on a hash lookup and callback. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 408 | if (IDVal == ".section") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 409 | return ParseDirectiveDarwinSection(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 410 | if (IDVal == ".text") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 411 | // FIXME: This changes behavior based on the -static flag to the |
| 412 | // assembler. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 413 | return ParseDirectiveSectionSwitch("__TEXT", "__text", |
| 414 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 415 | if (IDVal == ".const") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 416 | return ParseDirectiveSectionSwitch("__TEXT", "__const"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 417 | if (IDVal == ".static_const") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 418 | return ParseDirectiveSectionSwitch("__TEXT", "__static_const"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 419 | if (IDVal == ".cstring") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 420 | return ParseDirectiveSectionSwitch("__TEXT","__cstring", |
| 421 | MCSectionMachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 422 | if (IDVal == ".literal4") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 423 | return ParseDirectiveSectionSwitch("__TEXT", "__literal4", |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 424 | MCSectionMachO::S_4BYTE_LITERALS, |
| 425 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 426 | if (IDVal == ".literal8") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 427 | return ParseDirectiveSectionSwitch("__TEXT", "__literal8", |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 428 | MCSectionMachO::S_8BYTE_LITERALS, |
| 429 | 8); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 430 | if (IDVal == ".literal16") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 431 | return ParseDirectiveSectionSwitch("__TEXT","__literal16", |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 432 | MCSectionMachO::S_16BYTE_LITERALS, |
| 433 | 16); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 434 | if (IDVal == ".constructor") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 435 | return ParseDirectiveSectionSwitch("__TEXT","__constructor"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 436 | if (IDVal == ".destructor") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 437 | return ParseDirectiveSectionSwitch("__TEXT","__destructor"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 438 | if (IDVal == ".fvmlib_init0") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 439 | return ParseDirectiveSectionSwitch("__TEXT","__fvmlib_init0"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 440 | if (IDVal == ".fvmlib_init1") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 441 | return ParseDirectiveSectionSwitch("__TEXT","__fvmlib_init1"); |
| 442 | |
| 443 | // FIXME: The assembler manual claims that this has the self modify code |
| 444 | // flag, at least on x86-32, but that does not appear to be correct. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 445 | if (IDVal == ".symbol_stub") |
| 446 | return ParseDirectiveSectionSwitch("__TEXT","__symbol_stub", |
| 447 | MCSectionMachO::S_SYMBOL_STUBS | |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 448 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 449 | // FIXME: Different on PPC and ARM. |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 450 | 0, 16); |
| 451 | // FIXME: PowerPC only? |
| 452 | if (IDVal == ".picsymbol_stub") |
| 453 | return ParseDirectiveSectionSwitch("__TEXT","__picsymbol_stub", |
| 454 | MCSectionMachO::S_SYMBOL_STUBS | |
| 455 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 456 | 0, 26); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 457 | if (IDVal == ".data") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 458 | return ParseDirectiveSectionSwitch("__DATA", "__data"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 459 | if (IDVal == ".static_data") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 460 | return ParseDirectiveSectionSwitch("__DATA", "__static_data"); |
| 461 | |
| 462 | // FIXME: The section names of these two are misspelled in the assembler |
| 463 | // manual. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 464 | if (IDVal == ".non_lazy_symbol_pointer") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 465 | return ParseDirectiveSectionSwitch("__DATA", "__nl_symbol_ptr", |
| 466 | MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, |
| 467 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 468 | if (IDVal == ".lazy_symbol_pointer") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 469 | return ParseDirectiveSectionSwitch("__DATA", "__la_symbol_ptr", |
| 470 | MCSectionMachO::S_LAZY_SYMBOL_POINTERS, |
| 471 | 4); |
| 472 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 473 | if (IDVal == ".dyld") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 474 | return ParseDirectiveSectionSwitch("__DATA", "__dyld"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 475 | if (IDVal == ".mod_init_func") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 476 | return ParseDirectiveSectionSwitch("__DATA", "__mod_init_func", |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 477 | MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, |
| 478 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 479 | if (IDVal == ".mod_term_func") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 480 | return ParseDirectiveSectionSwitch("__DATA", "__mod_term_func", |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 481 | MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, |
| 482 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 483 | if (IDVal == ".const_data") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 484 | return ParseDirectiveSectionSwitch("__DATA", "__const"); |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 485 | |
| 486 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 487 | if (IDVal == ".objc_class") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 488 | return ParseDirectiveSectionSwitch("__OBJC", "__class", |
| 489 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 490 | if (IDVal == ".objc_meta_class") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 491 | return ParseDirectiveSectionSwitch("__OBJC", "__meta_class", |
| 492 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 493 | if (IDVal == ".objc_cat_cls_meth") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 494 | return ParseDirectiveSectionSwitch("__OBJC", "__cat_cls_meth", |
| 495 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 496 | if (IDVal == ".objc_cat_inst_meth") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 497 | return ParseDirectiveSectionSwitch("__OBJC", "__cat_inst_meth", |
| 498 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 499 | if (IDVal == ".objc_protocol") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 500 | return ParseDirectiveSectionSwitch("__OBJC", "__protocol", |
| 501 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 502 | if (IDVal == ".objc_string_object") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 503 | return ParseDirectiveSectionSwitch("__OBJC", "__string_object", |
| 504 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 505 | if (IDVal == ".objc_cls_meth") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 506 | return ParseDirectiveSectionSwitch("__OBJC", "__cls_meth", |
| 507 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 508 | if (IDVal == ".objc_inst_meth") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 509 | return ParseDirectiveSectionSwitch("__OBJC", "__inst_meth", |
| 510 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 511 | if (IDVal == ".objc_cls_refs") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 512 | return ParseDirectiveSectionSwitch("__OBJC", "__cls_refs", |
| 513 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP | |
| 514 | MCSectionMachO::S_LITERAL_POINTERS, |
| 515 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 516 | if (IDVal == ".objc_message_refs") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 517 | return ParseDirectiveSectionSwitch("__OBJC", "__message_refs", |
| 518 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP | |
| 519 | MCSectionMachO::S_LITERAL_POINTERS, |
| 520 | 4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 521 | if (IDVal == ".objc_symbols") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 522 | return ParseDirectiveSectionSwitch("__OBJC", "__symbols", |
| 523 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 524 | if (IDVal == ".objc_category") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 525 | return ParseDirectiveSectionSwitch("__OBJC", "__category", |
| 526 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 527 | if (IDVal == ".objc_class_vars") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 528 | return ParseDirectiveSectionSwitch("__OBJC", "__class_vars", |
| 529 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 530 | if (IDVal == ".objc_instance_vars") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 531 | return ParseDirectiveSectionSwitch("__OBJC", "__instance_vars", |
| 532 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 533 | if (IDVal == ".objc_module_info") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 534 | return ParseDirectiveSectionSwitch("__OBJC", "__module_info", |
| 535 | MCSectionMachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 536 | if (IDVal == ".objc_class_names") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 537 | return ParseDirectiveSectionSwitch("__TEXT", "__cstring", |
| 538 | MCSectionMachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 539 | if (IDVal == ".objc_meth_var_types") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 540 | return ParseDirectiveSectionSwitch("__TEXT", "__cstring", |
| 541 | MCSectionMachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 542 | if (IDVal == ".objc_meth_var_names") |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 543 | return ParseDirectiveSectionSwitch("__TEXT", "__cstring", |
| 544 | MCSectionMachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 545 | if (IDVal == ".objc_selector_strs") |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 546 | return ParseDirectiveSectionSwitch("__OBJC", "__selector_strs", |
| 547 | MCSectionMachO::S_CSTRING_LITERALS); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 548 | |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 549 | // Assembler features |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 550 | if (IDVal == ".set") |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 551 | return ParseDirectiveSet(); |
| 552 | |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 553 | // Data directives |
| 554 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 555 | if (IDVal == ".ascii") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 556 | return ParseDirectiveAscii(false); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 557 | if (IDVal == ".asciz") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 558 | return ParseDirectiveAscii(true); |
| 559 | |
| 560 | // FIXME: Target hooks for size? Also for "word", "hword". |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 561 | if (IDVal == ".byte") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 562 | return ParseDirectiveValue(1); |
Daniel Dunbar | 1e840b2 | 2009-08-11 04:44:00 +0000 | [diff] [blame] | 563 | if (IDVal == ".short" || IDVal == ".word") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 564 | return ParseDirectiveValue(2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 565 | if (IDVal == ".long") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 566 | return ParseDirectiveValue(4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 567 | if (IDVal == ".quad") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 568 | return ParseDirectiveValue(8); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 569 | |
| 570 | // FIXME: Target hooks for IsPow2. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 571 | if (IDVal == ".align") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 572 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 573 | if (IDVal == ".align32") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 574 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 575 | if (IDVal == ".balign") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 576 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 577 | if (IDVal == ".balignw") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 578 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 579 | if (IDVal == ".balignl") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 580 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 581 | if (IDVal == ".p2align") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 582 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 583 | if (IDVal == ".p2alignw") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 584 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 585 | if (IDVal == ".p2alignl") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 586 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); |
| 587 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 588 | if (IDVal == ".org") |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 589 | return ParseDirectiveOrg(); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 590 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 591 | if (IDVal == ".fill") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 592 | return ParseDirectiveFill(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 593 | if (IDVal == ".space") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 594 | return ParseDirectiveSpace(); |
| 595 | |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 596 | // Symbol attribute directives |
Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 597 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 598 | if (IDVal == ".globl" || IDVal == ".global") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 599 | return ParseDirectiveSymbolAttribute(MCStreamer::Global); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 600 | if (IDVal == ".hidden") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 601 | return ParseDirectiveSymbolAttribute(MCStreamer::Hidden); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 602 | if (IDVal == ".indirect_symbol") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 603 | return ParseDirectiveSymbolAttribute(MCStreamer::IndirectSymbol); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 604 | if (IDVal == ".internal") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 605 | return ParseDirectiveSymbolAttribute(MCStreamer::Internal); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 606 | if (IDVal == ".lazy_reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 607 | return ParseDirectiveSymbolAttribute(MCStreamer::LazyReference); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 608 | if (IDVal == ".no_dead_strip") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 609 | return ParseDirectiveSymbolAttribute(MCStreamer::NoDeadStrip); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 610 | if (IDVal == ".private_extern") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 611 | return ParseDirectiveSymbolAttribute(MCStreamer::PrivateExtern); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 612 | if (IDVal == ".protected") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 613 | return ParseDirectiveSymbolAttribute(MCStreamer::Protected); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 614 | if (IDVal == ".reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 615 | return ParseDirectiveSymbolAttribute(MCStreamer::Reference); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 616 | if (IDVal == ".weak") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 617 | return ParseDirectiveSymbolAttribute(MCStreamer::Weak); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 618 | if (IDVal == ".weak_definition") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 619 | return ParseDirectiveSymbolAttribute(MCStreamer::WeakDefinition); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 620 | if (IDVal == ".weak_reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 621 | return ParseDirectiveSymbolAttribute(MCStreamer::WeakReference); |
| 622 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 623 | if (IDVal == ".comm") |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 624 | return ParseDirectiveComm(/*IsLocal=*/false); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 625 | if (IDVal == ".lcomm") |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 626 | return ParseDirectiveComm(/*IsLocal=*/true); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 627 | if (IDVal == ".zerofill") |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 628 | return ParseDirectiveDarwinZerofill(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 629 | if (IDVal == ".desc") |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 630 | return ParseDirectiveDarwinSymbolDesc(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 631 | if (IDVal == ".lsym") |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 632 | return ParseDirectiveDarwinLsym(); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 633 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 634 | if (IDVal == ".subsections_via_symbols") |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 635 | return ParseDirectiveDarwinSubsectionsViaSymbols(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 636 | if (IDVal == ".abort") |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 637 | return ParseDirectiveAbort(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 638 | if (IDVal == ".include") |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 639 | return ParseDirectiveInclude(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 640 | if (IDVal == ".dump") |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 641 | return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsDump=*/true); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 642 | if (IDVal == ".load") |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 643 | return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 644 | |
Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 645 | // Debugging directives |
| 646 | |
| 647 | if (IDVal == ".file") |
| 648 | return ParseDirectiveFile(IDLoc); |
| 649 | if (IDVal == ".line") |
| 650 | return ParseDirectiveLine(IDLoc); |
| 651 | if (IDVal == ".loc") |
| 652 | return ParseDirectiveLoc(IDLoc); |
| 653 | |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 654 | Warning(IDLoc, "ignoring directive for now"); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 655 | EatToEndOfStatement(); |
| 656 | return false; |
| 657 | } |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 658 | |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 659 | MCInst Inst; |
Daniel Dunbar | 16cdcb3 | 2009-07-28 22:40:46 +0000 | [diff] [blame] | 660 | if (getTargetParser().ParseInstruction(IDVal, Inst)) |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 661 | return true; |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 662 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 663 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 664 | return TokError("unexpected token in argument list"); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 665 | |
| 666 | // Eat the end of statement marker. |
| 667 | Lexer.Lex(); |
| 668 | |
| 669 | // Instruction is good, process it. |
Daniel Dunbar | 0eebb05 | 2009-07-01 06:35:48 +0000 | [diff] [blame] | 670 | Out.EmitInstruction(Inst); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 671 | |
| 672 | // Skip to end of line for now. |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 673 | return false; |
| 674 | } |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 675 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 676 | bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) { |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 677 | // FIXME: Use better location, we should use proper tokens. |
| 678 | SMLoc EqualLoc = Lexer.getLoc(); |
| 679 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 680 | MCValue Value; |
| 681 | if (ParseRelocatableExpression(Value)) |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 682 | return true; |
| 683 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 684 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 685 | return TokError("unexpected token in assignment"); |
| 686 | |
| 687 | // Eat the end of statement marker. |
| 688 | Lexer.Lex(); |
| 689 | |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 690 | // Diagnose assignment to a label. |
| 691 | // |
| 692 | // FIXME: Diagnostics. Note the location of the definition as a label. |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 693 | // FIXME: Handle '.'. |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 694 | // FIXME: Diagnose assignment to protected identifier (e.g., register name). |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 695 | MCSymbol *Sym = CreateSymbol(Name); |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 696 | if (!Sym->isUndefined() && !Sym->isAbsolute()) |
| 697 | return Error(EqualLoc, "symbol has already been defined"); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 698 | |
| 699 | // Do the assignment. |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 700 | Out.EmitAssignment(Sym, Value, IsDotSet); |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 701 | |
| 702 | return false; |
| 703 | } |
| 704 | |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 705 | /// ParseIdentifier: |
| 706 | /// ::= identifier |
| 707 | /// ::= string |
| 708 | bool AsmParser::ParseIdentifier(StringRef &Res) { |
| 709 | if (Lexer.isNot(AsmToken::Identifier) && |
| 710 | Lexer.isNot(AsmToken::String)) |
| 711 | return true; |
| 712 | |
| 713 | Res = Lexer.getTok().getIdentifier(); |
| 714 | |
| 715 | Lexer.Lex(); // Consume the identifier token. |
| 716 | |
| 717 | return false; |
| 718 | } |
| 719 | |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 720 | /// ParseDirectiveSet: |
| 721 | /// ::= .set identifier ',' expression |
| 722 | bool AsmParser::ParseDirectiveSet() { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 723 | StringRef Name; |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 724 | |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 725 | if (ParseIdentifier(Name)) |
| 726 | return TokError("expected identifier after '.set' directive"); |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 727 | |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 728 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 729 | return TokError("unexpected token in '.set'"); |
| 730 | Lexer.Lex(); |
| 731 | |
| 732 | return ParseAssignment(Name, true); |
| 733 | } |
| 734 | |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 735 | /// ParseDirectiveSection: |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 736 | /// ::= .section identifier (',' identifier)* |
| 737 | /// FIXME: This should actually parse out the segment, section, attributes and |
| 738 | /// sizeof_stub fields. |
| 739 | bool AsmParser::ParseDirectiveDarwinSection() { |
Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 740 | SMLoc Loc = Lexer.getLoc(); |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 741 | |
Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 742 | StringRef SectionName; |
| 743 | if (ParseIdentifier(SectionName)) |
| 744 | return Error(Loc, "expected identifier after '.section' directive"); |
| 745 | |
| 746 | // Verify there is a following comma. |
| 747 | if (!Lexer.is(AsmToken::Comma)) |
| 748 | return TokError("unexpected token in '.section' directive"); |
| 749 | |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 750 | std::string SectionSpec = SectionName; |
Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 751 | SectionSpec += ","; |
| 752 | |
| 753 | // Add all the tokens until the end of the line, ParseSectionSpecifier will |
| 754 | // handle this. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 755 | StringRef EOL = Lexer.LexUntilEndOfStatement(); |
| 756 | SectionSpec.append(EOL.begin(), EOL.end()); |
Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 757 | |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 758 | Lexer.Lex(); |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 759 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 760 | return TokError("unexpected token in '.section' directive"); |
| 761 | Lexer.Lex(); |
| 762 | |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 763 | |
| 764 | StringRef Segment, Section; |
| 765 | unsigned TAA, StubSize; |
| 766 | std::string ErrorStr = |
| 767 | MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section, |
| 768 | TAA, StubSize); |
| 769 | |
| 770 | if (!ErrorStr.empty()) |
Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 771 | return Error(Loc, ErrorStr.c_str()); |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 772 | |
| 773 | // FIXME: CACHE THESE. |
| 774 | |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 775 | // FIXME: Arch specific. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 776 | MCSection *S = 0; //Ctx.GetSection(Section); |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 777 | if (S == 0) |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 778 | S = MCSectionMachO::Create(Segment, Section, TAA, StubSize, |
| 779 | SectionKind(), Ctx); |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 780 | |
| 781 | Out.SwitchSection(S); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 782 | return false; |
| 783 | } |
| 784 | |
Chris Lattner | e15c2d7 | 2009-08-10 18:05:55 +0000 | [diff] [blame] | 785 | /// ParseDirectiveSectionSwitch - |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 786 | bool AsmParser::ParseDirectiveSectionSwitch(const char *Segment, |
| 787 | const char *Section, |
Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 788 | unsigned TAA, unsigned Align, |
| 789 | unsigned StubSize) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 790 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 791 | return TokError("unexpected token in section switching directive"); |
| 792 | Lexer.Lex(); |
| 793 | |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 794 | // FIXME: Arch specific. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 795 | // FIXME: Cache this! |
| 796 | MCSection *S = 0; // Ctx.GetSection(Section); |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 797 | if (S == 0) |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 798 | S = MCSectionMachO::Create(Segment, Section, TAA, StubSize, |
| 799 | SectionKind(), Ctx); |
Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 800 | |
| 801 | Out.SwitchSection(S); |
Daniel Dunbar | 2330df6 | 2009-08-21 23:30:15 +0000 | [diff] [blame] | 802 | |
| 803 | // Set the implicit alignment, if any. |
| 804 | // |
| 805 | // FIXME: This isn't really what 'as' does; I think it just uses the implicit |
| 806 | // alignment on the section (e.g., if one manually inserts bytes into the |
| 807 | // section, then just issueing the section switch directive will not realign |
| 808 | // the section. However, this is arguably more reasonable behavior, and there |
| 809 | // is no good reason for someone to intentionally emit incorrectly sized |
| 810 | // values into the implicitly aligned sections. |
| 811 | if (Align) |
| 812 | Out.EmitValueToAlignment(Align, 0, 1, 0); |
| 813 | |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 814 | return false; |
| 815 | } |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 816 | |
Daniel Dunbar | 1ab7594 | 2009-08-14 18:19:52 +0000 | [diff] [blame] | 817 | bool AsmParser::ParseEscapedString(std::string &Data) { |
| 818 | assert(Lexer.is(AsmToken::String) && "Unexpected current token!"); |
| 819 | |
| 820 | Data = ""; |
| 821 | StringRef Str = Lexer.getTok().getStringContents(); |
| 822 | for (unsigned i = 0, e = Str.size(); i != e; ++i) { |
| 823 | if (Str[i] != '\\') { |
| 824 | Data += Str[i]; |
| 825 | continue; |
| 826 | } |
| 827 | |
| 828 | // Recognize escaped characters. Note that this escape semantics currently |
| 829 | // loosely follows Darwin 'as'. Notably, it doesn't support hex escapes. |
| 830 | ++i; |
| 831 | if (i == e) |
| 832 | return TokError("unexpected backslash at end of string"); |
| 833 | |
| 834 | // Recognize octal sequences. |
| 835 | if ((unsigned) (Str[i] - '0') <= 7) { |
| 836 | // Consume up to three octal characters. |
| 837 | unsigned Value = Str[i] - '0'; |
| 838 | |
| 839 | if (i + 1 != e && ((unsigned) (Str[i + 1] - '0')) <= 7) { |
| 840 | ++i; |
| 841 | Value = Value * 8 + (Str[i] - '0'); |
| 842 | |
| 843 | if (i + 1 != e && ((unsigned) (Str[i + 1] - '0')) <= 7) { |
| 844 | ++i; |
| 845 | Value = Value * 8 + (Str[i] - '0'); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | if (Value > 255) |
| 850 | return TokError("invalid octal escape sequence (out of range)"); |
| 851 | |
| 852 | Data += (unsigned char) Value; |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | // Otherwise recognize individual escapes. |
| 857 | switch (Str[i]) { |
| 858 | default: |
| 859 | // Just reject invalid escape sequences for now. |
| 860 | return TokError("invalid escape sequence (unrecognized character)"); |
| 861 | |
| 862 | case 'b': Data += '\b'; break; |
| 863 | case 'f': Data += '\f'; break; |
| 864 | case 'n': Data += '\n'; break; |
| 865 | case 'r': Data += '\r'; break; |
| 866 | case 't': Data += '\t'; break; |
| 867 | case '"': Data += '"'; break; |
| 868 | case '\\': Data += '\\'; break; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | return false; |
| 873 | } |
| 874 | |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 875 | /// ParseDirectiveAscii: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 876 | /// ::= ( .ascii | .asciz ) [ "string" ( , "string" )* ] |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 877 | bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 878 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 879 | for (;;) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 880 | if (Lexer.isNot(AsmToken::String)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 881 | return TokError("expected string in '.ascii' or '.asciz' directive"); |
| 882 | |
Daniel Dunbar | 1ab7594 | 2009-08-14 18:19:52 +0000 | [diff] [blame] | 883 | std::string Data; |
| 884 | if (ParseEscapedString(Data)) |
| 885 | return true; |
| 886 | |
| 887 | Out.EmitBytes(Data); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 888 | if (ZeroTerminated) |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 889 | Out.EmitBytes(StringRef("\0", 1)); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 890 | |
| 891 | Lexer.Lex(); |
| 892 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 893 | if (Lexer.is(AsmToken::EndOfStatement)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 894 | break; |
| 895 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 896 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 897 | return TokError("unexpected token in '.ascii' or '.asciz' directive"); |
| 898 | Lexer.Lex(); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | Lexer.Lex(); |
| 903 | return false; |
| 904 | } |
| 905 | |
| 906 | /// ParseDirectiveValue |
| 907 | /// ::= (.byte | .short | ... ) [ expression (, expression)* ] |
| 908 | bool AsmParser::ParseDirectiveValue(unsigned Size) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 909 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 910 | for (;;) { |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 911 | MCValue Expr; |
| 912 | if (ParseRelocatableExpression(Expr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 913 | return true; |
| 914 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 915 | Out.EmitValue(Expr, Size); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 916 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 917 | if (Lexer.is(AsmToken::EndOfStatement)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | // FIXME: Improve diagnostic. |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 921 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 922 | return TokError("unexpected token in directive"); |
| 923 | Lexer.Lex(); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | Lexer.Lex(); |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | /// ParseDirectiveSpace |
| 932 | /// ::= .space expression [ , expression ] |
| 933 | bool AsmParser::ParseDirectiveSpace() { |
| 934 | int64_t NumBytes; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 935 | if (ParseAbsoluteExpression(NumBytes)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 936 | return true; |
| 937 | |
| 938 | int64_t FillExpr = 0; |
| 939 | bool HasFillExpr = false; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 940 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 941 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 942 | return TokError("unexpected token in '.space' directive"); |
| 943 | Lexer.Lex(); |
| 944 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 945 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 946 | return true; |
| 947 | |
| 948 | HasFillExpr = true; |
| 949 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 950 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 951 | return TokError("unexpected token in '.space' directive"); |
| 952 | } |
| 953 | |
| 954 | Lexer.Lex(); |
| 955 | |
| 956 | if (NumBytes <= 0) |
| 957 | return TokError("invalid number of bytes in '.space' directive"); |
| 958 | |
| 959 | // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0. |
| 960 | for (uint64_t i = 0, e = NumBytes; i != e; ++i) |
| 961 | Out.EmitValue(MCValue::get(FillExpr), 1); |
| 962 | |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | /// ParseDirectiveFill |
| 967 | /// ::= .fill expression , expression , expression |
| 968 | bool AsmParser::ParseDirectiveFill() { |
| 969 | int64_t NumValues; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 970 | if (ParseAbsoluteExpression(NumValues)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 971 | return true; |
| 972 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 973 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 974 | return TokError("unexpected token in '.fill' directive"); |
| 975 | Lexer.Lex(); |
| 976 | |
| 977 | int64_t FillSize; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 978 | if (ParseAbsoluteExpression(FillSize)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 979 | return true; |
| 980 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 981 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 982 | return TokError("unexpected token in '.fill' directive"); |
| 983 | Lexer.Lex(); |
| 984 | |
| 985 | int64_t FillExpr; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 986 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 987 | return true; |
| 988 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 989 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 990 | return TokError("unexpected token in '.fill' directive"); |
| 991 | |
| 992 | Lexer.Lex(); |
| 993 | |
Daniel Dunbar | bc38ca7 | 2009-08-21 15:43:35 +0000 | [diff] [blame] | 994 | if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8) |
| 995 | return TokError("invalid '.fill' size, expected 1, 2, 4, or 8"); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 996 | |
| 997 | for (uint64_t i = 0, e = NumValues; i != e; ++i) |
| 998 | Out.EmitValue(MCValue::get(FillExpr), FillSize); |
| 999 | |
| 1000 | return false; |
| 1001 | } |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1002 | |
| 1003 | /// ParseDirectiveOrg |
| 1004 | /// ::= .org expression [ , expression ] |
| 1005 | bool AsmParser::ParseDirectiveOrg() { |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 1006 | MCValue Offset; |
| 1007 | if (ParseRelocatableExpression(Offset)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1008 | return true; |
| 1009 | |
| 1010 | // Parse optional fill expression. |
| 1011 | int64_t FillExpr = 0; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1012 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1013 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1014 | return TokError("unexpected token in '.org' directive"); |
| 1015 | Lexer.Lex(); |
| 1016 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1017 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1018 | return true; |
| 1019 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1020 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1021 | return TokError("unexpected token in '.org' directive"); |
| 1022 | } |
| 1023 | |
| 1024 | Lexer.Lex(); |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 1025 | |
| 1026 | // FIXME: Only limited forms of relocatable expressions are accepted here, it |
| 1027 | // has to be relative to the current section. |
| 1028 | Out.EmitValueToOffset(Offset, FillExpr); |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1029 | |
| 1030 | return false; |
| 1031 | } |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1032 | |
| 1033 | /// ParseDirectiveAlign |
| 1034 | /// ::= {.align, ...} expression [ , expression [ , expression ]] |
| 1035 | bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { |
Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1036 | SMLoc AlignmentLoc = Lexer.getLoc(); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1037 | int64_t Alignment; |
| 1038 | if (ParseAbsoluteExpression(Alignment)) |
| 1039 | return true; |
| 1040 | |
| 1041 | SMLoc MaxBytesLoc; |
| 1042 | bool HasFillExpr = false; |
| 1043 | int64_t FillExpr = 0; |
| 1044 | int64_t MaxBytesToFill = 0; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1045 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1046 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1047 | return TokError("unexpected token in directive"); |
| 1048 | Lexer.Lex(); |
| 1049 | |
| 1050 | // The fill expression can be omitted while specifying a maximum number of |
| 1051 | // alignment bytes, e.g: |
| 1052 | // .align 3,,4 |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1053 | if (Lexer.isNot(AsmToken::Comma)) { |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1054 | HasFillExpr = true; |
| 1055 | if (ParseAbsoluteExpression(FillExpr)) |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1059 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1060 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1061 | return TokError("unexpected token in directive"); |
| 1062 | Lexer.Lex(); |
| 1063 | |
| 1064 | MaxBytesLoc = Lexer.getLoc(); |
| 1065 | if (ParseAbsoluteExpression(MaxBytesToFill)) |
| 1066 | return true; |
| 1067 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1068 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1069 | return TokError("unexpected token in directive"); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | Lexer.Lex(); |
| 1074 | |
| 1075 | if (!HasFillExpr) { |
| 1076 | // FIXME: Sometimes fill with nop. |
| 1077 | FillExpr = 0; |
| 1078 | } |
| 1079 | |
| 1080 | // Compute alignment in bytes. |
| 1081 | if (IsPow2) { |
| 1082 | // FIXME: Diagnose overflow. |
Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1083 | if (Alignment >= 32) { |
| 1084 | Error(AlignmentLoc, "invalid alignment value"); |
| 1085 | Alignment = 31; |
| 1086 | } |
| 1087 | |
| 1088 | Alignment = 1 << Alignment; |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1091 | // Diagnose non-sensical max bytes to align. |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1092 | if (MaxBytesLoc.isValid()) { |
| 1093 | if (MaxBytesToFill < 1) { |
Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1094 | Error(MaxBytesLoc, "alignment directive can never be satisfied in this " |
| 1095 | "many bytes, ignoring maximum bytes expression"); |
Daniel Dunbar | 0afb9f5 | 2009-08-21 23:01:53 +0000 | [diff] [blame] | 1096 | MaxBytesToFill = 0; |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | if (MaxBytesToFill >= Alignment) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 1100 | Warning(MaxBytesLoc, "maximum bytes expression exceeds alignment and " |
| 1101 | "has no effect"); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1102 | MaxBytesToFill = 0; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | // FIXME: Target specific behavior about how the "extra" bytes are filled. |
| 1107 | Out.EmitValueToAlignment(Alignment, FillExpr, ValueSize, MaxBytesToFill); |
| 1108 | |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1112 | /// ParseDirectiveSymbolAttribute |
| 1113 | /// ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ] |
| 1114 | bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1115 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1116 | for (;;) { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1117 | StringRef Name; |
| 1118 | |
| 1119 | if (ParseIdentifier(Name)) |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1120 | return TokError("expected identifier in directive"); |
| 1121 | |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 1122 | MCSymbol *Sym = CreateSymbol(Name); |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1123 | |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1124 | Out.EmitSymbolAttribute(Sym, Attr); |
| 1125 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1126 | if (Lexer.is(AsmToken::EndOfStatement)) |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1127 | break; |
| 1128 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1129 | if (Lexer.isNot(AsmToken::Comma)) |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1130 | return TokError("unexpected token in directive"); |
| 1131 | Lexer.Lex(); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | Lexer.Lex(); |
| 1136 | return false; |
| 1137 | } |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1138 | |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1139 | /// ParseDirectiveDarwinSymbolDesc |
| 1140 | /// ::= .desc identifier , expression |
| 1141 | bool AsmParser::ParseDirectiveDarwinSymbolDesc() { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1142 | StringRef Name; |
| 1143 | if (ParseIdentifier(Name)) |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1144 | return TokError("expected identifier in directive"); |
| 1145 | |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1146 | // Handle the identifier as the key symbol. |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 1147 | MCSymbol *Sym = CreateSymbol(Name); |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1148 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1149 | if (Lexer.isNot(AsmToken::Comma)) |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1150 | return TokError("unexpected token in '.desc' directive"); |
| 1151 | Lexer.Lex(); |
| 1152 | |
| 1153 | SMLoc DescLoc = Lexer.getLoc(); |
| 1154 | int64_t DescValue; |
| 1155 | if (ParseAbsoluteExpression(DescValue)) |
| 1156 | return true; |
| 1157 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1158 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1159 | return TokError("unexpected token in '.desc' directive"); |
| 1160 | |
| 1161 | Lexer.Lex(); |
| 1162 | |
| 1163 | // Set the n_desc field of this Symbol to this DescValue |
| 1164 | Out.EmitSymbolDesc(Sym, DescValue); |
| 1165 | |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1169 | /// ParseDirectiveComm |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1170 | /// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ] |
| 1171 | bool AsmParser::ParseDirectiveComm(bool IsLocal) { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1172 | SMLoc IDLoc = Lexer.getLoc(); |
| 1173 | StringRef Name; |
| 1174 | if (ParseIdentifier(Name)) |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1175 | return TokError("expected identifier in directive"); |
| 1176 | |
Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 1177 | // Handle the identifier as the key symbol. |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 1178 | MCSymbol *Sym = CreateSymbol(Name); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1179 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1180 | if (Lexer.isNot(AsmToken::Comma)) |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1181 | return TokError("unexpected token in directive"); |
| 1182 | Lexer.Lex(); |
| 1183 | |
| 1184 | int64_t Size; |
| 1185 | SMLoc SizeLoc = Lexer.getLoc(); |
| 1186 | if (ParseAbsoluteExpression(Size)) |
| 1187 | return true; |
| 1188 | |
| 1189 | int64_t Pow2Alignment = 0; |
| 1190 | SMLoc Pow2AlignmentLoc; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1191 | if (Lexer.is(AsmToken::Comma)) { |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1192 | Lexer.Lex(); |
| 1193 | Pow2AlignmentLoc = Lexer.getLoc(); |
| 1194 | if (ParseAbsoluteExpression(Pow2Alignment)) |
| 1195 | return true; |
| 1196 | } |
| 1197 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1198 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1199 | return TokError("unexpected token in '.comm' or '.lcomm' directive"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1200 | |
| 1201 | Lexer.Lex(); |
| 1202 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1203 | // NOTE: a size of zero for a .comm should create a undefined symbol |
| 1204 | // but a size of .lcomm creates a bss symbol of size zero. |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1205 | if (Size < 0) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1206 | return Error(SizeLoc, "invalid '.comm' or '.lcomm' directive size, can't " |
| 1207 | "be less than zero"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1208 | |
| 1209 | // NOTE: The alignment in the directive is a power of 2 value, the assember |
| 1210 | // may internally end up wanting an alignment in bytes. |
| 1211 | // FIXME: Diagnose overflow. |
| 1212 | if (Pow2Alignment < 0) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1213 | return Error(Pow2AlignmentLoc, "invalid '.comm' or '.lcomm' directive " |
| 1214 | "alignment, can't be less than zero"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1215 | |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 1216 | if (!Sym->isUndefined()) |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1217 | return Error(IDLoc, "invalid symbol redefinition"); |
| 1218 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1219 | // Create the Symbol as a common or local common with Size and Pow2Alignment |
| 1220 | Out.EmitCommonSymbol(Sym, Size, Pow2Alignment, IsLocal); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1221 | |
| 1222 | return false; |
| 1223 | } |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1224 | |
| 1225 | /// ParseDirectiveDarwinZerofill |
| 1226 | /// ::= .zerofill segname , sectname [, identifier , size_expression [ |
| 1227 | /// , align_expression ]] |
| 1228 | bool AsmParser::ParseDirectiveDarwinZerofill() { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1229 | // FIXME: Handle quoted names here. |
| 1230 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1231 | if (Lexer.isNot(AsmToken::Identifier)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1232 | return TokError("expected segment name after '.zerofill' directive"); |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1233 | StringRef Segment = Lexer.getTok().getString(); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1234 | Lexer.Lex(); |
| 1235 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1236 | if (Lexer.isNot(AsmToken::Comma)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1237 | return TokError("unexpected token in directive"); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1238 | Lexer.Lex(); |
| 1239 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1240 | if (Lexer.isNot(AsmToken::Identifier)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1241 | return TokError("expected section name after comma in '.zerofill' " |
| 1242 | "directive"); |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1243 | StringRef Section = Lexer.getTok().getString(); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1244 | Lexer.Lex(); |
| 1245 | |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1246 | // If this is the end of the line all that was wanted was to create the |
| 1247 | // the section but with no symbol. |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1248 | if (Lexer.is(AsmToken::EndOfStatement)) { |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1249 | // FIXME: CACHE THIS. |
| 1250 | MCSection *S = 0; //Ctx.GetSection(Section); |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1251 | if (S == 0) |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1252 | S = MCSectionMachO::Create(Segment, Section, |
| 1253 | MCSectionMachO::S_ZEROFILL, 0, |
| 1254 | SectionKind(), Ctx); |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1255 | |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1256 | // Create the zerofill section but no symbol |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1257 | Out.EmitZerofill(S); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1258 | return false; |
| 1259 | } |
| 1260 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1261 | if (Lexer.isNot(AsmToken::Comma)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1262 | return TokError("unexpected token in directive"); |
| 1263 | Lexer.Lex(); |
| 1264 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1265 | if (Lexer.isNot(AsmToken::Identifier)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1266 | return TokError("expected identifier in directive"); |
| 1267 | |
| 1268 | // handle the identifier as the key symbol. |
| 1269 | SMLoc IDLoc = Lexer.getLoc(); |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 1270 | MCSymbol *Sym = CreateSymbol(Lexer.getTok().getString()); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1271 | Lexer.Lex(); |
| 1272 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1273 | if (Lexer.isNot(AsmToken::Comma)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1274 | return TokError("unexpected token in directive"); |
| 1275 | Lexer.Lex(); |
| 1276 | |
| 1277 | int64_t Size; |
| 1278 | SMLoc SizeLoc = Lexer.getLoc(); |
| 1279 | if (ParseAbsoluteExpression(Size)) |
| 1280 | return true; |
| 1281 | |
| 1282 | int64_t Pow2Alignment = 0; |
| 1283 | SMLoc Pow2AlignmentLoc; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1284 | if (Lexer.is(AsmToken::Comma)) { |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1285 | Lexer.Lex(); |
| 1286 | Pow2AlignmentLoc = Lexer.getLoc(); |
| 1287 | if (ParseAbsoluteExpression(Pow2Alignment)) |
| 1288 | return true; |
| 1289 | } |
| 1290 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1291 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1292 | return TokError("unexpected token in '.zerofill' directive"); |
| 1293 | |
| 1294 | Lexer.Lex(); |
| 1295 | |
| 1296 | if (Size < 0) |
| 1297 | return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " |
| 1298 | "than zero"); |
| 1299 | |
| 1300 | // NOTE: The alignment in the directive is a power of 2 value, the assember |
| 1301 | // may internally end up wanting an alignment in bytes. |
| 1302 | // FIXME: Diagnose overflow. |
| 1303 | if (Pow2Alignment < 0) |
| 1304 | return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " |
| 1305 | "can't be less than zero"); |
| 1306 | |
Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 1307 | if (!Sym->isUndefined()) |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1308 | return Error(IDLoc, "invalid symbol redefinition"); |
| 1309 | |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1310 | // FIXME: Arch specific. |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1311 | // FIXME: CACHE. |
| 1312 | MCSection *S = 0; //Ctx.GetSection(Section); |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1313 | if (S == 0) |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 1314 | S = MCSectionMachO::Create(Segment, Section, |
| 1315 | MCSectionMachO::S_ZEROFILL, 0, |
| 1316 | SectionKind(), Ctx); |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1317 | |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1318 | // Create the zerofill Symbol with Size and Pow2Alignment |
Chris Lattner | 6bdd74c | 2009-07-31 18:27:48 +0000 | [diff] [blame] | 1319 | Out.EmitZerofill(S, Sym, Size, Pow2Alignment); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1320 | |
| 1321 | return false; |
| 1322 | } |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1323 | |
| 1324 | /// ParseDirectiveDarwinSubsectionsViaSymbols |
| 1325 | /// ::= .subsections_via_symbols |
| 1326 | bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1327 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1328 | return TokError("unexpected token in '.subsections_via_symbols' directive"); |
| 1329 | |
| 1330 | Lexer.Lex(); |
| 1331 | |
Kevin Enderby | f96db46 | 2009-07-16 17:56:39 +0000 | [diff] [blame] | 1332 | Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1333 | |
| 1334 | return false; |
| 1335 | } |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1336 | |
| 1337 | /// ParseDirectiveAbort |
| 1338 | /// ::= .abort [ "abort_string" ] |
| 1339 | bool AsmParser::ParseDirectiveAbort() { |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 1340 | // FIXME: Use loc from directive. |
| 1341 | SMLoc Loc = Lexer.getLoc(); |
| 1342 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 1343 | StringRef Str = ""; |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1344 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1345 | if (Lexer.isNot(AsmToken::String)) |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1346 | return TokError("expected string in '.abort' directive"); |
| 1347 | |
Daniel Dunbar | 419aded | 2009-07-28 16:38:40 +0000 | [diff] [blame] | 1348 | Str = Lexer.getTok().getString(); |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1349 | |
| 1350 | Lexer.Lex(); |
| 1351 | } |
| 1352 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1353 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1354 | return TokError("unexpected token in '.abort' directive"); |
| 1355 | |
| 1356 | Lexer.Lex(); |
| 1357 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 1358 | // FIXME: Handle here. |
Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 1359 | if (Str.empty()) |
| 1360 | Error(Loc, ".abort detected. Assembly stopping."); |
| 1361 | else |
| 1362 | Error(Loc, ".abort '" + Str + "' detected. Assembly stopping."); |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1363 | |
| 1364 | return false; |
| 1365 | } |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1366 | |
| 1367 | /// ParseDirectiveLsym |
| 1368 | /// ::= .lsym identifier , expression |
| 1369 | bool AsmParser::ParseDirectiveDarwinLsym() { |
Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1370 | StringRef Name; |
| 1371 | if (ParseIdentifier(Name)) |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1372 | return TokError("expected identifier in directive"); |
| 1373 | |
Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 1374 | // Handle the identifier as the key symbol. |
Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame^] | 1375 | MCSymbol *Sym = CreateSymbol(Name); |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1376 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1377 | if (Lexer.isNot(AsmToken::Comma)) |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1378 | return TokError("unexpected token in '.lsym' directive"); |
| 1379 | Lexer.Lex(); |
| 1380 | |
| 1381 | MCValue Expr; |
| 1382 | if (ParseRelocatableExpression(Expr)) |
| 1383 | return true; |
| 1384 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1385 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1386 | return TokError("unexpected token in '.lsym' directive"); |
| 1387 | |
| 1388 | Lexer.Lex(); |
| 1389 | |
| 1390 | // Create the Sym with the value of the Expr |
| 1391 | Out.EmitLocalSymbol(Sym, Expr); |
| 1392 | |
| 1393 | return false; |
| 1394 | } |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1395 | |
| 1396 | /// ParseDirectiveInclude |
| 1397 | /// ::= .include "filename" |
| 1398 | bool AsmParser::ParseDirectiveInclude() { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1399 | if (Lexer.isNot(AsmToken::String)) |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1400 | return TokError("expected string in '.include' directive"); |
| 1401 | |
Daniel Dunbar | 419aded | 2009-07-28 16:38:40 +0000 | [diff] [blame] | 1402 | std::string Filename = Lexer.getTok().getString(); |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1403 | SMLoc IncludeLoc = Lexer.getLoc(); |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1404 | Lexer.Lex(); |
| 1405 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1406 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1407 | return TokError("unexpected token in '.include' directive"); |
| 1408 | |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1409 | // Strip the quotes. |
| 1410 | Filename = Filename.substr(1, Filename.size()-2); |
| 1411 | |
| 1412 | // Attempt to switch the lexer to the included file before consuming the end |
| 1413 | // of statement to avoid losing it when we switch. |
| 1414 | if (Lexer.EnterIncludeFile(Filename)) { |
| 1415 | Lexer.PrintMessage(IncludeLoc, |
| 1416 | "Could not find include file '" + Filename + "'", |
| 1417 | "error"); |
| 1418 | return true; |
| 1419 | } |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1420 | |
| 1421 | return false; |
| 1422 | } |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1423 | |
| 1424 | /// ParseDirectiveDarwinDumpOrLoad |
| 1425 | /// ::= ( .dump | .load ) "filename" |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1426 | bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1427 | if (Lexer.isNot(AsmToken::String)) |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1428 | return TokError("expected string in '.dump' or '.load' directive"); |
| 1429 | |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1430 | Lexer.Lex(); |
| 1431 | |
Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1432 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1433 | return TokError("unexpected token in '.dump' or '.load' directive"); |
| 1434 | |
| 1435 | Lexer.Lex(); |
| 1436 | |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1437 | // FIXME: If/when .dump and .load are implemented they will be done in the |
| 1438 | // the assembly parser and not have any need for an MCStreamer API. |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1439 | if (IsDump) |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1440 | Warning(IDLoc, "ignoring directive .dump for now"); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1441 | else |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1442 | Warning(IDLoc, "ignoring directive .load for now"); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1443 | |
| 1444 | return false; |
| 1445 | } |
Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1446 | |
| 1447 | /// ParseDirectiveIf |
| 1448 | /// ::= .if expression |
| 1449 | bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) { |
| 1450 | // Consume the identifier that was the .if directive |
| 1451 | Lexer.Lex(); |
| 1452 | |
| 1453 | TheCondStack.push_back(TheCondState); |
| 1454 | TheCondState.TheCond = AsmCond::IfCond; |
| 1455 | if(TheCondState.Ignore) { |
| 1456 | EatToEndOfStatement(); |
| 1457 | } |
| 1458 | else { |
| 1459 | int64_t ExprValue; |
| 1460 | if (ParseAbsoluteExpression(ExprValue)) |
| 1461 | return true; |
| 1462 | |
| 1463 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1464 | return TokError("unexpected token in '.if' directive"); |
| 1465 | |
| 1466 | Lexer.Lex(); |
| 1467 | |
| 1468 | TheCondState.CondMet = ExprValue; |
| 1469 | TheCondState.Ignore = !TheCondState.CondMet; |
| 1470 | } |
| 1471 | |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
| 1475 | /// ParseDirectiveElseIf |
| 1476 | /// ::= .elseif expression |
| 1477 | bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) { |
| 1478 | if (TheCondState.TheCond != AsmCond::IfCond && |
| 1479 | TheCondState.TheCond != AsmCond::ElseIfCond) |
| 1480 | Error(DirectiveLoc, "Encountered a .elseif that doesn't follow a .if or " |
| 1481 | " an .elseif"); |
| 1482 | TheCondState.TheCond = AsmCond::ElseIfCond; |
| 1483 | |
| 1484 | // Consume the identifier that was the .elseif directive |
| 1485 | Lexer.Lex(); |
| 1486 | |
| 1487 | bool LastIgnoreState = false; |
| 1488 | if (!TheCondStack.empty()) |
| 1489 | LastIgnoreState = TheCondStack.back().Ignore; |
| 1490 | if (LastIgnoreState || TheCondState.CondMet) { |
| 1491 | TheCondState.Ignore = true; |
| 1492 | EatToEndOfStatement(); |
| 1493 | } |
| 1494 | else { |
| 1495 | int64_t ExprValue; |
| 1496 | if (ParseAbsoluteExpression(ExprValue)) |
| 1497 | return true; |
| 1498 | |
| 1499 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1500 | return TokError("unexpected token in '.elseif' directive"); |
| 1501 | |
| 1502 | Lexer.Lex(); |
| 1503 | TheCondState.CondMet = ExprValue; |
| 1504 | TheCondState.Ignore = !TheCondState.CondMet; |
| 1505 | } |
| 1506 | |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
| 1510 | /// ParseDirectiveElse |
| 1511 | /// ::= .else |
| 1512 | bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) { |
| 1513 | // Consume the identifier that was the .else directive |
| 1514 | Lexer.Lex(); |
| 1515 | |
| 1516 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1517 | return TokError("unexpected token in '.else' directive"); |
| 1518 | |
| 1519 | Lexer.Lex(); |
| 1520 | |
| 1521 | if (TheCondState.TheCond != AsmCond::IfCond && |
| 1522 | TheCondState.TheCond != AsmCond::ElseIfCond) |
| 1523 | Error(DirectiveLoc, "Encountered a .else that doesn't follow a .if or an " |
| 1524 | ".elseif"); |
| 1525 | TheCondState.TheCond = AsmCond::ElseCond; |
| 1526 | bool LastIgnoreState = false; |
| 1527 | if (!TheCondStack.empty()) |
| 1528 | LastIgnoreState = TheCondStack.back().Ignore; |
| 1529 | if (LastIgnoreState || TheCondState.CondMet) |
| 1530 | TheCondState.Ignore = true; |
| 1531 | else |
| 1532 | TheCondState.Ignore = false; |
| 1533 | |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | /// ParseDirectiveEndIf |
| 1538 | /// ::= .endif |
| 1539 | bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) { |
| 1540 | // Consume the identifier that was the .endif directive |
| 1541 | Lexer.Lex(); |
| 1542 | |
| 1543 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1544 | return TokError("unexpected token in '.endif' directive"); |
| 1545 | |
| 1546 | Lexer.Lex(); |
| 1547 | |
| 1548 | if ((TheCondState.TheCond == AsmCond::NoCond) || |
| 1549 | TheCondStack.empty()) |
| 1550 | Error(DirectiveLoc, "Encountered a .endif that doesn't follow a .if or " |
| 1551 | ".else"); |
| 1552 | if (!TheCondStack.empty()) { |
| 1553 | TheCondState = TheCondStack.back(); |
| 1554 | TheCondStack.pop_back(); |
| 1555 | } |
| 1556 | |
| 1557 | return false; |
| 1558 | } |
Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1559 | |
| 1560 | /// ParseDirectiveFile |
| 1561 | /// ::= .file [number] string |
| 1562 | bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) { |
| 1563 | // FIXME: I'm not sure what this is. |
| 1564 | int64_t FileNumber = -1; |
| 1565 | if (Lexer.is(AsmToken::Integer)) { |
| 1566 | FileNumber = Lexer.getTok().getIntVal(); |
| 1567 | Lexer.Lex(); |
| 1568 | |
| 1569 | if (FileNumber < 1) |
| 1570 | return TokError("file number less than one"); |
| 1571 | } |
| 1572 | |
| 1573 | if (Lexer.isNot(AsmToken::String)) |
| 1574 | return TokError("unexpected token in '.file' directive"); |
| 1575 | |
| 1576 | StringRef FileName = Lexer.getTok().getString(); |
| 1577 | Lexer.Lex(); |
| 1578 | |
| 1579 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1580 | return TokError("unexpected token in '.file' directive"); |
| 1581 | |
| 1582 | // FIXME: Do something with the .file. |
| 1583 | |
| 1584 | return false; |
| 1585 | } |
| 1586 | |
| 1587 | /// ParseDirectiveLine |
| 1588 | /// ::= .line [number] |
| 1589 | bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) { |
| 1590 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1591 | if (Lexer.isNot(AsmToken::Integer)) |
| 1592 | return TokError("unexpected token in '.line' directive"); |
| 1593 | |
| 1594 | int64_t LineNumber = Lexer.getTok().getIntVal(); |
| 1595 | (void) LineNumber; |
| 1596 | Lexer.Lex(); |
| 1597 | |
| 1598 | // FIXME: Do something with the .line. |
| 1599 | } |
| 1600 | |
| 1601 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1602 | return TokError("unexpected token in '.file' directive"); |
| 1603 | |
| 1604 | return false; |
| 1605 | } |
| 1606 | |
| 1607 | |
| 1608 | /// ParseDirectiveLoc |
| 1609 | /// ::= .loc number [number [number]] |
| 1610 | bool AsmParser::ParseDirectiveLoc(SMLoc DirectiveLoc) { |
| 1611 | if (Lexer.isNot(AsmToken::Integer)) |
| 1612 | return TokError("unexpected token in '.loc' directive"); |
| 1613 | |
| 1614 | // FIXME: What are these fields? |
| 1615 | int64_t FileNumber = Lexer.getTok().getIntVal(); |
| 1616 | (void) FileNumber; |
| 1617 | // FIXME: Validate file. |
| 1618 | |
| 1619 | Lexer.Lex(); |
| 1620 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1621 | if (Lexer.isNot(AsmToken::Integer)) |
| 1622 | return TokError("unexpected token in '.loc' directive"); |
| 1623 | |
| 1624 | int64_t Param2 = Lexer.getTok().getIntVal(); |
| 1625 | (void) Param2; |
| 1626 | Lexer.Lex(); |
| 1627 | |
| 1628 | if (Lexer.isNot(AsmToken::EndOfStatement)) { |
| 1629 | if (Lexer.isNot(AsmToken::Integer)) |
| 1630 | return TokError("unexpected token in '.loc' directive"); |
| 1631 | |
| 1632 | int64_t Param3 = Lexer.getTok().getIntVal(); |
| 1633 | (void) Param3; |
| 1634 | Lexer.Lex(); |
| 1635 | |
| 1636 | // FIXME: Do something with the .loc. |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | if (Lexer.isNot(AsmToken::EndOfStatement)) |
| 1641 | return TokError("unexpected token in '.file' directive"); |
| 1642 | |
| 1643 | return false; |
| 1644 | } |
| 1645 | |