Example #1
0
File: opt.c Project: chiggs/nvc
void opt(tree_t top)
{
   if (tree_kind(top) == T_ELAB)
      opt_delete_wait_only(top);

   tree_visit(top, opt_tag, NULL);
}
Example #2
0
File: cover.c Project: a4a881d4/nvc
void cover_tag(tree_t top)
{
   stmt_tag_i = ident_new("stmt_tag");

   int line_tags = 0;
   tree_visit(top, cover_tag_stmts_fn, &line_tags);

   tree_add_attr_int(top, ident_new("stmt_tags"), line_tags);
}
Example #3
0
File: group.c Project: nickg/nvc
void group_nets(tree_t top)
{
   const int nnets = tree_attr_int(top, nnets_i, 0);

   group_nets_ctx_t ctx;
   group_init_context(&ctx, nnets);
   tree_visit(top, group_nets_visit_fn, &ctx);

   group_write_netdb(top, &ctx);

   if (opt_get_int("verbose")) {
      int ngroups = 0;
      for (group_t *it = ctx.groups; it != NULL; it = it->next)
         ngroups++;

      notef("%d nets, %d groups", nnets, ngroups);
      notef("nets:groups ratio %.3f", (float)nnets / (float)ngroups);
   }

   group_free_list(ctx.groups);
   group_free_list(ctx.free_list);
   free(ctx.lookup);
}
Example #4
0
File: cover.c Project: a4a881d4/nvc
void cover_report(tree_t top, const int32_t *stmts)
{
   stmt_tag_i = ident_new("stmt_tag");

   tree_visit(top, cover_report_stmts_fn, (void *)stmts);

   ident_t name = ident_strip(tree_ident(top), ident_new(".elab"));

   char dir[256];
   snprintf(dir, sizeof(dir), "%s.cover", istr(name));

   lib_t work = lib_work();
   lib_mkdir(work, dir);

   for (cover_file_t *f = files; f != NULL; f = f->next)
      cover_report_file(f, dir);

   cover_index(name, dir);

   char output[PATH_MAX];
   lib_realpath(work, dir, output, sizeof(output));
   notef("coverage report generated in %s/", output);
}
Example #5
0
int main(int argc, char **argv)
{
    int i, next_int;
    int num_threads;
    int *int_arr;
    FILE* f;
    char *fname;
    int arr_space = 1024 * 100; //100kb by default

    int option_balanced = 0;
    int keyword_start_index = 1;

    //Check args for -h flag, print help and exit if found.
    for(i = 1; i < argc; i++) {
        if( strcmp(argv[i], "-h") == 0) {
            printf("\n");
            printHelp();
            exit(0);
        }
        if( strcmp(argv[i], "-b") == 0) {
            option_balanced = 1;
            keyword_start_index = i+1;
        }
    }

    //Debug args
    /*printf("keyword index = %d\n", keyword_start_index);
    printf("argc - keyword index = %d\n", argc - keyword_start_index);
    for(i = 0; i < argc; i++){
        printf("argv[%d] = %s\n", i, argv[i]);
    }*/

    if((argc - keyword_start_index) != 3) {
        printArgError();
        printUsage();
        exit(1);
    }

    //Set search values
    fname = argv[keyword_start_index];
    search_val = atoi(argv[keyword_start_index+1]);
    num_threads = atoi(argv[keyword_start_index+2]);

    if(num_threads < 0 || num_threads > DFS_THREAD_MAX) {
        printArgError();
        printf(PROGNAME ": error: number of threads must nonnegative"
               " and less than or equal to %d\n", DFS_THREAD_MAX);
        printUsage();
        exit(1);
    }



    //------------- Read in data file ----------------

    //Open file.
    if((f = fopen(fname, "r")) == NULL) {
        perror(PROGNAME ": error: problem opening file");
        exit(1);
    }

    //Allocate initial array for the values.
    int_arr = (int*)malloc(sizeof(int) * arr_space);
    if(int_arr == NULL) {
        perror(PROGNAME ": error: error allocating memory");
        exit(1);
    }

    //Scan to get values, growing array if needed.
    fseek(f, 0, SEEK_SET);
    for(i = 0; (fscanf(f,"%d", &next_int) != EOF); i++) {
        if(i == arr_space) {
            arr_space *= 2;
            int_arr = (int*)realloc(int_arr, sizeof(int) * arr_space);
            if(int_arr == NULL) {
                perror(PROGNAME ": error: error reallocating memory for array");
                exit(1);
            }
        }
        int_arr[i] = next_int;
    }
    fclose(f);

    if(i == 0) {
        fprintf(stderr, PROGNAME ": error: no values to process!\n");
        exit(1);
    }

    DFS_TREE_SIZE = i;


    //------------- Build Tree -------------------

    tree *t;
    if(option_balanced) {
        prog_debug(1, PROGNAME ": building balanced tree from input values\n");
        t = makeBalancedTreeFromArray(int_arr[0], int_arr, DFS_TREE_SIZE);
    } else {
        prog_debug(1, PROGNAME ": building random tree from input values\n");
        t = makeRandomTreeFromArray(int_arr[0], int_arr, DFS_TREE_SIZE);
    }


    //tree_print(t, stdout);
    //Print tree using function pointer scheme. Left as an example of
    //how to use tree_visit.
    if(DFS_DEBUG_TREE > 0) {
        treenode_func func = printNode;
        tree_visit(t, func, (void *)stdout);
    }



    //--------------- Search The Tree -----------------

    //Single DFS search using a pointer to the findVal function. For fun.
    //func = findVal;
    //tree_visit(t, func, (void *)&search_val);

    //Call the threaded search algorithm.
    if(num_threads == 0) {
        for(num_threads = 1; num_threads <= DFS_THREAD_MAX; num_threads *= 2) {
            prog_debug(1, PROGNAME ": starting search_tree_for_val...\n");
            search_tree_for_val(t, num_threads, search_val);
        }
    } else {
        prog_debug(1, PROGNAME ": starting search_tree_for_val...\n");
        search_tree_for_val(t, num_threads, search_val);
    }


    return 0;
}