Main Page   Compound List   File List   Compound Members   File Members  

main.cc

Go to the documentation of this file.
00001 
00018 // ===================================================================
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 // ===================================================================
00022 
00023 
00024 
00025 // =================================================================
00026 // TYPES
00027 // Definitions of types for each field in the raw reference trace.
00028 // This is taken from tracer.cc in Laplace itself.
00029 
00032 typedef char tag_t;
00033 
00035 typedef unsigned long long int timestamp_t;
00036 
00038 typedef unsigned char length_t;
00039 
00042 typedef unsigned long int address_space_ID_t;
00043 
00045 typedef unsigned long int address_t;
00046 
00049 struct reference_record_s {
00050 
00051   tag_t tag;
00052   timestamp_t timestamp;
00053   length_t length;
00054   address_space_ID_t address_space_ID;
00055   address_t virtual_address;
00056 
00057 };
00058 // =================================================================
00059 
00060 
00061 
00062 // =================================================================
00063 // GLOBALS and CONSTANTS
00064 
00065 const tag_t TAG_END_OF_TRACE = 'e';
00066 // ===================================================================
00067 
00068 
00069 
00070 // ===================================================================
00084 int
00085 main (const unsigned int argc, const char** const argv) {
00086 
00087   // Were the correct number of arguments passed?
00088   if (argc != 1) {
00089 
00090     // No.  Emit usage and exit.
00091     fprintf(stderr, "Usage: %s <NO ARGUMENTS>\n", argv[0]);
00092     return 1;
00093 
00094   }
00095 
00096   // Allocate a single reference record into which the binary source
00097   // will be read, one record at a time.
00098   reference_record_s binary_record;
00099 
00100   // Read binary records until the end of the trace has been reached.
00101   do {
00102 
00103     // Attempt to read the next record.
00104     size_t read_result = fread(&binary_record,
00105              sizeof(binary_record),
00106              1,
00107              stdin);
00108 
00109     // Ensure that the read succeeded; otherwise, bail out.
00110     if (read_result != 1) {
00111 
00112       if (feof(stdin)) {
00113   fprintf(stderr, "Premature EOF\n");
00114       } else {
00115   fprintf(stderr, "Failed in reading binary record\n");
00116       }
00117 
00118       exit(1);
00119 
00120     }
00121 
00122     // Emit the binary record as text.  If the record is the
00123     // end-of-trace record, then emit just the tag.
00124     if (binary_record.tag == TAG_END_OF_TRACE) {
00125 
00126       printf("%c\n", binary_record.tag);
00127 
00128     } else {
00129 
00130       printf("%c %qx %hx %lx %lx\n",
00131        binary_record.tag,
00132        binary_record.timestamp,
00133        binary_record.length,
00134        binary_record.address_space_ID,
00135        binary_record.virtual_address);
00136 
00137     }
00138 
00139   } while (binary_record.tag != TAG_END_OF_TRACE);
00140 
00141   // Exit successfully.
00142   return 0;
00143 
00144 } // main
00145 // ===================================================================

Generated on Tue Jan 21 10:43:31 2003 for raw-reference-binary-to-text by doxygen1.3-rc2