示例#1
0
        /// <summary>
        /// Realizes a new-object operation that creates a new instance of a specified type.
        /// </summary>
        /// <param name="method">The target method.</param>
        private void MakeNewObject(MethodBase method)
        {
            var constructor = method as ConstructorInfo;

            if (constructor == null)
            {
                throw CompilationContext.GetInvalidILCodeException();
            }
            var type     = constructor.DeclaringType;
            var llvmType = Unit.GetType(type);

            // Use a temporary alloca to realize object creation
            // and initialize object with zero
            var tempAlloca = CreateTempAlloca(llvmType);

            BuildStore(Builder, ConstNull(llvmType), tempAlloca);

            // Invoke constructor for type
            Value[] values = new Value[constructor.GetParameters().Length + 1];
            values[0] = new Value(type.MakePointerType(), tempAlloca);
            CurrentBlock.PopMethodArgs(constructor, values, 1);
            CreateCall(constructor, values);

            // Push created instance on the stack
            if (type.IsValueType)
            {
                CurrentBlock.Push(type, BuildLoad(Builder, values[0].LLVMValue, string.Empty));
            }
            else
            {
                CurrentBlock.Push(values[0]);
            }
        }
示例#2
0
        /// <summary>
        /// Realizes a call instruction.
        /// </summary>
        /// <param name="target">The target method to invoke.</param>
        private void MakeCall(MethodBase target)
        {
            // Check parameter types for interfaces that involve virtual function calls
            Unit.GetType(target);
            var @params     = target.GetParameters();
            var valueOffset = target.GetParameterOffset();

            Value[] args = new Value[@params.Length + valueOffset];
            CurrentBlock.PopMethodArgs(target, args, valueOffset);
            CreateCall(target, args);
        }