Exemplo n.º 1
0
 /// <returns>Hashtable&lt;Namespace,ArrayList&lt;TerminalName&gt;&gt;</returns>
 private static ReadOnlyDictionary CreateNamespaceToVariablesAllocatedTherein(IEnumerable liveLocalNonParameterVariableNames)
 {
     var result=new Hashtable();
       foreach(TerminalName name in liveLocalNonParameterVariableNames) {
     result.LookupOrCreateArrayList(name.Namespace).Add(name);
       }
       return result.AsReadOnlyDictionary();
 }
Exemplo n.º 2
0
        private static ReadOnlyDictionary EstablishRegisterAllocationCounts(ReadOnlyDictionary depthToNamespaces, int freeRegisterMask,
      IEnumerable leaves, int maxDepth, ReadOnlyDictionary nsToLiveVars)
        {
            var initialBudget=0;
              while(freeRegisterMask>0) {
            ++initialBudget;
            freeRegisterMask&=(freeRegisterMask-1);
              }

              var budget=new Hashtable(); //Hashtable<Namespace,int>
              foreach(Namespace ns in leaves) {
            budget[ns]=initialBudget;
              }

              var result=new Hashtable(); //Hashtable<Namespace,int>
              object boxedMaxValue=int.MaxValue;
              for(var depth=maxDepth; depth>=0; --depth) {
            var itemsToProcess=(ArrayList)depthToNamespaces[depth];
            foreach(Namespace ns in itemsToProcess) {
              var capacity=(int)budget[ns];
              var liveVars=(ArrayList)nsToLiveVars[ns];
              var requested=liveVars!=null ? liveVars.Count : 0;
              var granted=Math.Min(capacity, requested);
              var remaining=capacity-granted;
              result.Add(ns, granted);
              result[ns]=granted;

              //now forward the budget to my parent
              var inner=ns.Inner;
              if(inner!=null) {
            var existingBudget=(int)(budget[inner] ?? boxedMaxValue);
            var newBudget=Math.Min(existingBudget, remaining);
            budget[inner]=newBudget;
              }
            }
              }
              return result.AsReadOnlyDictionary();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Find the namespace leaves
        /// </summary>
        /// <returns>Hashtable&lt;Namespace,null&gt;&gt;</returns>
        private static ReadOnlyDictionary FindLeaves(IEnumerable liveLocalNonParameterVariableNames)
        {
            var leaves=new Hashtable(); //Hashtable<Namespace,null>
              foreach(TerminalName name in liveLocalNonParameterVariableNames) {
            leaves[name.Namespace]=null;
              }

              foreach(TerminalName name in liveLocalNonParameterVariableNames) {
            for(var ns=name.Namespace.Inner; ns!=null; ns=ns.Inner) {
              leaves.Remove(ns);
            }
              }
              return leaves.AsReadOnlyDictionary();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Basically: liveVariables.Select(lv=>lv.Namespace).GroupBy(ns=>ns.Depth)
 /// </summary>
 /// <returns>Hashtable&lt;int,ArrayList&lt;Namespace&gt;&gt;</returns>
 private static ReadOnlyDictionary MakeDepthToNamespaces(IEnumerable liveLocalNonParameterVariableNames, out int maxDepth)
 {
     var result=new Hashtable();
       var beenHere=new Hashtable();
       maxDepth=-1;
       foreach(TerminalName name in liveLocalNonParameterVariableNames) {
     var ns=name.Namespace;
     maxDepth=Math.Max(maxDepth, ns.Depth);
     while(ns!=null) {
       if(beenHere.Contains(ns)) {
     break;
       }
       beenHere.Add(ns, null);
       result.LookupOrCreateArrayList(ns.Depth).Add(ns);
       ns=ns.Inner;
     }
       }
       return result.AsReadOnlyDictionary();
 }