aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-25 00:18:41 +0000
committerUbitUmarov2018-02-25 00:18:41 +0000
commit85b973ce1d8dc034546c9c572a7f57e73b6017d3 (patch)
treea03332d9233e3788f8bc2e535b6863d8fe195b0b /OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs
parentYengine fix its section name on opensim.ini.example (diff)
downloadopensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.zip
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.gz
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.bz2
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.xz
Y(xmr)engine cosmetics...
Diffstat (limited to 'OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs187
1 files changed, 61 insertions, 126 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs
index 4a57823..88cd6c1 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCollector.cs
@@ -511,20 +511,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine
511 } 511 }
512 public override bool MoveNext() 512 public override bool MoveNext()
513 { 513 {
514 /* 514 // First off, return any targets the instruction can come up with.
515 * First off, return any targets the instruction can come up with.
516 */
517 if(realEnumerator.MoveNext()) 515 if(realEnumerator.MoveNext())
518 { 516 {
519 nn = realEnumerator.Current; 517 nn = realEnumerator.Current;
520 return true; 518 return true;
521 } 519 }
522 520
523 /* 521 // Then if this instruction is in a try section, say this instruction
524 * Then if this instruction is in a try section, say this instruction 522 // can potentially branch to the beginning of the corresponding
525 * can potentially branch to the beginning of the corresponding 523 // catch/finally.
526 * catch/finally.
527 */
528 if((index == 0) && (gn.tryBlock != null)) 524 if((index == 0) && (gn.tryBlock != null))
529 { 525 {
530 index++; 526 index++;
@@ -532,9 +528,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
532 return true; 528 return true;
533 } 529 }
534 530
535 /* 531 // That's all we can do.
536 * That's all we can do.
537 */
538 nn = null; 532 nn = null;
539 return false; 533 return false;
540 } 534 }
@@ -1875,9 +1869,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1875 } 1869 }
1876 public override bool MoveNext() 1870 public override bool MoveNext()
1877 { 1871 {
1878 /* 1872 // Return next from list of switch case labels.
1879 * Return next from list of switch case labels.
1880 */
1881 while(index < gn.myLabels.Length) 1873 while(index < gn.myLabels.Length)
1882 { 1874 {
1883 nn = gn.myLabels[index++].whereAmI; 1875 nn = gn.myLabels[index++].whereAmI;
@@ -1885,9 +1877,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1885 return true; 1877 return true;
1886 } 1878 }
1887 1879
1888 /* 1880 // If all ran out, the switch instruction falls through.
1889 * If all ran out, the switch instruction falls through.
1890 */
1891 if(index == gn.myLabels.Length) 1881 if(index == gn.myLabels.Length)
1892 { 1882 {
1893 index++; 1883 index++;
@@ -1895,9 +1885,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1895 return true; 1885 return true;
1896 } 1886 }
1897 1887
1898 /* 1888 // Even ran out of that, say there's nothing more.
1899 * Even ran out of that, say there's nothing more.
1900 */
1901 nn = null; 1889 nn = null;
1902 return false; 1890 return false;
1903 } 1891 }
@@ -2527,10 +2515,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2527 if(curExcBlock != null) 2515 if(curExcBlock != null)
2528 throw new Exception("exception block still open"); 2516 throw new Exception("exception block still open");
2529 2517
2530 /* 2518 // If an instruction says it doesn't fall through, remove all instructions to
2531 * If an instruction says it doesn't fall through, remove all instructions to 2519 // the end of the block.
2532 * the end of the block.
2533 */
2534 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2520 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2535 { 2521 {
2536 if(!gn.CanFallThrough()) 2522 if(!gn.CanFallThrough())
@@ -2547,12 +2533,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2547 } 2533 }
2548 } 2534 }
2549 2535
2550 /* 2536 // Scan for OpCodes.Leave instructions.
2551 * Scan for OpCodes.Leave instructions. 2537 // For each found, its target for flow analysis purposes is the beginning of the corresponding
2552 * For each found, its target for flow analysis purposes is the beginning of the corresponding 2538 // finally block. And the end of the finally block gets a conditional branch target of the
2553 * finally block. And the end of the finally block gets a conditional branch target of the 2539 // leave instruction's target. A leave instruction can unwind zero or more finally blocks.
2554 * leave instruction's target. A leave instruction can unwind zero or more finally blocks.
2555 */
2556 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2540 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2557 { 2541 {
2558 if(gn is GraphNodeEmitLabelLeave) 2542 if(gn is GraphNodeEmitLabelLeave)
@@ -2562,12 +2546,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2562 GraphNodeBeginExceptionBlock leaveTargetsTryBlock = // try block directly enclosing leave target 2546 GraphNodeBeginExceptionBlock leaveTargetsTryBlock = // try block directly enclosing leave target
2563 (leaveTarget == null) ? null : leaveTarget.tryBlock; // ...it must not be unwound 2547 (leaveTarget == null) ? null : leaveTarget.tryBlock; // ...it must not be unwound
2564 2548
2565 /* 2549 // Step through try { }s from the leave instruction towards its target looking for try { }s with finally { }s.
2566 * Step through try { }s from the leave instruction towards its target looking for try { }s with finally { }s. 2550 // The leave instruction unconditionally branches to the beginning of the innermost one found.
2567 * The leave instruction unconditionally branches to the beginning of the innermost one found. 2551 // The end of the last one found conditionally branches to the leave instruction's target.
2568 * The end of the last one found conditionally branches to the leave instruction's target. 2552 // If none found, the leave is a simple unconditional branch to its target.
2569 * If none found, the leave is a simple unconditional branch to its target.
2570 */
2571 GraphNodeBeginFinallyBlock innerFinallyBlock = null; 2553 GraphNodeBeginFinallyBlock innerFinallyBlock = null;
2572 for(GraphNodeBeginExceptionBlock tryBlock = leaveInstr.tryBlock; 2554 for(GraphNodeBeginExceptionBlock tryBlock = leaveInstr.tryBlock;
2573 tryBlock != leaveTargetsTryBlock; 2555 tryBlock != leaveTargetsTryBlock;
@@ -2586,10 +2568,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2586 } 2568 }
2587 } 2569 }
2588 2570
2589 /* 2571 // The end of the outermost finally being unwound can conditionally jump to the target of the leave instruction.
2590 * The end of the outermost finally being unwound can conditionally jump to the target of the leave instruction. 2572 // In the case of no finallies being unwound, the leave is just a simple unconditional branch.
2591 * In the case of no finallies being unwound, the leave is just a simple unconditional branch.
2592 */
2593 if(innerFinallyBlock == null) 2573 if(innerFinallyBlock == null)
2594 { 2574 {
2595 leaveInstr.unwindTo = leaveTarget; 2575 leaveInstr.unwindTo = leaveTarget;
@@ -2601,10 +2581,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2601 } 2581 }
2602 } 2582 }
2603 2583
2604 /* 2584 // See which variables a particular block reads before writing.
2605 * See which variables a particular block reads before writing. 2585 // This just considers the block itself and nothing that it branches to or fallsthru to.
2606 * This just considers the block itself and nothing that it branches to or fallsthru to.
2607 */
2608 GraphNodeBlock currentBlock = null; 2586 GraphNodeBlock currentBlock = null;
2609 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2587 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2610 { 2588 {
@@ -2626,13 +2604,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2626 } 2604 }
2627 } 2605 }
2628 2606
2629 /* 2607 // For every block we branch to, add that blocks readables to our list of readables,
2630 * For every block we branch to, add that blocks readables to our list of readables, 2608 // because we need to have those values valid on entry to our block. But if we write the
2631 * because we need to have those values valid on entry to our block. But if we write the 2609 // variable before we can possibly branch to that block, then we don't need to have it valid
2632 * variable before we can possibly branch to that block, then we don't need to have it valid 2610 // on entry to our block. So basically it looks like the branch instruction is reading
2633 * on entry to our block. So basically it looks like the branch instruction is reading 2611 // everything required by any blocks it can branch to.
2634 * everything required by any blocks it can branch to.
2635 */
2636 do 2612 do
2637 { 2613 {
2638 this.resolvedSomething = false; 2614 this.resolvedSomething = false;
@@ -2640,17 +2616,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2640 this.ResolveBlock((GraphNodeBlock)firstLin); 2616 this.ResolveBlock((GraphNodeBlock)firstLin);
2641 } while(this.resolvedSomething); 2617 } while(this.resolvedSomething);
2642 2618
2643 /* 2619 // Repeat the cutting loops as long as we keep finding stuff.
2644 * Repeat the cutting loops as long as we keep finding stuff.
2645 */
2646 bool didSomething; 2620 bool didSomething;
2647 do 2621 do
2648 { 2622 {
2649 didSomething = false; 2623 didSomething = false;
2650 2624
2651 /* 2625 // Strip out ldc.i4.1/xor/ldc.i4.1/xor
2652 * Strip out ldc.i4.1/xor/ldc.i4.1/xor
2653 */
2654 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2626 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2655 { 2627 {
2656 if(!(gn is GraphNodeEmit)) 2628 if(!(gn is GraphNodeEmit))
@@ -2678,9 +2650,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2678 didSomething = true; 2650 didSomething = true;
2679 } 2651 }
2680 2652
2681 /* 2653 // Replace c{cond}/ldc.i4.1/xor/br{false,true} -> c{cond}/br{true,false}
2682 * Replace c{cond}/ldc.i4.1/xor/br{false,true} -> c{cond}/br{true,false}
2683 */
2684 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2654 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2685 { 2655 {
2686 if(!(gn is GraphNodeEmit)) 2656 if(!(gn is GraphNodeEmit))
@@ -2711,9 +2681,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2711 didSomething = true; 2681 didSomething = true;
2712 } 2682 }
2713 2683
2714 /* 2684 // Replace c{cond}/br{false,true} -> b{!,}{cond}
2715 * Replace c{cond}/br{false,true} -> b{!,}{cond}
2716 */
2717 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2685 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2718 { 2686 {
2719 if(!(gn is GraphNodeEmit)) 2687 if(!(gn is GraphNodeEmit))
@@ -2746,9 +2714,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2746 didSomething = true; 2714 didSomething = true;
2747 } 2715 }
2748 2716
2749 /* 2717 // Replace ld{c.i4.0,null}/br{ne.un,eq} -> br{true,false}
2750 * Replace ld{c.i4.0,null}/br{ne.un,eq} -> br{true,false}
2751 */
2752 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2718 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2753 { 2719 {
2754 if(!(gn is GraphNodeEmit)) 2720 if(!(gn is GraphNodeEmit))
@@ -2767,17 +2733,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2767 didSomething = true; 2733 didSomething = true;
2768 } 2734 }
2769 2735
2770 /* 2736 // Replace:
2771 * Replace: 2737 // ldloc v1
2772 * ldloc v1 2738 // stloc v2
2773 * stloc v2 2739 // ld<anything> except ld<anything> v2
2774 * ld<anything> except ld<anything> v2 2740 // ldloc v2
2775 * ldloc v2 2741 // ...v2 unreferenced hereafter
2776 * ...v2 unreferenced hereafter 2742 // With:
2777 * With: 2743 // ld<anything> except ld<anything> v2
2778 * ld<anything> except ld<anything> v2 2744 // ldloc v1
2779 * ldloc v1
2780 */
2781 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2745 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2782 { 2746 {
2783 2747
@@ -2833,11 +2797,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2833 didSomething = true; 2797 didSomething = true;
2834 } 2798 }
2835 2799
2836 /* 2800 // Remove all the stloc/ldloc that are back-to-back without the local
2837 * Remove all the stloc/ldloc that are back-to-back without the local 2801 // being needed afterwards. If it is needed afterwards, replace the
2838 * being needed afterwards. If it is needed afterwards, replace the 2802 // stloc/ldloc with dup/stloc.
2839 * stloc/ldloc with dup/stloc.
2840 */
2841 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2803 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2842 { 2804 {
2843 if((gn is GraphNodeEmitLocal) && 2805 if((gn is GraphNodeEmitLocal) &&
@@ -2871,10 +2833,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2871 } 2833 }
2872 } 2834 }
2873 2835
2874 /* 2836 // Remove all write-only local variables, ie, those with no ldloc[a] references.
2875 * Remove all write-only local variables, ie, those with no ldloc[a] references. 2837 // Replace any stloc instructions with pops.
2876 * Replace any stloc instructions with pops.
2877 */
2878 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2838 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2879 { 2839 {
2880 ScriptMyLocal rdlcl = gn.ReadsLocal(); 2840 ScriptMyLocal rdlcl = gn.ReadsLocal();
@@ -2900,9 +2860,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2900 } 2860 }
2901 } 2861 }
2902 2862
2903 /* 2863 // Remove any Ld<const>/Dup,Pop.
2904 * Remove any Ld<const>/Dup,Pop.
2905 */
2906 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin) 2864 for(GraphNode gn = firstLin; gn != null; gn = gn.nextLin)
2907 { 2865 {
2908 if((gn is GraphNodeEmit) && 2866 if((gn is GraphNodeEmit) &&
@@ -2921,9 +2879,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2921 } 2879 }
2922 } while(didSomething); 2880 } while(didSomething);
2923 2881
2924 /* 2882 // Dump out the results.
2925 * Dump out the results.
2926 */
2927 if(DEBUG) 2883 if(DEBUG)
2928 { 2884 {
2929 Console.WriteLine(""); 2885 Console.WriteLine("");
@@ -2982,55 +2938,39 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2982 if(currentBlock.hasBeenResolved == this.resolveSequence) 2938 if(currentBlock.hasBeenResolved == this.resolveSequence)
2983 return; 2939 return;
2984 2940
2985 /* 2941 // So we don't recurse forever on a backward branch.
2986 * So we don't recurse forever on a backward branch.
2987 */
2988 currentBlock.hasBeenResolved = this.resolveSequence; 2942 currentBlock.hasBeenResolved = this.resolveSequence;
2989 2943
2990 /* 2944 // Assume we haven't written any locals yet.
2991 * Assume we haven't written any locals yet.
2992 */
2993 List<ScriptMyLocal> localsWrittenSoFar = new List<ScriptMyLocal>(); 2945 List<ScriptMyLocal> localsWrittenSoFar = new List<ScriptMyLocal>();
2994 2946
2995 /* 2947 // Scan through the instructions in this block.
2996 * Scan through the instructions in this block.
2997 */
2998 for(GraphNode gn = currentBlock; gn != null;) 2948 for(GraphNode gn = currentBlock; gn != null;)
2999 { 2949 {
3000 2950
3001 /* 2951 // See if the instruction writes a local we don't know about yet.
3002 * See if the instruction writes a local we don't know about yet.
3003 */
3004 ScriptMyLocal wrlcl = gn.WritesLocal(); 2952 ScriptMyLocal wrlcl = gn.WritesLocal();
3005 if((wrlcl != null) && !localsWrittenSoFar.Contains(wrlcl)) 2953 if((wrlcl != null) && !localsWrittenSoFar.Contains(wrlcl))
3006 { 2954 {
3007 localsWrittenSoFar.Add(wrlcl); 2955 localsWrittenSoFar.Add(wrlcl);
3008 } 2956 }
3009 2957
3010 /* 2958 // Scan through all the possible next instructions after this.
3011 * Scan through all the possible next instructions after this. 2959 // Note that if we are in the first part of a try/catch/finally block,
3012 * Note that if we are in the first part of a try/catch/finally block, 2960 // every instruction conditionally branches to the beginning of the
3013 * every instruction conditionally branches to the beginning of the 2961 // second part (the catch/finally block).
3014 * second part (the catch/finally block).
3015 */
3016 GraphNode nextFallthruNode = null; 2962 GraphNode nextFallthruNode = null;
3017 foreach(GraphNode nn in gn.NextNodes) 2963 foreach(GraphNode nn in gn.NextNodes)
3018 { 2964 {
3019 if(nn is GraphNodeBlock) 2965 if(nn is GraphNodeBlock)
3020 { 2966 {
3021 2967 // Start of a block, go through all locals needed by that block on entry.
3022 /*
3023 * Start of a block, go through all locals needed by that block on entry.
3024 */
3025 GraphNodeBlock nextBlock = (GraphNodeBlock)nn; 2968 GraphNodeBlock nextBlock = (GraphNodeBlock)nn;
3026 ResolveBlock(nextBlock); 2969 ResolveBlock(nextBlock);
3027 foreach(ScriptMyLocal readByNextBlock in nextBlock.localsReadBeforeWritten) 2970 foreach(ScriptMyLocal readByNextBlock in nextBlock.localsReadBeforeWritten)
3028 { 2971 {
3029 2972 // If this block hasn't written it by now and this block doesn't already
3030 /* 2973 // require it on entry, say this block requires it on entry.
3031 * If this block hasn't written it by now and this block doesn't already
3032 * require it on entry, say this block requires it on entry.
3033 */
3034 if(!localsWrittenSoFar.Contains(readByNextBlock) && 2974 if(!localsWrittenSoFar.Contains(readByNextBlock) &&
3035 !currentBlock.localsReadBeforeWritten.Contains(readByNextBlock)) 2975 !currentBlock.localsReadBeforeWritten.Contains(readByNextBlock))
3036 { 2976 {
@@ -3041,19 +2981,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
3041 } 2981 }
3042 else 2982 else
3043 { 2983 {
3044 2984 // Not start of a block, should be normal fallthru instruction.
3045 /*
3046 * Not start of a block, should be normal fallthru instruction.
3047 */
3048 if(nextFallthruNode != null) 2985 if(nextFallthruNode != null)
3049 throw new Exception("more than one fallthru from " + gn.ToString()); 2986 throw new Exception("more than one fallthru from " + gn.ToString());
3050 nextFallthruNode = nn; 2987 nextFallthruNode = nn;
3051 } 2988 }
3052 } 2989 }
3053 2990
3054 /* 2991 // Process next instruction if it isn't the start of a block.
3055 * Process next instruction if it isn't the start of a block.
3056 */
3057 if(nextFallthruNode == gn) 2992 if(nextFallthruNode == gn)
3058 throw new Exception("can't fallthru to self"); 2993 throw new Exception("can't fallthru to self");
3059 gn = nextFallthruNode; 2994 gn = nextFallthruNode;