Michael J. Spencer | 7d49004 | 2010-10-09 11:01:07 +0000 | [diff] [blame] | 1 | //===- COFFAsmParser.cpp - COFF Assembly Parser ---------------------------===// |
| 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 | #include "llvm/MC/MCParser/MCAsmParserExtension.h" |
| 11 | #include "llvm/ADT/Twine.h" |
| 12 | #include "llvm/MC/MCAsmInfo.h" |
| 13 | #include "llvm/MC/MCContext.h" |
| 14 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 15 | #include "llvm/MC/MCSectionCOFF.h" |
| 16 | #include "llvm/MC/MCStreamer.h" |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetAsmInfo.h" |
| 19 | #include "llvm/Target/TargetAsmParser.h" |
Michael J. Spencer | 7d49004 | 2010-10-09 11:01:07 +0000 | [diff] [blame] | 20 | #include "llvm/Support/COFF.h" |
| 21 | using namespace llvm; |
| 22 | |
| 23 | namespace { |
| 24 | |
| 25 | class COFFAsmParser : public MCAsmParserExtension { |
| 26 | template<bool (COFFAsmParser::*Handler)(StringRef, SMLoc)> |
| 27 | void AddDirectiveHandler(StringRef Directive) { |
| 28 | getParser().AddDirectiveHandler(this, Directive, |
| 29 | HandleDirective<COFFAsmParser, Handler>); |
| 30 | } |
| 31 | |
| 32 | bool ParseSectionSwitch(StringRef Section, |
| 33 | unsigned Characteristics, |
| 34 | SectionKind Kind); |
| 35 | |
| 36 | virtual void Initialize(MCAsmParser &Parser) { |
| 37 | // Call the base implementation. |
| 38 | MCAsmParserExtension::Initialize(Parser); |
| 39 | |
| 40 | AddDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveText>(".text"); |
| 41 | AddDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveData>(".data"); |
| 42 | AddDirectiveHandler<&COFFAsmParser::ParseSectionDirectiveBSS>(".bss"); |
| 43 | AddDirectiveHandler<&COFFAsmParser::ParseDirectiveDef>(".def"); |
| 44 | AddDirectiveHandler<&COFFAsmParser::ParseDirectiveScl>(".scl"); |
| 45 | AddDirectiveHandler<&COFFAsmParser::ParseDirectiveType>(".type"); |
| 46 | AddDirectiveHandler<&COFFAsmParser::ParseDirectiveEndef>(".endef"); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 47 | |
| 48 | // Win64 EH directives. |
| 49 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>( |
| 50 | ".seh_proc"); |
| 51 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProc>( |
| 52 | ".seh_endproc"); |
| 53 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartChained>( |
| 54 | ".seh_startchained"); |
| 55 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndChained>( |
| 56 | ".seh_endchained"); |
| 57 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandler>( |
| 58 | ".seh_handler"); |
| 59 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveHandlerData>( |
| 60 | ".seh_handlerdata"); |
| 61 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushReg>( |
| 62 | ".seh_pushreg"); |
| 63 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSetFrame>( |
| 64 | ".seh_setframe"); |
| 65 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveAllocStack>( |
| 66 | ".seh_stackalloc"); |
| 67 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveReg>( |
| 68 | ".seh_savereg"); |
| 69 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveSaveXMM>( |
| 70 | ".seh_savexmm"); |
| 71 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectivePushFrame>( |
| 72 | ".seh_pushframe"); |
| 73 | AddDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>( |
| 74 | ".seh_endprologue"); |
Michael J. Spencer | 7d49004 | 2010-10-09 11:01:07 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | bool ParseSectionDirectiveText(StringRef, SMLoc) { |
| 78 | return ParseSectionSwitch(".text", |
| 79 | COFF::IMAGE_SCN_CNT_CODE |
| 80 | | COFF::IMAGE_SCN_MEM_EXECUTE |
| 81 | | COFF::IMAGE_SCN_MEM_READ, |
| 82 | SectionKind::getText()); |
| 83 | } |
| 84 | bool ParseSectionDirectiveData(StringRef, SMLoc) { |
| 85 | return ParseSectionSwitch(".data", |
| 86 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
| 87 | | COFF::IMAGE_SCN_MEM_READ |
| 88 | | COFF::IMAGE_SCN_MEM_WRITE, |
| 89 | SectionKind::getDataRel()); |
| 90 | } |
| 91 | bool ParseSectionDirectiveBSS(StringRef, SMLoc) { |
| 92 | return ParseSectionSwitch(".bss", |
| 93 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
| 94 | | COFF::IMAGE_SCN_MEM_READ |
| 95 | | COFF::IMAGE_SCN_MEM_WRITE, |
| 96 | SectionKind::getBSS()); |
| 97 | } |
| 98 | |
| 99 | bool ParseDirectiveDef(StringRef, SMLoc); |
| 100 | bool ParseDirectiveScl(StringRef, SMLoc); |
| 101 | bool ParseDirectiveType(StringRef, SMLoc); |
| 102 | bool ParseDirectiveEndef(StringRef, SMLoc); |
| 103 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 104 | // Win64 EH directives. |
| 105 | bool ParseSEHDirectiveStartProc(StringRef, SMLoc); |
| 106 | bool ParseSEHDirectiveEndProc(StringRef, SMLoc); |
| 107 | bool ParseSEHDirectiveStartChained(StringRef, SMLoc); |
| 108 | bool ParseSEHDirectiveEndChained(StringRef, SMLoc); |
| 109 | bool ParseSEHDirectiveHandler(StringRef, SMLoc); |
| 110 | bool ParseSEHDirectiveHandlerData(StringRef, SMLoc); |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 111 | bool ParseSEHDirectivePushReg(StringRef, SMLoc); |
| 112 | bool ParseSEHDirectiveSetFrame(StringRef, SMLoc); |
| 113 | bool ParseSEHDirectiveAllocStack(StringRef, SMLoc); |
| 114 | bool ParseSEHDirectiveSaveReg(StringRef, SMLoc); |
| 115 | bool ParseSEHDirectiveSaveXMM(StringRef, SMLoc); |
| 116 | bool ParseSEHDirectivePushFrame(StringRef, SMLoc); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 117 | bool ParseSEHDirectiveEndProlog(StringRef, SMLoc); |
| 118 | |
| 119 | bool ParseAtUnwindOrAtExcept(bool &unwind, bool &except); |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 120 | bool ParseSEHRegisterNumber(unsigned &RegNo); |
Michael J. Spencer | 7d49004 | 2010-10-09 11:01:07 +0000 | [diff] [blame] | 121 | public: |
| 122 | COFFAsmParser() {} |
| 123 | }; |
| 124 | |
| 125 | } // end annonomous namespace. |
| 126 | |
| 127 | bool COFFAsmParser::ParseSectionSwitch(StringRef Section, |
| 128 | unsigned Characteristics, |
| 129 | SectionKind Kind) { |
| 130 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 131 | return TokError("unexpected token in section switching directive"); |
| 132 | Lex(); |
| 133 | |
| 134 | getStreamer().SwitchSection(getContext().getCOFFSection( |
| 135 | Section, Characteristics, Kind)); |
| 136 | |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | bool COFFAsmParser::ParseDirectiveDef(StringRef, SMLoc) { |
| 141 | StringRef SymbolName; |
| 142 | |
| 143 | if (getParser().ParseIdentifier(SymbolName)) |
| 144 | return TokError("expected identifier in directive"); |
| 145 | |
| 146 | MCSymbol *Sym = getContext().GetOrCreateSymbol(SymbolName); |
| 147 | |
| 148 | getStreamer().BeginCOFFSymbolDef(Sym); |
| 149 | |
| 150 | Lex(); |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | bool COFFAsmParser::ParseDirectiveScl(StringRef, SMLoc) { |
| 155 | int64_t SymbolStorageClass; |
| 156 | if (getParser().ParseAbsoluteExpression(SymbolStorageClass)) |
| 157 | return true; |
| 158 | |
| 159 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 160 | return TokError("unexpected token in directive"); |
| 161 | |
| 162 | Lex(); |
| 163 | getStreamer().EmitCOFFSymbolStorageClass(SymbolStorageClass); |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | bool COFFAsmParser::ParseDirectiveType(StringRef, SMLoc) { |
| 168 | int64_t Type; |
| 169 | if (getParser().ParseAbsoluteExpression(Type)) |
| 170 | return true; |
| 171 | |
| 172 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 173 | return TokError("unexpected token in directive"); |
| 174 | |
| 175 | Lex(); |
| 176 | getStreamer().EmitCOFFSymbolType(Type); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | bool COFFAsmParser::ParseDirectiveEndef(StringRef, SMLoc) { |
| 181 | Lex(); |
| 182 | getStreamer().EndCOFFSymbolDef(); |
| 183 | return false; |
| 184 | } |
| 185 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 186 | bool COFFAsmParser::ParseSEHDirectiveStartProc(StringRef, SMLoc) { |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 187 | StringRef SymbolID; |
| 188 | if (getParser().ParseIdentifier(SymbolID)) |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 189 | return true; |
| 190 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 191 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 192 | return TokError("unexpected token in directive"); |
| 193 | |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 194 | MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID); |
| 195 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 196 | Lex(); |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 197 | getStreamer().EmitWin64EHStartProc(Symbol); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | |
| 201 | bool COFFAsmParser::ParseSEHDirectiveEndProc(StringRef, SMLoc) { |
| 202 | Lex(); |
| 203 | getStreamer().EmitWin64EHEndProc(); |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | bool COFFAsmParser::ParseSEHDirectiveStartChained(StringRef, SMLoc) { |
| 208 | Lex(); |
| 209 | getStreamer().EmitWin64EHStartChained(); |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | bool COFFAsmParser::ParseSEHDirectiveEndChained(StringRef, SMLoc) { |
| 214 | Lex(); |
| 215 | getStreamer().EmitWin64EHEndChained(); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | bool COFFAsmParser::ParseSEHDirectiveHandler(StringRef, SMLoc) { |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 220 | StringRef SymbolID; |
| 221 | if (getParser().ParseIdentifier(SymbolID)) |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 222 | return true; |
| 223 | |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 224 | if (getLexer().isNot(AsmToken::Comma)) |
| 225 | return TokError("you must specify one or both of @unwind or @except"); |
| 226 | Lex(); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 227 | bool unwind = false, except = false; |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 228 | if (ParseAtUnwindOrAtExcept(unwind, except)) |
| 229 | return true; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 230 | if (getLexer().is(AsmToken::Comma)) { |
| 231 | Lex(); |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 232 | if (ParseAtUnwindOrAtExcept(unwind, except)) |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 236 | return TokError("unexpected token in directive"); |
| 237 | |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 238 | MCSymbol *handler = getContext().GetOrCreateSymbol(SymbolID); |
| 239 | |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 240 | Lex(); |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 241 | getStreamer().EmitWin64EHHandler(handler, unwind, except); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | |
| 245 | bool COFFAsmParser::ParseSEHDirectiveHandlerData(StringRef, SMLoc) { |
| 246 | Lex(); |
| 247 | getStreamer().EmitWin64EHHandlerData(); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | bool COFFAsmParser::ParseSEHDirectivePushReg(StringRef, SMLoc L) { |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 252 | unsigned Reg; |
| 253 | if (ParseSEHRegisterNumber(Reg)) |
| 254 | return true; |
| 255 | |
| 256 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 257 | return TokError("unexpected token in directive"); |
| 258 | |
| 259 | Lex(); |
| 260 | getStreamer().EmitWin64EHPushReg(Reg); |
| 261 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | bool COFFAsmParser::ParseSEHDirectiveSetFrame(StringRef, SMLoc L) { |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 265 | unsigned Reg; |
| 266 | int64_t Off; |
| 267 | if (ParseSEHRegisterNumber(Reg)) |
| 268 | return true; |
| 269 | SMLoc startLoc = getLexer().getLoc(); |
| 270 | if (getParser().ParseAbsoluteExpression(Off)) |
| 271 | return true; |
| 272 | |
| 273 | if (Off & 0x0F) |
| 274 | return Error(startLoc, "offset is not a multiple of 16"); |
| 275 | |
| 276 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 277 | return TokError("unexpected token in directive"); |
| 278 | |
| 279 | Lex(); |
| 280 | getStreamer().EmitWin64EHSetFrame(Reg, Off); |
| 281 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Charles Davis | 16e1b3f | 2011-05-23 16:43:09 +0000 | [diff] [blame] | 284 | bool COFFAsmParser::ParseSEHDirectiveAllocStack(StringRef, SMLoc) { |
| 285 | int64_t Size; |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 286 | SMLoc startLoc = getLexer().getLoc(); |
Charles Davis | 16e1b3f | 2011-05-23 16:43:09 +0000 | [diff] [blame] | 287 | if (getParser().ParseAbsoluteExpression(Size)) |
| 288 | return true; |
| 289 | |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 290 | if (Size & 7) |
| 291 | return Error(startLoc, "size is not a multiple of 8"); |
| 292 | |
Charles Davis | 16e1b3f | 2011-05-23 16:43:09 +0000 | [diff] [blame] | 293 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 294 | return TokError("unexpected token in directive"); |
| 295 | |
| 296 | Lex(); |
| 297 | getStreamer().EmitWin64EHAllocStack(Size); |
| 298 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | bool COFFAsmParser::ParseSEHDirectiveSaveReg(StringRef, SMLoc L) { |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 302 | unsigned Reg; |
| 303 | int64_t Off; |
| 304 | if (ParseSEHRegisterNumber(Reg)) |
| 305 | return true; |
| 306 | SMLoc startLoc = getLexer().getLoc(); |
| 307 | if (getParser().ParseAbsoluteExpression(Off)) |
| 308 | return true; |
| 309 | |
| 310 | if (Off & 7) |
| 311 | return Error(startLoc, "size is not a multiple of 8"); |
| 312 | |
| 313 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 314 | return TokError("unexpected token in directive"); |
| 315 | |
| 316 | Lex(); |
| 317 | // FIXME: Err on %xmm* registers |
| 318 | getStreamer().EmitWin64EHSaveReg(Reg, Off); |
| 319 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 322 | // FIXME: This method is inherently x86-specific. It should really be in the |
| 323 | // x86 backend. |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 324 | bool COFFAsmParser::ParseSEHDirectiveSaveXMM(StringRef, SMLoc L) { |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 325 | unsigned Reg; |
| 326 | int64_t Off; |
| 327 | if (ParseSEHRegisterNumber(Reg)) |
| 328 | return true; |
| 329 | SMLoc startLoc = getLexer().getLoc(); |
| 330 | if (getParser().ParseAbsoluteExpression(Off)) |
| 331 | return true; |
| 332 | |
| 333 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 334 | return TokError("unexpected token in directive"); |
| 335 | |
| 336 | if (Off & 0x0F) |
| 337 | return Error(startLoc, "offset is not a multiple of 16"); |
| 338 | |
| 339 | Lex(); |
| 340 | // FIXME: Err on non-%xmm* registers |
| 341 | getStreamer().EmitWin64EHSaveXMM(Reg, Off); |
| 342 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Charles Davis | 16e1b3f | 2011-05-23 16:43:09 +0000 | [diff] [blame] | 345 | bool COFFAsmParser::ParseSEHDirectivePushFrame(StringRef, SMLoc) { |
| 346 | bool Code; |
| 347 | StringRef CodeID; |
| 348 | SMLoc startLoc = getLexer().getLoc(); |
| 349 | if (!getParser().ParseIdentifier(CodeID)) { |
| 350 | if (CodeID != "@code") |
| 351 | return Error(startLoc, "expected @code"); |
| 352 | Code = true; |
| 353 | } |
| 354 | |
| 355 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 356 | return TokError("unexpected token in directive"); |
| 357 | |
| 358 | Lex(); |
| 359 | getStreamer().EmitWin64EHPushFrame(Code); |
| 360 | return false; |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | bool COFFAsmParser::ParseSEHDirectiveEndProlog(StringRef, SMLoc) { |
| 364 | Lex(); |
| 365 | getStreamer().EmitWin64EHEndProlog(); |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | bool COFFAsmParser::ParseAtUnwindOrAtExcept(bool &unwind, bool &except) { |
| 370 | StringRef identifier; |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 371 | if (getLexer().isNot(AsmToken::At)) |
| 372 | return TokError("a handler attribute must begin with '@'"); |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 373 | SMLoc startLoc = getLexer().getLoc(); |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 374 | Lex(); |
| 375 | if (getParser().ParseIdentifier(identifier)) |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 376 | return Error(startLoc, "expected @unwind or @except"); |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 377 | if (identifier == "unwind") |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 378 | unwind = true; |
Charles Davis | 3092132 | 2011-05-25 01:33:42 +0000 | [diff] [blame^] | 379 | else if (identifier == "except") |
Charles Davis | fbc539f | 2011-05-22 21:12:15 +0000 | [diff] [blame] | 380 | except = true; |
| 381 | else |
| 382 | return Error(startLoc, "expected @unwind or @except"); |
| 383 | return false; |
| 384 | } |
| 385 | |
Charles Davis | 3b32d02 | 2011-05-24 20:06:30 +0000 | [diff] [blame] | 386 | bool COFFAsmParser::ParseSEHRegisterNumber(unsigned &RegNo) { |
| 387 | int64_t n; |
| 388 | SMLoc startLoc = getLexer().getLoc(); |
| 389 | if (getParser().ParseAbsoluteExpression(n)) { |
| 390 | const TargetAsmInfo &asmInfo = getContext().getTargetAsmInfo(); |
| 391 | SMLoc endLoc; |
| 392 | unsigned LLVMRegNo; |
| 393 | if (getParser().getTargetParser().ParseRegister(LLVMRegNo,startLoc,endLoc)) |
| 394 | return Error(startLoc, "expected register or number"); |
| 395 | |
| 396 | // Check that this is a non-volatile register. |
| 397 | const unsigned *NVRegs = asmInfo.getCalleeSavedRegs(); |
| 398 | unsigned i; |
| 399 | for (i = 0; NVRegs[i] != 0; ++i) |
| 400 | if (NVRegs[i] == LLVMRegNo) |
| 401 | break; |
| 402 | if (NVRegs[i] == 0) |
| 403 | return Error(startLoc, "expected non-volatile register"); |
| 404 | |
| 405 | int SEHRegNo = asmInfo.getSEHRegNum(LLVMRegNo); |
| 406 | if (SEHRegNo < 0) |
| 407 | return Error(startLoc,"register can't be represented in SEH unwind info"); |
| 408 | RegNo = SEHRegNo; |
| 409 | } |
| 410 | else |
| 411 | RegNo = n; |
| 412 | |
| 413 | if (RegNo > 15) |
| 414 | return Error(startLoc, "register number is too high"); |
| 415 | return false; |
| 416 | } |
| 417 | |
Michael J. Spencer | 7d49004 | 2010-10-09 11:01:07 +0000 | [diff] [blame] | 418 | namespace llvm { |
| 419 | |
| 420 | MCAsmParserExtension *createCOFFAsmParser() { |
| 421 | return new COFFAsmParser; |
| 422 | } |
| 423 | |
| 424 | } |