LogicCoreAdapter now makes global statistics for gate count
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 4 Feb 2020 10:53:34 +0000 (11:53 +0100)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 4 Feb 2020 10:53:34 +0000 (11:53 +0100)
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/CountGatesPerComponent.java [new file with mode: 0755]
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/LogicCoreAdapter.java

diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/CountGatesPerComponent.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/CountGatesPerComponent.java
new file mode 100755 (executable)
index 0000000..cac3aa7
--- /dev/null
@@ -0,0 +1,39 @@
+package net.mograsim.logic.model.examples;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map.Entry;
+
+import net.mograsim.logic.model.am2900.Am2900Loader;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+
+public class CountGatesPerComponent
+{
+       public static void main(String[] args) throws IOException
+       {
+               Am2900Loader.setup();
+
+               Path root = Path.of("components");
+               Files.walk(root).map(Path::toString).filter(s -> s.endsWith(".json")).map("jsonfile:"::concat)
+                               .forEach(CountGatesPerComponent::printGatesPerComponent);
+       }
+
+       private static void printGatesPerComponent(String componentID)
+       {
+               LogicModelModifiable model = new LogicModelModifiable();
+               IndirectModelComponentCreator.createComponent(model, componentID);
+
+               LogicCoreAdapter.gateCountsPerComponentClass.clear();
+               LogicCoreAdapter.convert(model, new CoreModelParameters());
+
+               System.out.println(componentID + ':');
+               for (Entry<Class<? extends ModelComponent>, Integer> e : LogicCoreAdapter.gateCountsPerComponentClass.entrySet())
+                       System.out.println("  " + e.getKey().getSimpleName() + ": " + e.getValue());
+               System.out.println();
+       }
+}
\ No newline at end of file
index 70f256a..cb807b6 100644 (file)
@@ -142,11 +142,14 @@ public class LogicCoreAdapter
                return connectedPinsPerPin;
        }
 
+       public static final Map<Class<? extends ModelComponent>, Integer> gateCountsPerComponentClass = new HashMap<>();
+
        @SuppressWarnings("unchecked")
        private static <G extends ModelComponent> void createAndLinkComponent(Timeline timeline, CoreModelParameters params,
                        ModelComponent modelComponent, Map<Pin, CoreWire> logicWiresPerPin)
        {
                Class<?> cls = modelComponent.getClass();
+               gateCountsPerComponentClass.merge(modelComponent.getClass(), 1, Integer::sum);
                ComponentAdapter<? super G> adapter = null;
                while (cls != ModelComponent.class && adapter == null)
                {