Exemplo n.º 1
0
        public void PlateauSizeMissWidthOrLengthShouldThrowException()
        {
            var instructionSet = new InstructionSet();
            instructionSet.Add("55");

            instructionSet.GetPlateau();
        }
Exemplo n.º 2
0
        public void InvalidPlateauSouthToNorthLengthShouldThrowException()
        {
            var instructionSet = new InstructionSet();
            instructionSet.Add("55 A");

            instructionSet.GetPlateau();
        }
Exemplo n.º 3
0
        public void InvalidPlateauWestToEastLengthShouldThrowException()
        {
            var instructionSet = new InstructionSet();
            instructionSet.Add("A 55");

            instructionSet.GetPlateau();
        }
Exemplo n.º 4
0
        public InstructionSet BuildPath(Point Start, ElementTypes Type, Direction CurrentDirection)
        {
            AlreadySearched = new List<Node>();

            Shortest = null;
            distance = int.MaxValue;
            AlreadyTraveled = new List<Point>();

            if (!GeneratedYet)
                GenerateMatrix();

            Path N = FindClosestPath(Start, CurrentDirection);

            if (N != null)
                AlreadyTraveled.Add(N.Start.Location);

            InstructionSet Mine = new InstructionSet();

            List<Path> Begin = new List<Path>();
            Begin.Add(N);
            if (N != null)
            {
                    BuildPath(new InstructionSet(Begin), Type, N.End);
            }

            //N.End.BuildPath(new InstructionSet(Begin), Type);

            return Shortest;
        }
Exemplo n.º 5
0
        public void PlateauWidthOrLengthIsNegativeShouldThrowException()
        {
            var instructionSet = new InstructionSet();
            instructionSet.Add("5 -1");

            instructionSet.GetPlateau();
        }
Exemplo n.º 6
0
        public SlotIndex(InstructionSet instructionSet, int index)
        {
            Debug.Assert(index >= 0);

            this.instructionSet = instructionSet;
            this.index = index;
        }
Exemplo n.º 7
0
        public SlotIndex(Context context)
        {
            Debug.Assert(context.Index >= 0);

            this.instructionSet = context.InstructionSet;
            this.index = context.Index;
        }
        public void Should_contain_expression_in_root_content( )
        {
            string addressLkTest = "Address lk 'Test'";

            var set = new InstructionSet<SampleData>( addressLkTest );

            Assert.AreEqual( addressLkTest, set.Root.Content );
        }
        public void MoveNextWhenHaveInstructionAddedTest()
        {
            InstructionSet instructionSet = new InstructionSet();
            instructionSet.Add("5 5");
            instructionSet.Add("1 2 N");
            instructionSet.Add("L");

            Assert.AreEqual(true, instructionSet.MoveNext());
        }
Exemplo n.º 10
0
 public void Set(InstructionSet instruction)
 {
     if (instruction != null)
     {
         TempInstructions = instruction;
         Rotor.SetValue("RotorLock", false);
         State = RotorState.single;
     }
 }
