Washi1337/Echo

Adding OpCodes Handlers From User Code.

CursedLand opened this issue · 2 comments

Make External Implemention ICilOpCodeHandler In User Code To Add His Own OpCode Support. :)

This is already possible, by configuring the CilDispatcher of the CilVirtualMachine.

Below an example on how to override the behaviour of the add opcode.

public class MyOpCodeHandler : ICilOpCodeHandler
{
    public IReadOnlyCollection<CilCode> SupportedOpCodes => new[] { CilCode.Add };
    
    public DispatchResult Execute(CilExecutionContext context, CilInstruction instruction)
    {
        // ...
    }
}

var dispatcher = new CilDispatcher();
dispatcher.DispatcherTable[CilCode.Add] = new MyOpCodeHandler();

vm.Dispatcher = dispatcher;

Nice, Thanks.