Ejemplo n.º 1
0
        public InstructionWidget( IInstruction op )
        {
            InitializeComponent();
            this.Font    = new Font("Lucida Console", 8.25f);
            m_ItalicFont = new Font(this.Font, FontStyle.Italic);

            this.Height = 15;
            this.Executed = true;
            m_Op = op;
            Selected = false;

            if (op is Scrutinizer.ISamplingInstruction)
            {
                Panel panel = new Panel();
                m_FilterBox = CreateFilterBox(op);
                m_FormatBox = CreateFormatBox(op);
                panel.Anchor = AnchorStyles.Right;
                panel.Width = m_FilterBox.Width + m_FormatBox.Width;
                m_FilterBox.Left = m_FormatBox.Width;
                panel.Controls.Add(m_FilterBox);
                panel.Controls.Add(m_FormatBox);
                this.Controls.Add(panel);
            }
            else if (op is Scrutinizer.ITextureInstruction)
            {
                m_FormatBox = CreateFormatBox(op);
                m_FormatBox.Anchor = AnchorStyles.Right;
                this.Controls.Add(m_FormatBox);
            }
        }
Ejemplo n.º 2
0
        public InstructionWidget( IInstruction op )
        {
            InitializeComponent();
            this.Font   = new Font("Lucida Console", 8.25f);
            this.Height = 15;
            m_Op = op;
            this.Brush = Brushes.Black;

            if (op is Scrutinizer.ITexelLoadInstruction)
            {
                ComboBox cb = CreateFormatBox(op);
                cb.Anchor = AnchorStyles.Right;
                this.Controls.Add(cb);
            }
            if (op is Scrutinizer.ISamplingInstruction)
            {
                Panel panel = new Panel();
                ComboBox cbFilter = CreateFilterBox(op);
                ComboBox cbFormat = CreateFormatBox(op);
                panel.Anchor = AnchorStyles.Right;
                panel.Width = cbFilter.Width + cbFormat.Width;
                cbFilter.Left = cbFormat.Width;
                panel.Controls.Add(cbFilter);
                panel.Controls.Add(cbFormat);
                this.Controls.Add(panel);
            }
        }
Ejemplo n.º 3
0
 public void Execute(IInstruction instruction)
 {
     var jtype = instruction as JTypeInstruction;
     if (jtype != null)
         JTypeExecutors[jtype.JumpType](jtype);
     else
     {
         var itype = instruction as ITypeInstruction;
         if (itype != null)
         {
             var cl = ITypeExecutors[itype.Opcode];
             cl(itype);
         }
         else
         {
             var rtype = instruction as RTypeInstruction;
             if (rtype != null)
                 RTypeExecutors[rtype.Function](rtype);
             else
             {
                 var coins = instruction as CoProcessorInstruction;
                 if (coins != null)
                     CoProcessorExecutors[coins.Format](coins);
             }
         }
     }
 }
		public SprocketScript(string source, string descriptiveName, string scriptIdentificationString)
		{
			this.source = source;
			this.identifier = new ExecutionState.ScriptRecursionIdentifier(descriptiveName, scriptIdentificationString);

			TokenList tokens;
			try
			{
				tokens = Tokeniser.Extract(source);
			}
			catch (TokeniserException ex)
			{
				Token falseToken = new Token(source.Substring(ex.Position, 1), TokenType.FreeText, ex.Position);
				Token token = new Token(GetErrorHTML(ex.Message, falseToken, null), TokenType.FreeText, 0);
				tokens = new TokenList(new List<Token>(new Token[] { token }));
				instruction = new ShowInstruction();
				instruction.Build(tokens);
				hasError = true;
				exception = ex;
				return;
			}

			try
			{
				instruction = TokenParser.BuildInstruction(tokens);
			}
			catch (TokenParserException ex)
			{
				Token token = new Token(GetErrorHTML(ex.Message, ex.Token, null), TokenType.FreeText, 0);
				tokens = new TokenList(new List<Token>(new Token[] { token }));
				instruction = new ShowInstruction();
				instruction.Build(tokens);
				hasError = true;
			}
		}
		public void Parse_All()
		{
			var reader = ConsolePlatformTester.LoadInput("input.simple.txt");
			var actual = Instruction.Read(reader).ToArray();

			var expected = new IInstruction[]
			{
				// Settings
				new HandsPerLevelInstruction(10),
				new StartingStackInstruction(2000),
				new YourBotInstruction(PlayerName.player1),
				new TimeBankInstruction(TimeSpan.FromSeconds(10)),
				new TimePerMoveInstruction(TimeSpan.FromMilliseconds(500)),
				// Match
				new RoundInstruction(1),
				new SmallBlindInstruction(10),
				new BigBlindInstruction(20),
				// Player
				new OnButtonInstruction(PlayerName.player2),
				new StackInstruction(PlayerName.player1, 2000),
				new StackInstruction(PlayerName.player2, 2000),
				new PostInstruction(PlayerName.player2, 10),
				new PostInstruction(PlayerName.player1, 20),
				new HandInstruction(PlayerName.player1, Cards.Parse("[9c,7h]")),
				new ActionInstruction(PlayerName.player2, GameAction.Call),
			};

			CollectionAssert.AreEqual(expected, actual.Take(expected.Length).ToArray());
			Assert.AreEqual(0, actual.Length);
		}
