Ejemplo n.º 1
0
        /// <summary>
        /// Push an expression named <paramref name="name"/> of kind <paramref name="kind"/>.
        /// </summary>
        /// <param name="kind">Kind of entry in stack</param>
        /// <param name="name">Variable to be pushed</param>
        /// <param name="type">Type if any of <paramref name="name"/></param>
        private void PushExpression(StackValueKind kind, string name, LLVMValueRef llvmValue, TypeDesc type = null)
        {
            Debug.Assert(kind != StackValueKind.Unknown, "Unknown stack kind");

            switch (kind)
            {
            case StackValueKind.Int32:
            {
                if (!type.IsWellKnownType(WellKnownType.Int32) &&
                    !type.IsWellKnownType(WellKnownType.IntPtr) &&
                    !type.IsWellKnownType(WellKnownType.UInt32) &&
                    !type.IsWellKnownType(WellKnownType.UIntPtr))
                {
                    llvmValue = LLVM.BuildIntCast(_builder, llvmValue, LLVM.Int32Type(), "");
                }
            }
            break;

            case StackValueKind.Int64:
            {
                if (!type.IsWellKnownType(WellKnownType.Int64) &&
                    !(type.IsWellKnownType(WellKnownType.UInt64)))
                {
                    llvmValue = LLVM.BuildIntCast(_builder, llvmValue, LLVM.Int64Type(), "");
                }
            }
            break;

            case StackValueKind.NativeInt:
                break;
            }

            _stack.Push(new ExpressionEntry(kind, name, llvmValue, type));
        }
Ejemplo n.º 2
0
        private void ImportFallthrough(BasicBlock next)
        {
            EvaluationStack <StackEntry> entryStack = next.EntryStack;

            if (entryStack != null)
            {
                if (entryStack.Length != _stack.Length)
                {
                    throw new InvalidProgramException();
                }

                for (int i = 0; i < entryStack.Length; i++)
                {
                    // TODO: Do we need to allow conversions?
                    if (entryStack[i].Kind != _stack[i].Kind)
                    {
                        throw new InvalidProgramException();
                    }

                    if (entryStack[i].Kind == StackValueKind.ValueType)
                    {
                        if (entryStack[i].Type != _stack[i].Type)
                        {
                            throw new InvalidProgramException();
                        }
                    }
                }
            }
            else
            {
                if (_stack.Length > 0)
                {
                    entryStack = new EvaluationStack <StackEntry>(_stack.Length);

#pragma warning disable 162 // Due to not implement3ed exception incrementer in for needs pragma warning disable
                    for (int i = 0; i < _stack.Length; i++)
                    {
                        // todo: do we need anything special for spilled stacks like cpp codegen does?
                        entryStack.Push(_stack[i]);
                        //entryStack.Push(NewSpillSlot(_stack[i]));
                    }
#pragma warning restore 162
                }
                next.EntryStack = entryStack;
            }

            if (entryStack != null)
            {
                // todo: do we have to do anything here?
#pragma warning disable 162// Due to not implement3ed exception incrementer in for needs pragma warning disable
                for (int i = 0; i < entryStack.Length; i++)
                {
                    /*AppendLine();
                     * Append(entryStack[i]);
                     * Append(" = ");
                     * Append(_stack[i]);
                     * AppendSemicolon();*/
                }
#pragma warning restore 162
            }

            MarkBasicBlock(next);
        }