61 lines
1.0 KiB
C
61 lines
1.0 KiB
C
#include "fpga_fdef_loader.h"
|
|
#include <stdio.h>
|
|
|
|
struct fpga_cell *fpga_fdef_loader_load(char *filename)
|
|
{
|
|
FILE *fdef;
|
|
int c;
|
|
int line = 1;
|
|
int col = 1;
|
|
|
|
struct fpga_cell *cell_left = NULL;
|
|
struct fpga_cell *cell_top = NULL;
|
|
struct fpga_cell *cell = NULL;
|
|
|
|
report(LL_INFO, "Loading FDEF from %s...", filename);
|
|
|
|
fdef = fopen(filename, "r");
|
|
|
|
if (!fdef)
|
|
return NULL;
|
|
|
|
while ((c = fgetc(fdef)) != EOF) {
|
|
switch (c) {
|
|
case '\n':
|
|
col = 0;
|
|
line++;
|
|
break;
|
|
|
|
default:
|
|
cell = fpga_cell_new((char) c);
|
|
if (!cell) {
|
|
/* TODO: clean up existing cells */
|
|
return NULL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (c == '\n') {
|
|
cell_left = NULL;
|
|
cell_top = fpga_cell_get_far(cell, LEFT);
|
|
report(LL_DEBUG, "");
|
|
|
|
} else {
|
|
if (cell_left)
|
|
fpga_cell_connect(cell, cell_left, RIGHT);
|
|
if (cell_top)
|
|
fpga_cell_connect(cell, cell_top, BOTTOM);
|
|
|
|
cell_left = cell;
|
|
if (cell_top)
|
|
cell_top = cell_top->cell_connections[RIGHT];
|
|
}
|
|
|
|
col++;
|
|
}
|
|
|
|
fclose(fdef);
|
|
|
|
return fpga_cell_get_far(fpga_cell_get_far(cell, LEFT), TOP);
|
|
}
|