コード例 #1
0
 public AsmILGenerator(bool isEntryPoint = false)
 {
     if (isEntryPoint)
     {
         OpCodes.Add(".entrypoint");
     }
 }
コード例 #2
0
 public void EmitStloc(ILocalBuilder local)
 {
     if (local == null)
     {
         throw new ArgumentNullException(nameof(local));
     }
     OpCodes.Add($"stloc {local.LocalIndex}");
 }
コード例 #3
0
        public void EmitTrue()
        {
            OpCodes.Add("ldc.i4.1");

            int @int = 42;

            GC.KeepAlive(@int);
        }
コード例 #4
0
        public void MarkLabel(ILabel label)
        {
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }
            var idx = ((AsmLabel)label).Idx;

            OpCodes.Add($"Label_{idx}:");
        }
コード例 #5
0
        public void EmitBrtrue(ILabel label)
        {
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }
            var idx = ((AsmLabel)label).Idx;

            OpCodes.Add($"brtrue Label_{idx}");
        }
コード例 #6
0
        public void ShouldBeAbleToAddTwoRegistersTogether()
        {
            var source = new List <IOperation>
            {
                //OpCodes.Move(DataType.VectorOfByte, new VectorConstantOperand<byte>(Vector<byte>.One), new RegisterOperand(1)),

                //OpCodes.Move(DataType.VectorOfByte, new VectorConstantOperand<byte>(Vector<byte>.One), new RegisterOperand(2)),

                OpCodes.Add(DataType.VectorOfByte, new RegisterOperand(1), new RegisterOperand(2), new RegisterOperand(3))
            };

            var cpu = BuildCpu(source);

            RunProgram(cpu, source);

            cpu.Registers[3].ShouldBe(new Vector <byte>(2));
        }
コード例 #7
0
ファイル: CPU.cs プロジェクト: jarkkopa/GeemuBoy
 private void CreateOpCode(byte command, Action instruction, string name)
 {
     OpCodes.Add(command, new OpCode(instruction, name));
 }
コード例 #8
0
 public void EmitRet()
 {
     OpCodes.Add("ret");
 }
コード例 #9
0
 public void EmitStarg(short idx)
 {
     OpCodes.Add($"starg {idx}");
 }
コード例 #10
0
 public void EmitLdthis()
 {
     OpCodes.Add("ldarg.0");
 }
コード例 #11
0
 public void EmitMul()
 {
     OpCodes.Add("mul");
 }
コード例 #12
0
 public void EmitCgt()
 {
     OpCodes.Add("cgt");
 }
コード例 #13
0
 public void EmitLdstr(string value)
 {
     // TODO escaping is going to break this
     OpCodes.Add($"ldstr \"{value}\"");
 }
コード例 #14
0
ファイル: Script.cs プロジェクト: rcawston/BitcoinWebSocket
        /// <summary>
        ///     Decodes the script into op_codes and data sections
        /// </summary>
        private void Decode()
        {
            // Iterate over each byte in the script.
            // When a data chunk (non-op_code section) is encountered,
            //   i will be incremented so as to skip reading op_codes from the data
            for (var i = 0; i < ScriptBytes.Length; i++)
            {
                // OP_PUSH - indicates a data section of ScriptBytes[i] length
                if (ScriptBytes[i] > 1 && ScriptBytes[i] < 76)
                {
                    // save the data chunk and add an OP_DATA code to the script
                    var dataLength = ScriptBytes[i];
                    DataChunks.Add(ScriptBytes.Skip(i + 1).Take(dataLength).ToArray());
                    OpCodes.Add(OpCodeType.OP_DATA);
                    // increment i to skip over the data section during further op_code processing
                    i += dataLength;
                }
                else
                {
                    switch (ScriptBytes[i])
                    {
                    // OP_PUSHDATA1 - indicates a data section of ScriptBytes[i+1] length
                    case (byte)OpCodeType.OP_PUSHDATA1:
                    {
                        // save the data chunk and an OP_DATA code to the script
                        var dataLength = ScriptBytes[i + 1];
                        DataChunks.Add(ScriptBytes.Skip(i + 2).Take(dataLength).ToArray());
                        OpCodes.Add(OpCodeType.OP_DATA);
                        // increment i to skip over the data section during further op_code processing
                        i += 1 + dataLength;
                        break;
                    }

                    // OP_PUSHDATA2 - indicates a data section with 2 bytes indicating length
                    case (byte)OpCodeType.OP_PUSHDATA2:
                    {
                        // get 2 byte count and data
                        var dataLength = BitConverter.ToInt16(ScriptBytes, i + 1);
                        DataChunks.Add(ScriptBytes.Skip(i + 3).Take(dataLength).ToArray());
                        OpCodes.Add(OpCodeType.OP_DATA);
                        i += 2 + dataLength;
                        break;
                    }

                    // OP_PUSHDATA2 - indicates a data section with 4 bytes indicating length
                    case (byte)OpCodeType.OP_PUSHDATA4:
                    {
                        // get 4 byte count and data
                        var dataLength = BitConverter.ToInt32(ScriptBytes, i + 1);
                        DataChunks.Add(ScriptBytes.Skip(i + 5).Take(dataLength).ToArray());
                        OpCodes.Add(OpCodeType.OP_DATA);
                        i += 4 + dataLength;
                        break;
                    }

                    // any other OP_CODE (non-data identifier)
                    default:
                    {
                        // check if this is a valid/known op code, and add it to the list
                        if (Enum.IsDefined(typeof(OpCodeType), ScriptBytes[i]) && ScriptBytes[i] != 218) // 218 = DA
                        {
                            OpCodes.Add((OpCodeType)ScriptBytes[i]);
                        }
                        else
                        {
                            // TODO: handle unknown OP_CODE... this shouldn't happen
                            return;
                        }
                        break;
                    }
                    }
                }
            }
        }
コード例 #15
0
 public void EmitLdcI40()
 {
     OpCodes.Add("ldc.i4.0");
 }
コード例 #16
0
 public void EmitFalse()
 {
     OpCodes.Add("Ldc.i4.0");
 }
コード例 #17
0
 public void EmitAdd()
 {
     OpCodes.Add("add");
 }
コード例 #18
0
 public void EmitDup()
 {
     OpCodes.Add("dup");
 }
コード例 #19
0
 public void EmitDiv()
 {
     OpCodes.Add("div");
 }
コード例 #20
0
 public void EmitClt()
 {
     OpCodes.Add("clt");
 }
コード例 #21
0
 public void EmitSub()
 {
     OpCodes.Add("sub");
 }
コード例 #22
0
 public void EmitLdnull()
 {
     OpCodes.Add("ldnull");
 }
コード例 #23
0
 public void EmitLdarga(short idx)
 {
     OpCodes.Add($"ldarga {idx}");
 }
コード例 #24
0
 public void EmitCeq()
 {
     OpCodes.Add("ceq");
 }
コード例 #25
0
 public void EmitPop()
 {
     OpCodes.Add("pop");
 }
コード例 #26
0
 public void EmitLdcI4(int value)
 {
     OpCodes.Add($"ldc.i4 {value}");
 }