static tree build_trivial_high_gimple_function () { /* Construct a trivial function, and gimplify it: */ tree fndecl = build_trivial_generic_function (); gimplify_function_tree (fndecl); return fndecl; }
void java_genericize (tree fndecl) { dump_java_tree (TDI_original, fndecl); /* Genericize with the gimplifier. */ gimplify_function_tree (fndecl); dump_function (TDI_generic, fndecl); }
static tree build_junk_fn(unsigned id) { char fnname[32] = {0}; tree decl, resdecl, initial, proto; /* Func decl */ snprintf(fnname, 31, "__func%d", id); proto = build_varargs_function_type_list(void_type_node, NULL_TREE); decl = build_fn_decl(fnname, proto); SET_DECL_ASSEMBLER_NAME(decl, get_identifier(fnname)); printf(TAG "Creating junk function: %s\n", fnname); /* Result */ resdecl=build_decl(BUILTINS_LOCATION,RESULT_DECL,NULL_TREE,void_type_node); DECL_ARTIFICIAL(resdecl) = 1; DECL_CONTEXT(resdecl) = decl; DECL_RESULT(decl) = resdecl; /* Initial */ initial = make_node(BLOCK); TREE_USED(initial) = 1; DECL_INITIAL(decl) = initial; DECL_UNINLINABLE(decl) = 1; DECL_EXTERNAL(decl) = 0; DECL_PRESERVE_P(decl) = 1; /* Func decl */ TREE_USED(decl) = 1; TREE_PUBLIC(decl) = 1; TREE_STATIC(decl) = 1; DECL_ARTIFICIAL(decl) = 1; /* Make the function */ push_struct_function(decl); /* DECL_SAVED_TREE(decl) = gen_junk(); */ cfun->function_end_locus = BUILTINS_LOCATION; gimplify_function_tree(decl); /* Update */ cgraph_add_new_function(decl, false); cgraph_mark_needed_node(cgraph_node(decl)); current_function_decl = NULL_TREE; pop_cfun(); return decl; }
/* 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 }
void c_genericize (tree fndecl) { FILE *dump_file; int local_dump_flags; struct cgraph_node *cgn; /* Dump the C-specific tree IR. */ dump_file = dump_begin (TDI_original, &local_dump_flags); if (dump_file) { fprintf (dump_file, "\n;; Function %s", lang_hooks.decl_printable_name (fndecl, 2)); fprintf (dump_file, " (%s)\n", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))); fprintf (dump_file, ";; enabled by -%s\n", dump_flag_name (TDI_original)); fprintf (dump_file, "\n"); if (local_dump_flags & TDF_RAW) dump_node (DECL_SAVED_TREE (fndecl), TDF_SLIM | local_dump_flags, dump_file); else print_c_tree (dump_file, DECL_SAVED_TREE (fndecl)); fprintf (dump_file, "\n"); dump_end (TDI_original, dump_file); } /* Go ahead and gimplify for now. */ push_context (); gimplify_function_tree (fndecl); pop_context (); /* Dump the genericized tree IR. */ dump_function (TDI_generic, fndecl); /* Genericize all nested functions now. We do things in this order so that items like VLA sizes are expanded properly in the context of the correct function. */ cgn = cgraph_node (fndecl); for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) c_genericize (cgn->decl); }
static void test_gimplification () { tree fndecl = build_trivial_generic_function (); /* Convert to gimple: */ gimplify_function_tree (fndecl); /* Verify that we got gimple out of it. */ /* The function is now in GIMPLE form but the CFG has not been built yet. */ /* We should have a struct function for the decl. */ function *fun = DECL_STRUCT_FUNCTION (fndecl); ASSERT_TRUE (fun != NULL); ASSERT_EQ (fndecl, fun->decl); /* We expect a GIMPLE_BIND, with two gimple statements within it: tmp = 42; return tmp; */ gimple_seq seq_fn_body = gimple_body (fndecl); ASSERT_TRUE (seq_fn_body != NULL); gimple *bind_stmt = gimple_seq_first_stmt (seq_fn_body); ASSERT_EQ (GIMPLE_BIND, gimple_code (bind_stmt)); ASSERT_EQ (NULL, bind_stmt->next); gimple_seq seq_bind_body = gimple_bind_body (as_a <gbind *> (bind_stmt)); /* Verify that we have the 2 statements we expect. */ ASSERT_TRUE (seq_bind_body != NULL); gimple *stmt1 = gimple_seq_first_stmt (seq_bind_body); ASSERT_TRUE (stmt1 != NULL); ASSERT_EQ (GIMPLE_ASSIGN, gimple_code (stmt1)); gimple *stmt2 = stmt1->next; ASSERT_TRUE (stmt2 != NULL); ASSERT_EQ (stmt1, stmt2->prev); ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt2)); }