예제 #1
0
        internal DASM16Assembly( DASM16Instruction[] instructions, ushort offset )
        {
            InstructionCount = instructions.Length;
            Instructions = (DASM16Instruction[]) instructions.Clone();

            Length = 0;
            foreach ( DASM16Instruction ins in Instructions )
                Length += ins.Length;

            Words = new ushort[ Length ];
            ushort i = 0;
            foreach ( DASM16Instruction ins in Instructions )
                foreach ( ushort word in ins.Words )
                    Words[ i++ ] = word;
        }
예제 #2
0
 public void AddInstruction( DASM16Instruction ins )
 {
     myInstructions.Add( ins );
     ++InstructionCount;
     Length += ins.Length;
 }
예제 #3
0
        private DASM16Instruction[] Assemble( Dictionary<String, ushort> consts, ushort offset )
        {
            Dictionary<String, ushort> newConsts = CombineLocals( consts, offset );

            foreach ( DASM16Instruction instruction in myInstructions )
                instruction.ResolveConstants( newConsts );

            DASM16Instruction[] output = new DASM16Instruction[ InstructionCount ];

            ushort word = 0;
            int i = 0, ins = 0;
            while ( word < Length )
            {
                if ( myChildren.ContainsKey( word ) )
                {
                    DASM16Builder child = myChildren[ word ];
                    foreach ( DASM16Instruction instruction in child.Assemble( consts, (ushort) ( offset + word ) ) )
                    {
                        word += instruction.Length;
                        output[ i++ ] = instruction;
                    }
                }
                else if ( ins < myInstructions.Count )
                {
                    DASM16Instruction instruction = myInstructions[ ins++ ];
                    word += instruction.Length;
                    output[ i++ ] = instruction;
                }
            }

            return output;
        }