private IntPtr CreateMethod(IntPtr stub) { Compiler compiler = new Compiler(); compiler.NewFunction(CallingConvention.Default, typeof(Func<int>)); GPVar x = compiler.NewGP(VariableType.INT32); compiler.Mov(x, 2); compiler.Ret(x); compiler.EndFunction(); return compiler.Make(); }
private static void Main(string[] args) { TestExceptionHandling test = new TestExceptionHandling(); test.RunTest(); Compiler compiler = new Compiler(); CallingConvention callingConvention = CallingConvention.Default; compiler.NewFunction(callingConvention, typeof(Func<int>)); GPVar var = compiler.NewGP(); compiler.Mov(var, 3); compiler.Ret(var); compiler.EndFunction(); IntPtr ptr = compiler.Make(); Method1 method = (Method1)Marshal.GetDelegateForFunctionPointer(ptr, typeof(Method1)); int result = method(); Console.WriteLine(result); IntPtr method2Ptr = CreateMethodStub(); TestMethod method2 = (TestMethod)Marshal.GetDelegateForFunctionPointer(method2Ptr, typeof(TestMethod)); Console.WriteLine(method2()); }
private static void GenerateLoadExceptionMessage(Compiler c, GPVar dst, GPVar exceptionVariable) { c.Mov(dst, Mem.dword_ptr(exceptionVariable, ExceptionData_CodeOffset)); }
private static void GenerateLoadCurrentException(Compiler c, GPVar dst, GPVar threadDataVariable) { GenerateLoadThreadData(c, dst, threadDataVariable); c.Mov(dst, Mem.sysint_ptr(dst, ThreadData_ExceptionDataOffset)); }
private static void GenerateLoadThreadData(Compiler c, GPVar dst, GPVar threadDataVariable) { c.Mov(dst, threadDataVariable); }
private static void GenerateNewException(Compiler c, GPVar dst, Imm code) { GPVar var = c.NewGP(); c.Mov(var, code); CompilerFunctionCall call = c.Call(AllocateExceptionFunction, CallingConvention.Default, typeof(Func<int, IntPtr>)); call.SetArgument(0, var); call.SetReturn(dst); }
private static void GenerateWriteLine(Compiler c, Imm value) { GPVar var = c.NewGP(); c.Mov(var, value); GenerateWriteLine(c, var); }
private static CpuIdMethod BuildCpuIdFunction() { Compiler compiler = new Compiler(); compiler.NewFunction(CallingConvention.Default, typeof(Action<IntPtr, IntPtr, IntPtr, IntPtr>)); compiler.Function.SetHint(FunctionHints.Naked, true); GPVar eaxPtr = compiler.ArgGP(0); GPVar ebxPtr = compiler.ArgGP(1); GPVar ecxPtr = compiler.ArgGP(2); GPVar edxPtr = compiler.ArgGP(3); GPVar eax = compiler.NewGP(); GPVar ebx = compiler.NewGP(); GPVar ecx = compiler.NewGP(); GPVar edx = compiler.NewGP(); compiler.Mov(eax, Mem.dword_ptr(eaxPtr)); compiler.Cpuid(eax, ebx, ecx, edx); compiler.Mov(Mem.dword_ptr(eaxPtr), eax); compiler.Mov(Mem.dword_ptr(ebxPtr), ebx); compiler.Mov(Mem.dword_ptr(ecxPtr), ecx); compiler.Mov(Mem.dword_ptr(edxPtr), edx); compiler.Ret(); compiler.EndFunction(); CpuIdMethod cpuId = (CpuIdMethod)Marshal.GetDelegateForFunctionPointer(compiler.Make(), typeof(CpuIdMethod)); return cpuId; }