コード例 #1
0
        public override string Populate(RandomConfiguration config)
        {
            // https://stackoverflow.com/a/23226806
            // jalr's rs and rd must be non-equal
            string register = config.RandomReadRegister();

            while (register == "$31")
            {
                register = config.RandomReadRegister();
            }
            return(Get(new[] { register, "$ra" }));
        }
コード例 #2
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;
            }
        }
コード例 #3
0
        public P5Generator(bool large = false)
        {
            _large           = large;
            InstructionCount = 100;
            _instructionSet  = new InstructionSet();
            _instructionSet.PopulateInstructionList(
                new List <(Instruction, double)>()
            {
                (new SimpleALU("addu"), 1),
                (new SimpleALU("add"), 1),
                (new SimpleALU("subu"), 1),
                (new SimpleALU("sub"), 1),
                (new SimpleALU("and"), 1),
                (new SimpleALU("or"), 1),
                (new SimpleALU("xor"), 1),
                (new SimpleALU("nor"), 1),
                (new SimpleALU("slt"), 1),
                (new SimpleALU("sltu"), 1),
                (new SimpleShift("sll"), 1),
                (new SimpleShift("srl"), 1),
                (new SimpleShift("sra"), 1),
                (new SimpleALU("sllv"), 1),
                (new SimpleALU("srlv"), 1),
                (new SimpleALU("srav"), 1),
                (new Lui(), 1),
                (new TwoOperandBranching("beq"), 1),
                (new TwoOperandBranching("bne"), 1),
                (new SimpleZeroBranching("bgtz"), 1),
                (new SimpleZeroBranching("bgez"), 1),
                (new SimpleZeroBranching("bltz"), 1),
                (new SimpleZeroBranching("blez"), 1),
                (new SimpleALUImmediate("slti", true, 32768), 1),
                (new SimpleALUImmediate("sltiu", false, 32768), 1),
                (new SimpleALUImmediate("addi"), 1),
                (new SimpleALUImmediate("addiu"), 1),
                (new SimpleALUImmediate("xori"), 1),
                (new SimpleALUImmediate("andi"), 1),
                (new SimpleALUImmediate("ori"), 1),
                (new J(), 1),
                (new Jal(), 1),
                (new Jr(), 0.3),
                (new Jalr(), 0.3),
                (new Lw(), 1),
                (new Sw(), 1),
                (new UnalignedLoad(MemoryOperationWidth.HalfWord, MemoryOperationFlags.ReadUnsigned), 1),
                (new UnalignedLoad(MemoryOperationWidth.HalfWord, MemoryOperationFlags.Read), 1),
                (new UnalignedLoad(MemoryOperationWidth.HalfWord, MemoryOperationFlags.Write), 1),
                (new UnalignedLoad(MemoryOperationWidth.Byte, MemoryOperationFlags.Write), 1),
                (new UnalignedLoad(MemoryOperationWidth.Byte, MemoryOperationFlags.ReadUnsigned), 1),
                (new UnalignedLoad(MemoryOperationWidth.Byte, MemoryOperationFlags.Read), 1),
                (new MultiplicationInstruction("mult"), 1),
                (new MultiplicationInstruction("multu"), 1),
                (new MultiplicationInstruction("div"), 1),
                (new MultiplicationInstruction("divu"), 1),
                (new MulMove("mthi"), 1),
                (new MulMove("mtlo"), 1),
                (new MulMove("mfhi"), 1),
                (new MulMove("mflo"), 1),
            }
                );
            _config = new RandomConfiguration();
            if (large)
            {
                _config.MaximumImmediate = 2147483647;
                _config.MaximumRegister  = 20;
                _config.NumberOfLabels   = 7;
            }
            else
            {
                _config.MaximumImmediate = 5;
                _config.MaximumRegister  = 3;
                _config.NumberOfLabels   = 3;
            }

            _config.NumberOfData = 3;
        }
コード例 #4
0
 public override string Populate(RandomConfiguration config)
 {
     return(Get(new[] { config.RandomWriteRegister(), config.RandomMemory() }));
 }
コード例 #5
0
 public override string Populate(RandomConfiguration config)
 {
     return(Get(new[] { config.RandomWriteRegister(), config.RandomReadRegister(), config.Random16BitImmediate() }));
 }
コード例 #6
0
 public override string Populate(RandomConfiguration config)
 {
     return(Get(new[] { "$ra" }));
 }
コード例 #7
0
 public override string Populate(RandomConfiguration config)
 {
     return(Get(new[] { config.RandomLabel() }));
 }
コード例 #8
0
 public abstract string Populate(RandomConfiguration config);
コード例 #9
0
 public override string Populate(RandomConfiguration config)
 {
     return(Get(new string[0]));
 }