Added pools, IndexedFishMap, IndexedFishSet, fixed bugs related to FishTable.Remove, added Preview.png, various smaller additions, some refactoring too

This commit is contained in:
bbradson
2024-01-27 10:02:57 +01:00
parent cdf209eb02
commit af759661bd
38 changed files with 1879 additions and 642 deletions
@@ -0,0 +1,35 @@
// Copyright (c) 2022 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v.2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using FisheryLib.Collections;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace FisheryLib.Cecil;
public static class InstructionExtensions
{
public static bool LoadsArgument(this Instruction instruction, int index)
=> instruction.LoadsArgument() && GetLoadArgumentIndex(instruction) == index;
public static bool LoadsArgument(this Instruction instruction) => LoadArgumentOpcodes.Contains(instruction.OpCode);
private static int GetLoadArgumentIndex(Instruction instruction)
{
var opCode = instruction.OpCode;
return opCode == OpCodes.Ldarg_0 ? 0
: opCode == OpCodes.Ldarg_1 ? 1
: opCode == OpCodes.Ldarg_2 ? 2
: opCode == OpCodes.Ldarg_3 ? 3
: instruction.Operand is ParameterDefinition parameterDefinition ? parameterDefinition.Index
: Convert.Type<object, int>(instruction.Operand);
}
public static readonly FishSet<OpCode> LoadArgumentOpcodes =
[
OpCodes.Ldarg, OpCodes.Ldarg_0, OpCodes.Ldarg_1, OpCodes.Ldarg_2, OpCodes.Ldarg_3, OpCodes.Ldarg_S,
OpCodes.Ldarga, OpCodes.Ldarga_S
];
}