file: read.cc
/* VLSI CAD Project 3 */
/* Placement Tool */
/* Recursive MinCut */
/* Fall 2000 Anno Domini */
/* Written by Suraj Sudhir */
/* ssudhir@ece.cmu.edu */
#include "main.h"
//read the netlist file
void readNetList(FILE *NetFile)
{
int i,j;
int junk;
fscanf(NetFile,"%d %d %d %d\n", &ChipX, &ChipY, &GatesInSite, &PinsInSite);
fscanf(NetFile,"%f %f\n",&K1, &K2);
fscanf(NetFile,"%d %d\n", &NumGates, &NumNets);
//gate information
GateArr = (gateList *)malloc(sizeof(gateList) * NumGates);
if (!GateArr)
{
cout << "FATAL: error allocating GateArr" << endl;
exit(1);
}
//gate X position
gateX = (int *)malloc(sizeof(int) * NumGates);
{
if (!gateX)
{
cout << "FATAL: error allocation gateX" << endl;
exit(1);
}
}
//gate Y position
gateY = (int *)malloc(sizeof(int) * NumGates);
{
if (!gateY)
{
cout << "FATAL: error allocation gateY" << endl;
exit(1);
}
}
//vertical cut X positions
tempX1 = (int *)malloc(sizeof(int) * NumGates);
{
if (!tempX1)
{
cout << "FATAL: error allocation tempX1" << endl;
exit(1);
}
}
//vertical cut Y positions.
tempY1 = (int *)malloc(sizeof(int) * NumGates);
{
if (!tempY1)
{
cout << "FATAL: error allocation tempY1" << endl;
exit(1);
}
}
//horizontal cut X positions
tempX2 = (int *)malloc(sizeof(int) * NumGates);
{
if (!tempX2)
{
cout << "FATAL: error allocation tempX2" << endl;
exit(1);
}
}
//horizontal cut Y positions
tempY2 = (int *)malloc(sizeof(int) * NumGates);
{
if (!tempY2)
{
cout << "FATAL: error allocation tempY2" << endl;
exit(1);
}
}
//net information
NetArr = (netList *)malloc(sizeof(netList) * NumNets);
if (!NetArr)
{
cout << "FATAL: error allocating NetArr" << endl;
exit(1);
}
//netlength information
netLen = (double *)malloc(sizeof(double) * NumNets);
if (!netLen)
{
cout << "FATAL: error allocating netLen" << endl;
exit(1);
}
//gates/net
GatesPerNet = (int *)malloc(sizeof(int) * NumNets);
if (!GatesPerNet)
{
cout << "FATAL: error allocating GatesPerNet" << endl;
exit(1);
}
//pads/net
PadsPerNet = (int *)malloc(sizeof(int) * NumNets);
if (!PadsPerNet)
{
cout << "FATAL: error allocating PadsPerNet" << endl;
exit(1);
}
//pad information
PadArr = (padList *)malloc(sizeof(padList) * NumNets);
if (!PadArr)
{
cout << "FATAL: error allocating PadArr" << endl;
exit(1);
}
//vertical cut partition information
tempPart1 = (int *)malloc(sizeof(int)*NumGates);
if (!tempPart1)
{
cout << "FATAL: error allocating tempPart1" << endl;
exit(1);
}
//horizontal cut partition information
tempPart2 = (int *)malloc(sizeof(int)*NumGates);
if (!tempPart2)
{
cout << "FATAL: error allocating tempPart2" << endl;
exit(1);
}
//final partition information
gatePart = (int *)malloc(sizeof(int)*NumGates);
if (!gatePart)
{
cout << "FATAL: error allocating gatePart" << endl;
exit(1);
}
//net delay information
netDelay = (double *)malloc(sizeof(double) * NumNets);
if (!netDelay)
{
cout << "FATAL: error allocating netDelay" << endl;
exit(1);
}
//initialize everything
initNetList();
//read gate info
for(i=0;i<NumGates;i++)
{
fscanf(NetFile, "%d %d ", &junk, &GateArr[i].netsOnGate);
GateArr[i].List = (int *)malloc(sizeof(int)*GateArr[i].netsOnGate);
for(j=0;j<GateArr[i].netsOnGate;j++)
{
fscanf(NetFile, "%d", &GateArr[i].List[j]);
/* add gate j to list of this net */
addToList(GateArr[i].List[j]-1, i, GATE);
GatesPerNet[GateArr[i].List[j]-1]++;
}
}
fscanf(NetFile, "%d\n", &NumPinsConnNets );
PinConnList = (pinList *)malloc(sizeof(pinList) * NumPinsConnNets);
//read pin info
for(i=0;i<NumPinsConnNets;i++)
{
fscanf(NetFile,"%d %d\n", &junk, &PinConnList[i].NetID );
PadsPerNet[PinConnList[i].NetID-1]++;
addToList(PinConnList[i].NetID-1, i+1, PIN);
if ( PadArr[PinConnList[i].NetID-1].PadID == -1 )
{
PadArr[PinConnList[i].NetID-1].PadID = i+1;
PadArr[PinConnList[i].NetID-1].next = NULL;
}
else
{
padList *pToEnd = &PadArr[PinConnList[i].NetID-1];
padList *pTemp = (padList *)malloc(sizeof(padList));
pTemp->PadID = i+1;
pTemp->next = NULL;
while( pToEnd->next != NULL )
{
pToEnd = pToEnd->next;
}
pToEnd->next = pTemp;
}
}
//read timing path info
fscanf(NetFile, "%d\n", &NumTimingPaths);
TimingPaths = (timingList *)malloc(sizeof(timingList) * NumTimingPaths);
for(i=0;i<NumTimingPaths;i++)
{
fscanf(NetFile,"%d %d", &junk, &TimingPaths[i].NumObjects);
TimingPaths[i].List = (int *)malloc(sizeof(int) * TimingPaths[i].NumObjects);
for(j=0;j<TimingPaths[i].NumObjects;j++)
{
fscanf(NetFile, "%d", &TimingPaths[i].List[j]);
}
}
}
//read the pin file
void readPinFile(FILE *PinFile)
{
int i;
int junk;
fscanf(PinFile,"%d\n", &junk);
for(i=0;i<NumPinsConnNets;i++)
{
fscanf(PinFile,"%d %d %d\n", &junk, &PinConnList[i].xSite, &PinConnList[i].ySite );
}
fclose(PinFile);
}
//add gateID to the linked list of the net
void addToList (int Net, int Gate, int Type)
{
if (NetArr[Net].GateID == -1)
{
/* none in this list as yet */
NetArr[Net].GateID = Gate;
NetArr[Net].Type = Type;
}
else
{
/* already there.. add at end */
netList *NewNode = (netList *)malloc(sizeof(netList));
NewNode->GateID = Gate;
NewNode->Type = Type;
NewNode->next = NULL;
netList *Temp = (NetArr + Net);
while ( (Temp->next != NULL) && (Temp->GateID != Gate))
Temp = Temp->next;
if (Temp->next != NULL)
return;
Temp->next = NewNode;
}
}
//initialize all the structures
void initNetList()
{
int i;
int x,y;
for(i=0;i<NumNets;i++)
{
NetArr[i].GateID = -1;
NetArr[i].next = NULL;
GatesPerNet[i] = 0;
PadsPerNet[i] = 0;
PadArr[i].PadID = -1;
PadArr[i].next = NULL;
}
x = 1, y = 1;
for(i=0;i<NumGates;i++)
{
gatePart[i] = 0;
//assume pin row/col is always width 1...
if ( InitScheme == DISTRIBUTE )
{
tempX1[i] = x;
tempY1[i] = y;
}
else if ( InitScheme == START )
{
tempX1[i] = 1;
tempY1[i] = 1;
}
else if ( InitScheme == CENTER )
{
tempX1[i] = ChipX/2;
tempY1[i] = ChipY/2;
}
else
{
tempX1[i] = ChipX-2;
tempY1[i] = ChipY-2;
}
y++;
if ( y > (ChipY-2) )
{
y = 1;
x++;
if ( x > (ChipX-2) )
x = 1;
}
gateX[i] = tempX1[i];
gateY[i] = tempY1[i];
}
}
C++ to HTML Conversion by ctoohtml