Ejemplo n.º 1
0
 public void Dispose( )
 {
     JIT.Dispose( );
     Module?.Dispose( );
     FunctionPassManager?.Dispose( );
     Context.Dispose( );
 }
Ejemplo n.º 2
0
        public static int Open(ref lua_State state)
        {
            ClientConsole.RerouteConsole();
            ClientConsole.Color = new Color(0, 150, 255);
            Lua = GLua.Get(state);

            Lua.CreateTable();

            Lua.Push <Action <string> >(Dump);
            Lua.SetField(-2, "Dump");

            Lua.SetField(GLua.LUA_GLOBALSINDEX, "csluaview");

            var container = NativeInterface.Load <INetworkStringTableContainer>("engine", StringTableInterfaceName.CLIENT);
            var tablePtr  = container.FindTable("client_lua_files");
            var table     = JIT.ConvertInstance <INetworkStringTable>(tablePtr);

            Console.WriteLine($"dotnet table ptr: {tablePtr.ToString("X8")}");
            //var path0 = table.GetString(0); //hangs here

            //for (int i = 0; i < table.GetNumStrings(); i++)
            //{
            //}

            //var stringTable = StringTable.FindTable<int>("client_lua_files");
            //var luaFiles = stringTable.Select(s => new LuaFile { Path = s.String, CRC = s.UserData }).ToList();

            Console.WriteLine("DotNet Clientside Lua Viewer Loaded!");
            return(0);
        }
Ejemplo n.º 3
0
        public static IServer GetIServer()
        {
            var ptrptr = SymbolFinder.ResolveOnBinary("engine.dll", IServer_sig);//this is IServer**
            var ptr    = Marshal.ReadIntPtr(ptrptr);

            return(JIT.ConvertInstance <IServer>(ptr));
        }
Ejemplo n.º 4
0
        public void TellMeDemands(EngineContainer container)
        {
            if (container == null || container.ItemFlows == null || container.ItemFlows.Count == 0)
            {
                return;
            }

            #region Initialize
            kb  = new KB(container.Plans, container.InvBalances, container.DemandChains);
            jit = new JIT(container.Plans, container.InvBalances, container.DemandChains);
            odp = new ODP(container.Plans, container.InvBalances, container.DemandChains);
            #endregion

            #region Container param
            List <ItemFlow>    ItemFlows    = container.ItemFlows;
            List <Plans>       Plans        = container.Plans;
            List <InvBalance>  InvBalances  = container.InvBalances;
            List <DemandChain> DemandChains = container.DemandChains;
            #endregion

            #region Process time
            List <Flow> flows = ItemFlows.Select(s => s.Flow).Distinct().ToList <Flow>();
            this.ProcessTime(flows);
            #endregion

            #region Process ReqQty
            foreach (var itemFlow in ItemFlows)
            {
                this.DataValidCheck(itemFlow);
                this.SetFlowProperty(itemFlow, flows);

                this.ProcessReqQty(itemFlow);
            }
            #endregion
        }
Ejemplo n.º 5
0
        public static TClass Load <TClass>(string dllname, string interfaceVersionString) where TClass : class
        {
            var factory  = LoadCreateInterface(dllname);
            var classptr = factory(interfaceVersionString, IntPtr.Zero);

            return(JIT.ConvertInstance <TClass>(classptr));
        }
