void write_asm(void) { entity *list = NULL; tree *current = NULL; write_header(); write_startup(); write_declarations(); write_externs(); /* write out all the source */ list = state.list; while (list != NULL) { current = list->node; switch(current->tag) { case node_decl: /* do nothing */ break; case node_func: write_procedure(current, 1); break; case node_proc: write_procedure(current, 0); break; default: assert(0); } list = list->next; } write_footer(); }
int main(int argc, char *argv[]) { int ret = 0; if (argc != 5) { printf( "ARM ELF relocation fixer\n" "Usage: %s inputelf inputbinary outputfile /path/to/startup.bin\n" ,argv[0]); return 0; } int fd = open(argv[1],O_RDONLY); if (fd < 0) { printf("%s: Unable to open \"%s\"\n", argv[0], argv[1]); goto error; } FILE *startup = NULL, *inbin = NULL, *out = NULL; if ( !(inbin = fopen(argv[2],"rb")) ) { printf("%s: Unable to open \"%s\"\n", argv[0], argv[2]); goto error; } if ( !(out = fopen(argv[3],"wb")) ) { printf("%s: Unable to open \"%s\"\n", argv[0], argv[3]); goto error; } if ( !(startup = fopen(argv[4],"rb")) ) { printf("%s: Unable to open \"%s\"\n", argv[0], argv[4]); goto error; } uint32_t count; uint32_t * offsets = elf_get_offsets(fd, &count); if (!offsets) { printf("%s: Unable to parse ELF file \"%s\"\n", argv[0], argv[1]); goto error; } write_startup(startup, out); write_offsets(offsets, count, out); write_exe(inbin, out); free(offsets); goto success; error: ret = -1; success: if (fd >= 0) close(fd); fclose(startup); fclose(out); fclose(inbin); return ret; }