Пример #1
0
        internal EffectInstruction(IList <EffectToken> tokens, ref int index)
        {
            Opcode = tokens[index++];

            string format;

            if (Opcode.MaybeInt32 && InstructionFormats.TryGetValue(Opcode.AsInt32, out format))
            {
                if (Opcode.AsInt32 == 0x85)
                {
                    while (index < tokens.Count && !tokens[index].IsFunction)
                    {
                        OperandsMutable.Add(tokens[index++]);
                    }
                }
                else if (Opcode.AsInt32 == 0x88)
                {
                    while (index < tokens.Count)
                    {
                        OperandsMutable.Add(tokens[index++]);
                    }
                }
                else
                {
                    foreach (char operandType in format)
                    {
                        if (index >= tokens.Count)
                        {
                            Opcode.AddError("Expected '{0}'; end of tokens.", operandType);
                            break;
                        }

                        if (tokens[index].IsFunction)
                        {
                            tokens[index].AddError("Last instruction expected '{0}', not a function.", operandType);
                            break;
                        }

                        var operand = tokens[index++];
                        OperandsMutable.Add(operand);

                        switch (operandType)
                        {
                        case 'i':
                            if (!operand.MaybeInt32)
                            {
                                operand.AddError("Expected an integer.");
                            }
                            break;

                        case 'p':
                            if (!operand.MaybePointer)
                            {
                                operand.AddError("Expected a pointer.");
                            }
                            break;

                        case 'z':
                            if (!operand.IsZero)
                            {
                                operand.AddError("Expected zero.");
                            }
                            break;

                        case 's':
                            if (!operand.MaybeSingle)
                            {
                                operand.AddError("Expected a Single.");
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                Opcode.AddError("Opcode is unknown or invalid; operands are crap.");
                while (index < tokens.Count && !(tokens[index].MaybeInt32 && InstructionFormats.ContainsKey(tokens[index].AsInt32)) && !tokens[index].IsFunction)
                {
                    OperandsMutable.Add(tokens[index++]);
                }
            }
        }