Exemplo n.º 1
0
        public void CreateAssembly()
        {
            AssemblyName aName = new AssemblyName("CpuAssembly");

            AssemblyBuilder aBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.RunAndSave);

            ModuleBuilder mBuilder = aBuilder.DefineDynamicModule(aName.Name, aName.Name + ".dll");

            TypeBuilder tb = mBuilder.DefineType("Cpu", TypeAttributes.Sealed | TypeAttributes.Public);

            IExpressionLibraryRegistry libRegistry = ExpressionRegistryHelper.Default;
            var DataAccessExp = libRegistry.GetLibrary<IDataAccessExpressionLibrary>();
            InstructionScanner instructionScanner = new InstructionScanner(libRegistry);
            var instructions = instructionScanner.BuildInstructionInfo(typeof(InstructionScanner).Assembly.GetTypes());
            IInstructionExpressionBuilder instructionExpressionBuilder = new InstructionExpressionBuilder(libRegistry);
            var opcodeResolver = (new DefaultInstructionSpaceBuilder()).BuildInstructionSpaceExpression(instructions,
                                                             libRegistry.GetLibrary<IProgramControlExpressionLibrary>(),
                                                             instructionExpressionBuilder, new InstructionSpace());

            
            var expressionBuilder = new ExpressionBuilder(libRegistry);

            MethodBuilder methodBuilder = tb.DefineMethod("DefaultInstructionSpace", MethodAttributes.Public | MethodAttributes.Static);

            CreateMethod(opcodeResolver, expressionBuilder, methodBuilder);
        
            tb.CreateType();
            
            aBuilder.Save("CpuAssembly.dll");
            //return lambda.Compile();*/
        }
Exemplo n.º 2
0
        static Z80Cpu()
        {
            _flagTables = new FlagTables();
            _flagTables.ScanForFlagTables(typeof(FlagTables).Assembly.GetTypes());

            var libRegistry = BuildExpressionLibraryRegistry(new ArraySystemBus(1024));
            var instructionScanner = new InstructionScanner(libRegistry);
            var instructions = instructionScanner.BuildInstructionInfo(typeof(InstructionScanner).Assembly.GetTypes());
            var instructionExpressionBuilder = new InstructionExpressionBuilder(libRegistry);

            /*if (IsDebugModeEnabled)
            {
                instructionExpressionBuilder.RegisterPreInstructionAdvice(new DisplayInstructionInDebugConsole());

                var broadCaster = new InstructionBroadcaster();
                broadCaster.InstructionRan += new EventHandler<CpuEventArgs>(broadCaster_InstructionRan);
                instructionExpressionBuilder.RegisterPostInstructionAdvice(broadCaster);
            }

            if (IsRecentHistoryEnabled)
            {
                _history = new RecentHistory();
                instructionExpressionBuilder.RegisterPreInstructionAdvice(_history);

                _instructions = new InstructionCalls();
                instructionExpressionBuilder.RegisterPreInstructionAdvice(_instructions);
            }*/

            var opcodeResolver = (new DefaultInstructionSpaceBuilder()).BuildInstructionSpaceExpression(instructions, libRegistry.GetLibrary<IProgramControlExpressionLibrary>(), instructionExpressionBuilder, new InstructionSpace());
            _expressionBuilder = new ExpressionBuilder(libRegistry);

            var methodBody = BuildLoopMethod(opcodeResolver, _expressionBuilder, libRegistry);
            var block = Expression.Block(_expressionBuilder.GetLocals(), methodBody);
            var lambda = Expression.Lambda(block, _expressionBuilder.GetParameterList());
            _cpuCode = lambda.Compile();
        }