Ejemplo n.º 6
0
 public void ResolveLables(IInstruction[] instructions)
 {
     if (IsResolved) return;
     int pos = 0;
     for(int i = 0; i < instructions.Length; i++)
     {
         if(this.labels.AsEnumerable().Any(x => x == instructions[i].Label))
         {
             if (this.additional.Length == 1)
             {
                 this.additional[0] = (ushort) pos;
                 this.IsResolved = true;
             } else if(this.additional.Length== 2)
             {
                 if (this.labels.First() == instructions[i].Label)
                 {
                     this.additional[0] = (ushort)pos;
                     this.labels[0] = string.Empty;
                 }
                 if(this.labels[1] == instructions[i].Label)
                 {
                     this.additional[1] = (ushort) pos;
                     this.labels[1] = string.Empty;
                 }
                 this.IsResolved = this.labels.All(s => s == string.Empty);
             }
         }
         pos += instructions[i].Size;
     }
 }
 private static string GenerateFromInstruction(IInstruction instruction)
 {
     var bytes = instruction.GetReportData();
     var sb = new StringBuilder();
     sb.Append("WR ");
     AppendBytesAsString(bytes, sb);
     return sb.ToString();
 }
        public IEnumerable<IInstruction> ResolveSymbolicInstructions(IInstruction[] instructions)
        {
            // must go through labels first, removing them when they've been added to the symbol table
            var linesWithLabelsRemoved = _hackLabelResolver.ResolveLabels(_symbolTable, instructions).ToArray();

            // then go through variables, resolving them after adding to table if not already there
            return _hackVariableResolver.ResolveVariables(_symbolTable, linesWithLabelsRemoved).ToArray();
        }
