parser
This commit is contained in:
parent
a1196e11b8
commit
bc28446ce4
121
gdsparse.c
121
gdsparse.c
@ -16,18 +16,60 @@ enum record {
|
|||||||
BGNSTR = 0x0502,
|
BGNSTR = 0x0502,
|
||||||
STRNAME = 0x0606,
|
STRNAME = 0x0606,
|
||||||
ENDSTR = 0x0700,
|
ENDSTR = 0x0700,
|
||||||
|
BOUNDARY = 0x0800,
|
||||||
|
PATH = 0x0900,
|
||||||
|
SREF = 0x0A00,
|
||||||
|
ENDEL = 0x1100
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct gds_library * append_library(struct gds_library *curr_arr, unsigned int curr_count)
|
static struct gds_library * append_library(struct gds_library *curr_arr, unsigned int curr_count)
|
||||||
{
|
{
|
||||||
unsigned int size = (curr_count +1) * sizeof(struct gds_library);
|
unsigned int size = (curr_count +1) * sizeof(struct gds_library);
|
||||||
return (struct gds_library *)realloc(curr_arr, size);
|
struct gds_library *ptr = (struct gds_library *)realloc(curr_arr, size);
|
||||||
|
if (ptr) {
|
||||||
|
ptr[curr_count].cells_count = 0;
|
||||||
|
ptr[curr_count].name[0] = 0;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct gds_graphics * append_graphics(struct gds_graphics *curr_arr, unsigned int curr_count)
|
||||||
|
{
|
||||||
|
unsigned int size = (curr_count +1) * sizeof(struct gds_graphics);
|
||||||
|
struct gds_graphics *ptr = (struct gds_graphics *)realloc(curr_arr, size);
|
||||||
|
if (ptr != NULL) {
|
||||||
|
ptr[curr_count].vertices_count = 0;
|
||||||
|
ptr[curr_count].vertices = NULL;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct gds_cell * append_cell(struct gds_cell *curr_arr, unsigned int curr_count)
|
static struct gds_cell * append_cell(struct gds_cell *curr_arr, unsigned int curr_count)
|
||||||
{
|
{
|
||||||
unsigned int size = (curr_count +1) * sizeof(struct gds_cell);
|
unsigned int size = (curr_count +1) * sizeof(struct gds_cell);
|
||||||
return (struct gds_cell *)realloc(curr_arr, size);
|
struct gds_cell *ptr = (struct gds_cell *)realloc(curr_arr, size);
|
||||||
|
|
||||||
|
if (ptr != NULL) {
|
||||||
|
ptr[curr_count].child_cells_count = 0;
|
||||||
|
ptr[curr_count].graphic_objs_count = 0;
|
||||||
|
ptr[curr_count].child_cells = NULL;
|
||||||
|
ptr[curr_count].graphic_objs = NULL;
|
||||||
|
ptr[curr_count].name[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gds_cell_instance * append_cell_ref(struct gds_cell_instance* curr_arr, unsigned int curr_count)
|
||||||
|
{
|
||||||
|
unsigned int size = (curr_count + 1) * sizeof(struct gds_cell_instance);
|
||||||
|
struct gds_cell_instance *ptr = (struct gds_cell_instance *)realloc(curr_arr, size);
|
||||||
|
if (ptr) {
|
||||||
|
ptr[curr_count].cell_ref = NULL;
|
||||||
|
ptr[curr_count].ref_name[0] = 0;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int name_library(struct gds_library *current_library, unsigned int bytes, char* data) {
|
static int name_library(struct gds_library *current_library, unsigned int bytes, char* data) {
|
||||||
@ -169,6 +211,16 @@ int parse_gds_from_file(const char *filename, struct gds_library **library_array
|
|||||||
GDS_ERROR("Closing Library with no opened library");
|
GDS_ERROR("Closing Library with no opened library");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for open Cells */
|
||||||
|
if (current_cell != NULL) {
|
||||||
|
run = -4;
|
||||||
|
GDS_ERROR("Closing Library with opened cells");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_lib->cells = cell_arr;
|
||||||
|
current_lib->cells_count = cell_arr_cnt;
|
||||||
|
|
||||||
current_lib = NULL;
|
current_lib = NULL;
|
||||||
printf("Leaving Library\n");
|
printf("Leaving Library\n");
|
||||||
break;
|
break;
|
||||||
@ -190,9 +242,70 @@ int parse_gds_from_file(const char *filename, struct gds_library **library_array
|
|||||||
GDS_ERROR("Closing cell with no opened cell");
|
GDS_ERROR("Closing cell with no opened cell");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* Check for open Elements */
|
||||||
|
if (current_graphics != NULL || current_s_reference != NULL) {
|
||||||
|
run = -4;
|
||||||
|
GDS_ERROR("Closing cell with opened Elements");
|
||||||
|
break;
|
||||||
|
}
|
||||||
current_cell = NULL;
|
current_cell = NULL;
|
||||||
printf("Leaving Cell\n");
|
printf("Leaving Cell\n");
|
||||||
break;
|
break;
|
||||||
|
case BOUNDARY:
|
||||||
|
if (current_cell == NULL) {
|
||||||
|
GDS_ERROR("Boundary outside of cell");
|
||||||
|
run = -3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_cell->graphic_objs = append_graphics(current_cell->graphic_objs, current_cell->graphic_objs_count);
|
||||||
|
current_cell->graphic_objs_count++;
|
||||||
|
if (current_cell->graphic_objs == NULL) {
|
||||||
|
GDS_ERROR("Memory allocation failed");
|
||||||
|
run = -4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_graphics = &(current_cell->graphic_objs[current_cell->graphic_objs_count-1]);
|
||||||
|
current_graphics->type = GRAPHIC_POLYGON;
|
||||||
|
printf("\tEntering boundary\n");
|
||||||
|
break;
|
||||||
|
case SREF:
|
||||||
|
if (current_cell == NULL) {
|
||||||
|
GDS_ERROR("Path outside of cell");
|
||||||
|
run = -3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_cell->child_cells = append_cell_ref(current_cell->child_cells, current_cell->child_cells_count);
|
||||||
|
if (current_cell->child_cells == NULL) {
|
||||||
|
GDS_ERROR("Memory allocation failed");
|
||||||
|
run = -4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case PATH:
|
||||||
|
if (current_cell == NULL) {
|
||||||
|
GDS_ERROR("Path outside of cell");
|
||||||
|
run = -3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_cell->graphic_objs = append_graphics(current_cell->graphic_objs, current_cell->graphic_objs_count);
|
||||||
|
current_cell->graphic_objs_count++;
|
||||||
|
if (current_cell->graphic_objs == NULL) {
|
||||||
|
GDS_ERROR("Memory allocation failed");
|
||||||
|
run = -4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current_graphics = &(current_cell->graphic_objs[current_cell->graphic_objs_count-1]);
|
||||||
|
current_graphics->type = GRAPHIC_PATH;
|
||||||
|
printf("\tEntering Path\n");
|
||||||
|
break;
|
||||||
|
case ENDEL:
|
||||||
|
if (current_graphics != NULL) {
|
||||||
|
|
||||||
|
printf("\tLeaving %s\n", (current_graphics->type == GRAPHIC_POLYGON ? "boundary" : "path"));
|
||||||
|
current_graphics = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -225,6 +338,10 @@ int parse_gds_from_file(const char *filename, struct gds_library **library_array
|
|||||||
|
|
||||||
fclose(gds_file);
|
fclose(gds_file);
|
||||||
|
|
||||||
|
|
||||||
|
/* Iterate and find references to cells */
|
||||||
|
|
||||||
|
|
||||||
*library_array = lib_arr;
|
*library_array = lib_arr;
|
||||||
*count = lib_arr_cnt;
|
*count = lib_arr_cnt;
|
||||||
return run;
|
return run;
|
||||||
|
@ -24,6 +24,8 @@ struct gds_graphics {
|
|||||||
enum graphics_type type;
|
enum graphics_type type;
|
||||||
struct gds_point *vertices;
|
struct gds_point *vertices;
|
||||||
int vertices_count;
|
int vertices_count;
|
||||||
|
unsigned int path_width;
|
||||||
|
int width_absolute;
|
||||||
uint16_t layer;
|
uint16_t layer;
|
||||||
uint16_t datatype;
|
uint16_t datatype;
|
||||||
};
|
};
|
||||||
|
6
main.c
6
main.c
@ -5,7 +5,13 @@ int main()
|
|||||||
{
|
{
|
||||||
struct gds_library *libs;
|
struct gds_library *libs;
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
parse_gds_from_file("/home/mari/Desktop/test.gds", &libs, &count);
|
parse_gds_from_file("/home/mari/Desktop/test.gds", &libs, &count);
|
||||||
|
|
||||||
|
printf("Lib count: %u\n", count);
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
printf("Lib %s: %d cells\n", libs[i].name, libs[i].cells_count);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user