// wrapper for OpenFiles // the while loop checks whether the file we wish to open is in the currently // open file list // we have to prevent it from opening directories above the one that might // be passed here void FileManager::OpenNewSet(int argc,char **argv) { file_iterator = filenames.begin(); // we have to check whether we're not opening a directory std::list<Glib::ustring>::iterator end = filenames.end(); // let's see if the file is already in our list if( initialised && filter_filename( argv[1] ) ) { while( file_iterator != end ) { #ifdef DEBUG std::cout << "OPENNEWSET: Looking for: " << argv[1] << " in " << *file_iterator << std::endl; #endif if( file_iterator->find( argv[1] ) != Glib::ustring::npos ) break; file_iterator++; } } // if we have a file which we cannot open, it must be a directory if( !initialised || file_iterator == end || !filter_filename( argv[1] ) ) { if( OpenFiles(argc,argv) ) initialised = true; else initialised = false; } else initialised = true; }
static void itable_c_insn (lf *file, insn_table *isa, insn_entry * instruction, void *data) { lf_printf (file, "{ "); lf_indent (file, +2); print_function_name (file, instruction->name, instruction->format_name, NULL, NULL, function_name_prefix_itable); lf_printf (file, ",\n"); lf_printf (file, "\""); print_insn_words (file, instruction); lf_printf (file, "\",\n"); lf_printf (file, "\"%s\",\n", instruction->format_name); itable_print_set (file, isa->flags, instruction->flags); itable_print_set (file, isa->options, instruction->options); itable_print_set (file, isa->model->processors, instruction->processors); lf_printf (file, "\"%s\",\n", instruction->name); lf_printf (file, "\"%s\",\n", filter_filename (instruction->line->file_name)); lf_printf (file, "%d,\n", instruction->line->line_nr); lf_printf (file, "},\n"); lf_indent (file, -2); }
void FileManager::OpenNewSet( std::list<Glib::ustring> &new_filenames ) { filenames.clear(); numfiles = 0; initialised = false; cwd_checked = false; filenames = new_filenames; std::list<Glib::ustring>::iterator begin = filenames.begin(); std::list<Glib::ustring>::iterator end = filenames.end(); std::list<Glib::ustring>::iterator iter = filenames.begin(); std::list<Glib::ustring>::iterator iter2 = filenames.begin(); while( iter != end ) { if( !filter_filename( *iter ) ) { iter2 = filenames.erase( iter ); iter = iter2; } else { iter++; numfiles++; } } std::cout << "Numfiles: " << numfiles << std::endl; if( numfiles > 0 ) { filenames.sort(); file_iterator = filenames.begin(); initialised = true; } // if we end up with only one file, let's scan that directory if( numfiles == 1 ) { initialised = false; char * tempfilename = new char[ (filenames.begin())->length() + 1 ]; strcpy( tempfilename, (filenames.begin())->c_str() ); char *arguments[] = { "empty", tempfilename }; OpenNewSet( 2, arguments ); // free the temporary memory #ifdef DEBUG std::cout << "OPENNEWSET(list,FileManager): deleting temporary memory\n"; #endif // DEBUG delete[] tempfilename; } }
static void itable_h_insn (lf *file, insn_table *entry, insn_entry * instruction, void *data) { int len; itable_info *info = data; lf_print__line_ref (file, instruction->line); lf_printf (file, " "); print_function_name (file, instruction->name, instruction->format_name, NULL, NULL, function_name_prefix_itable); lf_printf (file, ",\n"); /* update summary info */ len = strlen (instruction->format_name); if (info->sizeof_form <= len) info->sizeof_form = len + 1; len = strlen (instruction->name); if (info->sizeof_name <= len) info->sizeof_name = len + 1; len = strlen (filter_filename (instruction->line->file_name)); if (info->sizeof_file <= len) info->sizeof_file = len + 1; }
void print_semantic_body (lf *file, insn_entry * instruction, opcode_bits *expanded_bits, insn_opcodes *opcodes) { /* validate the instruction, if a cache this has already been done */ if (!options.gen.icache) { print_idecode_validate (file, instruction, opcodes); } print_itrace (file, instruction, 0 /*put_value_in_cache */ ); /* generate the instruction profile call - this is delayed until after the instruction has been verified. The count macro generated is prefixed by ITABLE_PREFIX */ { lf_printf (file, "\n"); lf_indent_suppress (file); lf_printf (file, "#if defined (%sPROFILE_COUNT_INSN)\n", options.module.itable.prefix.u); lf_printf (file, "%sPROFILE_COUNT_INSN (CPU, CIA, MY_INDEX);\n", options.module.itable.prefix.u); lf_indent_suppress (file); lf_printf (file, "#endif\n"); } /* generate the model call - this is delayed until after the instruction has been verified */ { lf_printf (file, "\n"); lf_indent_suppress (file); lf_printf (file, "#if defined (WITH_MON)\n"); lf_printf (file, "/* monitoring: */\n"); lf_printf (file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE)\n"); lf_printf (file, " mon_issue ("); print_function_name (file, instruction->name, instruction->format_name, NULL, NULL, function_name_prefix_itable); lf_printf (file, ", cpu, cia);\n"); lf_indent_suppress (file); lf_printf (file, "#endif\n"); lf_printf (file, "\n"); } /* determine the new instruction address */ { lf_printf (file, "/* keep the next instruction address handy */\n"); if (options.gen.nia == nia_is_invalid) { lf_printf (file, "nia = %sINVALID_INSTRUCTION_ADDRESS;\n", options.module.global.prefix.u); } else { int nr_immeds = instruction->nr_words - 1; if (options.gen.delayed_branch) { if (nr_immeds > 0) { lf_printf (file, "cia.dp += %d * %d; %s\n", options.insn_bit_size / 8, nr_immeds, "/* skip dp immeds */"); } lf_printf (file, "nia.ip = cia.dp; %s\n", "/* instruction pointer */"); lf_printf (file, "nia.dp = cia.dp + %d; %s\n", options.insn_bit_size / 8, "/* delayed-slot pointer */"); } else { if (nr_immeds > 0) { lf_printf (file, "nia = cia + %d * (%d + 1); %s\n", options.insn_bit_size / 8, nr_immeds, "/* skip immeds as well */"); } else { lf_printf (file, "nia = cia + %d;\n", options.insn_bit_size / 8); } } } } /* if conditional, generate code to verify that the instruction should be issued */ if (filter_is_member (instruction->options, "c") || options.gen.conditional_issue) { lf_printf (file, "\n"); lf_printf (file, "/* execute only if conditional passes */\n"); lf_printf (file, "if (IS_CONDITION_OK)\n"); lf_printf (file, " {\n"); lf_indent (file, +4); /* FIXME - need to log a conditional failure */ } /* Architecture expects a REG to be zero. Instead of having to check every read to see if it is refering to that REG just zap it at the start of every instruction */ if (options.gen.zero_reg) { lf_printf (file, "\n"); lf_printf (file, "/* Architecture expects REG to be zero */\n"); lf_printf (file, "GPR_CLEAR(%d);\n", options.gen.zero_reg_nr); } /* generate the code (or at least something */ lf_printf (file, "\n"); lf_printf (file, "/* semantics: */\n"); if (instruction->code != NULL) { /* true code */ lf_printf (file, "{\n"); lf_indent (file, +2); lf_print__line_ref (file, instruction->code->line); table_print_code (file, instruction->code); lf_indent (file, -2); lf_printf (file, "}\n"); lf_print__internal_ref (file); } else if (filter_is_member (instruction->options, "nop")) { lf_print__internal_ref (file); } else { const char *prefix = "sim_engine_abort ("; int indent = strlen (prefix); /* abort so it is implemented now */ lf_print__line_ref (file, instruction->line); lf_printf (file, "%sSD, CPU, cia, \\\n", prefix); lf_indent (file, +indent); lf_printf (file, "\"%s:%d:0x%%08lx:%%s unimplemented\\n\", \\\n", filter_filename (instruction->line->file_name), instruction->line->line_nr); lf_printf (file, "(long) CIA, \\\n"); lf_printf (file, "%sitable[MY_INDEX].name);\n", options.module.itable.prefix.l); lf_indent (file, -indent); lf_print__internal_ref (file); } /* Close off the conditional execution */ if (filter_is_member (instruction->options, "c") || options.gen.conditional_issue) { lf_indent (file, -4); lf_printf (file, " }\n"); } }
bool FileManager::OpenFiles(int argc, char **argv) { #ifdef DEBUG std::cout << "OPENFILES: OpenFiles called \n"; #endif // DEBUG // makes sure we're dealing with a clean slate filenames.clear(); numfiles = 0; cwd_checked = false; initialised = false; /* // if we have initialised already we're being called from the file selector and will // accept new files now, let's set initialised and cwd_checked to 'false' and clear our file list if( initialised == true ) { numfiles = 0; cwd_checked = false; initialised = false; } // */ #ifdef DEBUG std::cout << "OPENFILES: get_current_dir_name(): " << get_current_dir_name() << std::endl; #endif // DEBUG if( argc > 1 ) { for(int i = 1; i < argc; i++) { if( stat(argv[i], &filemode) != 0 ) { std::cout << GT( "OPENFILES: Stat Error! Level 1 " ) << argv[i] << std::endl; } else { Glib::ustring filename; // Resolve any ".." and double / in the filename and make the filename absolute if( Glib::path_is_absolute( argv[i] ) ) filename = argv[i] ; else filename = (Glib::ustring)get_current_dir_name() + "/" + (Glib::ustring)argv[i]; while( filename.find("..") != Glib::ustring::npos ) { filename.erase( filename.rfind( '/', filename.find("..")-2), filename.find("..")+2 - filename.rfind( '/', filename.find("..")-2) ); } while( filename.find("//") != Glib::ustring::npos ) filename.erase( filename.find("//"), filename.find("//")+1 ); if( filename[ filename.length()-1 ] == '/' ) filename.erase( filename.length()-1, filename.length() ); if(filemode.st_mode & S_IFREG ) // if the file is a regular file { if( filter_filename(filename) ) // and seems to be a supported format { #ifdef DEBUG std::cout << "FILEMANAGER: curent argv: " << filename << std::endl; std::cout << "FILEMANAGER: dirname from argv: " << Glib::path_get_dirname( filename ) << std::endl; std::cout << "FILEMANAGER: curent dir: " << get_current_dir_name() << std::endl; #endif filenames.insert( filenames.end(), filename ); // insert into list numfiles++; } } else if(filemode.st_mode & S_IFDIR) // if the file is a directory { cwd_checked = true; if((currdir = opendir(filename.c_str())) != NULL) // open it { while( (dirinfo = readdir(currdir)) != NULL ) // run through it { // don't forget, we're doing some string to char* conversions here // here to avoid memory errors.. Glib::ustring is nice! Glib::ustring currfile(filename); // store the directory name currfile += '/'; // add a directory dash currfile += dirinfo->d_name; // add the filename if(stat(currfile.c_str(), &filemode) != 0) // check for filetype { std::cout << GT( "OPENFILES: Stat Error! Level 2 " ) << currfile << std::endl; } else { if( filemode.st_mode & S_IFREG && filter_filename(currfile) ) // as above { filenames.insert( filenames.end(), currfile ); // insert into list numfiles++; } } } closedir(currdir); } } } } filenames.sort(); file_iterator = filenames.begin(); } // when only one file was openened, we'll scan through its directory // and give the user control over the files if ( numfiles == 1 && cwd_checked == false ) { cwd_checked = true; Glib::ustring tempfilename = *file_iterator; // prepare the file's directory name in such a way that we can pass // it to OpenFiles() which operates on argc/argv char *dirname = new char[ (Glib::path_get_dirname( *file_iterator )).length() + 1 ]; strcpy( dirname, (Glib::path_get_dirname( *file_iterator )).c_str() ); char *arguments[] = { "empty" , dirname }; // we erase the list of filenames as otherwise we would have one file twice filenames.clear(); numfiles = 0; // now let's open the file's directory and check its contents OpenFiles( 2, arguments ); // now we have a new set of files in the list, we have to find the file that // the user actually wanted to open! std::list<Glib::ustring>::iterator end = filenames.end(); while( file_iterator != end ) { #ifdef DEBUG std::cout << "OPENFILES: Looking for " << tempfilename << " in " << (*file_iterator) << std::endl; #endif if( (*file_iterator).find( tempfilename ) != Glib::ustring::npos ) { break; // break out of the while loop if we find the filename } file_iterator++; } // when we have reached the end while looking, let's just load the first image! // as that means that either we didn't recognize the filename in our search above // or there was only one file in the directory after all! if( file_iterator == end ) file_iterator = filenames.begin(); #ifdef DEBUG std::cout << "OPENFILES: Deleting temporary dirname. \n"; #endif delete[] dirname; } // everything seems to have worked out alright, let's return true if ( numfiles > 0 ) { #ifdef DEBUG std::cout << "OPENFILES: We're all set to go and we have " << numfiles << " files." << std::endl; #endif // DEBUG return true; } // we did not have sufficient arguments or we have made some mistake, return false else { #ifdef DEBUG std::cout << "OPENFILES: We have " << numfiles << " files." << std::endl; #endif return false; } }