Ejemplo n.º 9
0
        public BreakpointViewModel(IGameBoy gameboy, IInstruction inst)
        {
            _gameboy = gameboy;
              _instruction = inst;

              OriginalAddress = inst.Address;
              Address = "0x" + inst.Address.ToString("x2");
              Name = inst.Name;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:B4F.TotalGiro.PortfolioComparer.PortfolioCompareSetting">PortfolioCompareSetting</see> class.
        /// </summary>
        /// <param name="compareAction">
        /// When this argument equals 'CloseOrders' it is checked whether positions exist that do not exist in the modelportfolio. 
        /// When this is the case this will result in only sell close size based orders.
        /// When the argument equals 'Rebalance' a normal rebalance is done.
        /// However the method will generate an error when positions do exist that do not exist in the modelportfolio.
        /// When the argument equals 'CashFundOrders' the remaining cash will be transferred to cash fund.
        /// </param>
        /// <param name="instruction">The instruction that generated the orders</param>
        /// <param name="engineParams">The parameters used in porfolio compare action</param>
        public PortfolioCompareSetting(PortfolioCompareAction compareAction, IInstruction instruction, InstructionEngineParameters engineParams)
        {
            if (instruction == null)
                throw new ApplicationException("The instruction is mandatory");

            this.CompareAction = compareAction;
            this.Instruction = instruction;
            this.EngineParams = engineParams;
        }
		public bool Apply(IInstruction instruction)
		{
			if (Mapping.ContainsKey(instruction.GetType()))
			{
				Mapping[instruction.GetType()].Invoke(instruction, this);
				return true;
			}
			return false;
		}
Ejemplo n.º 12
0
 public Instruction(IInstruction src)
 {
     Operation = src.Operation;
     Modifier = src.Modifier;
     ModeA = src.ModeA;
     ValueA = src.ValueA;
     ModeB = src.ModeB;
     ValueB = src.ValueB;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// This method tries to cancel the instruction (if allowed).
        /// </summary>
        /// <param name="instruction">The <see cref="T:B4F.TotalGiro.Accounts.Instructions.Instruction">Instruction</see> to process</param>
        /// <param name="cancelOrders">The cancelled orders that might result from the processing</param>
        /// <returns>true when succesfull</returns>
        public bool CancelInstruction(IInstruction instruction)
        {
            int oldStatus = instruction.Status;
            string oldMessage = instruction.Message;
            int nextStatus;

            nextStatus = stateMachine.SetStatus(getStateTable(instruction.InstructionType), (int)oldStatus, (int)InstructionEvents.evCancel, (IStateMachineClient)instruction);
            if (nextStatus != 0)
                instruction.Status = nextStatus;
            return (instruction.Status != oldStatus || instruction.Message != oldMessage);
        }
Ejemplo n.º 14
0
        public override void Given()
        {
            this.StubbedRover = stub_a<IRover>();
            this.StubbedPlateau = stub_a<IPlateau>();
            this.StubbedInstruction = stub_a<IInstruction>();
            this.StubbedPositionChecks = stub_a<List<IPositionCheck>>();

            this.PlateauController = new PlateauController(this.StubbedPlateau);
            this.PlateauController.PositionChecks = this.StubbedPositionChecks;
            this.StubbedRover.Instruction = this.StubbedInstruction;
        }
Ejemplo n.º 15
0
 public EngineInstruction(int address, IRunningWarrior owner)
 {
     Operation = Operation.DAT;
     Modifier = Modifier.F;
     ModeA = Mode.Direct;
     ValueA = 0;
     ModeB = Mode.Direct;
     ValueB = 0;
     OriginalInstruction = null;
     Address = address;
     OriginalOwner = owner;
 }
Ejemplo n.º 16
0
 private void LogInstruction(IInstruction instruction, byte opCode)
 {
     var instructionSize = instruction.Variants[opCode].InstructionSize();
     var instructionBytes = mem.SequenceFrom(state.Pc).Take(instructionSize).ToArray();
     Console.WriteLine("{0:X2}  {1,-10}{2,-32}A:{3:X2} X:{4:X2} Y:{5:X2} P:{6:X2} SP:{7:X2}", // TODO: Cycle and scanline goes at the end
         state.Pc,
         string.Join(" ", instructionBytes.Select(x => x.ToString("X2"))),
         instruction.Disassemble(instructionBytes),
         state.A,
         state.X,
         state.Y,
         state.StatusRegister,
         state.Sp);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a new Program
        /// </summary>
        /// <param name="processor">the processor for this program</param>
        /// <param name="instructions">the program instructions</param>
        /// <param name="debugInfo">optional program debug information</param>
        public Program(Processor processor, IList<IInstruction> instructions,
                        ProgramDebugInfo debugInfo = null)
        {
            this.DebugInfo = debugInfo;
            this.Processor = processor;

            // Check instructions size
            if (instructions.Count > processor.RomSize)
            {
                throw new ArgumentException("Number of instructions > size of instruction ROM");
            }

            // Create new readonly instructions array
            IInstruction[] instructionArray = new IInstruction[processor.RomSize];
            instructions.CopyTo(instructionArray, 0);
            this.Instructions = new ReadOnlyCollection<IInstruction>(instructionArray);
        }
Ejemplo n.º 18
0
 public SprocketScript(string source)
 {
     this.source = source;
     List<Token> tokens = Tokeniser.Extract(source);
     try
     {
         instruction = TokenParser.BuildInstruction(tokens);
     }
     catch (TokenParserException ex)
     {
         tokens.Clear();
         tokens.Add(new Token(GetErrorHTML(ex.Message, ex.Token), TokenType.StringLiteral, 0));
         instruction = new ShowInstruction();
         int n = 0;
         instruction.Build(tokens, ref n);
     }
 }
Ejemplo n.º 19
0
 public void ResolveLables(IInstruction[] instructions)
 {
     //    if (IsResolved) return;
     //    int pos = 0;
     //    for (int i = 0; i < instructions.Length; i++)
     //    {
     //        if (this.labels.AsEnumerable().Any(x => x == instructions[i].Label))
     //        {
     //            if (this.additional.Length == 1)
     //            {
     //                this.additional[0] = (ushort)pos;
     //                this.IsResolved = true;
     //            }
     //        }
     //        pos += instructions[i].Size;
     //    }
 }
Ejemplo n.º 20
0
        public UInt32 disassemble(ulong offset, out IInstruction instr, ref DISASM_INOUT_PARAMS param)
        {
            byte[] bt = assembly.ReadBytes(offset, 10);
            dsm = new TUP.AsmResolver.ASM.x86Disassembler(bt);
            dsm.CurrentOffset = 0;
            Instr instr1 = new Instr();
            instr1.Addr = offset;
            instr1.ins = dsm.DisassembleNextInstruction();
            instr1.bytes = assembly.ReadBytes(offset, instr1.ins.Size);

            if (instr1.bytes[0] == 0xFF)
                if (instr1.bytes[1] == 0x15)
                    if (instr1.ins.Operand1 != null)
                        instr1.disp.value.d64 = ((Offset)instr1.ins.Operand1.Value).Va;//Call ExitProcess probably

            instr = instr1;
            return (UInt32)instr1.ins.Size;
        }
Ejemplo n.º 21
0
        private ComboBox CreateFilterBox( IInstruction op )
        {
            ComboBox cb = new ComboBox();
            foreach (string s in Enum.GetNames(typeof(Scrutinizer.TextureFilter)))
                cb.Items.Add(s);
            cb.Width = 96;
            cb.SelectedIndex = (int)Scrutinizer.TextureFilter.TRILINEAR;
            cb.DropDownStyle = ComboBoxStyle.DropDownList;
            cb.SelectedIndexChanged += delegate(object s, EventArgs e)
            {
                if (op is ISamplingInstruction)
                {
                    ISamplingInstruction samp = op as ISamplingInstruction;
                    samp.Filter = (TextureFilter)cb.SelectedIndex;
                }
            };

            return cb;
        }
Ejemplo n.º 22
0
 public EngineInstruction(IInstruction src, int address, IRunningWarrior owner)
 {
     Operation = src.Operation;
     Modifier = src.Modifier;
     ModeA = src.ModeA;
     ValueA = src.ValueA;
     ModeB = src.ModeB;
     ValueB = src.ValueB;
     Address = address;
     OriginalOwner = owner;
     if (src is EngineInstruction)
     {
         EngineInstruction ei = (EngineInstruction)src;
         OriginalInstruction = ei.OriginalInstruction;
     }
     else
     {
         OriginalInstruction = src;
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Adds a new instruction to the program
        /// </summary>
        /// <param name="instruction">instruction to add</param>
        /// <param name="line">optional line number for this instruction</param>
        /// <remarks>
        /// <para>The instruction is inserted at <see cref="Address"/> and <see cref="Address"/> is
        /// then incremented.</para>
        /// <para>You are not allowed to "rewrite" instructions by decrementing Address and then
        /// adding another instruction</para>
        /// </remarks>
        /// <exception cref="ImportException">
        /// If you attempt to "rewrite" an instruction
        /// </exception>
        public void Add(IInstruction instruction, int? line = null)
        {
            // Ensure store is large enough
            if (Address >= store.Count)
            {
                store.AddRange(Enumerable.Repeat<IInstruction>(null, Address - store.Count + 1));
            }
            else if (store[Address] != null)
            {
                throw new ImportException("You cannot insert 2 instructions at the same address");
            }

            // Store line number
            if (line.HasValue)
                lineNumbers[Address] = line.Value;

            // Insert instruction
            store[Address] = instruction;
            Address++;
        }
Ejemplo n.º 24
0
 public EngineInstruction(IInstruction src, int address)
 {
     Operation = src.Operation;
     Modifier = src.Modifier;
     ModeA = src.ModeA;
     ValueA = src.ValueA;
     ModeB = src.ModeB;
     ValueB = src.ValueB;
     Address = address;
     if (src is EngineInstruction)
     {
         EngineInstruction ei = (EngineInstruction)src;
         OriginalInstruction = ei.OriginalInstruction;
         OriginalOwner = ei.OriginalOwner;
     }
     else
     {
         OriginalInstruction = src;
         OriginalOwner = null;
     }
 }
Ejemplo n.º 25
0
        public InstructionViewModel(ICPU cpu, IInstruction instruction)
        {
            _cpu = cpu;

              _instruction = instruction;
              originalAddress = instruction.Address;
              Address = "0x" + instruction.Address.ToString("x2");
              Opcode = "0x" + instruction.OpCode.ToString("x2");
              Name = instruction.Name;
              Literal = "0x" + instruction.Literal.ToString("x2");
              Description = instruction.Description;

              if (!instruction.CB)
              {
            Ticks = CPUSpace.Dictionaries.CPUInstructionClocks.Get((byte)instruction.OpCode);
              }
              else
              {
            Ticks = CPUSpace.Dictionaries.CPUCBInstructionClocks.Get((byte)instruction.OpCode);
              }
        }
Ejemplo n.º 26
0
        private ComboBox CreateFormatBox( IInstruction op )
        {
            ComboBox cb = new ComboBox();
            foreach (string s in Enum.GetNames(typeof(Scrutinizer.TexelFormat)))
                cb.Items.Add(s);
            cb.Width = 80;
            cb.SelectedIndex = (int)Scrutinizer.TexelFormat.RGBA8;
            cb.DropDownStyle = ComboBoxStyle.DropDownList;

            cb.SelectedIndexChanged += delegate(object s, EventArgs e)
            {
                if (op is ISamplingInstruction)
                {
                    ISamplingInstruction samp = op as ISamplingInstruction;
                    samp.Format = (TexelFormat)cb.SelectedIndex;
                }
                else if( op is ITexelLoadInstruction )
                {
                    ITexelLoadInstruction ld = op as ITexelLoadInstruction;
                    ld.Format = (TexelFormat)cb.SelectedIndex;
                }
            };
            return cb;
        }
Ejemplo n.º 27
0
 public Instructions_ToggleStringModeShould()
 {
     _sit     = new ToggleStringMode();
     _runtime = MockIBefungeRunTimeFactory.Create();
 }
Ejemplo n.º 28
0
 public Instructions_LogicalNotShould()
 {
     _sit     = new LogicalNot();
     _runtime = MockIBefungeRunTimeFactory.Create();
 }
Ejemplo n.º 29
0
 protected virtual void ExecuteEditInstruction(IInstruction instruction)
 {
 }
Ejemplo n.º 30
0
    //This function actually creates the object associated with each Instruction by using a long switch statement. The object
    //created is polymorphed up to an IInstruction and then returned from the function to be stored in the encodedInstrs list.
    //Ugly? Very. Effective? Extremely.
    private IInstruction createObject(string comm, int valToUse, int currentInstruc)
    {
        IInstruction retVal = null;

        switch (comm)
        {
        case "exit":
            retVal = new Exit(valToUse) as IInstruction;
            break;

        case "swap":
            retVal = new Swap() as IInstruction;
            break;

        case "inpt":
            retVal = new Inpt() as IInstruction;
            break;

        case "nop":
            retVal = new Nop() as IInstruction;
            break;

        case "pop":
            retVal = new Pop() as IInstruction;
            break;

        case "add":
            retVal = new Add() as IInstruction;
            break;

        case "sub":
            retVal = new Sub() as IInstruction;
            break;

        case "mul":
            retVal = new Mul() as IInstruction;
            break;

        case "div":
            retVal = new Div() as IInstruction;
            break;

        case "rem":
            retVal = new Rem() as IInstruction;
            break;

        case "and":
            retVal = new And() as IInstruction;
            break;

        case "or":
            retVal = new Or() as IInstruction;
            break;

        case "xor":
            retVal = new Xor() as IInstruction;
            break;

        case "neg":
            retVal = new Neg() as IInstruction;
            break;

        case "not":
            retVal = new Not() as IInstruction;
            break;

        case "goto":
            retVal = new Goto(valToUse) as IInstruction;
            break;

        case "ifeq":
            retVal = new If1(0, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifne":
            retVal = new If1(1, valToUse, currentInstruc) as IInstruction;
            break;

        case "iflt":
            retVal = new If1(2, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifgt":
            retVal = new If1(3, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifle":
            retVal = new If1(4, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifge":
            retVal = new If1(5, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifez":
            retVal = new If2(0, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifnz":
            retVal = new If2(1, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifmi":
            retVal = new If2(2, valToUse, currentInstruc) as IInstruction;
            break;

        case "ifpl":
            retVal = new If2(3, valToUse, currentInstruc) as IInstruction;
            break;

        case "dup":
            retVal = new Dup(valToUse) as IInstruction;
            break;

        case "print":
            retVal = new Print() as IInstruction;
            break;

        case "dump":
            retVal = new Dump() as IInstruction;
            break;

        case "push":
            retVal = new Push(valToUse) as IInstruction;
            break;
        }
        return(retVal);
    }
Ejemplo n.º 31
0
                public void ChargerProgramme(string codeDuProgramme)
                 {
                        if (codeDuProgramme is null)
                         {
                                throw new System.ArgumentOutOfRangeException(nameof(codeDuProgramme));
                            
            }

                        IInstruction instructionCourante  =  new InstructionBFDebutProgramme();
                        this.Instructions  =  instructionCourante;
                        Stack <InstructionBFBoucleDebut>  debutBoucle  =  new Stack <InstructionBFBoucleDebut>();

                        for (int indexInstruction  =  0;  indexInstruction  <  codeDuProgramme.Length;  ++ indexInstruction)
                         {
                                char instruction  =  codeDuProgramme[indexInstruction];
                                IInstruction nouvelleInstruction  =  null;

                                switch (instruction)
                                 {
                                        case  '<' :
                                            nouvelleInstruction  =  new InstructionBFDeplacementMemoireGauche();
                                            break;
                                        case  '>' :
                                            nouvelleInstruction  =  new InstructionBFDeplacementMemoireDroite();
                                            break;

                                        case  '+' :
                                            nouvelleInstruction  =  new InstructionBFModifierValeurIncrementer();
                                            break;
                                        case  '-' :
                                            nouvelleInstruction  =  new InstructionBFModifierValeurDecrementer();
                                            break;

                                        case  '.' :
                                            nouvelleInstruction  =  new InstructionBFIOEcrireCaractere();
                                            break;
                                        case  ',' :
                                            nouvelleInstruction  =  new InstructionBFIOLireCaractere();
                                            break;

                                        case  '[' :
                                            nouvelleInstruction  =  new InstructionBFBoucleDebut();
                                            debutBoucle.Push((InstructionBFBoucleDebut)nouvelleInstruction);
                                            break;
                                        case  ']' :
                                            if (debutBoucle.Count  ==  0)
                                             {
                                                    this.Instructions  =  null;
                                                    throw new SyntaxErrorException();
                                                
                    }
                                            nouvelleInstruction  =  new InstructionBFBoucleFin()   {
                         DebutBoucle  =  debutBoucle.Pop()  
                    };
                                            break;

                    default:
                                            break;
                                    
                }

                                if (nouvelleInstruction  !=  null)
                                 {
                                        nouvelleInstruction.InformationInstruction  =  new InformationInstruction()
                                                                                                           {
                                                Instruction      =  instruction.ToString(),
                                                Longueur         =  1,
                                                NumeroCaractere  =  indexInstruction  +  1
                                                                                       
                    };
                                        instructionCourante.InstructionSuivante  =  nouvelleInstruction;
                                        instructionCourante  =  nouvelleInstruction;
                                    
                }
                            
            }

                        instructionCourante.InstructionSuivante  =  new InstructionBFFinProgramme();

                        if (debutBoucle.Count  !=  0)
                         {
                                this.Instructions  =  null;
                                throw new SyntaxErrorException();
                            
            }
                    
        }
Ejemplo n.º 32
0
        public override bool Equals(object obj)
        {
            IInstruction o = obj as IInstruction;

            return(Instruction.Equals(this, o, Rules.DefaultRules.CoreSize));
        }
Ejemplo n.º 33
0
 protected virtual void ExecuteCopyInstruction(IInstruction instruction)
 {
 }
Ejemplo n.º 34
0
 protected virtual void ExecuteDeleteInstruction(IInstruction instruction)
 {
 }
Ejemplo n.º 35
0
 protected ISExpression Closure(IInstruction body, IEnvironment e, ISExpression args)
 {
     return(new Closure(body, e, args));
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Sets the instruction.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="result">The result.</param>
 /// <param name="operand1">The operand1.</param>
 public void SetInstruction(IInstruction instruction, Operand result, Operand operand1)
 {
     SetInstruction(instruction, 1, (byte)((result == null) ? 0 : 1));
     Result = result;
     Operand1 = operand1;
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Sets the instruction.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="code">The code.</param>
 /// <param name="block">The block.</param>
 /// <param name="branchHint">if set to <c>true</c> [branch hint].</param>
 public void SetInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block, bool branchHint)
 {
     SetInstruction(instruction, code, block);
     BranchHint = branchHint;
 }
Ejemplo n.º 38
0
 public DefTypeInstruction Id(byte id)
 {
     _id = new LiteralInstruction(id);
     return(this);
 }
Ejemplo n.º 39
0
 public Instructions_BranchLeftOrRightShould()
 {
     _sit     = new BranchLeftOrRight();
     _runtime = MockIBefungeRunTimeFactory.Create();
 }
Ejemplo n.º 40
0
 public InstructionEventArgs(IInstruction instruction)
 {
     _instruction = instruction;
 }
Ejemplo n.º 41
0
 public ContiInstruction(IInstruction next)
 {
     Next = next;
 }
Ejemplo n.º 42
0
        public bool ExistsAndActive(IInstruction instruction)
        {
            Debug.Assert(instruction != null, "instruction is null");

            return(_instructions.ContainsKey(instruction.Id) && _instructions[instruction.Id].Active);
        }
Ejemplo n.º 43
0
 public Instructions_Discard()
 {
     _sit     = new Discard();
     _runtime = MockIBefungeRunTimeFactory.Create();
 }
Ejemplo n.º 44
0
 public static string GetInstructionEnding(IInstruction i) => i is IOneLineInstruction ? ";" : string.Empty;
 public Instructions_ModuloShould()
 {
     _sit     = new Modulo();
     _runtime = MockIBefungeRunTimeFactory.Create();
 }
Ejemplo n.º 46
0
 public virtual void AppendInstruction(IInstruction instruction)
 {
     _instructions.Add(instruction);
 }
Ejemplo n.º 47
0
 public TaskTween(
     float duration,
     IInstruction <T> instruction,
     Action <T> applyAction) : base(instruction, applyAction, duration)
 {
 }
Ejemplo n.º 48
0
        public override void Process(IList <IInstruction> instructions, int index)
        {
            IInstruction instruction = instructions[index];

            switch (instruction.OpCode.Value)
            {
            case 0x16:                     // Ldc_I4_0
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 0);
                break;
            }

            case 0x17:                     // Ldc_I4_1
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 1);
                break;
            }

            case 0x18:                     // Ldc_I4_2
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 2);
                break;
            }

            case 0x19:                     // Ldc_I4_3
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 3);
                break;
            }

            case 0x1a:                     // Ldc_I4_4
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 4);
                break;
            }

            case 0x1b:                     // Ldc_I4_5
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 5);
                break;
            }

            case 0x1c:                     // Ldc_I4_6
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 6);
                break;
            }

            case 0x1d:                     // Ldc_I4_7
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 7);
                break;
            }

            case 0x1e:                     // Ldc_I4_8
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, 8);
                break;
            }

            case 0x15:                     // Ldc_I4_M1
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, -1);
                break;
            }

            case 0x1f:                     // Ldc_I4_S
            {
                instructions[index] = new Instruction(OpCodes.Ldc_I4, instruction.IP, (int)((byte)instruction.Argument));
                break;
            }
            }
        }
