4 * Compile when BACK_END_IS_CP_FIRM_BE is defined
6 * (C) 2005 Michael Beck beck@ipd.info.uni-karlsruhe.de
13 #include <libfirm/dbginfo.h>
14 #include <libfirm/adt/xmalloc.h>
15 #include <libfirm/be.h>
21 #include "firm_codegen.h"
22 #include "firm_cmdline.h"
24 #include "firm_timing.h"
27 * Substitutes '.c' for '.s'.
29 static char *generate_asm_file_name(const char *file_name) {
30 int len = strlen(file_name);
31 char *asm_file_name = xmalloc(len + 5); /* .asm + \0 */
33 strcpy(asm_file_name, file_name);
34 if (asm_file_name[len - 2] == '.' && asm_file_name[len - 1] == 'c')
35 asm_file_name[len - 2] = '\0';
37 switch (firm_be_opt.selection) {
40 strncat(asm_file_name, ".s.c", 4);
46 strncat(asm_file_name, ".s", 4);
52 } /* generate_asm_file_name */
55 * Calls the specified backend.
56 * Code is written to file <file_name> ('.c' is substituted for '.asm')
58 void do_codegen(FILE *out, const char *file_name) {
59 FILE *close_out = NULL;
61 char *asm_file_name = generate_asm_file_name(file_name);
63 if ((out = fopen(asm_file_name, "w")) == NULL) {
64 fprintf(stderr, "Could not open output file %s\n", asm_file_name);
71 switch (firm_be_opt.selection) {
74 timer_push(TV_FIRM2C_BE);
75 cbackend_set_debug_retrieve(dbg_retrieve);
76 generate_code_file(out);
83 timer_push(TV_FIRM_BE);
84 ir_set_debug_retrieve(dbg_retrieve);
85 be_main(out, file_name);
91 fprintf(stderr, "Fatal: Unknown backend %d\n", firm_be_opt.selection);
92 } /* switch (firm_be_opt.selection) */