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 | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInst.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCStreamer.h" |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 21 | #include "llvm/Support/SourceMgr.h" |
| 22 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetAsmParser.h" |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 26 | void AsmParser::Warning(SMLoc L, const char *Msg) { |
| 27 | Lexer.PrintMessage(L, Msg, "warning"); |
| 28 | } |
| 29 | |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 30 | bool AsmParser::Error(SMLoc L, const char *Msg) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 31 | Lexer.PrintMessage(L, Msg, "error"); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 32 | return true; |
| 33 | } |
| 34 | |
| 35 | bool AsmParser::TokError(const char *Msg) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 36 | Lexer.PrintMessage(Lexer.getLoc(), Msg, "error"); |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 37 | return true; |
| 38 | } |
| 39 | |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 40 | bool AsmParser::Run() { |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 41 | // Prime the lexer. |
| 42 | Lexer.Lex(); |
| 43 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 44 | bool HadError = false; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 45 | |
Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 46 | // While we have input, parse each statement. |
| 47 | while (Lexer.isNot(asmtok::Eof)) { |
| 48 | if (!ParseStatement()) continue; |
| 49 | |
| 50 | // If we had an error, remember it and recover by skipping to the next line. |
| 51 | HadError = true; |
| 52 | EatToEndOfStatement(); |
| 53 | } |
| 54 | |
| 55 | return HadError; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 58 | /// EatToEndOfStatement - Throw away the rest of the line for testing purposes. |
| 59 | void AsmParser::EatToEndOfStatement() { |
| 60 | while (Lexer.isNot(asmtok::EndOfStatement) && |
| 61 | Lexer.isNot(asmtok::Eof)) |
| 62 | Lexer.Lex(); |
| 63 | |
| 64 | // Eat EOL. |
| 65 | if (Lexer.is(asmtok::EndOfStatement)) |
| 66 | Lexer.Lex(); |
| 67 | } |
| 68 | |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 70 | /// ParseParenExpr - Parse a paren expression and return it. |
| 71 | /// NOTE: This assumes the leading '(' has already been consumed. |
| 72 | /// |
| 73 | /// parenexpr ::= expr) |
| 74 | /// |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 75 | bool AsmParser::ParseParenExpr(AsmExpr *&Res) { |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 76 | if (ParseExpression(Res)) return true; |
| 77 | if (Lexer.isNot(asmtok::RParen)) |
| 78 | return TokError("expected ')' in parentheses expression"); |
| 79 | Lexer.Lex(); |
| 80 | return false; |
| 81 | } |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 83 | /// ParsePrimaryExpr - Parse a primary expression and return it. |
| 84 | /// primaryexpr ::= (parenexpr |
| 85 | /// primaryexpr ::= symbol |
| 86 | /// primaryexpr ::= number |
| 87 | /// primaryexpr ::= ~,+,- primaryexpr |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 88 | bool AsmParser::ParsePrimaryExpr(AsmExpr *&Res) { |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 89 | switch (Lexer.getKind()) { |
| 90 | default: |
| 91 | return TokError("unknown token in expression"); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 92 | case asmtok::Exclaim: |
| 93 | Lexer.Lex(); // Eat the operator. |
| 94 | if (ParsePrimaryExpr(Res)) |
| 95 | return true; |
| 96 | Res = new AsmUnaryExpr(AsmUnaryExpr::LNot, Res); |
| 97 | return false; |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 98 | case asmtok::Identifier: { |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 99 | // 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] | 100 | // handle things like LFOO+4. |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 101 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 102 | |
| 103 | // If this is use of an undefined symbol then mark it external. |
| 104 | if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym)) |
| 105 | Sym->setExternal(true); |
| 106 | |
| 107 | Res = new AsmSymbolRefExpr(Sym); |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 108 | Lexer.Lex(); // Eat identifier. |
| 109 | return false; |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 110 | } |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 111 | case asmtok::IntVal: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 112 | Res = new AsmConstantExpr(Lexer.getCurIntVal()); |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 113 | Lexer.Lex(); // Eat identifier. |
| 114 | return false; |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 115 | case asmtok::LParen: |
| 116 | Lexer.Lex(); // Eat the '('. |
| 117 | return ParseParenExpr(Res); |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 118 | case asmtok::Minus: |
| 119 | Lexer.Lex(); // Eat the operator. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 120 | if (ParsePrimaryExpr(Res)) |
| 121 | return true; |
| 122 | Res = new AsmUnaryExpr(AsmUnaryExpr::Minus, Res); |
| 123 | return false; |
| 124 | case asmtok::Plus: |
| 125 | Lexer.Lex(); // Eat the operator. |
| 126 | if (ParsePrimaryExpr(Res)) |
| 127 | return true; |
| 128 | Res = new AsmUnaryExpr(AsmUnaryExpr::Plus, Res); |
| 129 | return false; |
| 130 | case asmtok::Tilde: |
| 131 | Lexer.Lex(); // Eat the operator. |
| 132 | if (ParsePrimaryExpr(Res)) |
| 133 | return true; |
| 134 | Res = new AsmUnaryExpr(AsmUnaryExpr::Not, Res); |
| 135 | return false; |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 138 | |
| 139 | /// ParseExpression - Parse an expression and return it. |
| 140 | /// |
| 141 | /// expr ::= expr +,- expr -> lowest. |
| 142 | /// expr ::= expr |,^,&,! expr -> middle. |
| 143 | /// expr ::= expr *,/,%,<<,>> expr -> highest. |
| 144 | /// expr ::= primaryexpr |
| 145 | /// |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 146 | bool AsmParser::ParseExpression(AsmExpr *&Res) { |
| 147 | Res = 0; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 148 | return ParsePrimaryExpr(Res) || |
| 149 | ParseBinOpRHS(1, Res); |
Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 150 | } |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 151 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 152 | bool AsmParser::ParseAbsoluteExpression(int64_t &Res) { |
| 153 | AsmExpr *Expr; |
| 154 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 155 | SMLoc StartLoc = Lexer.getLoc(); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 156 | if (ParseExpression(Expr)) |
| 157 | return true; |
| 158 | |
| 159 | if (!Expr->EvaluateAsAbsolute(Ctx, Res)) |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 160 | return Error(StartLoc, "expected absolute expression"); |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 161 | |
| 162 | return false; |
| 163 | } |
| 164 | |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 165 | bool AsmParser::ParseRelocatableExpression(MCValue &Res) { |
| 166 | AsmExpr *Expr; |
| 167 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 168 | SMLoc StartLoc = Lexer.getLoc(); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 169 | if (ParseExpression(Expr)) |
| 170 | return true; |
| 171 | |
| 172 | if (!Expr->EvaluateAsRelocatable(Ctx, Res)) |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 173 | return Error(StartLoc, "expected relocatable expression"); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 174 | |
| 175 | return false; |
| 176 | } |
| 177 | |
Daniel Dunbar | 2c3f00c | 2009-07-02 02:09:07 +0000 | [diff] [blame] | 178 | bool AsmParser::ParseParenRelocatableExpression(MCValue &Res) { |
| 179 | AsmExpr *Expr; |
| 180 | |
| 181 | SMLoc StartLoc = Lexer.getLoc(); |
| 182 | if (ParseParenExpr(Expr)) |
| 183 | return true; |
| 184 | |
| 185 | if (!Expr->EvaluateAsRelocatable(Ctx, Res)) |
| 186 | return Error(StartLoc, "expected relocatable expression"); |
| 187 | |
| 188 | return false; |
| 189 | } |
| 190 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 191 | static unsigned getBinOpPrecedence(asmtok::TokKind K, |
| 192 | AsmBinaryExpr::Opcode &Kind) { |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 193 | switch (K) { |
| 194 | default: return 0; // not a binop. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 195 | |
| 196 | // Lowest Precedence: &&, || |
| 197 | case asmtok::AmpAmp: |
| 198 | Kind = AsmBinaryExpr::LAnd; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 199 | return 1; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 200 | case asmtok::PipePipe: |
| 201 | Kind = AsmBinaryExpr::LOr; |
| 202 | return 1; |
| 203 | |
| 204 | // Low Precedence: +, -, ==, !=, <>, <, <=, >, >= |
| 205 | case asmtok::Plus: |
| 206 | Kind = AsmBinaryExpr::Add; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 207 | return 2; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 208 | case asmtok::Minus: |
| 209 | Kind = AsmBinaryExpr::Sub; |
| 210 | return 2; |
| 211 | case asmtok::EqualEqual: |
| 212 | Kind = AsmBinaryExpr::EQ; |
| 213 | return 2; |
| 214 | case asmtok::ExclaimEqual: |
| 215 | case asmtok::LessGreater: |
| 216 | Kind = AsmBinaryExpr::NE; |
| 217 | return 2; |
| 218 | case asmtok::Less: |
| 219 | Kind = AsmBinaryExpr::LT; |
| 220 | return 2; |
| 221 | case asmtok::LessEqual: |
| 222 | Kind = AsmBinaryExpr::LTE; |
| 223 | return 2; |
| 224 | case asmtok::Greater: |
| 225 | Kind = AsmBinaryExpr::GT; |
| 226 | return 2; |
| 227 | case asmtok::GreaterEqual: |
| 228 | Kind = AsmBinaryExpr::GTE; |
| 229 | return 2; |
| 230 | |
| 231 | // Intermediate Precedence: |, &, ^ |
| 232 | // |
| 233 | // FIXME: gas seems to support '!' as an infix operator? |
| 234 | case asmtok::Pipe: |
| 235 | Kind = AsmBinaryExpr::Or; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 236 | return 3; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 237 | case asmtok::Caret: |
| 238 | Kind = AsmBinaryExpr::Xor; |
| 239 | return 3; |
| 240 | case asmtok::Amp: |
| 241 | Kind = AsmBinaryExpr::And; |
| 242 | return 3; |
| 243 | |
| 244 | // Highest Precedence: *, /, %, <<, >> |
| 245 | case asmtok::Star: |
| 246 | Kind = AsmBinaryExpr::Mul; |
| 247 | return 4; |
| 248 | case asmtok::Slash: |
| 249 | Kind = AsmBinaryExpr::Div; |
| 250 | return 4; |
| 251 | case asmtok::Percent: |
| 252 | Kind = AsmBinaryExpr::Mod; |
| 253 | return 4; |
| 254 | case asmtok::LessLess: |
| 255 | Kind = AsmBinaryExpr::Shl; |
| 256 | return 4; |
| 257 | case asmtok::GreaterGreater: |
| 258 | Kind = AsmBinaryExpr::Shr; |
| 259 | return 4; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
| 263 | |
| 264 | /// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'. |
| 265 | /// Res contains the LHS of the expression on input. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 266 | bool AsmParser::ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res) { |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 267 | while (1) { |
Daniel Dunbar | 5133063 | 2009-06-29 21:14:21 +0000 | [diff] [blame] | 268 | AsmBinaryExpr::Opcode Kind = AsmBinaryExpr::Add; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 269 | unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 270 | |
| 271 | // If the next token is lower precedence than we are allowed to eat, return |
| 272 | // successfully with what we ate already. |
| 273 | if (TokPrec < Precedence) |
| 274 | return false; |
| 275 | |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 276 | Lexer.Lex(); |
| 277 | |
| 278 | // Eat the next primary expression. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 279 | AsmExpr *RHS; |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 280 | if (ParsePrimaryExpr(RHS)) return true; |
| 281 | |
| 282 | // If BinOp binds less tightly with RHS than the operator after RHS, let |
| 283 | // the pending operator take RHS as its LHS. |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 284 | AsmBinaryExpr::Opcode Dummy; |
| 285 | unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 286 | if (TokPrec < NextTokPrec) { |
| 287 | if (ParseBinOpRHS(Precedence+1, RHS)) return true; |
| 288 | } |
| 289 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 290 | // Merge LHS and RHS according to operator. |
| 291 | Res = new AsmBinaryExpr(Kind, Res, RHS); |
Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 295 | |
| 296 | |
| 297 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 298 | /// ParseStatement: |
| 299 | /// ::= EndOfStatement |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 300 | /// ::= Label* Directive ...Operands... EndOfStatement |
| 301 | /// ::= Label* Identifier OperandList* EndOfStatement |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 302 | bool AsmParser::ParseStatement() { |
| 303 | switch (Lexer.getKind()) { |
| 304 | default: |
Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 305 | return TokError("unexpected token at start of statement"); |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 306 | case asmtok::EndOfStatement: |
| 307 | Lexer.Lex(); |
| 308 | return false; |
| 309 | case asmtok::Identifier: |
| 310 | break; |
| 311 | // TODO: Recurse on local labels etc. |
| 312 | } |
| 313 | |
| 314 | // If we have an identifier, handle it as the key symbol. |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 315 | SMLoc IDLoc = Lexer.getLoc(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 316 | StringRef IDVal = Lexer.getCurStrVal(); |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 317 | |
| 318 | // Consume the identifier, see what is after it. |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 319 | switch (Lexer.Lex()) { |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 320 | case asmtok::Colon: { |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 321 | // identifier ':' -> Label. |
| 322 | Lexer.Lex(); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 323 | |
| 324 | // Diagnose attempt to use a variable as a label. |
| 325 | // |
| 326 | // FIXME: Diagnostics. Note the location of the definition as a label. |
| 327 | // FIXME: This doesn't diagnose assignment to a symbol which has been |
| 328 | // implicitly marked as external. |
| 329 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(IDVal); |
| 330 | if (Sym->getSection()) |
| 331 | return Error(IDLoc, "invalid symbol redefinition"); |
| 332 | if (Ctx.GetSymbolValue(Sym)) |
| 333 | return Error(IDLoc, "symbol already used as assembler variable"); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 334 | |
| 335 | // Since we saw a label, create a symbol and emit it. |
| 336 | // FIXME: If the label starts with L it is an assembler temporary label. |
| 337 | // Why does the client of this api need to know this? |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 338 | Out.EmitLabel(Sym); |
| 339 | |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 340 | return ParseStatement(); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 341 | } |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 342 | |
| 343 | case asmtok::Equal: |
| 344 | // identifier '=' ... -> assignment statement |
| 345 | Lexer.Lex(); |
| 346 | |
| 347 | return ParseAssignment(IDVal, false); |
| 348 | |
| 349 | default: // Normal instruction or directive. |
| 350 | break; |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | // Otherwise, we have a normal instruction or directive. |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 354 | if (IDVal[0] == '.') { |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 355 | // FIXME: This should be driven based on a hash lookup and callback. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 356 | if (IDVal == ".section") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 357 | return ParseDirectiveDarwinSection(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 358 | if (IDVal == ".text") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 359 | // FIXME: This changes behavior based on the -static flag to the |
| 360 | // assembler. |
| 361 | return ParseDirectiveSectionSwitch("__TEXT,__text", |
| 362 | "regular,pure_instructions"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 363 | if (IDVal == ".const") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 364 | return ParseDirectiveSectionSwitch("__TEXT,__const"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 365 | if (IDVal == ".static_const") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 366 | return ParseDirectiveSectionSwitch("__TEXT,__static_const"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 367 | if (IDVal == ".cstring") |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 368 | return ParseDirectiveSectionSwitch("__TEXT,__cstring", |
| 369 | "cstring_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 370 | if (IDVal == ".literal4") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 371 | return ParseDirectiveSectionSwitch("__TEXT,__literal4", "4byte_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 372 | if (IDVal == ".literal8") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 373 | return ParseDirectiveSectionSwitch("__TEXT,__literal8", "8byte_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 374 | if (IDVal == ".literal16") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 375 | return ParseDirectiveSectionSwitch("__TEXT,__literal16", |
| 376 | "16byte_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 377 | if (IDVal == ".constructor") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 378 | return ParseDirectiveSectionSwitch("__TEXT,__constructor"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 379 | if (IDVal == ".destructor") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 380 | return ParseDirectiveSectionSwitch("__TEXT,__destructor"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 381 | if (IDVal == ".fvmlib_init0") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 382 | return ParseDirectiveSectionSwitch("__TEXT,__fvmlib_init0"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 383 | if (IDVal == ".fvmlib_init1") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 384 | return ParseDirectiveSectionSwitch("__TEXT,__fvmlib_init1"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 385 | if (IDVal == ".symbol_stub") // FIXME: Different on PPC. |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 386 | return ParseDirectiveSectionSwitch("__IMPORT,__jump_table,symbol_stubs", |
| 387 | "self_modifying_code+pure_instructions,5"); |
| 388 | // FIXME: .picsymbol_stub on PPC. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 389 | if (IDVal == ".data") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 390 | return ParseDirectiveSectionSwitch("__DATA,__data"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 391 | if (IDVal == ".static_data") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 392 | return ParseDirectiveSectionSwitch("__DATA,__static_data"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 393 | if (IDVal == ".non_lazy_symbol_pointer") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 394 | return ParseDirectiveSectionSwitch("__DATA,__nl_symbol_pointer", |
| 395 | "non_lazy_symbol_pointers"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 396 | if (IDVal == ".lazy_symbol_pointer") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 397 | return ParseDirectiveSectionSwitch("__DATA,__la_symbol_pointer", |
| 398 | "lazy_symbol_pointers"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 399 | if (IDVal == ".dyld") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 400 | return ParseDirectiveSectionSwitch("__DATA,__dyld"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 401 | if (IDVal == ".mod_init_func") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 402 | return ParseDirectiveSectionSwitch("__DATA,__mod_init_func", |
| 403 | "mod_init_funcs"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 404 | if (IDVal == ".mod_term_func") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 405 | return ParseDirectiveSectionSwitch("__DATA,__mod_term_func", |
| 406 | "mod_term_funcs"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 407 | if (IDVal == ".const_data") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 408 | return ParseDirectiveSectionSwitch("__DATA,__const", "regular"); |
| 409 | |
| 410 | |
| 411 | // FIXME: Verify attributes on sections. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 412 | if (IDVal == ".objc_class") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 413 | return ParseDirectiveSectionSwitch("__OBJC,__class"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 414 | if (IDVal == ".objc_meta_class") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 415 | return ParseDirectiveSectionSwitch("__OBJC,__meta_class"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 416 | if (IDVal == ".objc_cat_cls_meth") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 417 | return ParseDirectiveSectionSwitch("__OBJC,__cat_cls_meth"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 418 | if (IDVal == ".objc_cat_inst_meth") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 419 | return ParseDirectiveSectionSwitch("__OBJC,__cat_inst_meth"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 420 | if (IDVal == ".objc_protocol") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 421 | return ParseDirectiveSectionSwitch("__OBJC,__protocol"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 422 | if (IDVal == ".objc_string_object") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 423 | return ParseDirectiveSectionSwitch("__OBJC,__string_object"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 424 | if (IDVal == ".objc_cls_meth") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 425 | return ParseDirectiveSectionSwitch("__OBJC,__cls_meth"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 426 | if (IDVal == ".objc_inst_meth") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 427 | return ParseDirectiveSectionSwitch("__OBJC,__inst_meth"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 428 | if (IDVal == ".objc_cls_refs") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 429 | return ParseDirectiveSectionSwitch("__OBJC,__cls_refs"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 430 | if (IDVal == ".objc_message_refs") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 431 | return ParseDirectiveSectionSwitch("__OBJC,__message_refs"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 432 | if (IDVal == ".objc_symbols") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 433 | return ParseDirectiveSectionSwitch("__OBJC,__symbols"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 434 | if (IDVal == ".objc_category") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 435 | return ParseDirectiveSectionSwitch("__OBJC,__category"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 436 | if (IDVal == ".objc_class_vars") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 437 | return ParseDirectiveSectionSwitch("__OBJC,__class_vars"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 438 | if (IDVal == ".objc_instance_vars") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 439 | return ParseDirectiveSectionSwitch("__OBJC,__instance_vars"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 440 | if (IDVal == ".objc_module_info") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 441 | return ParseDirectiveSectionSwitch("__OBJC,__module_info"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 442 | if (IDVal == ".objc_class_names") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 443 | return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 444 | if (IDVal == ".objc_meth_var_types") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 445 | return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 446 | if (IDVal == ".objc_meth_var_names") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 447 | return ParseDirectiveSectionSwitch("__TEXT,__cstring","cstring_literals"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 448 | if (IDVal == ".objc_selector_strs") |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 449 | return ParseDirectiveSectionSwitch("__OBJC,__selector_strs"); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 450 | |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 451 | // Assembler features |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 452 | if (IDVal == ".set") |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 453 | return ParseDirectiveSet(); |
| 454 | |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 455 | // Data directives |
| 456 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 457 | if (IDVal == ".ascii") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 458 | return ParseDirectiveAscii(false); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 459 | if (IDVal == ".asciz") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 460 | return ParseDirectiveAscii(true); |
| 461 | |
| 462 | // FIXME: Target hooks for size? Also for "word", "hword". |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 463 | if (IDVal == ".byte") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 464 | return ParseDirectiveValue(1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 465 | if (IDVal == ".short") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 466 | return ParseDirectiveValue(2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 467 | if (IDVal == ".long") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 468 | return ParseDirectiveValue(4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 469 | if (IDVal == ".quad") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 470 | return ParseDirectiveValue(8); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 471 | |
| 472 | // FIXME: Target hooks for IsPow2. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 473 | if (IDVal == ".align") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 474 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 475 | if (IDVal == ".align32") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 476 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 477 | if (IDVal == ".balign") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 478 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 479 | if (IDVal == ".balignw") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 480 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 481 | if (IDVal == ".balignl") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 482 | return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/4); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 483 | if (IDVal == ".p2align") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 484 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 485 | if (IDVal == ".p2alignw") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 486 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/2); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 487 | if (IDVal == ".p2alignl") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 488 | return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); |
| 489 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 490 | if (IDVal == ".org") |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 491 | return ParseDirectiveOrg(); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 492 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 493 | if (IDVal == ".fill") |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 494 | return ParseDirectiveFill(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 495 | if (IDVal == ".space") |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 496 | return ParseDirectiveSpace(); |
| 497 | |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 498 | // Symbol attribute directives |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 499 | if (IDVal == ".globl" || IDVal == ".global") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 500 | return ParseDirectiveSymbolAttribute(MCStreamer::Global); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 501 | if (IDVal == ".hidden") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 502 | return ParseDirectiveSymbolAttribute(MCStreamer::Hidden); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 503 | if (IDVal == ".indirect_symbol") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 504 | return ParseDirectiveSymbolAttribute(MCStreamer::IndirectSymbol); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 505 | if (IDVal == ".internal") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 506 | return ParseDirectiveSymbolAttribute(MCStreamer::Internal); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 507 | if (IDVal == ".lazy_reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 508 | return ParseDirectiveSymbolAttribute(MCStreamer::LazyReference); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 509 | if (IDVal == ".no_dead_strip") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 510 | return ParseDirectiveSymbolAttribute(MCStreamer::NoDeadStrip); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 511 | if (IDVal == ".private_extern") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 512 | return ParseDirectiveSymbolAttribute(MCStreamer::PrivateExtern); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 513 | if (IDVal == ".protected") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 514 | return ParseDirectiveSymbolAttribute(MCStreamer::Protected); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 515 | if (IDVal == ".reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 516 | return ParseDirectiveSymbolAttribute(MCStreamer::Reference); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 517 | if (IDVal == ".weak") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 518 | return ParseDirectiveSymbolAttribute(MCStreamer::Weak); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 519 | if (IDVal == ".weak_definition") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 520 | return ParseDirectiveSymbolAttribute(MCStreamer::WeakDefinition); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 521 | if (IDVal == ".weak_reference") |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 522 | return ParseDirectiveSymbolAttribute(MCStreamer::WeakReference); |
| 523 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 524 | if (IDVal == ".comm") |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 525 | return ParseDirectiveComm(/*IsLocal=*/false); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 526 | if (IDVal == ".lcomm") |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 527 | return ParseDirectiveComm(/*IsLocal=*/true); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 528 | if (IDVal == ".zerofill") |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 529 | return ParseDirectiveDarwinZerofill(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 530 | if (IDVal == ".desc") |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 531 | return ParseDirectiveDarwinSymbolDesc(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 532 | if (IDVal == ".lsym") |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 533 | return ParseDirectiveDarwinLsym(); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 534 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 535 | if (IDVal == ".subsections_via_symbols") |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 536 | return ParseDirectiveDarwinSubsectionsViaSymbols(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 537 | if (IDVal == ".abort") |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 538 | return ParseDirectiveAbort(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 539 | if (IDVal == ".include") |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 540 | return ParseDirectiveInclude(); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 541 | if (IDVal == ".dump") |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 542 | return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsDump=*/true); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 543 | if (IDVal == ".load") |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 544 | return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 545 | |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 546 | Warning(IDLoc, "ignoring directive for now"); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 547 | EatToEndOfStatement(); |
| 548 | return false; |
| 549 | } |
Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 550 | |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 551 | MCInst Inst; |
Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 552 | if (ParseX86InstOperands(IDVal, Inst) && |
| 553 | getTargetParser().ParseInstruction(*this, IDVal, Inst)) |
Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 554 | return true; |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 555 | |
| 556 | if (Lexer.isNot(asmtok::EndOfStatement)) |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 557 | return TokError("unexpected token in argument list"); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 558 | |
| 559 | // Eat the end of statement marker. |
| 560 | Lexer.Lex(); |
| 561 | |
| 562 | // Instruction is good, process it. |
Daniel Dunbar | 0eebb05 | 2009-07-01 06:35:48 +0000 | [diff] [blame] | 563 | Out.EmitInstruction(Inst); |
Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 564 | |
| 565 | // Skip to end of line for now. |
Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 566 | return false; |
| 567 | } |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 568 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 569 | bool AsmParser::ParseAssignment(const StringRef &Name, bool IsDotSet) { |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 570 | // FIXME: Use better location, we should use proper tokens. |
| 571 | SMLoc EqualLoc = Lexer.getLoc(); |
| 572 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 573 | MCValue Value; |
| 574 | if (ParseRelocatableExpression(Value)) |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 575 | return true; |
| 576 | |
| 577 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 578 | return TokError("unexpected token in assignment"); |
| 579 | |
| 580 | // Eat the end of statement marker. |
| 581 | Lexer.Lex(); |
| 582 | |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 583 | // Diagnose assignment to a label. |
| 584 | // |
| 585 | // FIXME: Diagnostics. Note the location of the definition as a label. |
| 586 | // FIXME: This doesn't diagnose assignment to a symbol which has been |
| 587 | // implicitly marked as external. |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 588 | // FIXME: Handle '.'. |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 589 | // FIXME: Diagnose assignment to protected identifier (e.g., register name). |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 590 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name); |
Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 591 | if (Sym->getSection()) |
| 592 | return Error(EqualLoc, "invalid assignment to symbol emitted as a label"); |
| 593 | if (Sym->isExternal()) |
| 594 | return Error(EqualLoc, "invalid assignment to external symbol"); |
| 595 | |
| 596 | // Do the assignment. |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 597 | Out.EmitAssignment(Sym, Value, IsDotSet); |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 598 | |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | /// ParseDirectiveSet: |
| 603 | /// ::= .set identifier ',' expression |
| 604 | bool AsmParser::ParseDirectiveSet() { |
| 605 | if (Lexer.isNot(asmtok::Identifier)) |
| 606 | return TokError("expected identifier after '.set' directive"); |
| 607 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 608 | StringRef Name = Lexer.getCurStrVal(); |
Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 609 | |
| 610 | if (Lexer.Lex() != asmtok::Comma) |
| 611 | return TokError("unexpected token in '.set'"); |
| 612 | Lexer.Lex(); |
| 613 | |
| 614 | return ParseAssignment(Name, true); |
| 615 | } |
| 616 | |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 617 | /// ParseDirectiveSection: |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 618 | /// ::= .section identifier (',' identifier)* |
| 619 | /// FIXME: This should actually parse out the segment, section, attributes and |
| 620 | /// sizeof_stub fields. |
| 621 | bool AsmParser::ParseDirectiveDarwinSection() { |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 622 | if (Lexer.isNot(asmtok::Identifier)) |
| 623 | return TokError("expected identifier after '.section' directive"); |
| 624 | |
| 625 | std::string Section = Lexer.getCurStrVal(); |
| 626 | Lexer.Lex(); |
| 627 | |
| 628 | // Accept a comma separated list of modifiers. |
| 629 | while (Lexer.is(asmtok::Comma)) { |
| 630 | Lexer.Lex(); |
| 631 | |
| 632 | if (Lexer.isNot(asmtok::Identifier)) |
| 633 | return TokError("expected identifier in '.section' directive"); |
| 634 | Section += ','; |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 635 | Section += Lexer.getCurStrVal().str(); |
Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 636 | Lexer.Lex(); |
| 637 | } |
| 638 | |
| 639 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 640 | return TokError("unexpected token in '.section' directive"); |
| 641 | Lexer.Lex(); |
| 642 | |
| 643 | Out.SwitchSection(Ctx.GetSection(Section.c_str())); |
| 644 | return false; |
| 645 | } |
| 646 | |
Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 647 | bool AsmParser::ParseDirectiveSectionSwitch(const char *Section, |
| 648 | const char *Directives) { |
| 649 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 650 | return TokError("unexpected token in section switching directive"); |
| 651 | Lexer.Lex(); |
| 652 | |
| 653 | std::string SectionStr = Section; |
| 654 | if (Directives && Directives[0]) { |
| 655 | SectionStr += ","; |
| 656 | SectionStr += Directives; |
| 657 | } |
| 658 | |
| 659 | Out.SwitchSection(Ctx.GetSection(Section)); |
| 660 | return false; |
| 661 | } |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 662 | |
| 663 | /// ParseDirectiveAscii: |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 664 | /// ::= ( .ascii | .asciz ) [ "string" ( , "string" )* ] |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 665 | bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) { |
| 666 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 667 | for (;;) { |
| 668 | if (Lexer.isNot(asmtok::String)) |
| 669 | return TokError("expected string in '.ascii' or '.asciz' directive"); |
| 670 | |
| 671 | // FIXME: This shouldn't use a const char* + strlen, the string could have |
| 672 | // embedded nulls. |
| 673 | // FIXME: Should have accessor for getting string contents. |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 674 | StringRef Str = Lexer.getCurStrVal(); |
| 675 | Out.EmitBytes(Str.substr(1, Str.size() - 2)); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 676 | if (ZeroTerminated) |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 677 | Out.EmitBytes(StringRef("\0", 1)); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 678 | |
| 679 | Lexer.Lex(); |
| 680 | |
| 681 | if (Lexer.is(asmtok::EndOfStatement)) |
| 682 | break; |
| 683 | |
| 684 | if (Lexer.isNot(asmtok::Comma)) |
| 685 | return TokError("unexpected token in '.ascii' or '.asciz' directive"); |
| 686 | Lexer.Lex(); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | Lexer.Lex(); |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | /// ParseDirectiveValue |
| 695 | /// ::= (.byte | .short | ... ) [ expression (, expression)* ] |
| 696 | bool AsmParser::ParseDirectiveValue(unsigned Size) { |
| 697 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 698 | for (;;) { |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 699 | MCValue Expr; |
| 700 | if (ParseRelocatableExpression(Expr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 701 | return true; |
| 702 | |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 703 | Out.EmitValue(Expr, Size); |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 704 | |
| 705 | if (Lexer.is(asmtok::EndOfStatement)) |
| 706 | break; |
| 707 | |
| 708 | // FIXME: Improve diagnostic. |
| 709 | if (Lexer.isNot(asmtok::Comma)) |
| 710 | return TokError("unexpected token in directive"); |
| 711 | Lexer.Lex(); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | Lexer.Lex(); |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | /// ParseDirectiveSpace |
| 720 | /// ::= .space expression [ , expression ] |
| 721 | bool AsmParser::ParseDirectiveSpace() { |
| 722 | int64_t NumBytes; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 723 | if (ParseAbsoluteExpression(NumBytes)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 724 | return true; |
| 725 | |
| 726 | int64_t FillExpr = 0; |
| 727 | bool HasFillExpr = false; |
| 728 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 729 | if (Lexer.isNot(asmtok::Comma)) |
| 730 | return TokError("unexpected token in '.space' directive"); |
| 731 | Lexer.Lex(); |
| 732 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 733 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 734 | return true; |
| 735 | |
| 736 | HasFillExpr = true; |
| 737 | |
| 738 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 739 | return TokError("unexpected token in '.space' directive"); |
| 740 | } |
| 741 | |
| 742 | Lexer.Lex(); |
| 743 | |
| 744 | if (NumBytes <= 0) |
| 745 | return TokError("invalid number of bytes in '.space' directive"); |
| 746 | |
| 747 | // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0. |
| 748 | for (uint64_t i = 0, e = NumBytes; i != e; ++i) |
| 749 | Out.EmitValue(MCValue::get(FillExpr), 1); |
| 750 | |
| 751 | return false; |
| 752 | } |
| 753 | |
| 754 | /// ParseDirectiveFill |
| 755 | /// ::= .fill expression , expression , expression |
| 756 | bool AsmParser::ParseDirectiveFill() { |
| 757 | int64_t NumValues; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 758 | if (ParseAbsoluteExpression(NumValues)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 759 | return true; |
| 760 | |
| 761 | if (Lexer.isNot(asmtok::Comma)) |
| 762 | return TokError("unexpected token in '.fill' directive"); |
| 763 | Lexer.Lex(); |
| 764 | |
| 765 | int64_t FillSize; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 766 | if (ParseAbsoluteExpression(FillSize)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 767 | return true; |
| 768 | |
| 769 | if (Lexer.isNot(asmtok::Comma)) |
| 770 | return TokError("unexpected token in '.fill' directive"); |
| 771 | Lexer.Lex(); |
| 772 | |
| 773 | int64_t FillExpr; |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 774 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 775 | return true; |
| 776 | |
| 777 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 778 | return TokError("unexpected token in '.fill' directive"); |
| 779 | |
| 780 | Lexer.Lex(); |
| 781 | |
| 782 | if (FillSize != 1 && FillSize != 2 && FillSize != 4) |
| 783 | return TokError("invalid '.fill' size, expected 1, 2, or 4"); |
| 784 | |
| 785 | for (uint64_t i = 0, e = NumValues; i != e; ++i) |
| 786 | Out.EmitValue(MCValue::get(FillExpr), FillSize); |
| 787 | |
| 788 | return false; |
| 789 | } |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 790 | |
| 791 | /// ParseDirectiveOrg |
| 792 | /// ::= .org expression [ , expression ] |
| 793 | bool AsmParser::ParseDirectiveOrg() { |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 794 | MCValue Offset; |
| 795 | if (ParseRelocatableExpression(Offset)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 796 | return true; |
| 797 | |
| 798 | // Parse optional fill expression. |
| 799 | int64_t FillExpr = 0; |
| 800 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 801 | if (Lexer.isNot(asmtok::Comma)) |
| 802 | return TokError("unexpected token in '.org' directive"); |
| 803 | Lexer.Lex(); |
| 804 | |
Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 805 | if (ParseAbsoluteExpression(FillExpr)) |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 806 | return true; |
| 807 | |
| 808 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 809 | return TokError("unexpected token in '.org' directive"); |
| 810 | } |
| 811 | |
| 812 | Lexer.Lex(); |
Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 813 | |
| 814 | // FIXME: Only limited forms of relocatable expressions are accepted here, it |
| 815 | // has to be relative to the current section. |
| 816 | Out.EmitValueToOffset(Offset, FillExpr); |
Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 817 | |
| 818 | return false; |
| 819 | } |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 820 | |
| 821 | /// ParseDirectiveAlign |
| 822 | /// ::= {.align, ...} expression [ , expression [ , expression ]] |
| 823 | bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { |
| 824 | int64_t Alignment; |
| 825 | if (ParseAbsoluteExpression(Alignment)) |
| 826 | return true; |
| 827 | |
| 828 | SMLoc MaxBytesLoc; |
| 829 | bool HasFillExpr = false; |
| 830 | int64_t FillExpr = 0; |
| 831 | int64_t MaxBytesToFill = 0; |
| 832 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 833 | if (Lexer.isNot(asmtok::Comma)) |
| 834 | return TokError("unexpected token in directive"); |
| 835 | Lexer.Lex(); |
| 836 | |
| 837 | // The fill expression can be omitted while specifying a maximum number of |
| 838 | // alignment bytes, e.g: |
| 839 | // .align 3,,4 |
| 840 | if (Lexer.isNot(asmtok::Comma)) { |
| 841 | HasFillExpr = true; |
| 842 | if (ParseAbsoluteExpression(FillExpr)) |
| 843 | return true; |
| 844 | } |
| 845 | |
| 846 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 847 | if (Lexer.isNot(asmtok::Comma)) |
| 848 | return TokError("unexpected token in directive"); |
| 849 | Lexer.Lex(); |
| 850 | |
| 851 | MaxBytesLoc = Lexer.getLoc(); |
| 852 | if (ParseAbsoluteExpression(MaxBytesToFill)) |
| 853 | return true; |
| 854 | |
| 855 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 856 | return TokError("unexpected token in directive"); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | Lexer.Lex(); |
| 861 | |
| 862 | if (!HasFillExpr) { |
| 863 | // FIXME: Sometimes fill with nop. |
| 864 | FillExpr = 0; |
| 865 | } |
| 866 | |
| 867 | // Compute alignment in bytes. |
| 868 | if (IsPow2) { |
| 869 | // FIXME: Diagnose overflow. |
Chris Lattner | 3975025 | 2009-07-11 22:32:37 +0000 | [diff] [blame] | 870 | Alignment = 1LL << Alignment; |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | // Diagnose non-sensical max bytes to fill. |
| 874 | if (MaxBytesLoc.isValid()) { |
| 875 | if (MaxBytesToFill < 1) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 876 | Warning(MaxBytesLoc, "alignment directive can never be satisfied in this " |
| 877 | "many bytes, ignoring"); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 878 | return false; |
| 879 | } |
| 880 | |
| 881 | if (MaxBytesToFill >= Alignment) { |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 882 | Warning(MaxBytesLoc, "maximum bytes expression exceeds alignment and " |
| 883 | "has no effect"); |
Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 884 | MaxBytesToFill = 0; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | // FIXME: Target specific behavior about how the "extra" bytes are filled. |
| 889 | Out.EmitValueToAlignment(Alignment, FillExpr, ValueSize, MaxBytesToFill); |
| 890 | |
| 891 | return false; |
| 892 | } |
| 893 | |
Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 894 | /// ParseDirectiveSymbolAttribute |
| 895 | /// ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ] |
| 896 | bool AsmParser::ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr) { |
| 897 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 898 | for (;;) { |
| 899 | if (Lexer.isNot(asmtok::Identifier)) |
| 900 | return TokError("expected identifier in directive"); |
| 901 | |
| 902 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 903 | Lexer.Lex(); |
| 904 | |
| 905 | // If this is use of an undefined symbol then mark it external. |
| 906 | if (!Sym->getSection() && !Ctx.GetSymbolValue(Sym)) |
| 907 | Sym->setExternal(true); |
| 908 | |
| 909 | Out.EmitSymbolAttribute(Sym, Attr); |
| 910 | |
| 911 | if (Lexer.is(asmtok::EndOfStatement)) |
| 912 | break; |
| 913 | |
| 914 | if (Lexer.isNot(asmtok::Comma)) |
| 915 | return TokError("unexpected token in directive"); |
| 916 | Lexer.Lex(); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | Lexer.Lex(); |
| 921 | return false; |
| 922 | } |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 923 | |
Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 924 | /// ParseDirectiveDarwinSymbolDesc |
| 925 | /// ::= .desc identifier , expression |
| 926 | bool AsmParser::ParseDirectiveDarwinSymbolDesc() { |
| 927 | if (Lexer.isNot(asmtok::Identifier)) |
| 928 | return TokError("expected identifier in directive"); |
| 929 | |
| 930 | // handle the identifier as the key symbol. |
| 931 | SMLoc IDLoc = Lexer.getLoc(); |
| 932 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 933 | Lexer.Lex(); |
| 934 | |
| 935 | if (Lexer.isNot(asmtok::Comma)) |
| 936 | return TokError("unexpected token in '.desc' directive"); |
| 937 | Lexer.Lex(); |
| 938 | |
| 939 | SMLoc DescLoc = Lexer.getLoc(); |
| 940 | int64_t DescValue; |
| 941 | if (ParseAbsoluteExpression(DescValue)) |
| 942 | return true; |
| 943 | |
| 944 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 945 | return TokError("unexpected token in '.desc' directive"); |
| 946 | |
| 947 | Lexer.Lex(); |
| 948 | |
| 949 | // Set the n_desc field of this Symbol to this DescValue |
| 950 | Out.EmitSymbolDesc(Sym, DescValue); |
| 951 | |
| 952 | return false; |
| 953 | } |
| 954 | |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 955 | /// ParseDirectiveComm |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 956 | /// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ] |
| 957 | bool AsmParser::ParseDirectiveComm(bool IsLocal) { |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 958 | if (Lexer.isNot(asmtok::Identifier)) |
| 959 | return TokError("expected identifier in directive"); |
| 960 | |
| 961 | // handle the identifier as the key symbol. |
| 962 | SMLoc IDLoc = Lexer.getLoc(); |
| 963 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 964 | Lexer.Lex(); |
| 965 | |
| 966 | if (Lexer.isNot(asmtok::Comma)) |
| 967 | return TokError("unexpected token in directive"); |
| 968 | Lexer.Lex(); |
| 969 | |
| 970 | int64_t Size; |
| 971 | SMLoc SizeLoc = Lexer.getLoc(); |
| 972 | if (ParseAbsoluteExpression(Size)) |
| 973 | return true; |
| 974 | |
| 975 | int64_t Pow2Alignment = 0; |
| 976 | SMLoc Pow2AlignmentLoc; |
| 977 | if (Lexer.is(asmtok::Comma)) { |
| 978 | Lexer.Lex(); |
| 979 | Pow2AlignmentLoc = Lexer.getLoc(); |
| 980 | if (ParseAbsoluteExpression(Pow2Alignment)) |
| 981 | return true; |
| 982 | } |
| 983 | |
| 984 | if (Lexer.isNot(asmtok::EndOfStatement)) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 985 | return TokError("unexpected token in '.comm' or '.lcomm' directive"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 986 | |
| 987 | Lexer.Lex(); |
| 988 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 989 | // NOTE: a size of zero for a .comm should create a undefined symbol |
| 990 | // but a size of .lcomm creates a bss symbol of size zero. |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 991 | if (Size < 0) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 992 | return Error(SizeLoc, "invalid '.comm' or '.lcomm' directive size, can't " |
| 993 | "be less than zero"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 994 | |
| 995 | // NOTE: The alignment in the directive is a power of 2 value, the assember |
| 996 | // may internally end up wanting an alignment in bytes. |
| 997 | // FIXME: Diagnose overflow. |
| 998 | if (Pow2Alignment < 0) |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 999 | return Error(Pow2AlignmentLoc, "invalid '.comm' or '.lcomm' directive " |
| 1000 | "alignment, can't be less than zero"); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1001 | |
| 1002 | // TODO: Symbol must be undefined or it is a error to re-defined the symbol |
| 1003 | if (Sym->getSection() || Ctx.GetSymbolValue(Sym)) |
| 1004 | return Error(IDLoc, "invalid symbol redefinition"); |
| 1005 | |
Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1006 | // Create the Symbol as a common or local common with Size and Pow2Alignment |
| 1007 | Out.EmitCommonSymbol(Sym, Size, Pow2Alignment, IsLocal); |
Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1008 | |
| 1009 | return false; |
| 1010 | } |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1011 | |
| 1012 | /// ParseDirectiveDarwinZerofill |
| 1013 | /// ::= .zerofill segname , sectname [, identifier , size_expression [ |
| 1014 | /// , align_expression ]] |
| 1015 | bool AsmParser::ParseDirectiveDarwinZerofill() { |
| 1016 | if (Lexer.isNot(asmtok::Identifier)) |
| 1017 | return TokError("expected segment name after '.zerofill' directive"); |
| 1018 | std::string Section = Lexer.getCurStrVal(); |
| 1019 | Lexer.Lex(); |
| 1020 | |
| 1021 | if (Lexer.isNot(asmtok::Comma)) |
| 1022 | return TokError("unexpected token in directive"); |
| 1023 | Section += ','; |
| 1024 | Lexer.Lex(); |
| 1025 | |
| 1026 | if (Lexer.isNot(asmtok::Identifier)) |
| 1027 | return TokError("expected section name after comma in '.zerofill' " |
| 1028 | "directive"); |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 1029 | Section += Lexer.getCurStrVal().str(); |
Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1030 | Lexer.Lex(); |
| 1031 | |
| 1032 | // FIXME: we will need to tell GetSection() that this is to be created with or |
| 1033 | // must have the Mach-O section type of S_ZEROFILL. Something like the code |
| 1034 | // below could be done but for now it is not as EmitZerofill() does not know |
| 1035 | // how to deal with a section type in the section name like |
| 1036 | // ParseDirectiveDarwinSection() allows. |
| 1037 | // Section += ','; |
| 1038 | // Section += "zerofill"; |
| 1039 | |
| 1040 | // If this is the end of the line all that was wanted was to create the |
| 1041 | // the section but with no symbol. |
| 1042 | if (Lexer.is(asmtok::EndOfStatement)) { |
| 1043 | // Create the zerofill section but no symbol |
| 1044 | Out.EmitZerofill(Ctx.GetSection(Section.c_str())); |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
| 1048 | if (Lexer.isNot(asmtok::Comma)) |
| 1049 | return TokError("unexpected token in directive"); |
| 1050 | Lexer.Lex(); |
| 1051 | |
| 1052 | if (Lexer.isNot(asmtok::Identifier)) |
| 1053 | return TokError("expected identifier in directive"); |
| 1054 | |
| 1055 | // handle the identifier as the key symbol. |
| 1056 | SMLoc IDLoc = Lexer.getLoc(); |
| 1057 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 1058 | Lexer.Lex(); |
| 1059 | |
| 1060 | if (Lexer.isNot(asmtok::Comma)) |
| 1061 | return TokError("unexpected token in directive"); |
| 1062 | Lexer.Lex(); |
| 1063 | |
| 1064 | int64_t Size; |
| 1065 | SMLoc SizeLoc = Lexer.getLoc(); |
| 1066 | if (ParseAbsoluteExpression(Size)) |
| 1067 | return true; |
| 1068 | |
| 1069 | int64_t Pow2Alignment = 0; |
| 1070 | SMLoc Pow2AlignmentLoc; |
| 1071 | if (Lexer.is(asmtok::Comma)) { |
| 1072 | Lexer.Lex(); |
| 1073 | Pow2AlignmentLoc = Lexer.getLoc(); |
| 1074 | if (ParseAbsoluteExpression(Pow2Alignment)) |
| 1075 | return true; |
| 1076 | } |
| 1077 | |
| 1078 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1079 | return TokError("unexpected token in '.zerofill' directive"); |
| 1080 | |
| 1081 | Lexer.Lex(); |
| 1082 | |
| 1083 | if (Size < 0) |
| 1084 | return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " |
| 1085 | "than zero"); |
| 1086 | |
| 1087 | // NOTE: The alignment in the directive is a power of 2 value, the assember |
| 1088 | // may internally end up wanting an alignment in bytes. |
| 1089 | // FIXME: Diagnose overflow. |
| 1090 | if (Pow2Alignment < 0) |
| 1091 | return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " |
| 1092 | "can't be less than zero"); |
| 1093 | |
| 1094 | // TODO: Symbol must be undefined or it is a error to re-defined the symbol |
| 1095 | if (Sym->getSection() || Ctx.GetSymbolValue(Sym)) |
| 1096 | return Error(IDLoc, "invalid symbol redefinition"); |
| 1097 | |
| 1098 | // Create the zerofill Symbol with Size and Pow2Alignment |
| 1099 | Out.EmitZerofill(Ctx.GetSection(Section.c_str()), Sym, Size, Pow2Alignment); |
| 1100 | |
| 1101 | return false; |
| 1102 | } |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1103 | |
| 1104 | /// ParseDirectiveDarwinSubsectionsViaSymbols |
| 1105 | /// ::= .subsections_via_symbols |
| 1106 | bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() { |
| 1107 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1108 | return TokError("unexpected token in '.subsections_via_symbols' directive"); |
| 1109 | |
| 1110 | Lexer.Lex(); |
| 1111 | |
Kevin Enderby | f96db46 | 2009-07-16 17:56:39 +0000 | [diff] [blame] | 1112 | Out.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols); |
Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1113 | |
| 1114 | return false; |
| 1115 | } |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1116 | |
| 1117 | /// ParseDirectiveAbort |
| 1118 | /// ::= .abort [ "abort_string" ] |
| 1119 | bool AsmParser::ParseDirectiveAbort() { |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 1120 | StringRef Str = ""; |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1121 | if (Lexer.isNot(asmtok::EndOfStatement)) { |
| 1122 | if (Lexer.isNot(asmtok::String)) |
| 1123 | return TokError("expected string in '.abort' directive"); |
| 1124 | |
| 1125 | Str = Lexer.getCurStrVal(); |
| 1126 | |
| 1127 | Lexer.Lex(); |
| 1128 | } |
| 1129 | |
| 1130 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1131 | return TokError("unexpected token in '.abort' directive"); |
| 1132 | |
| 1133 | Lexer.Lex(); |
| 1134 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame^] | 1135 | // FIXME: Handle here. |
| 1136 | Out.AbortAssembly(Str.str().c_str()); |
Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1137 | |
| 1138 | return false; |
| 1139 | } |
Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1140 | |
| 1141 | /// ParseDirectiveLsym |
| 1142 | /// ::= .lsym identifier , expression |
| 1143 | bool AsmParser::ParseDirectiveDarwinLsym() { |
| 1144 | if (Lexer.isNot(asmtok::Identifier)) |
| 1145 | return TokError("expected identifier in directive"); |
| 1146 | |
| 1147 | // handle the identifier as the key symbol. |
| 1148 | SMLoc IDLoc = Lexer.getLoc(); |
| 1149 | MCSymbol *Sym = Ctx.GetOrCreateSymbol(Lexer.getCurStrVal()); |
| 1150 | Lexer.Lex(); |
| 1151 | |
| 1152 | if (Lexer.isNot(asmtok::Comma)) |
| 1153 | return TokError("unexpected token in '.lsym' directive"); |
| 1154 | Lexer.Lex(); |
| 1155 | |
| 1156 | MCValue Expr; |
| 1157 | if (ParseRelocatableExpression(Expr)) |
| 1158 | return true; |
| 1159 | |
| 1160 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1161 | return TokError("unexpected token in '.lsym' directive"); |
| 1162 | |
| 1163 | Lexer.Lex(); |
| 1164 | |
| 1165 | // Create the Sym with the value of the Expr |
| 1166 | Out.EmitLocalSymbol(Sym, Expr); |
| 1167 | |
| 1168 | return false; |
| 1169 | } |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1170 | |
| 1171 | /// ParseDirectiveInclude |
| 1172 | /// ::= .include "filename" |
| 1173 | bool AsmParser::ParseDirectiveInclude() { |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1174 | if (Lexer.isNot(asmtok::String)) |
| 1175 | return TokError("expected string in '.include' directive"); |
| 1176 | |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1177 | std::string Filename = Lexer.getCurStrVal(); |
| 1178 | SMLoc IncludeLoc = Lexer.getLoc(); |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1179 | Lexer.Lex(); |
| 1180 | |
| 1181 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1182 | return TokError("unexpected token in '.include' directive"); |
| 1183 | |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1184 | // Strip the quotes. |
| 1185 | Filename = Filename.substr(1, Filename.size()-2); |
| 1186 | |
| 1187 | // Attempt to switch the lexer to the included file before consuming the end |
| 1188 | // of statement to avoid losing it when we switch. |
| 1189 | if (Lexer.EnterIncludeFile(Filename)) { |
| 1190 | Lexer.PrintMessage(IncludeLoc, |
| 1191 | "Could not find include file '" + Filename + "'", |
| 1192 | "error"); |
| 1193 | return true; |
| 1194 | } |
Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1195 | |
| 1196 | return false; |
| 1197 | } |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1198 | |
| 1199 | /// ParseDirectiveDarwinDumpOrLoad |
| 1200 | /// ::= ( .dump | .load ) "filename" |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1201 | bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1202 | if (Lexer.isNot(asmtok::String)) |
| 1203 | return TokError("expected string in '.dump' or '.load' directive"); |
| 1204 | |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1205 | Lexer.getCurStrVal(); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1206 | |
| 1207 | Lexer.Lex(); |
| 1208 | |
| 1209 | if (Lexer.isNot(asmtok::EndOfStatement)) |
| 1210 | return TokError("unexpected token in '.dump' or '.load' directive"); |
| 1211 | |
| 1212 | Lexer.Lex(); |
| 1213 | |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1214 | // FIXME: If/when .dump and .load are implemented they will be done in the |
| 1215 | // the assembly parser and not have any need for an MCStreamer API. |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1216 | if (IsDump) |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1217 | Warning(IDLoc, "ignoring directive .dump for now"); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1218 | else |
Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1219 | Warning(IDLoc, "ignoring directive .load for now"); |
Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1220 | |
| 1221 | return false; |
| 1222 | } |