Ejemplo n.º 49
0
 public GetArrayInstruction Id(IInstruction id)
 {
     _id = id;
     return(this);
 }
Ejemplo n.º 50
0
 public ElementInstruction(IInstruction start, IInstruction <T> content, IInstruction finish)
 {
     _start   = start;
     _content = content;
     _finish  = finish;
 }
Ejemplo n.º 51
0
        public bool Exists(IInstruction instruction)
        {
            Debug.Assert(instruction != null, "instruction is null");

            return(_instructions.ContainsKey(instruction.Id));
        }
        /// <summary>
        /// Construct a control flow graph out of the method body
        /// </summary>
        /// <param name="instructions"></param>
        public ControlFlowGraph(SortedList <ushort, IInstruction> instructions)
        {
            // Iterate the list of instructions building a list of call graph nodes
            SortedList <ushort, CallGraphNode> nodes = new SortedList <ushort, CallGraphNode>();
            List <IInstruction> nodeInstructions     = new List <IInstruction>();

            foreach (IInstruction instruction in instructions.Values)
            {
                if ((instruction.IsTarget) && (nodeInstructions.Count > 0))
                {
                    // This is the start of a block.  Create the previous block
                    CallGraphNode callGraphNode = new CallGraphNode(nodeInstructions);
                    nodes.Add(callGraphNode.StartIP, callGraphNode);
                    nodeInstructions = new List <IInstruction>();
                }

                nodeInstructions.Add(instruction);
            }

            // Add the last node to the list
            if (nodeInstructions.Count > 0)
            {
                CallGraphNode callGraphNode = new CallGraphNode(nodeInstructions);
                nodes.Add(callGraphNode.StartIP, callGraphNode);
            }

            // Link the list of nodes
            for (int i = 0; i < nodes.Count; i++)
            {
                CallGraphNode node = nodes.Values[i];

                // Examine the last instruction to determine how to link this node to others
                IInstruction instruction = node.Instructions[node.Instructions.Count - 1];

                switch (instruction.OpCode.FlowControl)
                {
                case FlowControl.Branch:
                    // Direct branch to a new block
                    node.NodeType = NodeType.OneBranch;
                    LinkNode(node, nodes, (ushort)instruction.Argument);
                    break;

                case FlowControl.Cond_Branch:
                    if (instruction.OpCode.Value == OpCodes.Switch.Value)
                    {
                        // Conditional branch to n-blocks
                        node.NodeType = NodeType.MultiBranch;
                        foreach (ushort switchTargetIp in (ushort[])instruction.Argument)
                        {
                            LinkNode(node, nodes, switchTargetIp);
                        }
                    }
                    else
                    {
                        // Conditional branch to two blocks
                        node.NodeType = NodeType.TwoBranch;
                        LinkNode(node, nodes, (ushort)instruction.Argument);
                    }

                    // Add the continuation link
                    LinkContinuationNode(node, nodes);
                    break;

                case FlowControl.Return:
                    node.NodeType = NodeType.Exit;
                    break;

                case FlowControl.Throw:
                    node.NodeType = NodeType.Throw;
                    // End of graph
                    break;

                case FlowControl.Break:
                case FlowControl.Call:
                case FlowControl.Meta:
                case FlowControl.Next:
#pragma warning disable 612,618
                case FlowControl.Phi:
#pragma warning restore 612,618
                    // Add the continuation link
                    node.NodeType = LinkContinuationNode(node, nodes) ? NodeType.FallThrough : NodeType.ExitBlock;
                    break;

                default:
                    throw new ApplicationException("Unexpected flow control type in instruction " + instruction.OpCode.Name);
                }
            }

            _rootNode = nodes.Values[0];
            _nodes    = nodes;

            CheckGraph();

            // Remove redundancies and add in-edge information
            Optimize(nodes);

            IList <IGraphNode> ln = new List <IGraphNode>();
            foreach (CallGraphNode n in _nodes.Values)
            {
                ln.Add(n);
            }
            PrintGraph(ln);

            CheckGraph();

            // Visit the graph in depth first order and label the nodes
            _depthFirstSearchLast  = new CallGraphNode[nodes.Count];
            _depthFirstSearchFirst = new CallGraphNode[nodes.Count];
            int first = 0;
            int last  = nodes.Count - 1;
            DepthFirstTraverse(_rootNode, ref first, ref last);

            // Find the immediate dominators of each node
            FindImmediateDominators();

            // Check the graph for reducibility
            FindDerivedSequence();

            // Work out the graphs back edges
            DetermineBackEdges();

            ResetTraversal();
            StructureCases();
            StructureLoops();
            StructureIfs();
        }
