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));
if(currModule == null) design.addNet(currNet);
else currModule.addNet(currNet);
state = ParserState.NET_TYPE;
break;
case NET_TYPE:
if(token.equals(COMMA) || token.equals(WIRE)){
currNet.setType(NetType.WIRE);
}
else if(token.equals(CFG)){
state = ParserState.ATTRIBUTE;
break;
}
else if(token.equals(GND) || token.equals(GROUND)){
currNet.setType(NetType.GND);
}
else if(token.equals(VCC) || token.equals(POWER)){
currNet.setType(NetType.VCC);
}
else if(token.equals(INPIN)){
currPin = new Pin();
currPin.setIsOutputPin(false);
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
break;
}
else if(token.equals(OUTPIN)){
currPin = new Pin();
currPin.setIsOutputPin(true);
if(currNet.getSource() != null){
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", The net " +
currNet.getName() + " has two or more outpins (line " +
lineNumber + ")");
}
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
break;
}
else if(token.equals(INOUT)){
currPin = new Pin();
currPin.setPinType(PinType.INOUT);
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
break;
}
else{
expect("wire, vcc or power, gnd or ground or ,",token, ParserState.NET_TYPE);
}
state = ParserState.NET_STATEMENT;
break;
case NET_STATEMENT:
if(token.equals(PIP)){
currPIP = new PIP();
currNet.addPIP(currPIP);
state = ParserState.PIP_TILE;
}
else if(token.equals(INPIN)){
currPin = new Pin();
currPin.setIsOutputPin(false);
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
}
else if(token.equals(OUTPIN)){
currPin = new Pin();
currPin.setIsOutputPin(true);
if(currNet.getSource() != null){
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", The net " +
currNet.getName() + " has two or more outpins (line " +
lineNumber + ")");
}
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
}
else if(token.equals(INOUT)){
currPin = new Pin();
currPin.setPinType(PinType.INOUT);
currNet.addPin(currPin);
state = ParserState.PIN_INSTANCE_NAME;
break;
}
else if(token.equals(SEMICOLON)){
state = ParserState.XDL_STATEMENT;
}
else if(token.equals(CFG)){
state = ParserState.ATTRIBUTE;
}
break;
case PIN_INSTANCE_NAME:
Instance inst;
if(currModule == null) inst = design.getInstance(token);
else inst = currModule.getInstance(token);
if(inst == null){
MessageGenerator.briefErrorAndExit("ERROR: Could not find instance " +
token + " on line " + lineNumber);
}
currPin.setInstance(inst);
inst.addToNetList(currNet);
state = ParserState.PIN_NAME;
break;
case PIN_NAME:
currPin.setPinName(pool.getUnique(token));
currPin.getInstance().addPin(currPin);
if(currModule != null){
modPinMap.put(currPin.getInstanceName() + currPin.getName(), currPin);
}
state = ParserState.NET_STATEMENT;
break;
case PIP_TILE:
Tile pipTile = dev.getTile(token);
if(pipTile == null){
MessageGenerator.briefErrorAndExit("Invalid tile " +
token + " on line " + lineNumber);
}
currPIP.setTile(pipTile);
state = ParserState.PIP_WIRE0;
break;
case PIP_WIRE0:
int wire0 = we.getWireEnum(token);
if(wire0 == -1) {
MessageGenerator.briefErrorAndExit("ERROR: Invalid wire: " +
token + " found on line " + lineNumber);
}
currPIP.setStartWire(wire0);
state = ParserState.PIP_CONN_TYPE;
break;
case PIP_CONN_TYPE:
if(token.equals(PIP0) || token.equals(PIP1) || token.equals(PIP2) || token.equals(PIP3)){
state = ParserState.PIP_WIRE1;
}
else{
expect("->, =-, ==, or =>", token, ParserState.PIP_CONN_TYPE);
}
break;
case PIP_WIRE1:
int wire1 = we.getWireEnum(token);
if(wire1 == -1) {
MessageGenerator.briefErrorAndExit("XDL Design Parser Error in file: "+ fileName +", Invalid wire: " +
token + " found on line " + lineNumber);
}
currPIP.setEndWire(wire1);
state = ParserState.NET_STATEMENT;
break;
case MODULE_NAME:
currModule.setName(pool.getUnique(token));
state = ParserState.MODULE_ANCHOR_NAME;
break;
case MODULE_ANCHOR_NAME:
currModuleAnchorName = pool.getUnique(token);
state = ParserState.CFG_STRING;
break;
case MODULE_STATEMENT:
if(token.equals(PORT)){
state = ParserState.PORT_NAME;
}
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;