/**
* Parses the primitive_def construct in XDLRC and creates
* the appropriate objects.
*/
private void parsePrimitiveDef(){
PrimitiveDef def = new PrimitiveDef();
def.setType(Utils.createPrimitiveType(parts.get(2)));
int pinCount = Integer.parseInt(parts.get(3));
int elementCount = Integer.parseInt(parts.get(4));
ArrayList<PrimitiveDefPin> pins = new ArrayList<PrimitiveDefPin>(pinCount);
ArrayList<Element> elements = new ArrayList<Element>(elementCount);
for(int i = 0; i < pinCount; i++){
readLine();
PrimitiveDefPin p = new PrimitiveDefPin();
p.setExternalName(parts.get(2));
p.setInternalName(parts.get(3));
p.setOutput(parts.get(4).equals("output)"));
pins.add(p);
}
for(int i = 0; i < elementCount; i++){
readLine();
Element e = new Element();
e.setName(parts.get(2));
int elementPinCount = Integer.parseInt(parts.get(3).replace(")", ""));
e.setBel(parts.size() > 5 && parts.get(4).equals("#") && parts.get(5).equals("BEL"));
for(int j = 0; j < elementPinCount; j++){
readLine();
PrimitiveDefPin elementPin = new PrimitiveDefPin();
elementPin.setInternalName(parts.get(2));
elementPin.setOutput(parts.get(3).equals("output)"));
e.addPin(elementPin);
}
while(!readLine().startsWith("\t\t)")){
if(line.startsWith("\t\t\t(cfg ")){
for(int k = 2; k < parts.size(); k++){
e.addCfgOption(parts.get(k).replace(")", ""));
}
}
else if(line.startsWith("\t\t\t(conn ")){
Connection c = new Connection();
c.setElement0(parts.get(2));
c.setPin0(parts.get(3));
c.setForwardConnection(parts.get(4).equals("==>"));
c.setElement1(parts.get(5));
c.setPin1(parts.get(6).substring(0, parts.get(6).length() - 1));
e.addConnection(c);
}
}
elements.add(e);
}
def.setPins(pins);
def.setElements(elements);
defs.add(def);
}