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"
26 extern void be_main(FILE *f, const char *asm_file_name);
29 * Substitutes '.c' for '.s'.
31 static char *generate_asm_file_name(const char *file_name) {
32 int len = strlen(file_name);
33 char *asm_file_name = xmalloc(len + 5); /* .asm + \0 */
35 strcpy(asm_file_name, file_name);
36 if (asm_file_name[len - 2] == '.' && asm_file_name[len - 1] == 'c')
37 asm_file_name[len - 2] = '\0';
39 switch (firm_be_opt.selection) {
42 strncat(asm_file_name, ".s.c", 4);
48 strncat(asm_file_name, ".s", 4);
54 } /* generate_asm_file_name */
57 * Calls the specified backend.
58 * Code is written to file <file_name> ('.c' is substituted for '.asm')
60 void do_codegen(FILE *out, const char *file_name) {
61 FILE *close_out = NULL;
63 char *asm_file_name = generate_asm_file_name(file_name);
65 if ((out = fopen(asm_file_name, "w")) == NULL) {
66 fprintf(stderr, "Could not open output file %s\n", asm_file_name);
73 switch (firm_be_opt.selection) {
76 timer_push(TV_FIRM2C_BE);
77 cbackend_set_debug_retrieve(dbg_retrieve);
78 generate_code_file(out);
85 timer_push(TV_FIRM_BE);
86 ir_set_debug_retrieve(dbg_retrieve);
87 be_main(out, file_name);
93 fprintf(stderr, "Fatal: Unknown backend %d\n", firm_be_opt.selection);
94 } /* switch (firm_be_opt.selection) */