Exemple #1
0
 /// <summary>
 /// Creates a control-flow graph that contains only an empty
 /// entry point block.
 /// </summary>
 public FlowGraph()
 {
     this.instructions    = ImmutableDictionary.Create <ValueTag, Instruction>();
     this.blocks          = ImmutableOrderedDictionary.Create <BasicBlockTag, BasicBlockData>();
     this.blockParamTypes = ImmutableDictionary.Create <ValueTag, IType>();
     this.valueParents    = ImmutableDictionary.Create <ValueTag, BasicBlockTag>();
     this.analysisCache   = new MacroAnalysisCache();
     this.EntryPointTag   = new BasicBlockTag("entry-point");
     this.blocks          = this.blocks.SetItem(
         this.EntryPointTag,
         new BasicBlockData());
 }
Exemple #2
0
        /// <summary>
        /// Applies a member mapping to this flow graph.
        /// </summary>
        /// <param name="mapping">A member mapping.</param>
        /// <returns>A transformed flow graph.</returns>
        public FlowGraph Map(MemberMapping mapping)
        {
            // Apply the mapping to all instructions.
            var newInstructionMap = ImmutableDictionary
                                    .Create <ValueTag, Instruction>()
                                    .ToBuilder();

            foreach (var insnPair in instructions)
            {
                newInstructionMap[insnPair.Key] = insnPair.Value.Map(mapping);
            }

            // Apply the mapping to all basic blocks.
            var newBlockMap = ImmutableOrderedDictionary
                              .Create <BasicBlockTag, BasicBlockData>()
                              .ToBuilder();

            var newParamTypeMap = ImmutableDictionary
                                  .Create <ValueTag, IType>()
                                  .ToBuilder();

            foreach (var blockPair in blocks)
            {
                var newBlock = blockPair.Value.Map(mapping);
                newBlockMap[blockPair.Key] = newBlock;
                foreach (var newBlockParam in newBlock.Parameters)
                {
                    newParamTypeMap[newBlockParam.Tag] = newBlockParam.Type;
                }
            }

            var result = new FlowGraph(this, new MapMembersUpdate(mapping));

            result.instructions    = newInstructionMap.ToImmutable();
            result.blocks          = newBlockMap.ToImmutable();
            result.blockParamTypes = newParamTypeMap.ToImmutable();
            return(result);
        }