int module_dumpall(void) { MODULE *mod; int count=0; for (mod=first_module; mod!=NULL; mod=mod->next) { if (mod->export_file!=NULL) count += module_save(mod,NULL); } return count; }
int blue_main(int argc, char **argv){ int arg_index; int mode=0; char * filename = NULL; char * output_filename = NULL; /* Not enough arguments */ if (argc < 2 ) usage(); Global = malloc(sizeof(struct Global)); if ( ! Global){ printf("Out of Memory\n"); exit(1); } Global->dbg_status = 0; /* handle arguments to blue */ for (arg_index=1; arg_index<argc ; arg_index++){ if (argv[arg_index][0] == '-'){ /* disassemble and quit*/ if ( strcmp(argv[arg_index], "-d")==0 ) mode = 1; else if ( strcmp(argv[arg_index], "-c")==0 ) mode = 2; else if ( strcmp(argv[arg_index], "-g")==0 ) Global->dbg_status = 1; else if ( strcmp(argv[arg_index], "-o")==0 ){ arg_index++; output_filename = argv[arg_index]; } else if ( strcmp(argv[arg_index], "-s")==0 ){ mode = 3 ; } else if ( strcmp(argv[arg_index], "-a")==0 ){ mode = 4 ; } if (argc <3) return 0; }else{ filename = argv[arg_index]; break; } } /* Initialization routines */ global_init(); link_setThreadState(0); // turn multi-threading off until needed if (mode==1){ /* DISASSEMBLE */ Link module = create_module_filename(filename); string_t code = disassemble(module->value.module->bytecode); string_fprint(code , stdout); exit(0); } else if (mode == 2){ /* COMPILE */ Link module = create_module_filename(filename); module_save( module, output_filename ? output_filename : "blue.blx"); exit(0); }else if (mode == 3){ /* COMPILE TO ASSEMBLY CODE */ char * acode = compile_file( filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } if (output_filename){ FILE * fp = fopen( output_filename,"wb"); fprintf(fp,acode); fclose(fp); }else{ printf(acode); } free(acode); exit(0); }else if (mode == 4){ /* ASSEMBLE THS ASSEMBLY CODE TO BYTECODE */ char * acode = file_load(filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } Bytes bytes = assemble( acode ); if (output_filename){ bytes_save(bytes, output_filename); }else{ bytes_save(bytes, "out.blx"); } free(acode); exit(0); } /* Add arguments from call to this application */ Link Arg = array_new(argc-arg_index); Link * Argv = array_getArray(Arg); Link a = NULL; int c = 0; for(c=0; c <argc-arg_index; c++){ a = create_string_str( string_new((argv+arg_index)[c]) ); Argv[c] =a; } /* creates and runs the module */ Link main_ret = module_new(filename, Arg); link_free(Arg); if (main_ret){ showBacktrace(main_ret); link_free(main_ret); } fflush(stdout); fflush(stderr); exit(0); return 0; }