static unsigned int cyc_complexity_execute(void) { int complexity; expanded_location xloc; /* M = E - N + 2P */ complexity = n_edges_for_fn(cfun) - n_basic_blocks_for_fn(cfun) + 2; xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl)); fprintf(log_file, "%s%s:%d:%d:%s\t%d\n", has_log_file ? "" : "Cyclomatic Complexity ", xloc.file, xloc.line, xloc.column, DECL_NAME_POINTER(current_function_decl), complexity); return 0; }
void init_flow (struct function *the_fun) { if (!the_fun->cfg) the_fun->cfg = ggc_cleared_alloc<control_flow_graph> (); n_edges_for_fn (the_fun) = 0; ENTRY_BLOCK_PTR_FOR_FN (the_fun) = ggc_cleared_alloc<basic_block_def> (); ENTRY_BLOCK_PTR_FOR_FN (the_fun)->index = ENTRY_BLOCK; EXIT_BLOCK_PTR_FOR_FN (the_fun) = ggc_cleared_alloc<basic_block_def> (); EXIT_BLOCK_PTR_FOR_FN (the_fun)->index = EXIT_BLOCK; ENTRY_BLOCK_PTR_FOR_FN (the_fun)->next_bb = EXIT_BLOCK_PTR_FOR_FN (the_fun); EXIT_BLOCK_PTR_FOR_FN (the_fun)->prev_bb = ENTRY_BLOCK_PTR_FOR_FN (the_fun); }
void init_flow (struct function *the_fun) { if (!the_fun->cfg) the_fun->cfg = ggc_cleared_alloc<control_flow_graph> (); n_edges_for_fn (the_fun) = 0; the_fun->cfg->count_max = profile_count::uninitialized (); ENTRY_BLOCK_PTR_FOR_FN (the_fun) = alloc_block (); ENTRY_BLOCK_PTR_FOR_FN (the_fun)->index = ENTRY_BLOCK; EXIT_BLOCK_PTR_FOR_FN (the_fun) = alloc_block (); EXIT_BLOCK_PTR_FOR_FN (the_fun)->index = EXIT_BLOCK; ENTRY_BLOCK_PTR_FOR_FN (the_fun)->next_bb = EXIT_BLOCK_PTR_FOR_FN (the_fun); EXIT_BLOCK_PTR_FOR_FN (the_fun)->prev_bb = ENTRY_BLOCK_PTR_FOR_FN (the_fun); the_fun->cfg->edge_flags_allocated = EDGE_ALL_FLAGS; the_fun->cfg->bb_flags_allocated = BB_ALL_FLAGS; }
static void verify_three_block_cfg (function *fun) { ASSERT_TRUE (fun->cfg != NULL); ASSERT_EQ (3, n_basic_blocks_for_fn (fun)); ASSERT_EQ (2, n_edges_for_fn (fun)); /* The "fake" basic blocks. */ basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (fun); ASSERT_TRUE (entry != NULL); ASSERT_EQ (ENTRY_BLOCK, entry->index); basic_block exit = EXIT_BLOCK_PTR_FOR_FN (fun); ASSERT_TRUE (exit != NULL); ASSERT_EQ (EXIT_BLOCK, exit->index); /* The "real" basic block. */ basic_block bb2 = get_real_block (fun); ASSERT_TRUE (bb2 != NULL); ASSERT_EQ (2, bb2->index); /* Verify connectivity. */ ASSERT_EQ (NULL, entry->preds); ASSERT_EQ (1, entry->succs->length ()); edge from_entry_to_bb2 = (*entry->succs)[0]; ASSERT_EQ (entry, from_entry_to_bb2->src); ASSERT_EQ (bb2, from_entry_to_bb2->dest); ASSERT_EQ (1, bb2->preds->length ()); ASSERT_EQ (from_entry_to_bb2, (*bb2->preds)[0]); ASSERT_EQ (1, bb2->succs->length ()); edge from_bb2_to_exit = (*bb2->succs)[0]; ASSERT_EQ (bb2, from_bb2_to_exit->src); ASSERT_EQ (exit, from_bb2_to_exit->dest); ASSERT_EQ (1, exit->preds->length ()); ASSERT_EQ (from_bb2_to_exit, (*exit->preds)[0]); ASSERT_EQ (NULL, exit->succs); }
static void free_edge (function *fn, edge e) { n_edges_for_fn (fn)--; ggc_free (e); }
edge_iterator ei; FOR_EACH_BB_FN (bb, fn) { FOR_EACH_EDGE (e, ei, bb->succs) free_edge (fn, e); vec_safe_truncate (bb->succs, 0); vec_safe_truncate (bb->preds, 0); } FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fn)->succs) free_edge (fn, e); vec_safe_truncate (EXIT_BLOCK_PTR_FOR_FN (fn)->preds, 0); vec_safe_truncate (ENTRY_BLOCK_PTR_FOR_FN (fn)->succs, 0); gcc_assert (!n_edges_for_fn (fn)); } /* Allocate memory for basic_block. */ basic_block alloc_block (void) { basic_block bb; bb = ggc_cleared_alloc<basic_block_def> (); bb->count = profile_count::uninitialized (); return bb; } /* Link block B to chain after AFTER. */ void
static void free_edge (edge e) { n_edges_for_fn (cfun)--; ggc_free (e); }
edge_iterator ei; FOR_EACH_BB_FN (bb, cfun) { FOR_EACH_EDGE (e, ei, bb->succs) free_edge (e); vec_safe_truncate (bb->succs, 0); vec_safe_truncate (bb->preds, 0); } FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs) free_edge (e); vec_safe_truncate (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds, 0); vec_safe_truncate (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs, 0); gcc_assert (!n_edges_for_fn (cfun)); } /* Allocate memory for basic_block. */ basic_block alloc_block (void) { basic_block bb; bb = ggc_cleared_alloc<basic_block_def> (); return bb; } /* Link block B to chain after AFTER. */ void link_block (basic_block b, basic_block after)