public void Resize(int size) { TokenInstruction[] data = (TokenInstruction[])this.ToArray(typeof(TokenInstruction)); TokenInstruction[] newData = new TokenInstruction[size]; Array.Copy(data, 0, newData, 0, size); Clear(); AddRange(newData); }
// the method is expected to be recursive to allow for inline expansion of instructions if required bool Pass2scan( TokenInstruction[] Tokens, int size ) { // execute TokenInstructions to build MachineInstructions bool passed = true; SymbolDef cursymboldef; Symbol ActiveNTTRuleID; ClearMachineInstState(); // iterate through all the tokens and build machine instruction // for each machine instruction need: optype, opinst, and up to 5 parameters for ( int i = 0; i < size; i++ ) { // lookup instruction type in library cursymboldef = symbolTypeLib[ (int)Tokens[ i ].ID ]; ActiveNTTRuleID = (Symbol)Tokens[ i ].NTTRuleID; currentLine = Tokens[ i ].line; charPos = Tokens[ i ].pos; switch ( ActiveNTTRuleID ) { case Symbol.CONSTANT: case Symbol.COLOR: case Symbol.REG_PS1_4: case Symbol.TEX_PS1_4: case Symbol.REG_PS1_1_3: case Symbol.TEX_PS1_1_3: // registars can be used for read and write so they can be used for dst and arg passed = SetOpParam( cursymboldef ); break; case Symbol.DEFCONST: case Symbol.UNARYOP: case Symbol.BINARYOP: case Symbol.TERNARYOP: case Symbol.TEXOP_PS1_1_3: case Symbol.TEXOP_PS1_4: case Symbol.PHASEMARKER: case Symbol.TEXCISCOP_PS1_1_3: // if the last instruction has not been passed on then do it now // make sure the pipe is clear for a new instruction BuildMachineInst(); if ( opInst == Symbol.Invalid ) { opInst = cursymboldef.ID; } else { passed = false; } break; case Symbol.DSTMASK: case Symbol.SRCREP: case Symbol.TEXSWIZZLE: // could be a dst mask or a arg replicator // if dst mask and alpha included then make up a alpha instruction: maybe best to wait until instruction args completed opParams[ argCnt ].MaskRep = (uint)cursymboldef.pass2Data; break; case Symbol.DSTMOD: case Symbol.DSTSAT: case Symbol.PRESRCMOD: case Symbol.POSTSRCMOD: opParams[ argCnt ].Mod |= cursymboldef.pass2Data; break; case Symbol.NUMVAL: passed = SetOpParam( cursymboldef ); // keep track of how many values are used // update Constants array position constantsPos++; break; case Symbol.SEPERATOR: argCnt++; break; } // end of switch if ( !passed ) { break; } }// end of for: i<TokenInstCnt // check to see if there is still an instruction left in the pipe if ( passed ) { BuildMachineInst(); // if there are no more instructions in the pipe than OpInst should be invalid if ( opInst != Symbol.Invalid ) { passed = false; } } return passed; }
public MacroRegModify( TokenInstruction[] tokens, RegModOffset[] offsets ) { this.Macro = tokens; this.MacroSize = tokens.Length; this.RegMods = offsets; this.RegModSize = offsets.Length; }