Ejemplo n.º 6
0
        public StudyPage()
        {
            InitializeComponent();

            #region AnimationsInit
            Task.WhenAll(
                CSharpDef.FadeTo(0, 1),
                definitions.FadeTo(0, 1),
                progLang.FadeTo(0, 1),
                OOP.FadeTo(0, 1),
                DotNETFramework.FadeTo(0, 1),
                clr.FadeTo(0, 1),
                cls.FadeTo(0, 1),
                cts.FadeTo(0, 1),
                MSIL.FadeTo(0, 1),
                JIT.FadeTo(0, 1),
                Compiler.FadeTo(0, 1),
                SourceCode.FadeTo(0, 1),
                ExecutableCode.FadeTo(0, 1),
                boxview1.FadeTo(0, 1),
                generalProgTerms.FadeTo(0, 1),
                Variables.FadeTo(0, 1),
                DataType.FadeTo(0, 1),
                Keywords.FadeTo(0, 1),
                Operators.FadeTo(0, 1),
                Expression.FadeTo(0, 1),
                TypeCasting.FadeTo(0, 1),
                Arrays.FadeTo(0, 1),
                Function.FadeTo(0, 1),
                Class.FadeTo(0, 1),
                Object.FadeTo(0, 1),
                Constructor.FadeTo(0, 1),
                Destructor.FadeTo(0, 1),
                Namespaces.FadeTo(0, 1),
                Exceptions.FadeTo(0, 1),
                ExceptionHandling.FadeTo(0, 1),
                boxview2.FadeTo(0, 1),
                oopProgTerms.FadeTo(0, 1),
                Inheritance.FadeTo(0, 1),
                BaseClass.FadeTo(0, 1),
                DerivedClass.FadeTo(0, 1),
                AbstractClass.FadeTo(0, 1),
                MultilevelInheritance.FadeTo(0, 1),
                HierarchicalInheritance.FadeTo(0, 1),
                SingleInheritance.FadeTo(0, 1),
                Interface.FadeTo(0, 1),
                Polymorphism.FadeTo(0, 1),
                Overriding.FadeTo(0, 1),
                Encapsulation.FadeTo(0, 1),
                Abstraction.FadeTo(0, 1),
                Overloading.FadeTo(0, 1));
            #endregion


            // App.adCounter = 0;
        }
Ejemplo n.º 7
0
        protected async override void OnAppearing()
        {
            #region AnimationsFadeIn
            await Task.WhenAll(
                CSharpDef.FadeTo(1, 500),
                definitions.FadeTo(1, 500),
                progLang.FadeTo(1, 500),
                OOP.FadeTo(1, 500),
                DotNETFramework.FadeTo(1, 500),
                clr.FadeTo(1, 500),
                cls.FadeTo(1, 500),
                cts.FadeTo(1, 500),
                MSIL.FadeTo(1, 500),
                JIT.FadeTo(1, 500),
                Compiler.FadeTo(1, 500),
                SourceCode.FadeTo(1, 500),
                ExecutableCode.FadeTo(1, 500),
                boxview1.FadeTo(1, 500),
                generalProgTerms.FadeTo(1, 500),
                Variables.FadeTo(1, 500),
                DataType.FadeTo(1, 500),
                Keywords.FadeTo(1, 500),
                Operators.FadeTo(1, 500),
                Expression.FadeTo(1, 500),
                TypeCasting.FadeTo(1, 500),
                Arrays.FadeTo(1, 500),
                Function.FadeTo(1, 500),
                Class.FadeTo(1, 500),
                Object.FadeTo(1, 500),
                Constructor.FadeTo(1, 500),
                Destructor.FadeTo(1, 500),
                Namespaces.FadeTo(1, 500),
                Exceptions.FadeTo(1, 500),
                ExceptionHandling.FadeTo(1, 500),
                boxview2.FadeTo(1, 500),
                oopProgTerms.FadeTo(1, 500),
                Inheritance.FadeTo(1, 500),
                BaseClass.FadeTo(1, 500),
                DerivedClass.FadeTo(1, 500),
                AbstractClass.FadeTo(1, 500),
                MultilevelInheritance.FadeTo(1, 500),
                HierarchicalInheritance.FadeTo(1, 500),
                SingleInheritance.FadeTo(1, 500),
                Interface.FadeTo(1, 500),
                Polymorphism.FadeTo(1, 500),
                Overriding.FadeTo(1, 500),
                Encapsulation.FadeTo(1, 500),
                Abstraction.FadeTo(1, 500),
                Overloading.FadeTo(1, 500));

            #endregion
        }
