llvm.org GIT mirror llvm / 637e1da
[mips] Hoist common functionality into a new function. Given that we support multiple directives that enable a particular feature (e.g. '.set mips16'), it's best to hoist that code into a new function so that we don't repeat the same pattern w.r.t parsing and handling error cases. No functional changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204811 91177308-0d34-0410-b5e6-96231b3b80d8 Matheus Almeida 6 years ago
1 changed file(s) with 30 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
194194 const MCExpr *evaluateRelocExpr(const MCExpr *Expr, StringRef RelocStr);
195195
196196 bool isEvaluated(const MCExpr *Expr);
197 bool parseSetFeature(uint64_t Feature);
197198 bool parseDirectiveSet();
198199 bool parseDirectiveOption();
199200
203204 bool parseSetNoMacroDirective();
204205 bool parseSetReorderDirective();
205206 bool parseSetNoReorderDirective();
206 bool parseSetMips16Directive();
207207 bool parseSetNoMips16Directive();
208208
209209 bool parseSetAssignment();
24312431 return false;
24322432 }
24332433
2434 bool MipsAsmParser::parseSetMips16Directive() {
2435 Parser.Lex();
2436 // If this is not the end of the statement, report an error.
2437 if (getLexer().isNot(AsmToken::EndOfStatement)) {
2438 reportParseError("unexpected token in statement");
2439 return false;
2440 }
2441 getTargetStreamer().emitDirectiveSetMips16();
2442 Parser.Lex(); // Consume the EndOfStatement.
2443 return false;
2444 }
2445
24462434 bool MipsAsmParser::parseSetNoMips16Directive() {
24472435 Parser.Lex();
24482436 // If this is not the end of the statement, report an error.
24762464 Sym = getContext().GetOrCreateSymbol(Name);
24772465 Sym->setVariableValue(Value);
24782466
2467 return false;
2468 }
2469
2470 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
2471 Parser.Lex();
2472 if (getLexer().isNot(AsmToken::EndOfStatement))
2473 return reportParseError("unexpected token in .set directive");
2474
2475 switch(Feature) {
2476 default: llvm_unreachable("Unimplemented feature");
2477 case Mips::FeatureDSP:
2478 setFeatureBits(Mips::FeatureDSP, "dsp");
2479 getTargetStreamer().emitDirectiveSetDsp();
2480 break;
2481 case Mips::FeatureMicroMips:
2482 getTargetStreamer().emitDirectiveSetMicroMips();
2483 break;
2484 case Mips::FeatureMips16:
2485 getTargetStreamer().emitDirectiveSetMips16();
2486 break;
2487 case Mips::FeatureMips32r2:
2488 setFeatureBits(Mips::FeatureMips32r2, "mips32r2");
2489 getTargetStreamer().emitDirectiveSetMips32R2();
2490 break;
2491 }
24792492 return false;
24802493 }
24812494
24972510 } else if (Tok.getString() == "nomacro") {
24982511 return parseSetNoMacroDirective();
24992512 } else if (Tok.getString() == "mips16") {
2500 return parseSetMips16Directive();
2513 return parseSetFeature(Mips::FeatureMips16);
25012514 } else if (Tok.getString() == "nomips16") {
25022515 return parseSetNoMips16Directive();
25032516 } else if (Tok.getString() == "nomicromips") {
25052518 Parser.eatToEndOfStatement();
25062519 return false;
25072520 } else if (Tok.getString() == "micromips") {
2508 getTargetStreamer().emitDirectiveSetMicroMips();
2509 Parser.eatToEndOfStatement();
2510 return false;
2521 return parseSetFeature(Mips::FeatureMicroMips);
25112522 } else if (Tok.getString() == "mips32r2") {
2512 Parser.Lex(); // Eat token.
2513 if (getLexer().isNot(AsmToken::EndOfStatement))
2514 return reportParseError("unexpected token in .set directive");
2515 setFeatureBits(Mips::FeatureMips32r2,"mips32r2");
2516 getTargetStreamer().emitDirectiveSetMips32R2();
2517 return false;
2523 return parseSetFeature(Mips::FeatureMips32r2);
25182524 } else if (Tok.getString() == "dsp") {
2519 Parser.Lex(); // Eat token.
2520 if (getLexer().isNot(AsmToken::EndOfStatement))
2521 return reportParseError("unexpected token in .set directive");
2522 setFeatureBits(Mips::FeatureDSP, "dsp");
2523 getTargetStreamer().emitDirectiveSetDsp();
2524 return false;
2525 return parseSetFeature(Mips::FeatureDSP);
25252526 } else {
25262527 // It is just an identifier, look for an assignment.
25272528 parseSetAssignment();