Ejemplo n.º 53
0
        /// <summary>
        /// Eliminates the common subexpressions.
        /// </summary>
        /// <param name="ctx">The context.</param>
        private static void EliminateCommonSubexpressions(Context ctx)
        {
            List <AEBinExp> AEB = new List <AEBinExp>();
            List <AEBinExp> tmp;

            AEBinExp aeb;

            for (; !ctx.EndOfInstruction; ctx.GotoNext())
            {
                IInstruction    instruction = ctx.Instruction;              // block.Instructions[i];
                RegisterOperand temp        = null;
                bool            found       = false;

                if ((instruction is CIL.ArithmeticInstruction) && (instruction is CIL.BinaryInstruction))
                {
                    tmp = new List <AEBinExp>(AEB);

                    while (tmp.Count > 0)
                    {
                        aeb = tmp[0];
                        tmp.RemoveAt(0);

                        // Match current instruction's expression against those
                        // in AEB, including commutativity
                        if (IsCommutative(instruction))
                        {
                            //int position = aeb.Position;
                            found = true;

                            // If no variable in tuple, create a new temporary and
                            // insert an instruction evaluating the expression
                            // and assigning it to the temporary
                            if (aeb.Var == null)
                            {
                                // new_tmp()
                                AEB.Remove(aeb);
                                AEB.Add(new AEBinExp(aeb.Position, aeb.Operand1, aeb.Operator, aeb.Operand2, temp));

                                // Insert new assignment to instruction stream in block
                                Context inserted = ctx.InsertBefore();

                                switch (aeb.Operator)
                                {
                                case Operation.Add:
                                    inserted.SetInstruction(CIL.Instruction.Get(CIL.OpCode.Add), temp, aeb.Operand1, aeb.Operand2);
                                    break;

                                case Operation.Mul:
                                    inserted.SetInstruction(CIL.Instruction.Get(CIL.OpCode.Mul), temp, aeb.Operand1, aeb.Operand2);
                                    break;

                                case Operation.Or:
                                    inserted.SetInstruction(CIL.Instruction.Get(CIL.OpCode.Or), temp, aeb.Operand1, aeb.Operand2);
                                    break;

                                case Operation.Xor:
                                    inserted.SetInstruction(CIL.Instruction.Get(CIL.OpCode.Xor), temp, aeb.Operand1, aeb.Operand2);
                                    break;

                                default:
                                    break;
                                }

                                //block.Instructions.Insert(position, inst);

                                //++position;
                                //++i;

                                // Replace current instruction by one that copies
                                // the temporary instruction
                                // FIXME PG:
                                // block.Instructions[position] = new IR.MoveInstruction(block.Instructions[position].Results[0], temp);
                                // ctx.SetInstruction(IR.MoveInstruction); // FIXME PG
                                // ctx.Result = block.Instructions[position].Results[0]; // FIXME PG
                                ctx.Operand1 = temp;
                            }
                            else
                            {
                                temp = (RegisterOperand)aeb.Var;
                            }

                            // FIXME PG
                            // block.Instructions[i] = new IR.MoveInstruction(instruction.Results[0], temp);
                        }
                    }

                    if (!found)
                    {
                        Operation opr = Operation.None;

                        if (instruction is CIL.AddInstruction)
                        {
                            opr = Operation.Add;
                        }
                        else if (instruction is CIL.MulInstruction)
                        {
                            opr = Operation.Mul;
                        }
                        else if (instruction is IR.LogicalAndInstruction)
                        {
                            opr = Operation.And;
                        }
                        // Insert new tuple
                        AEB.Add(new AEBinExp(ctx.Index, ctx.Operand1, opr, ctx.Operand2, null));
                    }

                    // Remove all tuples that use the variable assigned to by
                    // the current instruction
                    tmp = new List <AEBinExp>(AEB);

                    while (tmp.Count > 0)
                    {
                        aeb = tmp[0];
                        tmp.RemoveAt(0);

                        if (ctx.Operand1 == aeb.Operand1 || ctx.Operand2 == aeb.Operand2)
                        {
                            AEB.Remove(aeb);
                        }
                    }
                }
            }
        }