Exemplo n.º 11
0
        private void LoadData(TabPage tabPage)
        {
            tabPage.Controls.Clear();
            InstructionSet instructionSet = tabPage.Tag as InstructionSet;

            instructionSet.Items = new List <ItemInfo>();
            LoadMasterData(tabPage);
            LoadDomainData(tabPage);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
        /// </summary>
        public TypeInitializerSchedulerStage()
        {
            basicBlocks = new BasicBlocks();
            instructionSet = new InstructionSet(25);
            context = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(context.BasicBlock);

            context.AppendInstruction(IRInstruction.Prologue);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Converts an instruction set enumeration from MemorySharp to a mode from Keystone.
        /// </summary>
        /// <param name="instructionSet"></param>
        /// <returns></returns>
        private Mode MapToKeystoneMode(InstructionSet instructionSet)
        {
            if (ModeMappings.TryGetValue(instructionSet, out var mode))
            {
                return(mode);
            }

            throw new ArgumentException("The instruction set is not supported", nameof(instructionSet));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LinkerMethodCompiler"/> class.
 /// </summary>
 /// <param name="compiler">The assembly compiler executing this method compiler.</param>
 /// <param name="method">The metadata of the method to compile.</param>
 /// <param name="instructionSet">The instruction set.</param>
 /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="method"/> or <paramref name="instructionSet"/> is null.</exception>
 public LinkerMethodCompiler(AssemblyCompiler compiler, RuntimeMethod method, InstructionSet instructionSet) :
     base(compiler.Pipeline.Find <IAssemblyLinker>(), compiler.Architecture, compiler.Assembly, method.DeclaringType, method)
 {
     InstructionSet = instructionSet;
     this.Pipeline.AddRange(new IMethodCompilerStage[] {
         new BasicBlockBuilderStage(),
         new CodeGenerationStage(),
     });
     compiler.Architecture.ExtendMethodCompilerPipeline(this.Pipeline);
 }
        public void TestBrkToCallIrq()
        {
            Mock <I6502> cpu = new Mock <I6502>();

            cpu.Setup(m => m.irq(true)).Verifiable("IRQ not called.");

            Assert.Equal(0, InstructionSet.BRK(cpu.Object));

            cpu.Verify();
        }
Exemplo n.º 16
0
        private void WithdrawlMaterial(InstructionSet instructionSet)
        {
            var request = instructionSet.ObjectToProcess as RequestItem;

            if (request == null)
            {
                throw new InvalidCastException(this.Name + " failed to Cast ProductionAgent on Instruction.ObjectToProcess");
            }
            Withdraw(request);
        }
        public void TestClearCarryStatus()
        {
            Mock <I6502> cpu = new Mock <I6502>();

            cpu.Setup(m => m.SetFlag(Flags.C, false)).Verifiable("Carry flag not cleared");

            Assert.Equal(0, InstructionSet.CLC(cpu.Object));

            cpu.Verify();
        }
Exemplo n.º 18
0
        public void TestClearOverflowStatus()
        {
            Mock <I6502> cpu = new Mock <I6502>();

            cpu.Setup(m => m.SetFlag(Flags.V, false)).Verifiable("Overflow flag not cleared");

            Assert.AreEqual(0, InstructionSet.CLV(cpu.Object));

            cpu.Verify();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a new instance of the <see cref="Memory"/> class with the specified maximum side 
        /// and the instructions to load into it.
        /// </summary>
        /// <param name="maximumSize">The maximum size of the memory; 
        /// that is, the instructions region size plus the stack region size.</param>
        /// <param name="instructions">The instructions to load into the memory.</param>
        /// <returns></returns>
        public static Memory CreateMemory(int maximumSize, InstructionSet instructions)
        {
            Memory memory = new Memory(maximumSize);
            int stackMemory;

            memory.LoadInstructions(instructions.Instructions);
            stackMemory = maximumSize - instructions.Size;
            memory.StackRegion = new Stack(stackMemory < 0 ? 0 : stackMemory);
            return memory;
        }
Exemplo n.º 20
0
        public void CorrectPlateauSizeTest()
        {
            var instructionSet = new InstructionSet();
            instructionSet.Add("5 3");

            Plateau plateau = instructionSet.GetPlateau();

            Assert.AreEqual(5, plateau.WestToEastLength);
            Assert.AreEqual(3, plateau.SouthToNorthLength);
        }
Exemplo n.º 21
0
        public void TestClearDecimalStatus()
        {
            Mock <I6502> cpu = new Mock <I6502>();

            cpu.Setup(m => m.SetFlag(Flags.D, false)).Verifiable("Decimal flag not cleared");

            Assert.AreEqual(0, InstructionSet.CLD(cpu.Object));

            cpu.Verify();
        }
Exemplo n.º 22
0
        public void TestClearInteruptStatus()
        {
            Mock <I6502> cpu = new Mock <I6502>();

            cpu.Setup(m => m.SetFlag(Flags.I, false)).Verifiable("Interupt flag not cleared");

            Assert.AreEqual(0, InstructionSet.CLI(cpu.Object));

            cpu.Verify();
        }
Exemplo n.º 23
0
 private Decoder[] EnsureDecoders()
 {
     if (this.primaryDecoders == null)
     {
         this.Options.TryGetValue("Model", out var model);
         var iset = InstructionSet.Create((string)model);
         this.primaryDecoders = iset.CreateDecoders();
     }
     return(this.primaryDecoders);
 }
Exemplo n.º 24
0
        private static void Problem1()
        {
            var instructionSet = new InstructionSet(LoadSample(_classType).ToLines());

            instructionSet.GetValueBeforeLoop().Should().Be(5);

            var result = new InstructionSet(LoadInput(_classType).ToLines()).GetValueBeforeLoop();

            Console.WriteLine($"Accumulated Value is {result}");
        }
Exemplo n.º 25
0
        //TODO: System Talk.

        private void CreateContractAgent(InstructionSet instructionSet)
        {
            //  Check 0 ref
            var requestItem = instructionSet.ObjectToProcess as OrderPart;

            if (requestItem == null)
            {
                throw new InvalidCastException(this.Name + " Cast to OrderPart Failed");
            }
            CreateAgents(requestItem);
        }
Exemplo n.º 26
0
 public void TestInstructionSet()
 {
     try
     {
         InstructionSet i = new InstructionSet();
     }
     catch (Exception e)
     {
         Assert.Fail(e.ToString());
     }
 }
Exemplo n.º 27
0
 public static bool IsValidInstruction(string instruction, InstructionSet iset)
 {
     try
     {
         return(!string.IsNullOrEmpty(iset.Instructions.Find(x => x.OpCode.Equals(instruction.ToUpper())).OpCode));
     }
     catch (NullReferenceException)
     {
         return(false);
     }
 }
Exemplo n.º 28
0
        private void ProposalFromMachine(InstructionSet instructionSet)
        {
            var proposal = instructionSet.ObjectToProcess as Proposal;

            if (proposal == null)
            {
                throw new InvalidCastException("Could not Cast Proposal on InstructionSet.ObjectToProcess");
            }
            // get releated workitem and add Proposal.
            var workItem         = WorkItemQueue.Single(x => x.Id == proposal.WorkItemId);
            var proposalToRemove = workItem.Proposals.FirstOrDefault(x => x.AgentId == proposal.AgentId);

            if (proposalToRemove != null)
            {
                workItem.Proposals.Remove(proposalToRemove);
            }

            workItem.Proposals.Add(proposal);

            DebugMessage("Proposal for Schedule: " + proposal.PossibleSchedule + " from: " + proposal.AgentId + "!");


            // if all Machines Answered
            if (workItem.Proposals.Count == MachineAgents.Count)
            {
                workItem.Status = workItem.WasSetReady ? Status.Ready : Status.InQueue;
                // item Postponed by All Machines ? -> reque after given amount of time.
                if (workItem.Proposals.All(x => x.Postponed))
                {
                    // Call Comunication Agent to Requeue
                    CreateAndEnqueueInstuction(methodName: ComunicationAgent.InstuctionsMethods.EnqueueWorkItem.ToString(),
                                               objectToProcess: workItem,
                                               targetAgent: workItem.ComunicationAgent,
                                               waitFor: proposal.PostponedFor);
                    return;
                }

                // aknowledge Machine -> therefore get Machine -> send aknowledgement
                var acknowledgement = workItem.Proposals.First(x => x.PossibleSchedule == workItem.Proposals.Where(y => y.Postponed == false)
                                                               .Min(p => p.PossibleSchedule) &&
                                                               x.Postponed == false);


                workItem.MachineAgentId = acknowledgement.AgentId;
                workItem.EstimatedEnd   = acknowledgement.PossibleSchedule + workItem.WorkSchedule.Duration;

                // set Proposal Start for Machine to Reque if time slot is closed.
                workItem.EstimatedStart = acknowledgement.PossibleSchedule;

                CreateAndEnqueueInstuction(methodName: MachineAgent.InstuctionsMethods.AcknowledgeProposal.ToString(),
                                           objectToProcess: workItem,
                                           targetAgent: GetMachineAgentById(acknowledgement.AgentId));
            }
        }
Exemplo n.º 29
0
        public static IEnumerable <int> AllIndexesOf(this InstructionSet set, string[] commands)
        {
            int minIndex = set.Instructions.ToList().FindIndex(i => commands.Contains(i.cmd));

            while (minIndex != -1)
            {
                yield return(minIndex);

                minIndex = set.Instructions.ToList().FindIndex(minIndex + 1, i => commands.Contains(i.cmd));
            }
        }
Exemplo n.º 30
0
 public void Run()
 {
     while (InstructionPointer < Instructions.Length)
     {
         if (InstructionSet.TryGetValue(Instructions[InstructionPointer], out var action))
         {
             action(this);
         }
         InstructionPointer++;
     }
 }
Exemplo n.º 31
0
        /// <summary>
        /// is Called if The Proposal is accepted by Comunication Agent
        /// </summary>
        /// <param name="instructionSet"></param>
        private void AcknowledgeProposal(InstructionSet instructionSet)
        {
            var workItem = instructionSet.ObjectToProcess as WorkItem;

            if (workItem == null)
            {
                throw new InvalidCastException("Could not Cast Workitem on InstructionSet.ObjectToProcess");
            }

            if (Queue.Any(e => e.Priority(Context.TimePeriod) <= workItem.Priority(Context.TimePeriod)))
            {
                // Get item Latest End.
                var maxItem = Queue.Where(e => e.Priority(Context.TimePeriod) <= workItem.Priority(Context.TimePeriod)).Max(e => e.EstimatedEnd);

                // check if Queuable
                if (maxItem > workItem.EstimatedStart)
                {
                    // reset Agent Status
                    workItem.Status         = Status.Created;
                    workItem.EstimatedStart = 0;
                    SendProposalTo(instructionSet.SourceAgent, workItem);
                    return;
                }
            }

            DebugMessage("AcknowledgeProposal and Enqueued Item: " + workItem.WorkSchedule.Name);
            Queue.Add(workItem);

            // Enqued before another item?
            var position = Queue.OrderBy(x => x.Priority(Context.TimePeriod)).ToList().IndexOf(workItem);

            DebugMessage("Position: " + position + " Priority:" + workItem.Priority(Context.TimePeriod) + " Queue length " + Queue.Count());

            // reorganize Queue if an Element has ben Queued which is More Important.
            if (position + 1 < Queue.Count)
            {
                var toRequeue = Queue.OrderBy(x => x.Priority(Context.TimePeriod)).ToList().GetRange(position + 1, Queue.Count() - position - 1);

                CallToReQueue(toRequeue);

                DebugMessage("New Queue length = " + Queue.Count);
            }


            if (workItem.Status == Status.Ready)
            {
                // update Processing queue
                UpdateProcessingQueue(workItem);

                // there is at least Something Ready so Start Work
                DoWork(new InstructionSet());
            }
        }
Exemplo n.º 32
0
    /*
     * public InstructionSet RandomizeInstructionSet(InstructionSet iSet){
     *      return iSet;
     * }
     *
     * public InstructionSet createDeepCopy(){
     *      InstructionSet iSet = new InstructionSet();
     *      //for(int i = 0; i < )
     * }
     */

    //No new joint/segment creation, modify existing instructions
    public InstructionSet asexualRandomization(InstructionSet iSet)
    {
        InstructionSet result = new InstructionSet();

        for (int i = 0; i < iSet.getCount(); i++)
        {
            Instruction newIns = iSet.getInstruction(i).copy();
            newIns.setSpeed(newIns.getSpeed() + Random.Range(-1, 1));
            result.addInstruction(newIns);
        }
        return(result);
    }
        public void TestShiftLeftToAccumulator()
        {
            Cpu cpu = new Cpu();

            cpu.ImpliedAddress = true;
            cpu.Fetched        = 0x81;

            Assert.Equal(0, InstructionSet.ASL(cpu));

            Assert.True(cpu.GetFlag(Flags.C));
            Assert.Equal(0x02, cpu.A);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Extend the base x86 architecture.
        /// </summary>
        private void Extend()
        {
            // Extend the base x86 register set.
            RegisterSet.UnionWith(
                new HashSet <string>
            {
                "rax", "rbx", "rcx", "rdx",
                "rsp", "rbp", "rsi", "rdi",
                "r8b", "r8w", "r8d", "r8",
                "r9b", "r9w", "r9d", "r9",
                "r10b", "r10w", "r10d", "r10",
                "r11b", "r11w", "r11d", "r11",
                "r12b", "r12w", "r12d", "r12",
                "r13b", "r13w", "r13d", "r13",
                "r14b", "r14w", "r14d", "r14",
                "r15b", "r15w", "r15d", "r15",
                "mm8", "mm9", "mm10", "mm11",
                "mm12", "mm13", "mm14", "mm15",
                "xmm8", "xmm9", "xmm10", "xmm11",
                "xmm12", "xmm13", "xmm14", "xmm15",
                "xmm16", "xmm17", "xmm18", "xmm19",
                "xmm20", "xmm21", "xmm22", "xmm23",
                "xmm24", "xmm25", "xmm26", "xmm27",
                "xmm28", "xmm29", "xmm30", "xmm31",
                "ymm8", "ymm9", "ymm10", "ymm11",
                "ymm12", "ymm13", "ymm14", "ymm15",
                "ymm16", "ymm17", "ymm18", "ymm19",
                "ymm20", "ymm21", "ymm22", "ymm23",
                "ymm24", "ymm25", "ymm26", "ymm27",
                "ymm28", "ymm29", "ymm30", "ymm31",
                "zmm8", "zmm9", "zmm10", "zmm11",
                "zmm12", "zmm13", "zmm14", "zmm15",
                "zmm16", "zmm17", "zmm18", "zmm19",
                "zmm20", "zmm21", "zmm22", "zmm23",
                "zmm24", "zmm25", "zmm26", "zmm27",
                "zmm28", "zmm29", "zmm30", "zmm31",
                "st8", "st9", "st10", "st11",
                "st12", "st13", "st14", "st15",
                "cr8", "cr9", "cr10", "cr11",
                "cr12", "cr13", "cr14", "cr15",
            }
                );

            // Extend the base x86 instruction set.
            InstructionSet.UnionWith(new HashSet <string>
            {
                "cdqe", "cqo", "cmpsq", "cmpxchg16b",
                "iretq", "jrcxz", "lodsq", "movsxd",
                "popfq", "pushfq", "rdtscp", "scasq",
                "stosq", "swapgs"
            });
        }
Exemplo n.º 35
0
        public GreedyRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, InstructionSet instructionSet, StackLayout stackLayout, BaseArchitecture architecture, CompilerTrace trace)
        {
            this.trace = trace;

            this.basicBlocks = basicBlocks;
            this.instructionSet = instructionSet;
            this.stackLayout = stackLayout;
            this.architecture = architecture;

            this.virtualRegisterCount = compilerVirtualRegisters.Count;
            this.physicalRegisterCount = architecture.RegisterSet.Length;
            this.registerCount = virtualRegisterCount + physicalRegisterCount;

            this.liveIntervalTracks = new List<LiveIntervalTrack>(physicalRegisterCount);
            this.virtualRegisters = new List<VirtualRegister>(registerCount);
            this.extendedBlocks = new List<ExtendedBlock>(basicBlocks.Count);

            stackFrameRegister = architecture.StackFrameRegister;
            stackPointerRegister = architecture.StackPointerRegister;
            programCounter = architecture.ProgramCounter;

            // Setup extended physical registers
            foreach (var physicalRegister in architecture.RegisterSet)
            {
                Debug.Assert(physicalRegister.Index == virtualRegisters.Count);
                Debug.Assert(physicalRegister.Index == liveIntervalTracks.Count);

                bool reserved = (physicalRegister == stackFrameRegister
                    || physicalRegister == stackPointerRegister
                    || (programCounter != null && physicalRegister == programCounter));

                this.virtualRegisters.Add(new VirtualRegister(physicalRegister, reserved));
                this.liveIntervalTracks.Add(new LiveIntervalTrack(physicalRegister, reserved));
            }

            // Setup extended virtual registers
            foreach (var virtualRegister in compilerVirtualRegisters)
            {
                Debug.Assert(virtualRegister.Index == virtualRegisters.Count - physicalRegisterCount + 1);

                this.virtualRegisters.Add(new VirtualRegister(virtualRegister));
            }

            priorityQueue = new SimpleKeyPriorityQueue<LiveInterval>();
            spilledIntervals = new List<LiveInterval>();

            callSlots = new List<SlotIndex>();

            moveHints = new Dictionary<SlotIndex, MoveHint>();

            Start();
        }
Exemplo n.º 36
0
        public SpecificInstructionGenerator(bool large, params Instruction[] ins)
        {
            InstructionCount       = 50;
            this.Instructions      = new ReadOnlyCollection <Instruction>(ins);
            _instructionSet        = new InstructionSet();
            _config                = new RandomConfiguration();
            _config.NoZeroRegister = true;
            var ilist =
                new List <(Instruction, double)>()
            {
                (new Addu(), 1),
                (new Ori(), 2),
                (new Subu(), 1),
                (new Nop(), 1),
                (new TwoOperandBranching("beq"), 1),
            };

            foreach (var i in this.Instructions)
            {
                ilist.Add((i, 2));
            }
            if (large)
            {
                ilist.Add((new Lui(), 2));
            }
            if (ilist.Any(i => i.Item1.NeedMemory))
            {
                _config.NumberOfData = 3;
                ilist.Add((new Lw(), 1));
                ilist.Add((new Sw(), 1));
            }
            else
            {
                _config.NumberOfData = 0;
            }


            _instructionSet.PopulateInstructionList(ilist);
            _large = large;
            if (large)
            {
                _config.MaximumImmediate = 2147483647;
                _config.MaximumRegister  = 3;
                _config.NumberOfLabels   = 2;
            }
            else
            {
                _config.MaximumImmediate = 5;
                _config.MaximumRegister  = 3;
                _config.NumberOfLabels   = 2;
            }
        }
        public static string DefaultToEditorContent(this InstructionSet instructionSet, bool highlight = false)
        {
            if (instructionSet.instructions == null)
            {
                instructionSet.instructions = new List <InstructionSet.Instruction>();
            }
            string result             = "";
            string defaultStringField = instructionSet.DefaultStringField();

            foreach (var(field, value, indent) in instructionSet.FunctionIterateInstructions(force: true))
            {
                string valueStr = value.ValueToString();
                if (valueStr == null)
                {
                    valueStr = "";
                }

                if (result.Length > 0)
                {
                    result += "\n\n";
                }
                var indentTxt = "";
                for (var i = 0; i < indent; i++)
                {
                    indentTxt += '\t';
                }
                valueStr = valueStr.Replace("\n", $"\n{indentTxt}");

                result += indentTxt;
                if (field == defaultStringField)
                {
                    result += valueStr;
                }
                else
                {
                    if (highlight)
                    {
                        result += $"<b>{field} </b>: {valueStr}";
                    }
                    else
                    {
                        result += $"{field}: {valueStr}";
                    }
                }
            }

            if (highlight)
            {
                result += "\n";
            }
            return(result);
        }
Exemplo n.º 38
0
        private void AddMachineToComunicationAgent(InstructionSet instructionSet)
        {
            var machine = instructionSet.ObjectToProcess as MachineAgent;

            if (machine == null)
            {
                throw new InvalidCastException("Could not Cast MachineAgent on InstructionSet.ObjectToProcess");
            }
            // Add Machine to Pool
            this.MachineAgents.Add(machine);
            // Added Machine Agent To Machine Pool
            DebugMessage("Added Machine Agent " + machine.Name + " to Machine Pool: " + ContractType);
        }
Exemplo n.º 39
0
        public bool IsHardwareInstrinsicWithRuntimeDeterminedSupport(MethodDesc method)
        {
            string intrinsicId = InstructionSetSupport.GetHardwareIntrinsicId(TypeSystemContext.Target.Architecture, method.OwningType);

            if (!string.IsNullOrEmpty(intrinsicId))
            {
                InstructionSet instructionSet = _instructionSetMap[intrinsicId];
                return(!InstructionSetSupport.IsInstructionSetSupported(instructionSet) &&
                       InstructionSetSupport.OptimisticFlags.HasInstructionSet(instructionSet));
            }

            return(false);
        }
Exemplo n.º 40
0
        public void TestALtFetch()
        {
            Cpu cpu = new Cpu();

            cpu.A       = 0x30;
            cpu.Fetched = 0x45;

            Assert.Equal(1, InstructionSet.CMP(cpu));

            Assert.False(cpu.GetFlag(Flags.C));
            Assert.True(cpu.GetFlag(Flags.N));
            Assert.False(cpu.GetFlag(Flags.Z));
        }
Exemplo n.º 41
0
        public Instruction(
			InstructionSet Opcode, 
			Operand FirstOperand, 
			Operand SecondOperand, 
			Operand ThirdOperand,
			String Annotation = null)
        {
            this.Opcode = Opcode;
            this.FirstOperand = FirstOperand;
            this.SecondOperand = SecondOperand;
            this.ThirdOperand = ThirdOperand;
            this.Annotation = Annotation;
        }
Exemplo n.º 42
0
        public void TestAEqualFetch()
        {
            Cpu cpu = new Cpu();

            cpu.A       = 0x45;
            cpu.Fetched = 0x45;

            Assert.AreEqual(1, InstructionSet.CMP(cpu));

            Assert.IsTrue(cpu.GetFlag(Flags.C));
            Assert.IsFalse(cpu.GetFlag(Flags.N));
            Assert.IsTrue(cpu.GetFlag(Flags.Z));
        }
Exemplo n.º 43
0
        public void TestXLtFetch()
        {
            Cpu cpu = new Cpu();

            cpu.X       = 0x30;
            cpu.Fetched = 0x45;

            Assert.AreEqual(0, InstructionSet.CPX(cpu));

            Assert.IsFalse(cpu.GetFlag(Flags.C));
            Assert.IsTrue(cpu.GetFlag(Flags.N));
            Assert.IsFalse(cpu.GetFlag(Flags.Z));
        }
Exemplo n.º 44
0
        public void TestYGtFetch()
        {
            Cpu cpu = new Cpu();

            cpu.Y       = 0x45;
            cpu.Fetched = 0x20;

            Assert.Equal(0, InstructionSet.CPY(cpu));

            Assert.True(cpu.GetFlag(Flags.C));
            Assert.False(cpu.GetFlag(Flags.N));
            Assert.False(cpu.GetFlag(Flags.Z));
        }
Exemplo n.º 45
0
        public InstructionSet ToInstructionSet(FlatRedBall.Scene scene)
        {
            InstructionSet instructionSet = new InstructionSet();
            instructionSet.Name = this.Target;

            INameable nameable = null;
            

            foreach (KeyframeListSave keyframeList in Instructions)
            {
                KeyframeList keyframes = new KeyframeList();
                keyframes.Name = keyframeList.Name;

                instructionSet.Add(keyframes);
                foreach (KeyframeSave keyframe in keyframeList.SceneKeyframes)
                {
                    InstructionList list = new InstructionList();
                    list.Name = keyframe.Name;
                    keyframes.Add(list);

                    foreach (InstructionSave instructionSave in keyframe.InstructionSaves)
                    {
                        if (nameable == null || nameable.Name != instructionSave.TargetName)
                        {
                            // We don't have a nameable yet, or the current instruction is 
                            // not modifying the one referenced by nameable.
                            nameable = scene.Sprites.FindByName(instructionSave.TargetName);

                            if (nameable == null)
                            {
                                nameable = scene.SpriteFrames.FindByName(instructionSave.TargetName);
                            }

                        }

                        if (nameable == null)
                        {
                            throw new NullReferenceException("Could not find an object of instance " + instructionSave.Type + " with the name " + instructionSave.TargetName);
                        }

                        list.Add(instructionSave.ToInstruction(nameable));
                    }
                }

            }

            return instructionSet;
        }
        public void Context( )
        {
            _expressionToTest = "Address lk 'Test' and ( Value gt '20' or AddDate gt '1/1/2011' )";

            _set = new InstructionSet<SampleData>( _expressionToTest );

            _repository = new SampleRepository
                              {
                                  DataSource = new[ ]
                                                   {
                                                       new SampleData() {Address = "Test 1"},
                                                       new SampleData() {Address = "Test 2", Value = 21, AddDate = new DateTime(2012,1,1)},
                                                       new SampleData() {Address = "Could Not Pass", Value = 45},
                                                       new SampleData() {Address = "No Pass", Value = 33},
                                                   }
                              };
        }
        public void Context( )
        {
            _expressionToTest = "Address lk 'Test' and Value gt '20'";

            _set = new InstructionSet<SampleData>( _expressionToTest );

            _repository = new SampleRepository
                              {
                                  DataSource = new[ ]
                                                   {
                                                       new SampleData() {Address = "Test 1"},
                                                       new SampleData() {Address = "Test 2", Value = 21},
                                                       new SampleData() {Address = "Could Not Pass", Value = 45},
                                                       new SampleData() {Address = "No Pass", Value = 33},
                                                   }
                              };
        }
        public void ResetTest()
        {
            InstructionSet instructionSet = new InstructionSet();
            instructionSet.Add("5 5");
            instructionSet.Add("1 2 N");
            instructionSet.Add("L");
            instructionSet.Add("2 3 W");
            instructionSet.Add("R");

            instructionSet.MoveNext();
            Assert.AreEqual(typeof(HeadingNorth), instructionSet.Current.GetLandingHeading().GetType());

            instructionSet.MoveNext();
            Assert.AreEqual(typeof(HeadingWest), instructionSet.Current.GetLandingHeading().GetType());

            instructionSet.Reset();
            instructionSet.MoveNext();
            Assert.AreEqual(typeof(HeadingNorth), instructionSet.Current.GetLandingHeading().GetType());
        }
Exemplo n.º 49
0
        public static RobotCollection LandingRobots(InstructionSet instructionSet)
        {
            var robotCollection = new RobotCollection();

            Plateau plateau = instructionSet.GetPlateau();

            foreach (IInstruction instruction in instructionSet)
            {
                var robot = new Robot(robotCollection.Count
                                      , instruction.GetLandingPosition()
                                      , instruction.GetLandingHeading()
                                      , instruction.GetMovingSequence()
                                      , plateau);

                robotCollection.Add(robot);
            }

            return robotCollection;
        }
Exemplo n.º 50
0
        private static InstructionSet ReceiveInstructions()
        {
            var instructionSet = new InstructionSet();

            string instruction;

            while ((instruction = Console.ReadLine()) != string.Empty)
            {
                instructionSet.Add(instruction);
            }

            //instructionSet.Add("5 5");
            //instructionSet.Add("1 2 N");
            //instructionSet.Add("LMLMLMLMM");
            //instructionSet.Add("3 3 E");
            //instructionSet.Add("MMRMMRMRRM");
            //instructionSet.Add("3 3 E");
            //instructionSet.Add("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");

            return instructionSet;
        }
Exemplo n.º 51
0
        public void InsertResolvingMoves(BaseArchitecture architecture, InstructionSet instructionSet)
        {
            if (moves.Count == 0)
                return;

            Context context = new Context(instructionSet, Source == Anchor ? Source.EndIndex : Destination.StartIndex);

            if (Source == Anchor)
            {
                context.GotoPrevious();

                // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway
                while (context.IsEmpty || context.Instruction.FlowControl == FlowControl.UnconditionalBranch || context.Instruction.FlowControl == FlowControl.ConditionalBranch || context.Instruction.FlowControl == FlowControl.Return)
                {
                    context.GotoPrevious();
                }
            }

            TrySimpleMoves(architecture, context);
            TryExchange(architecture, context);
            CreateMemoryMoves(architecture, context);

            Debug.Assert(moves.Count == 0);
        }
        public SparseConditionalConstantPropagation(BasicBlocks basicBlocks, InstructionSet instructionSet, SectionTrace trace)
        {
            this.Trace = trace;
            this.BasicBlocks = basicBlocks;
            this.InstructionSet = instructionSet;

            MainTrace = CreateTrace("ConditionalConstantPropagation");

            // Method is empty - must be a plugged method
            if (BasicBlocks.HeadBlocks.Count == 0)
                return;

            blockStates = new bool[BasicBlocks.Count];

            for (int i = 0; i < BasicBlocks.Count; i++)
            {
                blockStates[i] = false;
            }

            // Initialize
            foreach (var block in BasicBlocks.HeadBlocks)
            {
                AddExecutionBlock(block);
            }

            while (blockWorklist.Count > 0 || instructionWorkList.Count > 0)
            {
                ProcessBlocks();
                ProcessInstructions();
            }

            DumpTrace();

            // Release
            phiStatements = null;
        }
 public BasicRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters compilerVirtualRegisters, InstructionSet instructionSet, StackLayout stackLayout, BaseArchitecture architecture, SectionTrace trace)
     : base(basicBlocks, compilerVirtualRegisters, instructionSet, stackLayout, architecture, trace)
 {
 }
Exemplo n.º 54
0
 public void NoPlateauInfoShouldThrowException()
 {
     var instructionSet = new InstructionSet();
     instructionSet.GetPlateau();
 }
Exemplo n.º 55
0
        public InstructionSet ToInstructionSet(IInstructable instructable)
        {
            InstructionSet instructionSet = new InstructionSet();
            instructionSet.Name = this.Target;

            //INameable nameable = null;


            foreach (KeyframeListSave keyframeList in Instructions)
            {
                KeyframeList keyframes = new KeyframeList();
                keyframes.Name = keyframeList.Name;

                instructionSet.Add(keyframes);
                foreach (KeyframeSave keyframe in keyframeList.SceneKeyframes)
                {
                    InstructionList list = new InstructionList();
                    list.Name = keyframe.Name;
                    keyframes.Add(list);

                    foreach (InstructionSave instructionSave in keyframe.InstructionSaves)
                    {
                        list.Add(instructionSave.ToInstruction(instructable));
                    }
                }

            }

            return instructionSet;
        }
Exemplo n.º 56
0
        private static void AddSetToSave(InstructionSet instructionSet, InstructionSetSaveList instructionSetSaveList, 
            string targetName)
        {
            // This following members be used as a buffer for holding the lists that will be saved.
            // In the following loop the code will only copy over instructions that set properties
            // which are included in EditorData.SavedMembers
            List<InstructionList> temporaryListList = new List<InstructionList>();
            InstructionList temporaryList = new InstructionList();

            InstructionSetSave instructionSetSave = new InstructionSetSave();
            
            foreach (KeyframeList keyframeList in instructionSet)
            {
                temporaryListList = new List<InstructionList>();

                foreach (InstructionList instructionList in keyframeList)
                {
                    temporaryList = new InstructionList();
                    temporaryList.Name = instructionList.Name;

                    foreach (Instruction instruction in instructionList)
                    {
                        // Assume that all instructions are GenericInstructions
                        GenericInstruction asGenericInstruction = instruction as GenericInstruction;

                        bool toAdd = false;

                        if (asGenericInstruction.Target is PositionedModel)
                        {
                            toAdd = EditorData.CurrentPositionedModelMembersWatching.Contains(asGenericInstruction.Member);
                        }
                        else if (asGenericInstruction.Target is Sprite)
                        {
                            toAdd = EditorData.CurrentSpriteMembersWatching.Contains(asGenericInstruction.Member);
                        }
                        else if (asGenericInstruction.Target is SpriteFrame)
                        {
                            toAdd = EditorData.CurrentSpriteFrameMembersWatching.Contains(asGenericInstruction.Member);
                        }
                        else if (asGenericInstruction.Target is Text)
                        {
                            toAdd = EditorData.CurrentTextMembersWatching.Contains(asGenericInstruction.Member);
                        }

                        if (toAdd)
                        {
                            // this instruction is one we want to save
                            temporaryList.Add(instruction);
                        }
                    }

                    if (temporaryList.Count != 0)
                    {
                        temporaryListList.Add(temporaryList);
                    }
                }

                if (temporaryListList.Count != 0)
                {
                    instructionSetSave.AddInstructions(temporaryListList, keyframeList.Name);
                }
            }
            if (instructionSetSave.Instructions.Count != 0)
            {
                instructionSetSave.Target = targetName;
                instructionSetSaveList.InstructionSetSaves.Add(instructionSetSave);
            }
        }
 public void MoveNextWhenNoInstructionAddedTest()
 {
     InstructionSet instructionSet = new InstructionSet();
     Assert.AreEqual(false, instructionSet.MoveNext());
 }
Exemplo n.º 58
0
 RegisterMap(InstructionSet instructionSet)
 {
     this.instructionSet = instructionSet;
     map = new RegisterBitmap[instructionSet.Size];
 }
Exemplo n.º 59
0
 private void UpdateInstructions()
 {
     #if XBOX
         Thread.CurrentThread.SetProcessorAffinity(new int[]{ currentCore++ });
     #endif
     updating = true;
     LetsGo = Node.Handle.BuildPath(new Point((int)Math.Round(Me.X), (int)Math.Round(Me.Y)), ElementTypes.PacDot, Previous);
     updating = false;
 }
Exemplo n.º 60
0
 public void Setup()
 {
     _instructionSet = new InstructionSet();
     _instructionSet.Add("5 5");
     _instructionSet.Add("1 2 N");
 }