From 8bf231b2cb1d185d7e9c6b90e218e5763b1e7a9c Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 28 Jun 2019 18:28:41 +0200 Subject: [PATCH] allow inverted inputs at substituted circuits --- .../digital/analyse/SubstituteLibrary.java | 4 +- .../digital/draw/model/InverterConfig.java | 14 +- .../digital/draw/model/ModelCreator.java | 5 - src/main/resources/analyser/Counter.dig | 132 ++++++-- src/main/resources/analyser/CounterPreset.dig | 320 +++++++++++++----- src/main/resources/analyser/JK_FF.dig | 78 ++++- src/main/resources/analyser/T_FF_EN.dig | 31 +- 7 files changed, 459 insertions(+), 125 deletions(-) diff --git a/src/main/java/de/neemann/digital/analyse/SubstituteLibrary.java b/src/main/java/de/neemann/digital/analyse/SubstituteLibrary.java index 01fc79e8f..8145d1e10 100644 --- a/src/main/java/de/neemann/digital/analyse/SubstituteLibrary.java +++ b/src/main/java/de/neemann/digital/analyse/SubstituteLibrary.java @@ -37,9 +37,9 @@ public class SubstituteLibrary implements LibraryInterface { private static final Map MAP = new HashMap<>(); static { - MAP.put("JK_FF", new Substitute("JK_FF.dig")); + MAP.put("JK_FF", new SubstituteGenericHGSParser("JK_FF.dig")); MAP.put("T_FF", new SubstituteMatching() - .add(attr -> attr.get(Keys.WITH_ENABLE), new Substitute("T_FF_EN.dig")) + .add(attr -> attr.get(Keys.WITH_ENABLE), new SubstituteGenericHGSParser("T_FF_EN.dig")) .add(attr -> true, new Substitute("T_FF.dig")) ); MAP.put("Counter", new SubstituteGenericHGSParser("Counter.dig")); diff --git a/src/main/java/de/neemann/digital/draw/model/InverterConfig.java b/src/main/java/de/neemann/digital/draw/model/InverterConfig.java index e09845f9f..3df26a194 100644 --- a/src/main/java/de/neemann/digital/draw/model/InverterConfig.java +++ b/src/main/java/de/neemann/digital/draw/model/InverterConfig.java @@ -7,13 +7,15 @@ package de.neemann.digital.draw.model; import de.neemann.digital.core.NodeWithoutDelay; import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.hdl.hgs.HGSMap; import java.util.HashSet; +import java.util.Objects; /** * Manages the input inverting of a component */ -public class InverterConfig { +public class InverterConfig implements HGSMap { private HashSet inputs; @@ -103,7 +105,7 @@ public class InverterConfig { InverterConfig that = (InverterConfig) o; - return inputs != null ? inputs.equals(that.inputs) : that.inputs == null; + return Objects.equals(inputs, that.inputs); } @Override @@ -119,4 +121,12 @@ public class InverterConfig { return 0; return inputs.size(); } + + @Override + public Object hgsMapGet(String key) { + if (inputs == null) + return false; + + return inputs.contains(key); + } } diff --git a/src/main/java/de/neemann/digital/draw/model/ModelCreator.java b/src/main/java/de/neemann/digital/draw/model/ModelCreator.java index 945522373..4f52c6197 100644 --- a/src/main/java/de/neemann/digital/draw/model/ModelCreator.java +++ b/src/main/java/de/neemann/digital/draw/model/ModelCreator.java @@ -147,11 +147,6 @@ public class ModelCreator implements Iterable { ModelEntry me = it.next(); if (me.getElement() instanceof CustomElement) { // at first look for custom elements - // Input invert of custom components is not jet supported! - InverterConfig ic = me.getVisualElement().getElementAttributes().get(Keys.INVERTER_CONFIG); - if (!ic.isEmpty()) - throw new NodeException(Lang.get("err_customComponentInputInvert", me.getVisualElement().getElementName())); - CustomElement ce = (CustomElement) me.getElement(); ModelCreator child = ce.getModelCreator( combineNames(subName, me.getVisualElement().getElementAttributes().getLabel()), diff --git a/src/main/resources/analyser/Counter.dig b/src/main/resources/analyser/Counter.dig index 807ae8b4c..3ccd5fe9b 100644 --- a/src/main/resources/analyser/Counter.dig +++ b/src/main/resources/analyser/Counter.dig @@ -11,7 +11,7 @@ en - + Clock @@ -21,7 +21,7 @@ C - + In @@ -31,7 +31,7 @@ clr - + Out @@ -59,7 +59,7 @@ ovf - + D_FF @@ -157,7 +157,49 @@ And - + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.en) { + this.Value=1; +} + + + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.clr) { + this.Value=1; +} + + + @@ -181,6 +223,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -190,20 +260,8 @@ - - - - - - - - - - - - - - + + @@ -221,33 +279,33 @@ + + + + + + + + + + + + - - - - - - - - - - - - - - + + - + - + @@ -271,11 +329,11 @@ - + - + diff --git a/src/main/resources/analyser/CounterPreset.dig b/src/main/resources/analyser/CounterPreset.dig index f619bc067..45e41e2fe 100644 --- a/src/main/resources/analyser/CounterPreset.dig +++ b/src/main/resources/analyser/CounterPreset.dig @@ -11,7 +11,7 @@ en - + Clock @@ -20,6 +20,10 @@ runRealTime true + + rotation + + Label C @@ -29,7 +33,7 @@ 2 - + In @@ -39,7 +43,7 @@ dir - + Out @@ -57,7 +61,7 @@ this.Bits=orig.Bits; - + Out @@ -67,7 +71,7 @@ ovf - + D_FF @@ -85,7 +89,7 @@ this.Bits=orig.Bits; - + Multiplexer @@ -151,7 +155,7 @@ And - + Multiplexer @@ -205,7 +209,7 @@ this.Bits=orig.Bits; - + Comparator @@ -219,7 +223,7 @@ this.Bits=orig.Bits; - + Const @@ -242,7 +246,7 @@ if (orig.maxValue=0) { } - + Or @@ -310,7 +314,7 @@ if (orig.maxValue=0) { this.Bits=orig.Bits; - + In @@ -324,7 +328,7 @@ if (orig.maxValue=0) { ld - + In @@ -334,7 +338,7 @@ if (orig.maxValue=0) { clr - + Multiplexer @@ -352,7 +356,7 @@ if (orig.maxValue=0) { this.Bits=orig.Bits; - + Const @@ -370,13 +374,141 @@ if (orig.maxValue=0) { this.Bits=orig.Bits; - + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.clr) { + this.Value=1; +} + + + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.en) { + this.Value=1; +} + + + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.dir) { + this.Value=1; +} + + + + + + XOr + + + rotation + + + + + + + Const + + + rotation + + + + Value + 0 + + + generic + if (orig.inverterConfig.ld) { + this.Value=1; +} + + + + + + XOr + + + rotation + + + + generic + this.Bits=orig.Bits; + + + + + + Const + + + rotation + + + + Value + 0 + + + generic + this.Bits=orig.Bits; +if (orig.inverterConfig.in) { + this.Value=-1; +} + + + - + @@ -394,6 +526,14 @@ if (orig.maxValue=0) { + + + + + + + + @@ -410,6 +550,18 @@ if (orig.maxValue=0) { + + + + + + + + + + + + @@ -423,40 +575,36 @@ if (orig.maxValue=0) { - + + + + + - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + @@ -464,27 +612,23 @@ if (orig.maxValue=0) { - + - - + + - - + + - - - - - - + + @@ -495,40 +639,48 @@ if (orig.maxValue=0) { - - + + - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + - - + + @@ -536,19 +688,35 @@ if (orig.maxValue=0) { - + + + + + + + + + + + + + - - + + + + + + @@ -568,11 +736,11 @@ if (orig.maxValue=0) { - + - + @@ -584,11 +752,15 @@ if (orig.maxValue=0) { - + + + + + - + @@ -596,11 +768,7 @@ if (orig.maxValue=0) { - - - - - + diff --git a/src/main/resources/analyser/JK_FF.dig b/src/main/resources/analyser/JK_FF.dig index 002275efe..6d7c380a2 100644 --- a/src/main/resources/analyser/JK_FF.dig +++ b/src/main/resources/analyser/JK_FF.dig @@ -75,7 +75,7 @@ J - + Clock @@ -103,7 +103,49 @@ K - + + + + XOr + + + + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.J) { + this.Value=1; +} + + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.K) { + this.Value=1; +} + + + @@ -111,6 +153,10 @@ + + + + @@ -127,6 +173,10 @@ + + + + @@ -139,10 +189,18 @@ + + + + + + + + @@ -159,6 +217,10 @@ + + + + @@ -167,6 +229,10 @@ + + + + @@ -187,6 +253,14 @@ + + + + + + + + diff --git a/src/main/resources/analyser/T_FF_EN.dig b/src/main/resources/analyser/T_FF_EN.dig index 42a43e656..8d3d878f8 100644 --- a/src/main/resources/analyser/T_FF_EN.dig +++ b/src/main/resources/analyser/T_FF_EN.dig @@ -75,7 +75,7 @@ T - + Clock @@ -95,6 +95,27 @@ + + XOr + + + + + Const + + + Value + 0 + + + generic + if (orig.inverterConfig.T) { + this.Value=1; +} + + + + @@ -129,6 +150,10 @@ + + + + @@ -161,6 +186,10 @@ + + + +