diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 0795cb963b3..c4e41de2791 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -20,6 +20,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/Support/TargetRegistry.h" +#include "llvm/ADT/APInt.h" using namespace llvm; @@ -1290,8 +1291,16 @@ bool MipsAsmParser::searchSymbolAlias( const MCSymbolRefExpr *Ref = static_cast(Expr); const StringRef DefSymbol = Ref->getSymbol().getName(); if (DefSymbol.startswith("$")) { - // Lookup for the register with the corresponding name. - int RegNum = matchRegisterName(DefSymbol.substr(1), isMips64()); + int RegNum = -1; + APInt IntVal(32, -1); + if (!DefSymbol.substr(1).getAsInteger(10, IntVal)) + RegNum = matchRegisterByNumber(IntVal.getZExtValue(), + isMips64() + ? Mips::CPU64RegsRegClassID + : Mips::CPURegsRegClassID); + else + // Lookup for the register with corresponding name + RegNum = matchRegisterName(DefSymbol.substr(1), isMips64()); if (RegNum > -1) { Parser.Lex(); MipsOperand *op = MipsOperand::CreateReg(RegNum, S, @@ -1305,7 +1314,7 @@ bool MipsAsmParser::searchSymbolAlias( Parser.Lex(); const MCConstantExpr *Const = static_cast(Expr); MipsOperand *op = MipsOperand::CreateImm(Const, S, - Parser.getTok().getLoc()); + Parser.getTok().getLoc()); Operands.push_back(op); return true; } @@ -1741,8 +1750,22 @@ bool MipsAsmParser::parseSetAssignment() { return reportParseError("unexpected token in .set directive"); Lex(); // Eat comma - if (Parser.parseExpression(Value)) - reportParseError("expected valid expression after comma"); + if (getLexer().is(AsmToken::Dollar)) { + MCSymbol *Symbol; + SMLoc DollarLoc = getLexer().getLoc(); + // Consume the dollar sign, and check for a following identifier. + Parser.Lex(); + // We have a '$' followed by something, make sure they are adjacent. + if (DollarLoc.getPointer() + 1 != getTok().getLoc().getPointer()) + return true; + StringRef Res = StringRef(DollarLoc.getPointer(), + getTok().getEndLoc().getPointer() - DollarLoc.getPointer()); + Symbol = getContext().GetOrCreateSymbol(Res); + Parser.Lex(); + Value = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, + getContext()); + } else if (Parser.parseExpression(Value)) + return reportParseError("expected valid expression after comma"); // Check if the Name already exists as a symbol. MCSymbol *Sym = getContext().LookupSymbol(Name); diff --git a/test/MC/Mips/mips_directives.s b/test/MC/Mips/mips_directives.s index 45247cd162b..24bef613c6b 100644 --- a/test/MC/Mips/mips_directives.s +++ b/test/MC/Mips/mips_directives.s @@ -37,7 +37,8 @@ $JTI0_0: .set at=$a0 .set STORE_MASK,$t7 .set FPU_MASK,$f7 + .set r3,$3 #CHECK: abs.s $f6, $f7 # encoding: [0x46,0x00,0x39,0x85] #CHECK: and $3, $15, $15 # encoding: [0x01,0xef,0x18,0x24] - abs.s $f6,FPU_MASK - and $3,$t7,STORE_MASK + abs.s $f6,FPU_MASK + and r3,$t7,STORE_MASK