/// <summary> /// Handles call instructions which reference the Asm.XXX stubs provided by the AOT. /// </summary> /// <param name="block">The block.</param> /// <param name="instruction">The instruction.</param> private void HandleAssemblyStub (SharpOS.AOT.IR.Instructions.Call call) { string parameterTypes = string.Empty; object [] operands = new object [call.Method.Arguments.Count]; for (int i = 0; i < call.Method.Arguments.Count; i++) { Argument argument = call.Method.Arguments [i]; if (parameterTypes.Length > 0) parameterTypes += " "; IR.Operands.Operand operand = call.Use [i]; while (operand is IR.Operands.Register && !((operand as IR.Operands.Register).Parent is Newobj)) { IR.Operands.Register register = operand as IR.Operands.Register; if (register.Parent.Use.Length != 1) throw new EngineException (string.Format ("Could not process '{0}'. ({1})", register.Parent.ToString (), this.method.MethodFullName)); operand = register.Parent.Use [0]; } if (operand is IR.Operands.Register && (operand as IR.Operands.Register).Parent is Newobj) { Memory memory = this.GetAssemblyStubMemoryAddress ((operand as IR.Operands.Register).Parent as Newobj); parameterTypes += memory.GetType ().Name; operands [i] = memory; } else if (operand is FieldOperand) { FieldOperand field = operand as FieldOperand; MemberReference memberReference = field.Field.FieldDefinition; parameterTypes += field.ShortFieldTypeName; operands [i] = memberReference.Name; } else if (operand is Constant) { parameterTypes += argument.TypeName; operands [i] = operand; } else if (operand is SharpOS.AOT.IR.Operands.Identifier) { IR.Operands.Identifier identifier = operand as SharpOS.AOT.IR.Operands.Identifier; if (identifier.IsRegisterSet) { Register register = Assembly.GetRegister (identifier.Register); parameterTypes += register.GetType ().Name; operands [i] = register; } else { Memory memory = this.GetMemory (identifier); parameterTypes += memory.GetType ().Name; operands [i] = memory; } } else throw new EngineException (string.Format ("Could not process '{0}'. ({1})", call.ToString (), this.method.MethodFullName)); } parameterTypes = call.Method.Name + " " + parameterTypes; assembly.GetAssemblyInstruction (call, operands, parameterTypes.Trim ()); }
/// <summary> /// Checks whether the call instruction references a builtin feature of the AOT and handles /// it if so. /// </summary> private void HandleBuiltIns (SharpOS.AOT.IR.Instructions.Call call) { if (!this.IsKernelString (call) && !this.IsKernelAlloc (call) && !this.IsKernelLabelledAlloc (call) && !this.IsKernelLabelAddress (call) && !this.IsKernelObjectConversion (call)) throw new EngineException (string.Format ("Unknown Built-In '{0}'. ({1})", call.ToString (), this.method.MethodFullName)); }