Chromium Code Reviews| Index: src/PNaClTranslator.cpp |
| diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp |
| index 8f157a64984efcb52154366f0fb93e59b04dc901..b7f750ea8177eccfad1dcf3ef0838ecee2573944 100644 |
| --- a/src/PNaClTranslator.cpp |
| +++ b/src/PNaClTranslator.cpp |
| @@ -909,6 +909,12 @@ private: |
| return LocalOperands[LocalIndex]; |
| } |
| + // Returns the relative operand (wrt to next instruction) referenced by |
| + // the given value index. |
| + Ice::Operand *getRelativeOperand(uint32_t Index) { |
|
jvoung (off chromium)
2014/09/02 21:06:46
could these methods have been const?
Karl
2014/09/02 22:45:11
No. The parser needs to be able to generate an err
|
| + return getOperand(convertRelativeToAbsIndex(Index)); |
| + } |
| + |
| // Generates type error message for binary operator Op |
| // operating on Type OpTy. |
| void ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy); |
| @@ -1143,8 +1149,8 @@ void FunctionParser::ProcessRecord() { |
| // BINOP: [opval, opval, opcode] |
| if (!isValidRecordSize(3, "function block binop")) |
| return; |
| - Ice::Operand *Op1 = getOperand(convertRelativeToAbsIndex(Values[0])); |
| - Ice::Operand *Op2 = getOperand(convertRelativeToAbsIndex(Values[1])); |
| + Ice::Operand *Op1 = getRelativeOperand(Values[0]); |
| + Ice::Operand *Op2 = getRelativeOperand(Values[1]); |
| Ice::Type Type1 = Op1->getType(); |
| Ice::Type Type2 = Op2->getType(); |
| if (Type1 != Type2) { |
| @@ -1167,7 +1173,7 @@ void FunctionParser::ProcessRecord() { |
| // CAST: [opval, destty, castopc] |
| if (!isValidRecordSize(3, "function block cast")) |
| return; |
| - Ice::Operand *Src = getOperand(convertRelativeToAbsIndex(Values[0])); |
| + Ice::Operand *Src = getRelativeOperand(Values[0]); |
| Type *CastType = Context->getTypeByID(Values[1]); |
| Instruction::CastOps LLVMCastOp; |
| Ice::InstCast::OpKind CastKind; |
| @@ -1192,6 +1198,57 @@ void FunctionParser::ProcessRecord() { |
| Inst = Ice::InstCast::create(Func, CastKind, Dest, Src); |
| break; |
| } |
| + case naclbitc::FUNC_CODE_INST_EXTRACTELT: { |
| + // EXTRACTELT: [opval, opval] |
| + Ice::Operand *Vec = getRelativeOperand(Values[0]); |
| + Ice::Type VecType = Vec->getType(); |
| + if (!Ice::isVectorType(VecType)) { |
| + std::string Buffer; |
| + raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Extractelement not on vector. Found: " << Vec; |
| + Error(StrBuf.str()); |
| + } |
| + Ice::Operand *Index = getRelativeOperand(Values[1]); |
| + if (Index->getType() != Ice::IceType_i32) { |
| + std::string Buffer; |
| + raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Extractlement index not i32. Found: " << Index; |
|
jvoung (off chromium)
2014/09/02 21:06:46
Extractelement
Karl
2014/09/02 22:45:11
Done.
|
| + Error(StrBuf.str()); |
| + } |
| + Ice::Variable *Dest = NextInstVar(typeElementType(VecType)); |
| + Inst = Ice::InstExtractElement::create(Func, Dest, Vec, Index); |
| + break; |
| + } |
| + case naclbitc::FUNC_CODE_INST_INSERTELT: { |
| + // INSERTELT: [opval,opval,opval] |
|
jvoung (off chromium)
2014/09/02 21:06:46
spaces between , opval ?
Karl
2014/09/02 22:45:11
Done.
|
| + Ice::Operand *Vec = getRelativeOperand(Values[0]); |
| + Ice::Type VecType = Vec->getType(); |
| + if (!Ice::isVectorType(VecType)) { |
| + std::string Buffer; |
| + raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Insertelement not on vector. Found: " << Vec; |
| + Error(StrBuf.str()); |
| + } |
| + Ice::Operand *Elt = getRelativeOperand(Values[1]); |
| + Ice::Type EltType = Elt->getType(); |
| + if (EltType != typeElementType(VecType)) { |
| + std::string Buffer; |
| + raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Insertelement element not " << typeElementType(VecType) |
| + << ". Found: " << Elt; |
| + Error(StrBuf.str()); |
| + } |
| + Ice::Operand *Index = getRelativeOperand(Values[2]); |
| + if (Index->getType() != Ice::IceType_i32) { |
| + std::string Buffer; |
| + raw_string_ostream StrBuf(Buffer); |
| + StrBuf << "Insertelement index not i32. Found: " << Index; |
| + Error(StrBuf.str()); |
| + } |
| + Ice::Variable *Dest = NextInstVar(EltType); |
| + Inst = Ice::InstInsertElement::create(Func, Dest, Vec, Elt, Index); |
| + break; |
| + } |
| case naclbitc::FUNC_CODE_INST_RET: { |
| // RET: [opval?] |
| InstIsTerminating = true; |
| @@ -1201,7 +1258,7 @@ void FunctionParser::ProcessRecord() { |
| Inst = Ice::InstRet::create(Func); |
| } else { |
| Inst = Ice::InstRet::create( |
| - Func, getOperand(convertRelativeToAbsIndex(Values[0]))); |
| + Func, getRelativeOperand(Values[0])); |
| } |
| break; |
| } |