Ejemplo n.º 54
0
 public GetArrayInstruction Id(byte id)
 {
     _id = new LiteralInstruction(id);
     return(this);
 }
Ejemplo n.º 55
0
 public DefTypeInstruction NumberOfFields(IInstruction numberOfFields)
 {
     _numberOfFields = numberOfFields;
     return(this);
 }
Ejemplo n.º 56
0
 protected void PushFrame(ISchemeVM vm, IInstruction x, IEnvironment e, Stack <ISExpression> r, Stack <IFrame> s)
 {
     vm.S.Push(new Frame(x, e, r, s));
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Sets the instruction.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="result">The result.</param>
 public void SetInstruction(IInstruction instruction, Operand result)
 {
     SetInstruction(instruction, 0, 1);
     Result = result;
 }
Ejemplo n.º 58
0
 public DefTypeInstruction NumberOfFields(byte numberOfFields)
 {
     _numberOfFields = new LiteralInstruction(numberOfFields);
     return(this);
 }
Ejemplo n.º 59
0
 /// <summary>
 /// Sets the instruction.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="result">The result.</param>
 /// <param name="operand1">The operand1.</param>
 /// <param name="operand2">The operand2.</param>
 /// <param name="operand3">The operand3.</param>
 public void SetInstruction(IInstruction instruction, Operand result, Operand operand1, Operand operand2, Operand operand3)
 {
     SetInstruction(instruction, 3, (byte)((result == null) ? 0 : 1));
     Result = result;
     Operand1 = operand1;
     Operand2 = operand2;
     Operand3 = operand3;
 }
Ejemplo n.º 60
0
 public DefTypeInstruction Id(IInstruction id)
 {
     _id = id;
     return(this);
 }