diff options
| author | Rusty Wagner <rusty@vector35.com> | 2017-09-18 23:25:08 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2017-10-03 23:08:48 -0400 |
| commit | 1c6f11277096534479c958b6d9fc5265d318ca2a (patch) | |
| tree | 8263ebd0ecbcd72840bb70d008c33d6d21f73c24 /mediumlevelilinstruction.cpp | |
| parent | d7701ace7ac399c26e3ef3eca17e36324c5ea19d (diff) | |
Add basic floating point instructions
Diffstat (limited to 'mediumlevelilinstruction.cpp')
| -rw-r--r-- | mediumlevelilinstruction.cpp | 250 |
1 files changed, 197 insertions, 53 deletions
diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index ec6aa1c6..b0e607b2 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -45,8 +45,6 @@ unordered_map<MediumLevelILOperandUsage, MediumLevelILOperandType> {LeftExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {RightExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {CarryExprMediumLevelOperandUsage, ExprMediumLevelOperand}, - {HighExprMediumLevelOperandUsage, ExprMediumLevelOperand}, - {LowExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {StackExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {ConditionExprMediumLevelOperandUsage, ExprMediumLevelOperand}, {HighVariableMediumLevelOperandUsage, VariableMediumLevelOperand}, @@ -112,10 +110,12 @@ unordered_map<BNMediumLevelILOperation, vector<MediumLevelILOperandUsage>> SourceExprMediumLevelOperandUsage}}, {MLIL_VAR, {SourceVariableMediumLevelOperandUsage}}, {MLIL_VAR_FIELD, {SourceVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, + {MLIL_VAR_SPLIT, {HighVariableMediumLevelOperandUsage, LowVariableMediumLevelOperandUsage}}, {MLIL_VAR_SSA, {SourceSSAVariableMediumLevelOperandUsage}}, {MLIL_VAR_SSA_FIELD, {SourceSSAVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, {MLIL_VAR_ALIASED, {SourceSSAVariableMediumLevelOperandUsage}}, {MLIL_VAR_ALIASED_FIELD, {SourceSSAVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, + {MLIL_VAR_SPLIT_SSA, {HighSSAVariableMediumLevelOperandUsage, LowSSAVariableMediumLevelOperandUsage}}, {MLIL_ADDRESS_OF, {SourceVariableMediumLevelOperandUsage}}, {MLIL_ADDRESS_OF_FIELD, {SourceVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, {MLIL_JUMP, {DestExprMediumLevelOperandUsage}}, @@ -187,21 +187,34 @@ unordered_map<BNMediumLevelILOperation, vector<MediumLevelILOperandUsage>> CarryExprMediumLevelOperandUsage}}, {MLIL_RRC, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage, CarryExprMediumLevelOperandUsage}}, - {MLIL_DIVU_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_DIVS_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_MODU_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, - {MLIL_MODS_DP, {HighExprMediumLevelOperandUsage, LowExprMediumLevelOperandUsage, - RightExprMediumLevelOperandUsage}}, + {MLIL_DIVU_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_DIVS_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_MODU_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_MODS_DP, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, {MLIL_NEG, {SourceExprMediumLevelOperandUsage}}, {MLIL_NOT, {SourceExprMediumLevelOperandUsage}}, {MLIL_SX, {SourceExprMediumLevelOperandUsage}}, {MLIL_ZX, {SourceExprMediumLevelOperandUsage}}, {MLIL_LOW_PART, {SourceExprMediumLevelOperandUsage}}, {MLIL_BOOL_TO_INT, {SourceExprMediumLevelOperandUsage}}, - {MLIL_UNIMPL_MEM, {SourceExprMediumLevelOperandUsage}} + {MLIL_UNIMPL_MEM, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FADD, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FSUB, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FMUL, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FDIV, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FSQRT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FNEG, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FABS, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FLOAT_TO_INT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_INT_TO_FLOAT, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FLOAT_CONV, {SourceExprMediumLevelOperandUsage}}, + {MLIL_FCMP_E, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_NE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_LT, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_LE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_GE, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_GT, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}}, + {MLIL_FCMP_UO, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}} }; @@ -1266,6 +1279,12 @@ void MediumLevelILInstruction::VisitExprs(const std::function<bool(const MediumL case MLIL_LOAD_STRUCT: case MLIL_LOAD_SSA: case MLIL_LOAD_STRUCT_SSA: + case MLIL_FSQRT: + case MLIL_FNEG: + case MLIL_FABS: + case MLIL_FLOAT_TO_INT: + case MLIL_INT_TO_FLOAT: + case MLIL_FLOAT_CONV: AsOneOperand().GetSourceExpr().VisitExprs(func); break; case MLIL_ADD: @@ -1285,6 +1304,10 @@ void MediumLevelILInstruction::VisitExprs(const std::function<bool(const MediumL case MLIL_DIVS: case MLIL_MODU: case MLIL_MODS: + case MLIL_DIVU_DP: + case MLIL_DIVS_DP: + case MLIL_MODU_DP: + case MLIL_MODS_DP: case MLIL_CMP_E: case MLIL_CMP_NE: case MLIL_CMP_SLT: @@ -1297,6 +1320,17 @@ void MediumLevelILInstruction::VisitExprs(const std::function<bool(const MediumL case MLIL_CMP_UGT: case MLIL_TEST_BIT: case MLIL_ADD_OVERFLOW: + case MLIL_FADD: + case MLIL_FSUB: + case MLIL_FMUL: + case MLIL_FDIV: + case MLIL_FCMP_E: + case MLIL_FCMP_NE: + case MLIL_FCMP_LT: + case MLIL_FCMP_LE: + case MLIL_FCMP_GE: + case MLIL_FCMP_GT: + case MLIL_FCMP_UO: AsTwoOperand().GetLeftExpr().VisitExprs(func); AsTwoOperand().GetRightExpr().VisitExprs(func); break; @@ -1308,14 +1342,6 @@ void MediumLevelILInstruction::VisitExprs(const std::function<bool(const MediumL AsTwoOperandWithCarry().GetRightExpr().VisitExprs(func); AsTwoOperandWithCarry().GetCarryExpr().VisitExprs(func); break; - case MLIL_DIVU_DP: - case MLIL_DIVS_DP: - case MLIL_MODU_DP: - case MLIL_MODS_DP: - AsDoublePrecision().GetHighExpr().VisitExprs(func); - AsDoublePrecision().GetLowExpr().VisitExprs(func); - AsDoublePrecision().GetRightExpr().VisitExprs(func); - break; default: break; } @@ -1380,6 +1406,9 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_VAR_FIELD: return dest->VarField(size, GetSourceVariable<MLIL_VAR_FIELD>(), GetOffset<MLIL_VAR_FIELD>(), *this); + case MLIL_VAR_SPLIT: + return dest->VarSplit(size, GetHighVariable<MLIL_VAR_SPLIT>(), + GetLowVariable<MLIL_VAR_SPLIT>(), *this); case MLIL_VAR_SSA: return dest->VarSSA(size, GetSourceSSAVariable<MLIL_VAR_SSA>(), *this); case MLIL_VAR_SSA_FIELD: @@ -1392,6 +1421,9 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, return dest->VarAliasedField(size, GetSourceSSAVariable<MLIL_VAR_ALIASED_FIELD>().var, GetSourceSSAVariable<MLIL_VAR_ALIASED_FIELD>().version, GetOffset<MLIL_VAR_ALIASED_FIELD>(), *this); + case MLIL_VAR_SPLIT_SSA: + return dest->VarSplitSSA(size, GetHighSSAVariable<MLIL_VAR_SPLIT_SSA>(), + GetLowSSAVariable<MLIL_VAR_SPLIT_SSA>(), *this); case MLIL_ADDRESS_OF: return dest->AddressOf(GetSourceVariable<MLIL_ADDRESS_OF>(), *this); case MLIL_ADDRESS_OF_FIELD: @@ -1477,6 +1509,12 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_BOOL_TO_INT: case MLIL_JUMP: case MLIL_UNIMPL_MEM: + case MLIL_FSQRT: + case MLIL_FNEG: + case MLIL_FABS: + case MLIL_FLOAT_TO_INT: + case MLIL_INT_TO_FLOAT: + case MLIL_FLOAT_CONV: return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsOneOperand().GetSourceExpr())); case MLIL_ADD: @@ -1496,6 +1534,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_DIVS: case MLIL_MODU: case MLIL_MODS: + case MLIL_DIVU_DP: + case MLIL_DIVS_DP: + case MLIL_MODU_DP: + case MLIL_MODS_DP: case MLIL_CMP_E: case MLIL_CMP_NE: case MLIL_CMP_SLT: @@ -1508,6 +1550,17 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, case MLIL_CMP_UGT: case MLIL_TEST_BIT: case MLIL_ADD_OVERFLOW: + case MLIL_FADD: + case MLIL_FSUB: + case MLIL_FMUL: + case MLIL_FDIV: + case MLIL_FCMP_E: + case MLIL_FCMP_NE: + case MLIL_FCMP_LT: + case MLIL_FCMP_LE: + case MLIL_FCMP_GE: + case MLIL_FCMP_GT: + case MLIL_FCMP_UO: return dest->AddExprWithLocation(operation, *this, size, subExprHandler(AsTwoOperand().GetLeftExpr()), subExprHandler(AsTwoOperand().GetRightExpr())); case MLIL_ADC: @@ -1518,14 +1571,6 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, subExprHandler(AsTwoOperandWithCarry().GetLeftExpr()), subExprHandler(AsTwoOperandWithCarry().GetRightExpr()), subExprHandler(AsTwoOperandWithCarry().GetCarryExpr())); - case MLIL_DIVU_DP: - case MLIL_DIVS_DP: - case MLIL_MODU_DP: - case MLIL_MODS_DP: - return dest->AddExprWithLocation(operation, *this, size, - subExprHandler(AsDoublePrecision().GetHighExpr()), - subExprHandler(AsDoublePrecision().GetLowExpr()), - subExprHandler(AsDoublePrecision().GetRightExpr())); case MLIL_JUMP_TO: for (auto target : GetTargetList<MLIL_JUMP_TO>()) { @@ -1665,24 +1710,6 @@ MediumLevelILInstruction MediumLevelILInstruction::GetCarryExpr() const } -MediumLevelILInstruction MediumLevelILInstruction::GetHighExpr() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(HighExprMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex); - throw MediumLevelILInstructionAccessException(); -} - - -MediumLevelILInstruction MediumLevelILInstruction::GetLowExpr() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(LowExprMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex); - throw MediumLevelILInstructionAccessException(); -} - - MediumLevelILInstruction MediumLevelILInstruction::GetStackExpr() const { size_t operandIndex; @@ -2036,6 +2063,13 @@ ExprId MediumLevelILFunction::VarField(size_t size, const Variable& src, uint64_ } +ExprId MediumLevelILFunction::VarSplit(size_t size, const Variable& high, const Variable& low, + const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_VAR_SPLIT, loc, size, high.ToIdentifier(), low.ToIdentifier()); +} + + ExprId MediumLevelILFunction::VarSSA(size_t size, const SSAVariable& src, const ILSourceLocation& loc) { @@ -2064,6 +2098,14 @@ ExprId MediumLevelILFunction::VarAliasedField(size_t size, const Variable& src, } +ExprId MediumLevelILFunction::VarSplitSSA(size_t size, const SSAVariable& high, const SSAVariable& low, + const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_VAR_SPLIT_SSA, loc, size, high.var.ToIdentifier(), high.version, + low.var.ToIdentifier(), low.version); +} + + ExprId MediumLevelILFunction::AddressOf(const Variable& var, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_ADDRESS_OF, loc, 0, var.ToIdentifier()); @@ -2223,17 +2265,17 @@ ExprId MediumLevelILFunction::DivUnsigned(size_t size, ExprId left, ExprId right } -ExprId MediumLevelILFunction::DivDoublePrecSigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::DivDoublePrecSigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_DIVS_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_DIVS_DP, loc, size, left, right); } -ExprId MediumLevelILFunction::DivDoublePrecUnsigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::DivDoublePrecUnsigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_DIVU_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_DIVU_DP, loc, size, left, right); } @@ -2251,17 +2293,17 @@ ExprId MediumLevelILFunction::ModUnsigned(size_t size, ExprId left, ExprId right } -ExprId MediumLevelILFunction::ModDoublePrecSigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::ModDoublePrecSigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_MODS_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_MODS_DP, loc, size, left, right); } -ExprId MediumLevelILFunction::ModDoublePrecUnsigned(size_t size, ExprId high, ExprId low, ExprId right, +ExprId MediumLevelILFunction::ModDoublePrecUnsigned(size_t size, ExprId left, ExprId right, const ILSourceLocation& loc) { - return AddExprWithLocation(MLIL_MODU_DP, loc, size, high, low, right); + return AddExprWithLocation(MLIL_MODU_DP, loc, size, left, right); } @@ -2533,3 +2575,105 @@ ExprId MediumLevelILFunction::MemoryPhi(size_t destMemVersion, const vector<size return AddExprWithLocation(MLIL_MEM_PHI, loc, 0, destMemVersion, sourceMemVersions.size(), AddIndexList(sourceMemVersions)); } + + +ExprId MediumLevelILFunction::FloatAdd(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FADD, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatSub(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FSUB, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatMult(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FMUL, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatDiv(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FDIV, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatSqrt(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FSQRT, loc, size, a); +} + + +ExprId MediumLevelILFunction::FloatNeg(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FNEG, loc, size, a); +} + + +ExprId MediumLevelILFunction::FloatAbs(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FABS, loc, size, a); +} + + +ExprId MediumLevelILFunction::FloatToInt(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FLOAT_TO_INT, loc, size, a); +} + + +ExprId MediumLevelILFunction::IntToFloat(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_INT_TO_FLOAT, loc, size, a); +} + + +ExprId MediumLevelILFunction::FloatConvert(size_t size, ExprId a, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FLOAT_CONV, loc, size, a); +} + + +ExprId MediumLevelILFunction::FloatCompareEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_E, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareNotEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_NE, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareLessThan(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_LT, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareLessEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_LE, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareGreaterEqual(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_GE, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareGreaterThan(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_GT, loc, size, a, b); +} + + +ExprId MediumLevelILFunction::FloatCompareUnordered(size_t size, ExprId a, ExprId b, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_FCMP_UO, loc, size, a, b); +} |
