00001
00015
00016 #include <math.h>
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019
00020
00021
00022
00023
00024
00025
00026
00027
00030 typedef char tag_t;
00031
00033 typedef unsigned long long int timestamp_t;
00034
00036 typedef unsigned char length_t;
00037
00040 typedef unsigned long int address_space_ID_t;
00041
00043 typedef unsigned long int address_t;
00044
00047 struct reference_record_s {
00048
00049 tag_t tag;
00050 timestamp_t timestamp;
00051 length_t length;
00052 address_space_ID_t address_space_ID;
00053 address_t virtual_address;
00054
00055 };
00056
00057
00058
00059
00060
00061
00062
00064 const tag_t TAG_END_OF_TRACE = 'e';
00065
00066
00067
00068
00069
00078 void
00079 process_trace () {
00080
00081
00082
00083 reference_record_s binary_record;
00084
00085
00086 timestamp_t previous_timestamp = 0;
00087
00088
00089
00090 address_space_ID_t previous_address_space_ID = 0;
00091
00092
00093
00094
00095
00096 const unsigned int bits_per_byte = 8;
00097 const unsigned int number_possible_tags =
00098 (unsigned int)pow(2.0, (double)(sizeof(tag_t) * bits_per_byte));
00099 address_t previous_address[number_possible_tags];
00100 for (unsigned int i = 0; i < number_possible_tags; i++) {
00101 previous_address[i] = 0;
00102 }
00103
00104
00105 unsigned long long int record_number = 1;
00106
00107
00108 do {
00109
00110
00111 size_t read_result = fread(&binary_record,
00112 sizeof(binary_record),
00113 1,
00114 stdin);
00115
00116
00117 if (read_result != 1) {
00118
00119 if (feof(stdin)) {
00120 fprintf(stderr, "Premature EOF\n");
00121 } else {
00122 fprintf(stderr, "Failed in reading binary record\n");
00123 }
00124
00125 exit(1);
00126
00127 }
00128
00129
00130 if (binary_record.tag == TAG_END_OF_TRACE) {
00131
00132
00133 printf("%c\n", binary_record.tag);
00134
00135 } else {
00136
00137
00138
00139 timestamp_t timestamp_difference =
00140 binary_record.timestamp - previous_timestamp;
00141 previous_timestamp = binary_record.timestamp;
00142
00143
00144
00145
00146 address_space_ID_t address_space_ID = 0;
00147 if (binary_record.address_space_ID !=
00148 previous_address_space_ID) {
00149 address_space_ID = binary_record.address_space_ID;
00150 previous_address_space_ID = address_space_ID;
00151 }
00152
00153
00154
00155 char address_difference_sign;
00156 address_t address_difference_magnitude;
00157 if (binary_record.virtual_address <
00158 previous_address[binary_record.tag]) {
00159
00160 address_difference_sign = '-';
00161 address_difference_magnitude =
00162 previous_address[binary_record.tag] -
00163 binary_record.virtual_address;
00164
00165 } else {
00166
00167 address_difference_sign = '+';
00168 address_difference_magnitude =
00169 binary_record.virtual_address -
00170 previous_address[binary_record.tag];
00171
00172 }
00173 previous_address[binary_record.tag] =
00174 binary_record.virtual_address;
00175
00176 printf("%c %qx %hx %lx %c %lx\n",
00177 binary_record.tag,
00178 timestamp_difference,
00179 binary_record.length,
00180 address_space_ID,
00181 address_difference_sign,
00182 address_difference_magnitude);
00183
00184 record_number++;
00185
00186 }
00187
00188 } while (binary_record.tag != TAG_END_OF_TRACE);
00189
00190 }
00191
00192
00193
00194
00195
00209 int
00210 main (const unsigned int argc, const char** const argv) {
00211
00212
00213 if (argc != 1) {
00214
00215
00216 fprintf(stderr, "Usage: %s <NO ARGUMENTS>\n", argv[0]);
00217 exit(1);
00218
00219 }
00220
00221
00222 process_trace();
00223
00224
00225 return 0;
00226
00227 }
00228