From e9604c37df479a991d131d9540fafe78c7a0f7d4 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 9 Nov 2023 18:39:55 -0500 Subject: Add LLIL/MLIL instructions to describe integer vs. floating point argument usage --- mediumlevelilinstruction.cpp | 146 ++++++++++++++++++++++++++++--------------- 1 file changed, 96 insertions(+), 50 deletions(-) (limited to 'mediumlevelilinstruction.cpp') diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index f16d160e..bbf5988b 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -72,8 +72,8 @@ unordered_map MediumLevelIL {OutputSSAMemoryVersionMediumLevelOperandUsage, IndexMediumLevelOperand}, {ParameterExprsMediumLevelOperandUsage, ExprListMediumLevelOperand}, {SourceExprsMediumLevelOperandUsage, ExprListMediumLevelOperand}, - {ParameterVariablesMediumLevelOperandUsage, VariableListMediumLevelOperand}, - {ParameterSSAVariablesMediumLevelOperandUsage, SSAVariableListMediumLevelOperand}, + {UntypedParameterExprsMediumLevelOperandUsage, ExprListMediumLevelOperand}, + {UntypedParameterSSAExprsMediumLevelOperandUsage, ExprListMediumLevelOperand}, {ParameterSSAMemoryVersionMediumLevelOperandUsage, IndexMediumLevelOperand}, {SourceSSAVariablesMediumLevelOperandUsages, SSAVariableListMediumLevelOperand}}; @@ -126,35 +126,37 @@ unordered_map> {MLIL_CALL, {OutputVariablesMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage}}, {MLIL_CALL_UNTYPED, {OutputVariablesSubExprMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, - ParameterVariablesMediumLevelOperandUsage}}, + UntypedParameterExprsMediumLevelOperandUsage}}, {MLIL_SYSCALL, {OutputVariablesMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage}}, {MLIL_SYSCALL_UNTYPED, {OutputVariablesSubExprMediumLevelOperandUsage, - ParameterVariablesMediumLevelOperandUsage, StackExprMediumLevelOperandUsage}}, + UntypedParameterExprsMediumLevelOperandUsage, StackExprMediumLevelOperandUsage}}, {MLIL_TAILCALL, {OutputVariablesMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage}}, {MLIL_TAILCALL_UNTYPED, {OutputVariablesSubExprMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, - ParameterVariablesMediumLevelOperandUsage}}, + UntypedParameterExprsMediumLevelOperandUsage}}, {MLIL_CALL_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage, SourceMemoryVersionMediumLevelOperandUsage}}, {MLIL_CALL_UNTYPED_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, - DestExprMediumLevelOperandUsage, ParameterSSAVariablesMediumLevelOperandUsage, + DestExprMediumLevelOperandUsage, UntypedParameterSSAExprsMediumLevelOperandUsage, ParameterSSAMemoryVersionMediumLevelOperandUsage, StackExprMediumLevelOperandUsage}}, {MLIL_SYSCALL_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage, SourceMemoryVersionMediumLevelOperandUsage}}, {MLIL_SYSCALL_UNTYPED_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, - ParameterSSAVariablesMediumLevelOperandUsage, ParameterSSAMemoryVersionMediumLevelOperandUsage, + UntypedParameterSSAExprsMediumLevelOperandUsage, ParameterSSAMemoryVersionMediumLevelOperandUsage, StackExprMediumLevelOperandUsage}}, {MLIL_TAILCALL_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage, SourceMemoryVersionMediumLevelOperandUsage}}, {MLIL_TAILCALL_UNTYPED_SSA, {OutputSSAVariablesSubExprMediumLevelOperandUsage, OutputSSAMemoryVersionMediumLevelOperandUsage, - DestExprMediumLevelOperandUsage, ParameterSSAVariablesMediumLevelOperandUsage, + DestExprMediumLevelOperandUsage, UntypedParameterSSAExprsMediumLevelOperandUsage, ParameterSSAMemoryVersionMediumLevelOperandUsage, StackExprMediumLevelOperandUsage}}, + {MLIL_SEPARATE_PARAM_LIST, {ParameterExprsMediumLevelOperandUsage}}, + {MLIL_SHARED_PARAM_SLOT, {ParameterExprsMediumLevelOperandUsage}}, {MLIL_RET, {SourceExprsMediumLevelOperandUsage}}, {MLIL_IF, {ConditionExprMediumLevelOperandUsage, TrueTargetMediumLevelOperandUsage, FalseTargetMediumLevelOperandUsage}}, @@ -260,14 +262,14 @@ static unordered_map().VisitExprs(func); + for (auto i : GetParameterExprs()) + i.VisitExprs(func); break; case MLIL_CALL_SSA: GetDestExpr().VisitExprs(func); @@ -1429,15 +1435,25 @@ void MediumLevelILInstruction::VisitExprs(const std::function().VisitExprs(func); + for (auto i : GetParameterExprs()) + i.VisitExprs(func); break; case MLIL_SYSCALL: for (auto i : GetParameterExprs()) i.VisitExprs(func); break; + case MLIL_SYSCALL_UNTYPED: + for (auto i : GetParameterExprs()) + i.VisitExprs(func); + break; case MLIL_SYSCALL_SSA: for (auto i : GetParameterExprs()) i.VisitExprs(func); break; + case MLIL_SYSCALL_UNTYPED_SSA: + for (auto i : GetParameterExprs()) + i.VisitExprs(func); + break; case MLIL_TAILCALL: GetDestExpr().VisitExprs(func); for (auto i : GetParameterExprs()) @@ -1445,6 +1461,8 @@ void MediumLevelILInstruction::VisitExprs(const std::function().VisitExprs(func); + for (auto i : GetParameterExprs()) + i.VisitExprs(func); break; case MLIL_TAILCALL_SSA: GetDestExpr().VisitExprs(func); @@ -1453,6 +1471,16 @@ void MediumLevelILInstruction::VisitExprs(const std::function().VisitExprs(func); + for (auto i : GetParameterExprs()) + i.VisitExprs(func); + break; + case MLIL_SEPARATE_PARAM_LIST: + for (auto i : GetParameterExprs()) + i.VisitExprs(func); + break; + case MLIL_SHARED_PARAM_SLOT: + for (auto i : GetParameterExprs()) + i.VisitExprs(func); break; case MLIL_RET: for (auto i : GetSourceExprs()) @@ -1647,8 +1675,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, params.push_back(subExprHandler(i)); return dest->Call(GetOutputVariables(), subExprHandler(GetDestExpr()), params, *this); case MLIL_CALL_UNTYPED: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->CallUntyped(GetOutputVariables(), - subExprHandler(GetDestExpr()), GetParameterVariables(), + subExprHandler(GetDestExpr()), params, subExprHandler(GetStackExpr()), *this); case MLIL_CALL_SSA: for (auto i : GetParameterExprs()) @@ -1656,8 +1686,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, return dest->CallSSA(GetOutputSSAVariables(), subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); case MLIL_CALL_UNTYPED_SSA: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->CallUntypedSSA(GetOutputSSAVariables(), - subExprHandler(GetDestExpr()), GetParameterSSAVariables(), + subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), subExprHandler(GetStackExpr()), *this); case MLIL_SYSCALL: @@ -1665,16 +1697,20 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, params.push_back(subExprHandler(i)); return dest->Syscall(GetOutputVariables(), params, *this); case MLIL_SYSCALL_UNTYPED: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->SyscallUntyped(GetOutputVariables(), - GetParameterVariables(), subExprHandler(GetStackExpr()), *this); + params, subExprHandler(GetStackExpr()), *this); case MLIL_SYSCALL_SSA: for (auto i : GetParameterExprs()) params.push_back(subExprHandler(i)); return dest->SyscallSSA(GetOutputSSAVariables(), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); case MLIL_SYSCALL_UNTYPED_SSA: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->SyscallUntypedSSA(GetOutputSSAVariables(), - GetParameterSSAVariables(), GetDestMemoryVersion(), + params, GetDestMemoryVersion(), GetSourceMemoryVersion(), subExprHandler(GetStackExpr()), *this); case MLIL_TAILCALL: @@ -1683,8 +1719,10 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, return dest->TailCall( GetOutputVariables(), subExprHandler(GetDestExpr()), params, *this); case MLIL_TAILCALL_UNTYPED: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->TailCallUntyped(GetOutputVariables(), - subExprHandler(GetDestExpr()), GetParameterVariables(), + subExprHandler(GetDestExpr()), params, subExprHandler(GetStackExpr()), *this); case MLIL_TAILCALL_SSA: for (auto i : GetParameterExprs()) @@ -1693,11 +1731,21 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest, subExprHandler(GetDestExpr()), params, GetDestMemoryVersion(), GetSourceMemoryVersion(), *this); case MLIL_TAILCALL_UNTYPED_SSA: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); return dest->TailCallUntypedSSA(GetOutputSSAVariables(), subExprHandler(GetDestExpr()), - GetParameterSSAVariables(), GetDestMemoryVersion(), + params, GetDestMemoryVersion(), GetSourceMemoryVersion(), subExprHandler(GetStackExpr()), *this); + case MLIL_SEPARATE_PARAM_LIST: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); + return dest->SeparateParamList(params, *this); + case MLIL_SHARED_PARAM_SLOT: + for (auto i : GetParameterExprs()) + params.push_back(subExprHandler(i)); + return dest->SharedParamSlot(params, *this); case MLIL_RET: for (auto i : GetSourceExprs()) params.push_back(subExprHandler(i)); @@ -2161,6 +2209,10 @@ MediumLevelILInstructionList MediumLevelILInstruction::GetParameterExprs() const size_t operandIndex; if (GetOperandIndexForUsage(ParameterExprsMediumLevelOperandUsage, operandIndex)) return GetRawOperandAsExprList(operandIndex); + if (GetOperandIndexForUsage(UntypedParameterExprsMediumLevelOperandUsage, operandIndex)) + return GetRawOperandAsExpr(operandIndex).GetRawOperandAsExprList(0); + if (GetOperandIndexForUsage(UntypedParameterSSAExprsMediumLevelOperandUsage, operandIndex)) + return GetRawOperandAsExpr(operandIndex).GetRawOperandAsExprList(1); throw MediumLevelILInstructionAccessException(); } @@ -2174,24 +2226,6 @@ MediumLevelILInstructionList MediumLevelILInstruction::GetSourceExprs() const } -MediumLevelILVariableList MediumLevelILInstruction::GetParameterVariables() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(ParameterVariablesMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex).GetRawOperandAsVariableList(0); - throw MediumLevelILInstructionAccessException(); -} - - -MediumLevelILSSAVariableList MediumLevelILInstruction::GetParameterSSAVariables() const -{ - size_t operandIndex; - if (GetOperandIndexForUsage(ParameterSSAVariablesMediumLevelOperandUsage, operandIndex)) - return GetRawOperandAsExpr(operandIndex).GetRawOperandAsSSAVariableList(1); - throw MediumLevelILInstructionAccessException(); -} - - MediumLevelILSSAVariableList MediumLevelILInstruction::GetSourceSSAVariables() const { size_t operandIndex; @@ -2655,12 +2689,12 @@ ExprId MediumLevelILFunction::Call( } -ExprId MediumLevelILFunction::CallUntyped(const vector& output, ExprId dest, const vector& params, +ExprId MediumLevelILFunction::CallUntyped(const vector& output, ExprId dest, const vector& params, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_CALL_UNTYPED, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT, loc, 0, output.size(), AddVariableList(output)), dest, - AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddVariableList(params)), stack); + AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddOperandList(params)), stack); } @@ -2673,11 +2707,11 @@ ExprId MediumLevelILFunction::Syscall( ExprId MediumLevelILFunction::SyscallUntyped( - const vector& output, const vector& params, ExprId stack, const ILSourceLocation& loc) + const vector& output, const vector& params, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_SYSCALL_UNTYPED, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT, loc, 0, output.size(), AddVariableList(output)), - AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddVariableList(params)), stack); + AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddOperandList(params)), stack); } @@ -2690,11 +2724,11 @@ ExprId MediumLevelILFunction::TailCall( ExprId MediumLevelILFunction::TailCallUntyped(const vector& output, ExprId dest, - const vector& params, ExprId stack, const ILSourceLocation& loc) + const vector& params, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_TAILCALL_UNTYPED, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT, loc, 0, output.size(), AddVariableList(output)), dest, - AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddVariableList(params)), stack); + AddExprWithLocation(MLIL_CALL_PARAM, loc, 0, params.size(), AddOperandList(params)), stack); } @@ -2708,13 +2742,13 @@ ExprId MediumLevelILFunction::CallSSA(const vector& output, ExprId ExprId MediumLevelILFunction::CallUntypedSSA(const vector& output, ExprId dest, - const vector& params, size_t newMemVersion, size_t prevMemVersion, ExprId stack, + const vector& params, size_t newMemVersion, size_t prevMemVersion, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_CALL_UNTYPED_SSA, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT_SSA, loc, 0, newMemVersion, output.size() * 2, AddSSAVariableList(output)), dest, - AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size() * 2, AddSSAVariableList(params)), + AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size(), AddOperandList(params)), stack); } @@ -2728,12 +2762,12 @@ ExprId MediumLevelILFunction::SyscallSSA(const vector& output, cons } -ExprId MediumLevelILFunction::SyscallUntypedSSA(const vector& output, const vector& params, +ExprId MediumLevelILFunction::SyscallUntypedSSA(const vector& output, const vector& params, size_t newMemVersion, size_t prevMemVersion, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_SYSCALL_UNTYPED_SSA, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT_SSA, loc, 0, newMemVersion, output.size() * 2, AddSSAVariableList(output)), - AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size() * 2, AddSSAVariableList(params)), + AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size(), AddOperandList(params)), stack); } @@ -2748,17 +2782,29 @@ ExprId MediumLevelILFunction::TailCallSSA(const vector& output, Exp ExprId MediumLevelILFunction::TailCallUntypedSSA(const vector& output, ExprId dest, - const vector& params, size_t newMemVersion, size_t prevMemVersion, ExprId stack, + const vector& params, size_t newMemVersion, size_t prevMemVersion, ExprId stack, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_TAILCALL_UNTYPED_SSA, loc, 0, AddExprWithLocation(MLIL_CALL_OUTPUT_SSA, loc, 0, newMemVersion, output.size() * 2, AddSSAVariableList(output)), dest, - AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size() * 2, AddSSAVariableList(params)), + AddExprWithLocation(MLIL_CALL_PARAM_SSA, loc, 0, prevMemVersion, params.size(), AddOperandList(params)), stack); } +ExprId MediumLevelILFunction::SeparateParamList(const vector& params, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_SEPARATE_PARAM_LIST, loc, 0, params.size(), AddOperandList(params)); +} + + +ExprId MediumLevelILFunction::SharedParamSlot(const vector& params, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_SHARED_PARAM_SLOT, loc, 0, params.size(), AddOperandList(params)); +} + + ExprId MediumLevelILFunction::Return(const vector& sources, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_RET, loc, 0, sources.size(), AddOperandList(sources)); -- cgit v1.3.1