Attribute attribute = createAttribute(token);
if(currInstance != null) currInstance.addAttribute(attribute);
else if(currNet != null){
currNet.addAttribute(attribute);
if(attribute.getPhysicalName().equals("_MACRO")){
ModuleInstance mi = design.getModuleInstance(attribute.getValue());
currNet.setModuleInstance(mi);
mi.addNet(currNet);
Module module = mi.getModule();
currNet.setModuleTemplate(module);
currNet.setModuleTemplateNet(module.getNet(currNet.getName().replaceFirst(mi.getName() + "/", "")));
}
}
else if(currModule != null) currModule.addAttribute(attribute);
else design.addAttribute(attribute);
}
break;
case XDL_STATEMENT:
if(token.equals(INST)|| token.equals(INSTANCE)){
currInstance = new Instance();
state = ParserState.INSTANCE_NAME;
}
else if(token.equals(NET)){
currNet = new Net();
state = ParserState.NET_NAME;
}
else if(token.equals(MODULE)){
currModule = new Module();
modPinMap = new HashMap<String, Pin>();
portNames = new ArrayList<String>();
portInstanceNames = new ArrayList<String>();
portPinNames = new ArrayList<String>();
state = ParserState.MODULE_NAME;
}
else if(token.equals(ENDMODULE)){
state = ParserState.END_MODULE_NAME;
}
else{
expect("inst, net, module or endmodule", token, ParserState.XDL_STATEMENT);
}
break;
case INSTANCE_NAME:
currInstance.setName(pool.getUnique(token));
currInstance.setDesign(design);
if(currModule == null){
design.addInstance(currInstance);
}
else{
currModule.addInstance(currInstance);
currInstance.setModuleTemplate(currModule);
if(currInstance.getName().equals(currModuleAnchorName)){
currModule.setAnchor(currInstance);
}
}
state = ParserState.INSTANCE_TYPE;
break;
case INSTANCE_TYPE:
PrimitiveType t = Utils.createPrimitiveType(token);
if(t == null){
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", Failed parsing Instance type: \"" + token + "\"");
}
currInstance.setType(t);
state = ParserState.INSTANCE_PLACED;
break;
case INSTANCE_PLACED:
if(token.equals(PLACED)) state = ParserState.INSTANCE_TILE;
else if(token.equals(UNPLACED)) state = ParserState.INSTANCE_BONDED;
else expect("placed or unplaced", token, ParserState.INSTANCE_PLACED);
break;
case INSTANCE_TILE:
Tile tile = dev.getTile(token);
if(tile == null){
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", Invalid tile " +
token + " on line " + lineNumber);
}
state = ParserState.INSTANCE_SITE;
break;
case INSTANCE_SITE:
PrimitiveSite site = dev.getPrimitiveSite(token);
if(site == null){
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", Invalid primitive site " +
token + " on line " + lineNumber);
}
if(currModule != null){
currInstance.setSite(dev.getPrimitiveSite(token));
}else{
currInstance.place(dev.getPrimitiveSite(token));
}
state = ParserState.MODULE_INSTANCE_TOKEN;
break;
case INSTANCE_BONDED:
if(token.equals(COMMA)){
state = ParserState.MODULE_INSTANCE_TOKEN;
}
else if(token.equals(CFG)){
state = ParserState.ATTRIBUTE;
}
else if(token.equals(MODULE)){
state = ParserState.MODULE_INSTANCE_NAME;
}
else if(token.equals(BONDED)){
currInstance.setBonded(true);
state = ParserState.MODULE_INSTANCE_TOKEN;
}
else if(token.equals(UNBONDED)){
currInstance.setBonded(false);
state = ParserState.MODULE_INSTANCE_TOKEN;
}
else{
expect("bonded, unbonded or ,", token, ParserState.INSTANCE_BONDED);
}
break;
case MODULE_INSTANCE_TOKEN:
if(token.equals(CFG)) state = ParserState.ATTRIBUTE;
else if(token.equals(MODULE)) state = ParserState.MODULE_INSTANCE_NAME;
else expect("cfg or module", token, ParserState.MODULE_INSTANCE_TOKEN);
break;
case MODULE_INSTANCE_NAME:
currModuleInstanceName = pool.getUnique(token);
state = ParserState.MODULE_TEMPLATE_NAME;
break;
case MODULE_TEMPLATE_NAME:
currInstance.setModuleTemplate(design.getModule(token));
state = ParserState.MODULE_TEMPLATE_INSTANCE_NAME;
break;
case MODULE_TEMPLATE_INSTANCE_NAME:
currInstance.setModuleTemplateInstance(currInstance.getModuleTemplate().getInstance(token));
ModuleInstance moduleInstance = design.addInstanceToModuleInstances(currInstance, currModuleInstanceName);
if(currInstance.getModuleTemplateInstance().equals(currInstance.getModuleTemplate().getAnchor())){
moduleInstance.setAnchor(currInstance);
}
state = ParserState.CFG_STRING;
break;
case NET_NAME:
currNet.setName(pool.getUnique(token));