Пример #1
0
        /// <summary>
        /// Get the HLProgram for furthur processing, like translating.
        /// </summary>
        /// <returns></returns>
        public HLProgram GetHLProgram()
        {
            HLProgram result = new HLProgram();

            for (int pvmIndex = 0; pvmIndex < this.Count(); pvmIndex++)
            {
                Instruction ins = program[this[pvmIndex]];

                if (ins.opcode == Instruction.IF || ins.opcode == Instruction.LOOP)
                {
                    result.Add(GetSubProgram(pvmIndex));
                }
                else
                {
                    // Single instruction.
                    result.Add(GetInstruction(pvmIndex));
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Get the sub-program pointed by the pointer at specified index.
        /// </summary>
        /// <param name="index">The index of pointer.</param>
        /// <returns>The sub-program pointed by the pointer.</returns>
        public HLProgram GetSubProgram(int pvmIndex)
        {
            int         programIndex = this[pvmIndex];
            Instruction ins          = program[programIndex];

            if (ins.opcode == Instruction.IF)
            {
                return(program.SubProgram(programIndex, program.FindEndIf(programIndex)));
            }
            else if (ins.opcode == Instruction.LOOP)
            {
                return(program.SubProgram(programIndex, program.FindEndLoop(programIndex)));
            }
            else
            {
                // A HLProgram with only one instruction.
                HLProgram result = new HLProgram();
                result.Add(ins);
                return(result);
            }
        }
Пример #3
0
 /// <summary>
 /// Add new Instrction at specified index.
 /// </summary>
 /// <param name="index">The zero-base index at which the new instruction should be inserted. </param>
 /// <param name="newIns">The new Instruction.</param>
 public void InsertInstruction(int index, Instruction newIns)
 {
     this.Insert(index, program.Count);
     program.Add(newIns);
 }