2222import vadl .dump .InfoEnricher ;
2323import vadl .dump .InfoUtils ;
2424import vadl .dump .entities .VdtEntity ;
25+ import vadl .pass .PassResults ;
26+ import vadl .vdt .impl .irregular .model .DecodeEntry ;
27+ import vadl .vdt .passes .VdtConstraintSynthesisPass ;
28+ import vadl .vdt .passes .VdtInputPreparationPass ;
2529import vadl .vdt .target .common .DecisionTreeStatsCalculator ;
2630import vadl .vdt .target .dump .DotGraphGenerator ;
2731import vadl .vdt .target .dump .InsnDecisionTableGenerator ;
@@ -108,21 +112,36 @@ public class VdtEnricherCollection {
108112 entity .addInfo (info );
109113 });
110114
115+ @ SuppressWarnings ("unchecked" )
111116 public static InfoEnricher VDT_STATS_EXPANDABLE =
112117 InfoEnricher .forType (VdtEntity .class , (entity , passResults ) -> {
113118
114119 var stats = DecisionTreeStatsCalculator .statistics (entity .tree ());
115120
116121 final var statsTable = new ArrayList <List <String >>();
117122
118- statsTable .add (List .of ("Property" , "Number of Nodes" , "Number of Leaves (Instructions)" ,
119- "Minimum Depth" ,
120- "Maximal Depth" , "Average Depth" , "Longest instruction width" ));
121- statsTable .add (List .of ("Value" , String .valueOf (stats .getNumberOfNodes ()),
122- String .valueOf (stats .getNumberOfLeafNodes ()), String .valueOf (stats .getMinDepth ()),
123- String .valueOf (stats .getMaxDepth ()),
124- String .valueOf (Math .round (stats .getAvgDepth () * 100 ) / 100.0 ),
125- stats .getMaxInstructionWidth () + " bit" ));
123+ final List <String > categories = new ArrayList <>(
124+ List .of ("Property" , "Number of Nodes" , "Number of Instructions" ,
125+ "Number of Leaves" , "Minimum Depth" , "Maximal Depth" , "Average Depth" ));
126+ if (stats .getOccurrenceProbability () > 0.0 ) {
127+ categories .add ("Weighted Average Depth" );
128+ }
129+ categories .add ("Longest instruction width" );
130+ statsTable .add (categories );
131+
132+ final List <String > values = new ArrayList <>(
133+ List .of ("Value" , String .valueOf (stats .getNumberOfNodes ()),
134+ String .valueOf (getInsnCount (passResults )),
135+ String .valueOf (stats .getNumberOfLeafNodes ()), String .valueOf (stats .getMinDepth ()),
136+ String .valueOf (stats .getMaxDepth ()),
137+ String .valueOf (Math .round (stats .getAvgDepth () * 100 ) / 100.0 ))
138+ );
139+ if (stats .getOccurrenceProbability () > 0.0 ) {
140+ values .add (String .valueOf (Math .round (stats .getWeightedAvgDepth () * 100 ) / 100.0 ));
141+ }
142+ values .add (stats .getMaxInstructionWidth () + " bit" );
143+
144+ statsTable .add (values );
126145
127146 var info = InfoUtils .createTableExpandable ("Statistics" , statsTable );
128147 entity .addInfo (info );
@@ -133,13 +152,33 @@ public class VdtEnricherCollection {
133152
134153 var stats = DecisionTreeStatsCalculator .statistics (entity .tree ());
135154
136- entity .addInfo (Info .Tag .of ("Instructions" , String .valueOf (stats . getNumberOfLeafNodes ( ))));
155+ entity .addInfo (Info .Tag .of ("Instructions" , String .valueOf (getInsnCount ( passResults ))));
137156 entity .addInfo (Info .Tag .of ("Nodes" , String .valueOf (stats .getNumberOfNodes ())));
157+ entity .addInfo (Info .Tag .of ("Leaves" , String .valueOf (stats .getNumberOfLeafNodes ())));
138158 entity .addInfo (Info .Tag .of ("Max Depth" , String .valueOf (stats .getMaxDepth ())));
139159 entity .addInfo (Info .Tag .of ("Avg Depth" ,
140160 String .valueOf (Math .round (stats .getAvgDepth () * 100 ) / 100.0 )));
161+
162+ if (stats .getOccurrenceProbability () > 0.0 ) {
163+ entity .addInfo (Info .Tag .of ("Weighted Avg Depth" ,
164+ String .valueOf (Math .round (stats .getWeightedAvgDepth () * 100 ) / 100.0 )));
165+ }
141166 });
142167
168+ @ SuppressWarnings ("unchecked" )
169+ private static int getInsnCount (PassResults passResults ) {
170+ final List <DecodeEntry > entries ;
171+ if (passResults .hasRunPassOnce (VdtConstraintSynthesisPass .class )) {
172+ entries =
173+ (List <DecodeEntry >) passResults .lastNullableResultOf (
174+ VdtConstraintSynthesisPass .class );
175+ } else {
176+ entries =
177+ (List <DecodeEntry >) passResults .lastNullableResultOf (VdtInputPreparationPass .class );
178+ }
179+ return entries != null ? entries .size () : 0 ;
180+ }
181+
143182 public static List <InfoEnricher > all = List .of (
144183 VDT_STATS_TAGS ,
145184 VDT_STATS_EXPANDABLE ,
0 commit comments