예제 #1
0
        public override AstNode Visit(BlockNode node)
        {
            // Ignore pure declarations.
            if(node.GetChildren() == null)
                return node;

            // Update the scope.
            PushScope(node.GetScope());

            // Visit the children.
            VisitList(node.GetChildren());

            // Restore the scope.
            PopScope();

            return node;
        }
예제 #2
0
        public override AstNode Visit(BlockNode node)
        {
            // Begin the node.
            builder.BeginNode(node);

            // Create the block lexical scope.
            LexicalScope blockScope = (LexicalScope) node.GetScope();
            node.SetScope(blockScope);

            // Create the new basic block.
            BasicBlock block = CreateBasicBlock();
            block.SetName("block");

            // Jump into the basic block.
            builder.CreateJmp(block);
            builder.SetBlock(block);

            // Push the scope.
            PushScope(blockScope);

            // Visit the block  children.
            VisitList(node.GetChildren());

            // Pop the scope.
            PopScope();

            // Create a merge block and jump into it.
            if(!builder.IsLastTerminator())
            {
                BasicBlock mergeBlock = CreateBasicBlock();
                mergeBlock.SetName("merge");

                builder.CreateJmp(mergeBlock);
                builder.SetBlock(mergeBlock);
            }

            return builder.EndNode();
        }