示例#1
0
        private void StartImportingBasicBlock(BasicBlock basicBlock)
        {
            _stack.Clear();

            EvaluationStack <StackEntry> entryStack = basicBlock.EntryStack;

            if (entryStack != null)
            {
                int n = entryStack.Length;
                for (int i = 0; i < n; i++)
                {
                    _stack.Push(entryStack[i].Duplicate());
                }
            }

            bool isFirstBlock = false;

            if (_curBasicBlock.Equals(default(LLVMBasicBlockRef)))
            {
                isFirstBlock = true;
            }
            _curBasicBlock = GetLLVMBasicBlockForBlock(basicBlock);

            LLVM.PositionBuilderAtEnd(_builder, _curBasicBlock);

            if (isFirstBlock)
            {
                GenerateProlog();
            }
        }
示例#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);
        }