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