Ejemplo n.º 8
0
        public Value Generate(IAstNode ast, Action <CodeGeneratorException> codeGenerationErroHandler)
        {
            try
            {
                // Prototypes, including extern are ignored as AST generation
                // adds them to the RuntimeState so that already has the declarations
                if (!(ast is FunctionDefinition definition))
                {
                    return(null);
                }

                InitializeModuleAndPassManager( );

                var function = ( IrFunction )definition.Accept(this);

                if (definition.IsAnonymous)
                {
                    // eagerly compile modules for anonymous functions as calling the function is the guaranteed next step
                    ulong jitHandle  = JIT.AddEagerlyCompiledModule(Module);
                    var   nativeFunc = JIT.GetFunctionDelegate <KaleidoscopeJIT.CallbackHandler0>(definition.Name);
                    var   retVal     = Context.CreateConstant(nativeFunc( ));
                    JIT.RemoveModule(jitHandle);
                    return(retVal);
                }
                else
                {
                    // Destroy any previously generated module for this function.
                    // This allows re-definition as the new module will provide the
                    // implementation. This is needed, otherwise both the MCJIT
                    // and OrcJit engines will resolve to the original module, despite
                    // claims to the contrary in the official tutorial text. (Though,
                    // to be fair it may have been true in the original JIT and might
                    // still be true for the interpreter)
                    if (FunctionModuleMap.Remove(definition.Name, out ulong handle))
                    {
                        JIT.RemoveModule(handle);
                    }

                    // Unknown if any future input will call the function so add it for lazy compilation.
                    // Native code is generated for the module automatically only when required.
                    ulong jitHandle = JIT.AddLazyCompiledModule(Module);
                    FunctionModuleMap.Add(definition.Name, jitHandle);
                    return(function);
                }
            }
            catch (CodeGeneratorException ex) when(codeGenerationErroHandler != null)
            {
                codeGenerationErroHandler(ex);
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates Instance of <typeparamref name="TClass"/>, using a preloaded CreateInterface delegate from a Module in memory
        /// </summary>
        /// <typeparam name="TClass">Interface Wrapper/Representory Class</typeparam>
        /// <param name="factory">CreateInterface Delegate</param>
        /// <returns>Instance of <typeparamref name="TClass"/></returns>
        public static TClass GetFromFactory <TClass>(CreateInterfaceFn factory) where TClass : class
        {
            if (factory == null)
            {
                return(null);
                //throw new JITEngineException("GetFromFactory called with NULL factory");
            }

            // Create Instance of TClass
            IntPtr classptr = factory(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)), IntPtr.Zero);

            // if not NULL cast Pointer to TClass via JIT Conversion. And Return
            return(classptr == IntPtr.Zero ? null : JIT.ConvertInstance <TClass>(classptr));
        }
Ejemplo n.º 10
0
        public override Value VisitTopLevelExpression([NotNull] TopLevelExpressionContext context)
        {
            var proto    = new Prototype($"anon_expr_{AnonNameIndex++}");
            var function = GetOrDeclareFunction(proto
                                                , isAnonymous: true
                                                );

            var(_, jitHandle) = DefineFunction(function, context.expression());

            var nativeFunc = JIT.GetDelegateForFunction <AnonExpressionFunc>(proto.Identifier.Name);
            var retVal     = Context.CreateConstant(nativeFunc( ));

            JIT.RemoveModule(jitHandle);
            return(retVal);
        }
Ejemplo n.º 11
0
        private static INetworkStringTable FindTableInternal(string name)
        {
            if (container == null)
            {
                return(null);
            }
            var stringTablePointer = container.FindTable(name);

            if (stringTablePointer == IntPtr.Zero)
            {
                return(null);
            }
            var stringTable = JIT.ConvertInstance <INetworkStringTable>(stringTablePointer);

            return(stringTable);
        }
Ejemplo n.º 12
0
        public static TClass GetFromFactory <TClass>(CreateInterfaceFn factory) where TClass : class
        {
            if (factory == null)
            {
                return(null);
                //throw new JITEngineException("GetFromFactory called with NULL factory");
            }

            IntPtr classptr = factory(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)), IntPtr.Zero);

            if (classptr == IntPtr.Zero)
            {
                return(null);
            }

            return(JIT.ConvertInstance <TClass>(classptr));
        }
