Ejemplo n.º 1
0
        public bool VisitIterateTunnel(IterateTunnel iterateTunnel)
        {
            ValueSource iteratorSource = GetTerminalValueSource(iterateTunnel.InputTerminals[0]),
                        itemSource     = GetTerminalValueSource(iterateTunnel.OutputTerminals[0]);

            // call the Iterator::next function on the iterator reference
            // TODO: create an alloca'd Option<Item> variable, so that we can pass its address to Iterator::next
            LLVMValueRef itemOption = _builder.CreateCall(
                GetImportedCommonFunction(CommonModules.RangeIteratorNextName), // TODO: determine the name of this function from the input type
                new LLVMValueRef[]
            {
                iteratorSource.GetValue(_builder)
            },
                "itemOption");
            LLVMValueRef isSome = _builder.CreateExtractValue(itemOption, 0u, "isSome"),
                         item   = _builder.CreateExtractValue(itemOption, 1u, "item");

            // &&= the loop condition with the isSome value
            var loop = (Compiler.Nodes.Loop)iterateTunnel.ParentStructure;
            LocalAllocationValueSource loopConditionAllocationSource = _loopData[loop].ConditionAllocationSource;
            LLVMValueRef condition          = loopConditionAllocationSource.GetValue(_builder);
            LLVMValueRef conditionAndIsSome = _builder.CreateAnd(condition, isSome, "conditionAndIsSome");

            loopConditionAllocationSource.UpdateValue(_builder, conditionAndIsSome);

            // bind the inner value to the output tunnel
            itemSource.UpdateValue(_builder, item);
            return(true);
        }
Ejemplo n.º 2
0
 public LoopData(
     LocalAllocationValueSource conditionAllocationSource,
     LLVMBasicBlockRef startBlock,
     LLVMBasicBlockRef interiorBlock,
     LLVMBasicBlockRef endBlock)
 {
     ConditionAllocationSource = conditionAllocationSource;
     StartBlock    = startBlock;
     InteriorBlock = interiorBlock;
     EndBlock      = endBlock;
 }
Ejemplo n.º 3
0
        private void BorrowFromVariableIntoVariable(VariableReference from, VariableReference into)
        {
            LocalAllocationValueSource intoAllocation = _variableValues[into] as LocalAllocationValueSource;

            if (intoAllocation != null)
            {
                LocalAllocationValueSource fromAllocation = (LocalAllocationValueSource)_variableValues[from];
                LLVMValueRef fromAddress = fromAllocation.AllocationPointer;
                intoAllocation.UpdateValue(_builder, fromAddress);
            }
        }
Ejemplo n.º 4
0
 public ConstantLocalReferenceValueSource(LocalAllocationValueSource referencedAllocation)
 {
     ReferencedAllocation = referencedAllocation;
 }