From 73e4806e650b80b7a3b3f970fbc132c2090cff5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 5 Mar 2019 20:14:07 +0100 Subject: [PATCH] Implenment child cell resolve checker --- gds-parser/gds-tree-checker.c | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/gds-parser/gds-tree-checker.c b/gds-parser/gds-tree-checker.c index 7833ec0..e848219 100644 --- a/gds-parser/gds-tree-checker.c +++ b/gds-parser/gds-tree-checker.c @@ -34,10 +34,53 @@ */ #include "gds-tree-checker.h" +#include int gds_tree_check_cell_references(struct gds_library *lib) { - return 0; + GList *cell_iter; + struct gds_cell *cell; + GList *instance_iter; + struct gds_cell_instance *cell_inst; + int total_unresolved_count = 0; + + if (!lib) + return -1; + + /* Iterate over all cells in library */ + for (cell_iter = lib->cells; cell_iter != NULL; cell_iter = g_list_next(cell_iter)) { + cell = (struct gds_cell *)cell_iter->data; + + /* Check if this list element is broken. This should never happen */ + if (!cell) { + fprintf(stderr, "Broken cell list item found. Will continue.\n"); + continue; + } + + /* Reset the unresolved cell reference counter to 0 */ + cell->checks.unresolved_child_count = 0; + + /* Iterate through all child cell references and check if the references are set */ + for (instance_iter = cell->child_cells; instance_iter != NULL; + instance_iter = g_list_next(instance_iter)) { + cell_inst = (struct gds_cell_instance *)instance_iter->data; + + /* Check if broken. This should also not happen */ + if (!cell_inst) { + fprintf(stderr, "Broken cell list item found in cell %s. Will continue.\n", + cell->name); + continue; + } + + /* Check if instance is valid; else increment "error" counter of cell */ + if (!cell_inst->cell_ref) { + total_unresolved_count++; + cell->checks.unresolved_child_count++; + } + } + } + + return total_unresolved_count; } int gds_tree_check_reference_loops(struct gds_library *lib)