示例#1
0
 public OpCodeDescription GetDesc(PapyrusOpCodes code)
 {
     lock (descLock)
     {
         return(Instructions.FirstOrDefault(i => i.OpCode == code));
     }
 }
 public static PapyrusInstructionOpCodeDescription FromOpCode(PapyrusOpCodes opcode)
 {
     if (Descriptions.ContainsKey(opcode))
     {
         return(Descriptions[opcode]);
     }
     return(null);
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PapyrusAsmInstruction" /> class.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <param name="argumentCount">The argument count.</param>
 /// <param name="hasOperandArguments">if set to <c>true</c> [has operand arguments].</param>
 /// <param name="aliases">The aliases.</param>
 public PapyrusAsmInstruction(PapyrusOpCodes opcode, int argumentCount, bool hasOperandArguments, params string[] aliases)
 {
     this.opcode         = opcode;
     this.aliases        = aliases;
     ArgumentCount       = argumentCount;
     HasOperandArguments = hasOperandArguments;
     For.Do(argumentCount, () => args.Add(new PapyrusAsmValue()));
     //For.Do(argumentCount, () => opargs.Add(new PapyrusAsmValue()));
 }
示例#4
0
        public static string GetDescription(this PapyrusOpCodes code)
        {
            switch (code)
            {
            case PapyrusOpCodes.Iadd:
                return
                    ("Integer Add math operator, takes two references or constant values and adds them together and then assigns the result to the destination variable.");

            case PapyrusOpCodes.Fadd:
                return
                    ("Float Add math operator, takes two references or constant values and adds them together and then assigns the result to the destination variable.");

            case PapyrusOpCodes.Return:
                return
                    ("Terminate the method and returns a value. If the method is a void (none) it should return a ::nonevar.");

            case PapyrusOpCodes.Callparent:
                return
                    ("Invokes a parent method from inside a state by its name, using a location reference, set of arguments and assigns the result to the destination variable.");

            case PapyrusOpCodes.Callstatic:
                return
                    ("Invokes a static method by its name, using a location reference, set of arguments and assigns the result to the destination variable.");

            case PapyrusOpCodes.Callmethod:
                return
                    ("Invokes a instance method by its name, using a location reference, set of arguments and assigns the result to the destination variable.");

            case PapyrusOpCodes.Cast:
                return("Casts variable, parameter or reference into the same type as the target reference.");

            case PapyrusOpCodes.ArrayCreate:
                return
                    ("Creates a new array instance of a target type and size and  then assigns the destination variable with the new array.");

            case PapyrusOpCodes.ArrayLength:
                return("Gets the length of the target array and assigns the destination variable with the count.");

            case PapyrusOpCodes.Assign:
                return("Assign a field, variable or parameter with the target value.");

            case PapyrusOpCodes.Jmp:
                return("Jumps to the target instruction by an offset from the current position.");

            case PapyrusOpCodes.Jmpf:
                return
                    ("If the condition is false then jump to the target instruction by an offset from the current position.");

            case PapyrusOpCodes.Jmpt:
                return
                    ("If the condition is true then jump to the target instruction by an offset from the current position.");
            }
            return("This OpCode has not yet been documented.");
        }
示例#5
0
        //public static string GetArgumentsDescription(this PapyrusOpCodes code)
        //{
        //    var noArgs = "No arguments expected.";

        //    switch (code)
        //    {
        //        case PapyrusOpCodes.PropSet:
        //            return "[0] Constant String: Property Name\r\n[1] Reference or Constant: Location\r\n[2] Reference or Constant: Value";
        //        case PapyrusOpCodes.PropGet:
        //            return "[0] Constant String: Property Name\r\n[1] Reference or Constant: Location\r\n[2] Reference: Destination";
        //        case PapyrusOpCodes.Assign:
        //            return "[0] Reference or Constant: Value\r\n[1] Reference: Destination";
        //        case PapyrusOpCodes.Callstatic:
        //            return "[0] Reference or Constant: Location/Class\r\n[1] Constant String: Method Name\r\n[2] Reference: Destination";
        //        case PapyrusOpCodes.Callmethod:
        //            return "[0] Constant String: Method Name\r\n[1] Reference or Constant: Location/Class\r\n[2] Reference: Destination";
        //        case PapyrusOpCodes.Return:
        //            return "[0] Reference or Constant: value\r\n[1] (Expects ::nonevar if void)";
        //        case PapyrusOpCodes.CmpEq:
        //        case PapyrusOpCodes.CmpGte:
        //        case PapyrusOpCodes.CmpGt:
        //        case PapyrusOpCodes.CmpLt:
        //        case PapyrusOpCodes.CmpLte:
        //            return "[0] Reference: Destination\r\n[1] Reference or Constant: Value\r\n[2]  Reference or Constant: Value";
        //        case PapyrusOpCodes.Jmp:
        //            return "[0] Constant Integer: offset from current position";
        //        case PapyrusOpCodes.Jmpf:
        //            return "[0] Reference Bool: Conditional\r\n[1] Constant Integer: offset from current position";
        //        case PapyrusOpCodes.Jmpt:
        //            return "[0] Reference Bool: Conditional\r\n[1] Constant Integer: offset from current position";
        //    }

        //    return "This OpCode has no arguments or the arguments has not yet been documented.";
        //}

        public static string GetOperandArgumentsDescription(this PapyrusOpCodes code)
        {
            var noArgs = "No operand arguments expected.";

            switch (code)
            {
            case PapyrusOpCodes.Callparent:
            case PapyrusOpCodes.Callstatic:
            case PapyrusOpCodes.Callmethod:
                return("Method Parameters can be either Constant or Reference. One parameter per row.");

            default:
                return(noArgs);
            }
        }
示例#6
0
 private bool IsJump(PapyrusOpCodes opCode)
 {
     return(opCode == PapyrusOpCodes.Jmp || opCode == PapyrusOpCodes.Jmpf || opCode == PapyrusOpCodes.Jmpt);
 }
示例#7
0
 /// <summary>
 /// Sets the op code.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 public void SetOpCode(PapyrusOpCodes opcode) => this.opcode = opcode;
示例#8
0
        /// <summary>
        /// Creates a papyrus call instruction.
        /// </summary>
        /// <param name="mainInstructionProcessor">The main instruction processor.</param>
        /// <param name="callOpCode">The call op code.</param>
        /// <param name="methodRef">The method reference.</param>
        /// <param name="callerLocation">The caller location.</param>
        /// <param name="destinationVariable">The destination variable.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="structGets">The structure gets.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <returns></returns>
        public PapyrusInstruction CreatePapyrusCallInstruction(
            IClrInstructionProcessor mainInstructionProcessor,
            PapyrusOpCodes callOpCode, MethodReference methodRef,
            string callerLocation, string destinationVariable, List <object> parameters,
            out List <PapyrusInstruction> structGets, string methodName = null)
        {
            structGets = new List <PapyrusInstruction>();

            var inst = new PapyrusInstruction {
                OpCode = callOpCode
            };

            var param = parameters.ToArray();

            for (var index = 0; index < param.Length; index++)
            {
                var p = param[index];
                PapyrusStructFieldReference structRef = null;
                var evalItem = p as EvaluationStackItem;

                if (evalItem != null)
                {
                    structRef = evalItem.Value as PapyrusStructFieldReference;
                }
                if (structRef == null)
                {
                    structRef = p as PapyrusStructFieldReference;
                }
                if (structRef != null)
                {
                    var structSource = structRef.StructSource as PapyrusFieldDefinition;
                    var structField  = structRef.StructVariable;

                    var fieldType = GetStructFieldType(papyrusAssemblyCollection, structSource, structField);

                    // 1. Create Temp Var
                    bool isStructAccess;
                    var  tempVar = mainInstructionProcessor.GetTargetVariable(currentInstruction, null,
                                                                              out isStructAccess,
                                                                              fieldType, true);

                    param[index] = mainInstructionProcessor.CreateVariableReferenceFromName(tempVar);

                    // 2. StructGet -> tempVar
                    // 3. Assign var <- tempVar
                    structGets.Add(mainInstructionProcessor.CreatePapyrusInstruction(
                                       PapyrusOpCodes.StructGet,
                                       mainInstructionProcessor.CreateVariableReferenceFromName(tempVar), structSource,
                                       structField));
                }
            }

            methodName = methodName ?? methodRef.Name;

            if (callOpCode == PapyrusOpCodes.Callstatic)
            {
                inst.Arguments.AddRange(mainInstructionProcessor.ParsePapyrusParameters(new object[]
                {
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, callerLocation),
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, methodName),
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, destinationVariable)
                }));
            }
            else
            {
                inst.Arguments.AddRange(mainInstructionProcessor.ParsePapyrusParameters(new object[]
                {
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, methodName),
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, callerLocation),
                    mainInstructionProcessor.CreateVariableReference(PapyrusPrimitiveType.Reference, destinationVariable)
                }));
            }
            inst.OperandArguments.AddRange(EnsureParameterTypes(mainInstructionProcessor, methodRef.Parameters,
                                                                mainInstructionProcessor.ParsePapyrusParameters(param)));
            inst.Operand = methodRef;
            return(inst);
        }
 public PapyrusOpCodes TryInvertJump(PapyrusOpCodes jmpt)
 {
     throw new NotImplementedException();
 }
 public PapyrusInstruction ConditionalJump(PapyrusOpCodes jumpType, PapyrusVariableReference conditionalVar,
                                           object destinationInstruction)
 {
     throw new NotImplementedException();
 }
 public PapyrusInstruction CreatePapyrusInstruction(PapyrusOpCodes papyrusOpCode, params object[] values)
 {
     throw new NotImplementedException();
 }
示例#12
0
 /// <summary>
 ///     Gets the size of the instruction parameter.
 /// </summary>
 /// <param name="opcode">The opcode.</param>
 /// <returns></returns>
 public static int GetInstructionParamSize(this PapyrusOpCodes opcode)
 {
     return(PapyrusInstructionOpCodeDescription.FromOpCode(opcode).ArgumentCount);
 }