private AnalysisNet.IInstruction ProcessLoadConstant(Cecil.Cil.Instruction op) { AnalysisNetBytecode.LoadOperation operation = OperationHelper.ToLoadOperation(op.OpCode.Code); AnalysisNet.Types.IType type = OperationHelper.GetOperationType(op.OpCode.Code); object value = OperationHelper.GetOperationConstant(op); AnalysisNetTac.Values.Constant source = new AnalysisNetTac.Values.Constant(value) { Type = type }; AnalysisNetBytecode.LoadInstruction instruction = new AnalysisNetBytecode.LoadInstruction((uint)op.Offset, operation, source); return(instruction); }
private AnalysisNet.IInstruction ProcessLoadArgument(Cecil.Cil.Instruction op) { AnalysisNetBytecode.LoadOperation operation = OperationHelper.ToLoadOperation(op.OpCode.Code); AnalysisNetTac.Values.IVariable source = thisParameter; int argIdx = -1; switch (op.OpCode.Code) { case Mono.Cecil.Cil.Code.Ldarg_0: argIdx = 0; break; case Mono.Cecil.Cil.Code.Ldarg_1: argIdx = 1; break; case Mono.Cecil.Cil.Code.Ldarg_2: argIdx = 2; break; case Mono.Cecil.Cil.Code.Ldarg_3: argIdx = 3; break; } if (argIdx > -1) { if (thisParameter != null && argIdx == 0) { source = thisParameter; } else { int hasThis = thisParameter != null ? 1 : 0; source = parameters[argIdx - hasThis]; } } if (op.Operand is Cecil.ParameterDefinition) { Cecil.ParameterDefinition parameter = op.Operand as Cecil.ParameterDefinition; source = parameters[parameter.Index]; } if (source == null) { throw new Exception("source cannot be null."); } AnalysisNetBytecode.LoadInstruction instruction = new AnalysisNetBytecode.LoadInstruction((uint)op.Offset, operation, source); return(instruction); }
private AnalysisNet.IInstruction ProcessLoadLocal(Cecil.Cil.Instruction op) { AnalysisNetBytecode.LoadOperation operation = OperationHelper.ToLoadOperation(op.OpCode.Code); AnalysisNetTac.Values.IVariable source = null; int localIdx = -1; switch (op.OpCode.Code) { case Mono.Cecil.Cil.Code.Ldloc_0: localIdx = 0; break; case Mono.Cecil.Cil.Code.Ldloc_1: localIdx = 1; break; case Mono.Cecil.Cil.Code.Ldloc_2: localIdx = 2; break; case Mono.Cecil.Cil.Code.Ldloc_3: localIdx = 3; break; case Mono.Cecil.Cil.Code.Ldloc_S: case Mono.Cecil.Cil.Code.Ldloca_S: case Mono.Cecil.Cil.Code.Ldloc: case Mono.Cecil.Cil.Code.Ldloca: Cecil.Cil.VariableDefinition varDef = (Cecil.Cil.VariableDefinition)op.Operand; source = locals[varDef.Index]; break; default: throw new NotImplementedException(); } if (localIdx > -1) { source = locals[localIdx]; } AnalysisNetBytecode.LoadInstruction instruction = new AnalysisNetBytecode.LoadInstruction((uint)op.Offset, operation, source); return(instruction); }