Пример #1
0
/* parsing language hook */
static void slang_parse_file ()
{

    int i;
    for(i = 0; i<num_in_fnames; ++i) {
        parse_program(in_fnames[i]);
    } 
#if 0
  tree  char_p = build_pointer_type (char_type_node);
  tree  puts_type   = build_function_type_list (integer_type_node,
						char_p, NULL_TREE);
  tree  puts_fndecl = build_function_decl ("puts", true, puts_type);

  tree  main_type   = build_function_type_list (integer_type_node, NULL_TREE);
  tree  main_fndecl = build_function_decl ("main", false, main_type);

  const char *msg = "HelloWorld , ... This is pradeeps compiler";
  tree hello_str = build_string_literal (strlen(msg) + 1, msg);

  tree  call = build_call_expr (puts_fndecl,1, hello_str);
  tree block = make_node(BLOCK);
  tree       c1 = build_pointer_type (char_type_node);
  tree stmts = NULL_TREE ;//alloc_stmt_list ();
  append_to_statement_list (call, &stmts);

  build_function (main_fndecl, stmts, block);

  FILE *fd = fopen("/home/pradeep/Desktop/dump.txt","w");


  gimplify_function_tree (main_fndecl);

  dump_function_to_file (main_fndecl, fd, 0);

  fclose(fd);

  cgraph_finalize_function (main_fndecl, false);

  current_function_decl = NULL_TREE;
  pop_cfun();
#endif

}
Пример #2
0
static unsigned int
execute_trace ()
{
    gimple_seq body, body_bind_body, inner_cleanup, outer_cleanup;
    gimple inner_try, outer_try;
    tree record_type, func_start_decl, func_end_decl, var_decl,
         function_name_decl, constructor_clobber;
    gimple call_func_start;
    gimple_stmt_iterator gsi;

    // build record type
    record_type = build_type ();
    // build start & end function decl
    func_start_decl = build_function_decl ("__start_ctrace__", record_type);
    func_end_decl = build_function_decl ("__end_ctrace__", record_type);
    // init variables of current body
    body = gimple_body (current_function_decl);

    var_decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
                           get_identifier ("__ctrace_var__"), record_type);
    DECL_CONTEXT (var_decl) = current_function_decl;
    TREE_ADDRESSABLE (var_decl) = 1;
    declare_vars (var_decl, body, false);
    TREE_USED (var_decl) = 1;
    // mimic __FUNCTION__ builtin.
    function_name_decl = make_fname_decl ();
    declare_vars (function_name_decl, body, false);
    // construct inner try
    // init calls
    call_func_start = gimple_build_call (
                          func_start_decl, 2,
                          build1 (ADDR_EXPR, build_pointer_type (record_type), var_decl),
                          build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (function_name_decl)),
                                  function_name_decl));
    // make inner clean up
    inner_cleanup = gimple_build_call (
                        func_end_decl, 2,
                        build1 (ADDR_EXPR, build_pointer_type (record_type), var_decl),
                        build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (function_name_decl)),
                                function_name_decl));
    // update inner try
    body_bind_body = gimple_bind_body (body);
    inner_try
        = gimple_build_try (body_bind_body, inner_cleanup, GIMPLE_TRY_FINALLY);
    gsi = gsi_start (inner_try);
    gsi_insert_before (&gsi, call_func_start, GSI_NEW_STMT);
    // construct outer try
    constructor_clobber = make_node (CONSTRUCTOR);
    TREE_THIS_VOLATILE (constructor_clobber) = 1;
    TREE_TYPE (constructor_clobber) = TREE_TYPE (var_decl);
    outer_cleanup = gimple_build_assign (var_decl, constructor_clobber);
    // update outer try
    outer_try
        = gimple_build_try (call_func_start, outer_cleanup, GIMPLE_TRY_FINALLY);
    // update body bind body
    gimple_bind_set_body (body, outer_try);
    if (dump_file)
    {
        dump_function_to_file (current_function_decl, dump_file,
                               TDF_TREE | TDF_BLOCKS | TDF_VERBOSE);
    }
    // exit (0);
    return 0;
}