Go to the previous, next section.

The File Set

The file set, which contains a list of file set entries, is implemented by the file_set class. The list of files can be accessed directly using the file_list method, but most users will not need to do that because other methods are available to perform the common operations. The add_file method adds a new file set entry to the list. This method takes the names of the input file and output file and returns the new file set entry. Either the input file or the output file may be NULL. The file_set class also contains an iterator, as most SUIF programmers will want to iterate through the list of files. The reset_iter method resets the iterator to the first file set entry. The next_file method returns the next file set entry in the list.

Besides the list of files, the file set also contains the global symbol table (see section The Global Symbol Table) which can be accessed using the globals method. This symbol table contains the symbols and types that are visible in all of the source files. Before a group of files can be combined into a file set, their global symbol tables must be merged together. A separate SUIF linker is provided for this purpose. The library will complain if the files in the file set have not been properly linked.

Currently, only one file set is allowed per SUIF program. This restriction was made so that predefined types could be entered into the global symbol table at initialization time. See section Predefined Types. If multiple file sets were permitted, these predefined types would be duplicated. A single global file set is created when the SUIF library is initialized; the fileset global variable points to this file set.

All of the low-level access to SUIF files is performed automatically by the library. The global and file symbol tables are read from the input files when they are added to the file set. Users can then read and write individual procedure bodies using methods on the procedure symbols (see section Procedure Symbols). The global symbol tables are not written out until the file set is destroyed. Throughout this process, the file set keeps track of the number of open files in order to avoid exceeding the OS limit. If there are too many files open at once, the file set will automatically find one to close. This is totally invisible to users. Files that are temporarily closed are automatically reopened as needed.

As an example of using the file set, the following code reads in the files infile1 and infile2 and writes them out to outfile1 and outfile2, respectively, after processing them with the user-defined routine process_file.

fileset->add_file("infile1", "outfile1");
fileset->add_file("infile2", "outfile2");

file_set_entry *fse;

fileset->reset_iter();
while (fse = fileset->next_file()) {
    process_file(fse);
}

delete fileset;

Go to the previous, next section.