mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
Default code for generic circuits is set.
This commit is contained in:
parent
52968d013d
commit
55c5ec171a
@ -18,11 +18,15 @@ import de.neemann.digital.draw.model.ModelCreator;
|
||||
import de.neemann.digital.draw.model.NetList;
|
||||
import de.neemann.digital.hdl.hgs.*;
|
||||
import de.neemann.digital.hdl.hgs.function.Function;
|
||||
import de.neemann.digital.hdl.hgs.refs.Reference;
|
||||
import de.neemann.digital.hdl.hgs.refs.ReferenceToStruct;
|
||||
import de.neemann.digital.hdl.hgs.refs.ReferenceToVar;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* The description of a nested element.
|
||||
@ -36,6 +40,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
||||
private String description;
|
||||
private NetList netList;
|
||||
private boolean isCustom = true;
|
||||
private String declarationDefault;
|
||||
|
||||
/**
|
||||
* Creates a new element
|
||||
@ -53,7 +58,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
||||
addAttribute(Keys.ROTATE);
|
||||
addAttribute(Keys.LABEL);
|
||||
addAttribute(Keys.SHAPE_TYPE);
|
||||
if (circuit.getAttributes().get(Keys.IS_GENERIC))
|
||||
if (isGeneric())
|
||||
addAttribute(Keys.GENERIC);
|
||||
}
|
||||
|
||||
@ -118,7 +123,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
||||
if (depth > MAX_DEPTH)
|
||||
throw new NodeException(Lang.get("err_recursiveNestingAt_N0", circuit.getOrigin()));
|
||||
|
||||
if (circuit.getAttributes().get(Keys.IS_GENERIC)) {
|
||||
if (isGeneric()) {
|
||||
try {
|
||||
Context args;
|
||||
if (containingVisualElement != null) {
|
||||
@ -201,4 +206,51 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
||||
isCustom = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generics field default value
|
||||
*/
|
||||
public String getDeclarationDefault() {
|
||||
if (declarationDefault == null)
|
||||
declarationDefault = createDeclarationDefault();
|
||||
return declarationDefault;
|
||||
}
|
||||
|
||||
private String createDeclarationDefault() {
|
||||
TreeSet<String> nameSet = new TreeSet<>();
|
||||
for (VisualElement ve : circuit.getElements()) {
|
||||
String gen = ve.getElementAttributes().get(Keys.GENERIC).trim();
|
||||
try {
|
||||
if (!gen.isEmpty()) {
|
||||
Parser p = new Parser(gen);
|
||||
p.enableRefReadCollection();
|
||||
p.parse(false);
|
||||
for (Reference r : p.getRefsRead()) {
|
||||
if (r instanceof ReferenceToStruct) {
|
||||
ReferenceToStruct st = (ReferenceToStruct) r;
|
||||
if (st.getParent() instanceof ReferenceToVar) {
|
||||
ReferenceToVar var = (ReferenceToVar) st.getParent();
|
||||
if (var.getName().equals("args")) {
|
||||
nameSet.add(st.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ParserException | IOException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String name : nameSet)
|
||||
sb.append(name).append(" := ;\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the circuit is generic
|
||||
*/
|
||||
public boolean isGeneric() {
|
||||
return circuit.getAttributes().get(Keys.IS_GENERIC);
|
||||
}
|
||||
}
|
||||
|
@ -1023,10 +1023,19 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
||||
try {
|
||||
ArrayList<Key> list = getAttributeList(element);
|
||||
if (list.size() > 0) {
|
||||
ElementTypeDescription elementType = library.getElementType(element.getElementName());
|
||||
|
||||
if (elementType instanceof ElementTypeDescriptionCustom) {
|
||||
ElementTypeDescriptionCustom customDescr = (ElementTypeDescriptionCustom) elementType;
|
||||
if (customDescr.isGeneric()) {
|
||||
if (element.getElementAttributes().get(Keys.GENERIC).isEmpty())
|
||||
element.getElementAttributes().set(Keys.GENERIC, customDescr.getDeclarationDefault());
|
||||
}
|
||||
}
|
||||
|
||||
Point p = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||
AttributeDialog attributeDialog = new AttributeDialog(parent, p, list, element.getElementAttributes()).setVisualElement(element);
|
||||
ElementTypeDescription elementType = library.getElementType(element.getElementName());
|
||||
if (elementType instanceof ElementTypeDescriptionCustom) {
|
||||
attributeDialog.addButton(Lang.get("attr_openCircuitLabel"), new ToolTipAction(Lang.get("attr_openCircuit")) {
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.hdl.hgs;
|
||||
|
||||
import de.neemann.digital.builder.tt2.TT2Exporter;
|
||||
import de.neemann.digital.core.Bits;
|
||||
import de.neemann.digital.hdl.hgs.function.FirstClassFunction;
|
||||
import de.neemann.digital.hdl.hgs.function.FirstClassFunctionCall;
|
||||
@ -55,6 +56,7 @@ public class Parser {
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Reference> refRead;
|
||||
private final Tokenizer tok;
|
||||
private Context staticContext;
|
||||
|
||||
@ -78,6 +80,20 @@ public class Parser {
|
||||
staticContext = new Context();
|
||||
}
|
||||
|
||||
/**
|
||||
* If called all read references are collected.
|
||||
*/
|
||||
public void enableRefReadCollection() {
|
||||
refRead = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return returns the references read
|
||||
*/
|
||||
public ArrayList<Reference> getRefsRead() {
|
||||
return refRead;
|
||||
}
|
||||
|
||||
private Statement lino(Statement statement) {
|
||||
if (statement instanceof StatementWithLine)
|
||||
return statement;
|
||||
@ -517,6 +533,8 @@ public class Parser {
|
||||
case IDENT:
|
||||
String name = tok.getIdent();
|
||||
Reference r = parseReference(name);
|
||||
if (refRead != null)
|
||||
refRead.add(r);
|
||||
return r::get;
|
||||
case NUMBER:
|
||||
long num = convToLong(tok.getIdent());
|
||||
|
@ -53,4 +53,17 @@ public class ReferenceToStruct implements Reference {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parent reference
|
||||
*/
|
||||
public Reference getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the struct field name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,11 @@ public class ReferenceToVar implements Reference {
|
||||
public Object get(Context context) throws HGSEvalException {
|
||||
return context.getVar(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the var name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
<int>16</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="460" y="260"/>
|
||||
<pos x="460" y="240"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -80,8 +80,11 @@ end loop
|
||||
|
||||
# read data
|
||||
loop(n,1<<8)
|
||||
C 0 (n) 0 (n+2)
|
||||
end loop</dataString>
|
||||
0 0 (n) 0 (n+2)
|
||||
end loop
|
||||
|
||||
0 0 (1<<8) 0 (2)
|
||||
</dataString>
|
||||
</testData>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -92,8 +95,8 @@ end loop</dataString>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>bits:=int(16);
|
||||
addr:=8;</string>
|
||||
<string>dataBits := 16;
|
||||
addrBits := 8;</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="520" y="260"/>
|
||||
@ -105,8 +108,8 @@ addr:=8;</string>
|
||||
<p2 x="520" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="260"/>
|
||||
<p2 x="520" y="260"/>
|
||||
<p1 x="460" y="240"/>
|
||||
<p2 x="480" y="240"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="460" y="340"/>
|
||||
@ -116,6 +119,10 @@ addr:=8;</string>
|
||||
<p1 x="500" y="340"/>
|
||||
<p2 x="520" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="260"/>
|
||||
<p2 x="520" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="280"/>
|
||||
<p2 x="520" y="280"/>
|
||||
@ -140,6 +147,10 @@ addr:=8;</string>
|
||||
<p1 x="480" y="320"/>
|
||||
<p2 x="480" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="480" y="240"/>
|
||||
<p2 x="480" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="500" y="340"/>
|
||||
<p2 x="500" y="380"/>
|
||||
|
@ -13,7 +13,7 @@
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>this.Bits=args.bits;</string>
|
||||
<string>this.Bits=int(args.dataBits);</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="560" y="140"/>
|
||||
@ -23,7 +23,7 @@
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>this.Bits=args.bits;</string>
|
||||
<string>this.Bits=int(args.dataBits);</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="560" y="260"/>
|
||||
@ -33,7 +33,7 @@
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>this.Bits=args.bits;</string>
|
||||
<string>this.Bits=int(args.dataBits);</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="660" y="160"/>
|
||||
|
@ -68,7 +68,7 @@
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>if (isPresent(args)) {
|
||||
this.Bits=args.bits;
|
||||
this.Bits=int(args.dataBits);
|
||||
}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -106,12 +106,12 @@
|
||||
<string>generic</string>
|
||||
<string>if (isPresent(args)) {
|
||||
|
||||
if (args.addr<2) {
|
||||
if (args.addrBits<2) {
|
||||
panic("at least two address bits are necessary!");
|
||||
}
|
||||
|
||||
this.'Input Splitting'=""+args.addr;
|
||||
this.'Output Splitting'=(args.addr-1)+",1";
|
||||
this.'Input Splitting'=""+args.addrBits;
|
||||
this.'Output Splitting'=(args.addrBits-1)+",1";
|
||||
}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -123,13 +123,13 @@
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>if (isPresent(args)) {
|
||||
export bits:=args.bits;
|
||||
export addr:=args.addr-1;
|
||||
if (args.addr>2) {
|
||||
export dataBits:=args.dataBits;
|
||||
export addrBits:=args.addrBits-1;
|
||||
if (args.addrBits>2) {
|
||||
setCircuit("memNode.dig");
|
||||
}
|
||||
} else {
|
||||
export bits:=int(1);
|
||||
export dataBits:=int(1);
|
||||
}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -141,13 +141,13 @@
|
||||
<entry>
|
||||
<string>generic</string>
|
||||
<string>if (isPresent(args)) {
|
||||
export bits:=args.bits;
|
||||
export addr:=args.addr-1;
|
||||
if (args.addr>2) {
|
||||
export dataBits:=args.dataBits;
|
||||
export addrBits:=args.addrBits-1;
|
||||
if (args.addrBits>2) {
|
||||
setCircuit("memNode.dig");
|
||||
}
|
||||
} else {
|
||||
export bits:=int(1);
|
||||
export dataBits:=int(1);
|
||||
}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -161,14 +161,14 @@
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="300" y="320"/>
|
||||
<p2 x="360" y="320"/>
|
||||
<p2 x="340" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="320" y="160"/>
|
||||
<p2 x="520" y="160"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="420"/>
|
||||
<p1 x="340" y="420"/>
|
||||
<p2 x="640" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
@ -185,10 +185,10 @@
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="240" y="200"/>
|
||||
<p2 x="340" y="200"/>
|
||||
<p2 x="360" y="200"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="200"/>
|
||||
<p1 x="360" y="200"/>
|
||||
<p2 x="400" y="200"/>
|
||||
</wire>
|
||||
<wire>
|
||||
@ -212,7 +212,7 @@
|
||||
<p2 x="520" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="240"/>
|
||||
<p1 x="340" y="240"/>
|
||||
<p2 x="380" y="240"/>
|
||||
</wire>
|
||||
<wire>
|
||||
@ -224,7 +224,7 @@
|
||||
<p2 x="520" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="340"/>
|
||||
<p1 x="360" y="340"/>
|
||||
<p2 x="400" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
@ -244,7 +244,7 @@
|
||||
<p2 x="620" y="220"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="380"/>
|
||||
<p1 x="340" y="380"/>
|
||||
<p2 x="400" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
@ -268,25 +268,25 @@
|
||||
<p2 x="500" y="440"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="200"/>
|
||||
<p2 x="340" y="340"/>
|
||||
<p1 x="340" y="240"/>
|
||||
<p2 x="340" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="380"/>
|
||||
<p2 x="340" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="340" y="320"/>
|
||||
<p2 x="340" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="200"/>
|
||||
<p2 x="360" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="600" y="220"/>
|
||||
<p2 x="600" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="240"/>
|
||||
<p2 x="360" y="320"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="380"/>
|
||||
<p2 x="360" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="360" y="320"/>
|
||||
<p2 x="360" y="380"/>
|
||||
</wire>
|
||||
</wires>
|
||||
<measurementOrdering/>
|
||||
</circuit>
|
Loading…
x
Reference in New Issue
Block a user