Ejemplo n.º 13
0
        public static tMethodState *Direct(tThread *pThread, tMD_MethodDef *pMethod, tMethodState *pCaller, uint isInternalNewObjCall)
        {
            tMethodState *pThis;

            Mem.heapcheck();

            if (pMethod->isFilled == 0)
            {
                tMD_TypeDef *pTypeDef;

                pTypeDef = MetaData.GetTypeDefFromMethodDef(pMethod);
                MetaData.Fill_TypeDef(pTypeDef, null, null);
            }

            pThis = (tMethodState *)Thread.StackAlloc(pThread, (uint)sizeof(tMethodState));
            pThis->finalizerThis = null;
            pThis->pCaller       = pCaller;
            pThis->pMetaData     = pMethod->pMetaData;
            pThis->pMethod       = pMethod;
            if (pMethod->pJITted == null)
            {
                // If method has not already been JITted
                JIT.Prepare(pMethod, 0);
            }
            pThis->pJIT                 = pMethod->pJITted;
            pThis->ipOffset             = 0;
            pThis->pEvalStack           = (byte *)Thread.StackAlloc(pThread, pThis->pMethod->pJITted->maxStack);
            pThis->stackOfs             = 0;
            pThis->isInternalNewObjCall = isInternalNewObjCall;
            pThis->pNextDelegate        = null;
            pThis->pDelegateParams      = null;

            pThis->pParamsLocals = (byte *)Thread.StackAlloc(pThread, pMethod->parameterStackSize + pMethod->pJITted->localsStackSize);
            Mem.memset(pThis->pParamsLocals, 0, pMethod->parameterStackSize + pMethod->pJITted->localsStackSize);

#if DIAG_METHOD_CALLS
            // Keep track of the number of times this method is called
            pMethod->callCount++;
            pThis->startTime = microTime();
#endif

            Mem.heapcheck();

            return(pThis);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Resets entire DNA environment to it's initial state, clearing all DnaObject references to null.
        /// </summary>
        public static void Reset()
        {
            Type.Clear();
            CLIFile.Clear();
            InternalCall.Clear();
            Finalizer.Clear();
            Heap.Clear();
            Generics.Clear();
            MonoType.Clear();
            MetaData.Clear();
            DnaObject.Clear();
            JIT_Execute.Clear();
            JIT.Clear();
            Sys.Clear();
            H.Clear();
            Mem.Clear();

            _isInitialized = false;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes the DNA script engine.
        /// </summary>
        /// <param name="memsize">The heap memory size to use (note: can not be expanded)</param>
        /// <param name="assemblySearchPaths">Array of assembly search paths to use when loading assemblies</param>
        public static void Init(int memsize = DEFAULT_MEM_SIZE, string[] assemblySearchPaths = null)
        {
            if (_isInitialized)
            {
                throw new System.InvalidOperationException("Dna has already been initialized.  Use Dna.Reset() to reset the interpreter");
            }

            if (assemblySearchPaths == null)
            {
                assemblySearchPaths = defaultAssemblySearchPaths;
            }
            #if UNITY_EDITOR
            string[] finalAssemblySearchPaths = new string[assemblySearchPaths.Length];
            string   unityDir   = UnityEditor.EditorApplication.applicationContentsPath;
            string   projectDir = System.IO.Path.GetDirectoryName(UnityEngine.Application.dataPath);
            for (int i = 0; i < assemblySearchPaths.Length; i++)
            {
                finalAssemblySearchPaths[i] = assemblySearchPaths[i]
                                              .Replace("${UNITY_DIR}", unityDir)
                                              .Replace("${PROJECT_DIR}", projectDir);
            }
            #else
            string[] finalAssemblySearchPaths = assemblySearchPaths;
            #endif

            Mem.Init(memsize);
            H.Init();
            Sys.Init();
            JIT.Init();
            JIT_Execute.Init();
            DnaObject.Init();
            MetaData.Init();
            MonoType.Init();
            Generics.Init();
            Serialization.Init();
            Heap.Init();
            Finalizer.Init();
            InternalCall.Init();
            CLIFile.Init(finalAssemblySearchPaths);
            Type.Init();

            _isInitialized = true;
        }
Ejemplo n.º 16
0
            public override void Process(ConfusionParameter parameter)
            {
                IAntiTamper ver;

                Confuser.Database.AddEntry("AntiTamper", "Type", parameter.GlobalParameters["type"] ?? "normal");
                if (parameter.GlobalParameters["type"] == "jit")
                {
                    ver = new JIT();
                }
                else
                {
                    ver = new Mem();
                }
                ver.AddHelper  = AddHelper;
                ver.Confuser   = Confuser;
                cion.vers[mod] = ver;

                ver.InitPhase1(mod);
                ver.Phase1(mod);
            }
Ejemplo n.º 17
0
        public Value Generate(IAstNode ast, Action <CodeGeneratorException> codeGenerationErroHandler)
        {
            try
            {
                // Prototypes, including extern are ignored as AST generation
                // adds them to the RuntimeState so that already has the declarations
                if (!(ast is FunctionDefinition definition))
                {
                    return(null);
                }

                // Anonymous functions are called immediately then removed from the JIT
                // so no point in setting them up as a lazy compilation item.
                if (definition.IsAnonymous)
                {
                    InitializeModuleAndPassManager( );
                    var function = ( IrFunction )definition.Accept(this);

                    // eagerly compile modules for anonymous functions as calling the function is the guaranteed next step
                    ulong jitHandle  = JIT.AddEagerlyCompiledModule(Module);
                    var   nativeFunc = JIT.GetFunctionDelegate <KaleidoscopeJIT.CallbackHandler0>(definition.Name);
                    var   retVal     = Context.CreateConstant(nativeFunc( ));
                    JIT.RemoveModule(jitHandle);
                    return(retVal);
                }

                // Unknown if any future input will call the function so don't even generate IR
                // until it is needed. JIT triggers the callback to generate the IR module so the JIT
                // can then generate native code only when required.
                FunctionDefinition implDefinition = CloneAndRenameFunction(definition);

                // register the generator as a stub with the original source name
                JIT.AddLazyFunctionGenerator(definition.Name, () =>
                {
                    InitializeModuleAndPassManager( );
                    var function = ( IrFunction )implDefinition.Accept(this);
                    return(implDefinition.Name, function.ParentModule);
                });
                return(null);
            }
Ejemplo n.º 18
0
            public static int Process(JIT args)
            {
                if (!System.IO.File.Exists(args.File))
                {
                    Console.WriteLine($"File does not exists: { args.File }");
                    return(1);
                }

                /* LLVM */
                LLVM.LinkInMCJIT();
                LLVM.InitializeX86TargetInfo();
                LLVM.InitializeX86Target();
                LLVM.InitializeX86TargetMC();

                LLVM.InitializeX86AsmParser();
                LLVM.InitializeX86AsmPrinter();

                LLVMMCJITCompilerOptions options = new LLVMMCJITCompilerOptions()
                {
                    NoFramePointerElim = 1
                };

                return(0);
            }
Ejemplo n.º 19
0
 private GLua(Lua_State luaState)
 {
     this.State   = luaState;
     this.LuaBase = JIT.ConvertInstance <ILuaBase>(luaState.Luabase);
 }
Ejemplo n.º 20
0
 private GLua(lua_State luaState)
 {
     State        = luaState;
     LuaBase      = JIT.ConvertInstance <ILuaBase>(luaState.luabase);
     LuaInterface = JIT.ConvertInstance <ILuaInterface>(luaState.luabase);
 }
Ejemplo n.º 21
0
            public override void Process(ConfusionParameter parameter)
            {
                IAntiTamper ver;

                Confuser.Database.AddEntry("AntiTamper", "Type", parameter.GlobalParameters["type"] ?? "normal");
                if (parameter.GlobalParameters["type"] == "jit")
                    ver = new JIT();
                else
                    ver = new Mem();
                ver.AddHelper = AddHelper;
                ver.Confuser = Confuser;
                cion.vers[mod] = ver;

                ver.InitPhase1(mod);
                ver.Phase1(mod);
            }
Ejemplo n.º 22
0
 public void Dispose( )
 {
     JIT.Dispose( );
     Module?.Dispose( );
     Context.Dispose( );
 }