[158] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : xml_parser.c |
---|
| 3 | // Date : 04/04/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // This program translate an xml file containing a MAPPING_INFO data structure |
---|
| 8 | // to a binary file that can be directly loaded in the boot ROM and used by the GIET. |
---|
| 9 | // The C strcutures are defined in the mapping_info.h file. |
---|
| 10 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 11 | |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <fcntl.h> |
---|
[162] | 14 | #include <sys/types.h> |
---|
| 15 | #include <sys/stat.h> |
---|
[158] | 16 | #include <unistd.h> |
---|
| 17 | #include <stdio.h> |
---|
| 18 | #include <string.h> |
---|
| 19 | #include <libxml/xmlreader.h> |
---|
| 20 | #include <mapping_info.h> |
---|
| 21 | |
---|
[160] | 22 | #define MAX_CLUSTERS 1024 |
---|
[158] | 23 | #define MAX_PSEGS 4096 |
---|
| 24 | #define MAX_VSPACES 1024 |
---|
| 25 | #define MAX_TASKS 4096 |
---|
| 26 | #define MAX_MWMRS 4096 |
---|
| 27 | #define MAX_VSEGS 4096 |
---|
[160] | 28 | #define MAX_VOBJS 8192 |
---|
[158] | 29 | |
---|
| 30 | #define XML_PARSER_DEBUG 0 |
---|
| 31 | |
---|
| 32 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | // global variables used to store and index the data structures |
---|
| 34 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 35 | |
---|
| 36 | mapping_header_t* header; |
---|
| 37 | mapping_cluster_t* cluster[MAX_CLUSTERS]; // cluster array |
---|
| 38 | mapping_pseg_t* pseg[MAX_PSEGS]; // pseg array |
---|
| 39 | mapping_vspace_t* vspace[MAX_VSPACES]; // vspace array |
---|
| 40 | mapping_vseg_t* vseg[MAX_VSEGS]; // vseg array |
---|
[160] | 41 | mapping_vobj_t* vobj[MAX_VOBJS]; // vobj array |
---|
[158] | 42 | mapping_task_t* task[MAX_TASKS]; // task array |
---|
| 43 | |
---|
| 44 | unsigned int cluster_index = 0; |
---|
| 45 | unsigned int vspace_index = 0; |
---|
| 46 | unsigned int global_index = 0; |
---|
| 47 | unsigned int pseg_index = 0; |
---|
| 48 | unsigned int vseg_index = 0; |
---|
| 49 | unsigned int vseg_loc_index = 0; |
---|
| 50 | unsigned int task_index = 0; |
---|
| 51 | unsigned int task_loc_index = 0; |
---|
[160] | 52 | unsigned int vobj_index = 0; |
---|
| 53 | unsigned int vobj_loc_index = 0; |
---|
[165] | 54 | unsigned int vobj_count = 0; |
---|
| 55 | |
---|
| 56 | unsigned int tty_index = 1; |
---|
| 57 | unsigned int fb_index = 0; |
---|
[160] | 58 | |
---|
[158] | 59 | ////////////////////////////////////////////////// |
---|
| 60 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
| 61 | const char* attributeName, |
---|
| 62 | unsigned int* ok ) |
---|
| 63 | { |
---|
| 64 | unsigned int value = 0; |
---|
| 65 | unsigned int i; |
---|
| 66 | char c; |
---|
| 67 | |
---|
| 68 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
| 69 | |
---|
| 70 | if ( string == NULL ) // missing argument |
---|
| 71 | { |
---|
| 72 | *ok = 0; |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
| 77 | if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) ) // Hexa |
---|
| 78 | { |
---|
| 79 | for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ ) |
---|
| 80 | { |
---|
| 81 | c = string[i]; |
---|
| 82 | if ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48; |
---|
| 83 | else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87; |
---|
| 84 | else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55; |
---|
| 85 | else |
---|
| 86 | { |
---|
| 87 | *ok = 0; |
---|
| 88 | return 0; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | else // Decimal |
---|
| 93 | { |
---|
| 94 | for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ ) |
---|
| 95 | { |
---|
| 96 | c = string[i]; |
---|
| 97 | if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48; |
---|
| 98 | else |
---|
| 99 | { |
---|
| 100 | *ok = 0; |
---|
| 101 | return 0; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | *ok = 1; |
---|
| 106 | return value; |
---|
| 107 | } |
---|
| 108 | } // end getIntValue() |
---|
| 109 | |
---|
| 110 | /////////////////////////////////////////////// |
---|
| 111 | char* getStringValue ( xmlTextReaderPtr reader, |
---|
| 112 | const char* attributeName, |
---|
| 113 | unsigned int* ok ) |
---|
| 114 | { |
---|
| 115 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
| 116 | |
---|
| 117 | if ( string == NULL ) // missing argument |
---|
| 118 | { |
---|
| 119 | *ok = 0; |
---|
| 120 | return NULL; |
---|
| 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | *ok = 1; |
---|
| 125 | return string; |
---|
| 126 | } |
---|
| 127 | } // end getStringValue() |
---|
| 128 | |
---|
| 129 | ////////////////////////// |
---|
| 130 | int getPsegId( char* str ) |
---|
| 131 | { |
---|
| 132 | unsigned int pseg_id; |
---|
| 133 | |
---|
| 134 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 135 | { |
---|
| 136 | if ( strcmp(pseg[pseg_id]->name, str) == 0 ) return pseg_id; |
---|
| 137 | } |
---|
| 138 | return -1; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | ////////////////////////////////////////// |
---|
[160] | 142 | int getVobjLocId( unsigned int vspace_id, |
---|
[158] | 143 | char* str ) |
---|
| 144 | { |
---|
[160] | 145 | unsigned int vobj_id; |
---|
| 146 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
---|
[165] | 147 | unsigned int vobj_max = vobj_min + vobj_loc_index; |
---|
[158] | 148 | |
---|
[160] | 149 | for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) |
---|
[158] | 150 | { |
---|
[160] | 151 | if ( strcmp(vobj[vobj_id]->name, str) == 0 ) |
---|
| 152 | { |
---|
| 153 | return (vobj_id - vobj_min); |
---|
| 154 | } |
---|
[158] | 155 | } |
---|
| 156 | return -1; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | ////////////////////////////////////////// |
---|
| 160 | void taskNode ( xmlTextReaderPtr reader ) |
---|
| 161 | { |
---|
| 162 | unsigned int ok; |
---|
| 163 | unsigned int value; |
---|
| 164 | char* str; |
---|
| 165 | |
---|
| 166 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 167 | |
---|
| 168 | if ( task_index >= MAX_TASKS ) |
---|
| 169 | { |
---|
| 170 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | #if XML_PARSER_DEBUG |
---|
| 174 | printf(" task %d\n", task_loc_index); |
---|
| 175 | #endif |
---|
| 176 | |
---|
| 177 | task[task_index] = (mapping_task_t*)malloc(sizeof(mapping_task_t)); |
---|
| 178 | |
---|
| 179 | ////////// get name attribute |
---|
| 180 | str = getStringValue(reader, "name", &ok); |
---|
| 181 | if ( ok ) |
---|
| 182 | { |
---|
| 183 | #if XML_PARSER_DEBUG |
---|
| 184 | printf(" name = %s\n", str); |
---|
| 185 | #endif |
---|
| 186 | strncpy( task[task_index]->name, str, 31 ); |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
| 191 | vspace_index, task_loc_index); |
---|
| 192 | exit(1); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | ///////// get clusterid attribute |
---|
| 196 | value = getIntValue(reader,"clusterid", &ok); |
---|
| 197 | if ( ok ) |
---|
| 198 | { |
---|
| 199 | #if XML_PARSER_DEBUG |
---|
| 200 | printf(" clusterid = %x\n", value); |
---|
| 201 | #endif |
---|
[165] | 202 | if ( value >= header->clusters ) |
---|
| 203 | { |
---|
| 204 | printf("[XML ERROR] <clusterid> too large for task (%d,%d)\n", |
---|
| 205 | vspace_index, task_loc_index); |
---|
| 206 | exit(1); |
---|
| 207 | } |
---|
[158] | 208 | task[task_index]->clusterid = value; |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", |
---|
| 213 | vspace_index, task_loc_index); |
---|
| 214 | exit(1); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | ////////// get proclocid attribute |
---|
| 218 | value = getIntValue(reader,"proclocid", &ok); |
---|
| 219 | if ( ok ) |
---|
| 220 | { |
---|
| 221 | #if XML_PARSER_DEBUG |
---|
| 222 | printf(" proclocid = %x\n", value); |
---|
| 223 | #endif |
---|
[165] | 224 | if ( value >= cluster[task[task_index]->clusterid]->procs ) |
---|
| 225 | { |
---|
| 226 | printf("[XML ERROR] <proclocid> too large for task (%d,%d)\n", |
---|
| 227 | vspace_index, task_loc_index); |
---|
| 228 | exit(1); |
---|
| 229 | } |
---|
[158] | 230 | task[task_index]->proclocid = value; |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
| 234 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
---|
| 235 | vspace_index, task_loc_index); |
---|
| 236 | exit(1); |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | ////////// get stackname attribute |
---|
| 240 | str = getStringValue(reader, "stackname" , &ok); |
---|
| 241 | if ( ok ) |
---|
| 242 | { |
---|
[160] | 243 | int index = getVobjLocId( vspace_index, str ); |
---|
[158] | 244 | if ( index >= 0 ) |
---|
| 245 | { |
---|
| 246 | #if XML_PARSER_DEBUG |
---|
| 247 | printf(" stackname = %s\n", str); |
---|
[165] | 248 | printf(" stackid = %d\n", index); |
---|
[158] | 249 | #endif |
---|
[160] | 250 | task[task_index]->vobjlocid = index; |
---|
[158] | 251 | } |
---|
| 252 | else |
---|
| 253 | { |
---|
[165] | 254 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
| 255 | vspace_index, task_loc_index); |
---|
[158] | 256 | exit(1); |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | else |
---|
| 260 | { |
---|
[165] | 261 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
---|
[158] | 262 | vspace_index, task_loc_index); |
---|
| 263 | exit(1); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | ////////// get startid attribute |
---|
| 267 | value = getIntValue(reader,"startid", &ok); |
---|
| 268 | if ( ok ) |
---|
| 269 | { |
---|
| 270 | #if XML_PARSER_DEBUG |
---|
| 271 | printf(" startid = %x\n", value); |
---|
| 272 | #endif |
---|
| 273 | task[task_index]->startid = value; |
---|
| 274 | } |
---|
| 275 | else |
---|
| 276 | { |
---|
| 277 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
| 278 | vspace_index, task_loc_index); |
---|
| 279 | exit(1); |
---|
| 280 | } |
---|
| 281 | |
---|
[165] | 282 | /////////// get use_tty attribute (optionnal : 0 if missing) |
---|
| 283 | value = getIntValue(reader,"usetty", &ok); |
---|
[158] | 284 | if ( ok ) |
---|
| 285 | { |
---|
| 286 | #if XML_PARSER_DEBUG |
---|
[165] | 287 | printf(" usetty = %x\n", value); |
---|
[158] | 288 | #endif |
---|
[165] | 289 | if ( (value != 0) && (tty_index >= header->ttys) ) |
---|
[158] | 290 | { |
---|
[165] | 291 | printf("[XML ERROR] The tty index is too large for task (%d,%d)\n", |
---|
[158] | 292 | vspace_index, task_loc_index); |
---|
| 293 | exit(1); |
---|
| 294 | } |
---|
[165] | 295 | task[task_index]->use_tty = value; |
---|
| 296 | if (value != 0) tty_index++; |
---|
[158] | 297 | } |
---|
| 298 | else |
---|
| 299 | { |
---|
[165] | 300 | task[task_index]->use_tty = 0; |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | /////////// get use_fb attribute (optionnal : 0 if missing) |
---|
| 304 | value = getIntValue(reader,"usefb", &ok); |
---|
| 305 | if ( ok ) |
---|
| 306 | { |
---|
| 307 | #if XML_PARSER_DEBUG |
---|
| 308 | printf(" usefb = %x\n", value); |
---|
| 309 | #endif |
---|
| 310 | if ( (value != 0) && (fb_index >= header->fbs) ) |
---|
| 311 | { |
---|
| 312 | printf("[XML ERROR] The fb channel index is too large for task (%d,%d)\n", |
---|
[158] | 313 | vspace_index, task_loc_index); |
---|
[165] | 314 | exit(1); |
---|
| 315 | } |
---|
| 316 | task[task_index]->use_fb = value; |
---|
| 317 | if (value != 0) fb_index++; |
---|
| 318 | } |
---|
| 319 | else |
---|
| 320 | { |
---|
| 321 | task[task_index]->use_fb = 0; |
---|
[158] | 322 | } |
---|
| 323 | |
---|
| 324 | task_index++; |
---|
| 325 | task_loc_index++; |
---|
| 326 | } // end taskNode() |
---|
| 327 | |
---|
[165] | 328 | ////////////////////////////////////////// |
---|
[160] | 329 | void vobjNode ( xmlTextReaderPtr reader ) |
---|
| 330 | { |
---|
| 331 | unsigned int ok; |
---|
| 332 | unsigned int value; |
---|
| 333 | char* str; |
---|
| 334 | |
---|
| 335 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 336 | |
---|
| 337 | if ( vobj_index >= MAX_VOBJS ) |
---|
| 338 | { |
---|
| 339 | printf("[XML ERROR] The number of vobjs is larger than %d\n", MAX_VSEGS); |
---|
| 340 | exit(1); |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | #if XML_PARSER_DEBUG |
---|
[165] | 344 | printf(" vobj %d\n", vobj_loc_index); |
---|
[160] | 345 | #endif |
---|
| 346 | |
---|
| 347 | vobj[vobj_index] = (mapping_vobj_t*)malloc(sizeof(mapping_vobj_t)); |
---|
| 348 | |
---|
| 349 | ///////// get name attribute |
---|
| 350 | str = getStringValue(reader, "name", &ok); |
---|
| 351 | if ( ok ) |
---|
| 352 | { |
---|
| 353 | #if XML_PARSER_DEBUG |
---|
[165] | 354 | printf(" name = %s\n", str); |
---|
[160] | 355 | #endif |
---|
| 356 | strncpy( vobj[vobj_index]->name, str, 31); |
---|
| 357 | } |
---|
| 358 | else |
---|
| 359 | { |
---|
| 360 | printf("[XML ERROR] illegal or missing <name> attribute for vobj (%d,%d)\n", |
---|
| 361 | vseg_index, vobj_loc_index); |
---|
| 362 | exit(1); |
---|
| 363 | } |
---|
| 364 | |
---|
[165] | 365 | //////// get type attribute |
---|
[175] | 366 | char *type_str = getStringValue(reader, "type", &ok); |
---|
[160] | 367 | #if XML_PARSER_DEBUG |
---|
[175] | 368 | printf(" type = %s\n", type_str); |
---|
[160] | 369 | #endif |
---|
[175] | 370 | if (ok && (strcmp(type_str, "ELF") == 0)) |
---|
[165] | 371 | { |
---|
| 372 | vobj[vobj_index]->type = VOBJ_TYPE_ELF; |
---|
| 373 | |
---|
| 374 | //check that this vobj is the first in vseg |
---|
| 375 | if(vobj_count != 0) |
---|
[160] | 376 | { |
---|
[165] | 377 | printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", |
---|
| 378 | vspace_index, vobj_loc_index); |
---|
[160] | 379 | exit(1); |
---|
| 380 | } |
---|
| 381 | } |
---|
[175] | 382 | else if (ok && (strcmp(type_str, "BLOB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BLOB; |
---|
| 383 | else if (ok && (strcmp(type_str, "PTAB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB; |
---|
| 384 | else if (ok && (strcmp(type_str, "PERI") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI; |
---|
| 385 | else if (ok && (strcmp(type_str, "MWMR") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR; |
---|
| 386 | else if (ok && (strcmp(type_str, "LOCK") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK; |
---|
| 387 | else if (ok && (strcmp(type_str, "BUFFER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; |
---|
| 388 | else if (ok && (strcmp(type_str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; |
---|
[160] | 389 | else |
---|
| 390 | { |
---|
| 391 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
---|
[165] | 392 | vspace_index, vobj_loc_index); |
---|
[160] | 393 | exit(1); |
---|
| 394 | } |
---|
| 395 | |
---|
[165] | 396 | ////////// get length attribute |
---|
[160] | 397 | value = getIntValue(reader,"length", &ok); |
---|
| 398 | if ( ok ) |
---|
| 399 | { |
---|
| 400 | #if XML_PARSER_DEBUG |
---|
[165] | 401 | printf(" length = %d\n", value); |
---|
[160] | 402 | #endif |
---|
| 403 | vobj[vobj_index]->length = value; |
---|
| 404 | } |
---|
| 405 | else |
---|
| 406 | { |
---|
[165] | 407 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
---|
| 408 | vspace_index, vobj_loc_index); |
---|
| 409 | exit(1); |
---|
[160] | 410 | } |
---|
| 411 | |
---|
[165] | 412 | ////////// get align attribute (optional : 0 if missing) |
---|
[160] | 413 | value = getIntValue(reader,"align", &ok); |
---|
| 414 | if ( ok ) |
---|
| 415 | { |
---|
| 416 | #if XML_PARSER_DEBUG |
---|
[165] | 417 | printf(" align = %d\n", value); |
---|
[160] | 418 | #endif |
---|
| 419 | vobj[vobj_index]->align = value; |
---|
| 420 | } |
---|
| 421 | else |
---|
| 422 | { |
---|
| 423 | vobj[vobj_index]->align = 0; |
---|
| 424 | } |
---|
| 425 | |
---|
[165] | 426 | ////////// get binpath attribute (optional : '\0' if missing) |
---|
[160] | 427 | str = getStringValue(reader, "binpath", &ok); |
---|
| 428 | if ( ok ) |
---|
| 429 | { |
---|
| 430 | #if XML_PARSER_DEBUG |
---|
[165] | 431 | printf(" binpath = %s\n", str); |
---|
[160] | 432 | #endif |
---|
| 433 | strncpy(vobj[vobj_index]->binpath, str, 63); |
---|
| 434 | } |
---|
| 435 | else |
---|
| 436 | { |
---|
| 437 | vobj[vobj_index]->binpath[0] = '\0'; |
---|
| 438 | } |
---|
| 439 | |
---|
[175] | 440 | ////////// get init attribute (mandatory for mwmr and barrier) |
---|
[165] | 441 | value = getIntValue(reader,"init", &ok); |
---|
| 442 | if ( ok ) |
---|
| 443 | { |
---|
| 444 | #if XML_PARSER_DEBUG |
---|
| 445 | printf(" init = %d\n", value); |
---|
| 446 | #endif |
---|
| 447 | vobj[vobj_index]->init = value; |
---|
| 448 | } |
---|
| 449 | else |
---|
| 450 | { |
---|
[175] | 451 | if(vobj[vobj_index]->type == VOBJ_TYPE_MWMR || vobj[vobj_index]->type == VOBJ_TYPE_BARRIER ) |
---|
| 452 | { |
---|
| 453 | printf("[XML ERROR] illegal or missing <value> attribute for vobj (%d,%d), of type: %s\n", |
---|
| 454 | vspace_index, vobj_loc_index, type_str); |
---|
| 455 | exit(1); |
---|
| 456 | } |
---|
| 457 | else |
---|
| 458 | vobj[vobj_index]->init = 0; |
---|
[165] | 459 | } |
---|
| 460 | |
---|
[160] | 461 | vobj_index++; |
---|
[165] | 462 | vobj_count++; |
---|
[160] | 463 | vobj_loc_index++; |
---|
[165] | 464 | } // end vobjNode() |
---|
[160] | 465 | |
---|
[165] | 466 | ////////////////////////////////////////// |
---|
[158] | 467 | void vsegNode ( xmlTextReaderPtr reader ) |
---|
| 468 | { |
---|
| 469 | unsigned int ok; |
---|
| 470 | unsigned int value; |
---|
| 471 | char* str; |
---|
| 472 | |
---|
[165] | 473 | vobj_count = 0; |
---|
| 474 | |
---|
[158] | 475 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 476 | |
---|
| 477 | if ( vseg_index >= MAX_VSEGS ) |
---|
| 478 | { |
---|
| 479 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
| 480 | exit(1); |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | #if XML_PARSER_DEBUG |
---|
| 484 | printf(" vseg %d\n", vseg_loc_index); |
---|
| 485 | #endif |
---|
| 486 | |
---|
| 487 | vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t)); |
---|
[160] | 488 | |
---|
| 489 | ////////// set vobj_offset attributes |
---|
| 490 | vseg[vseg_index]->vobj_offset = vobj_index; |
---|
| 491 | #if XML_PARSER_DEBUG |
---|
[165] | 492 | printf(" vobj_offset = %d\n", vobj_index); |
---|
[160] | 493 | #endif |
---|
[158] | 494 | |
---|
| 495 | ///////// get name attribute |
---|
| 496 | str = getStringValue(reader, "name", &ok); |
---|
| 497 | if ( ok ) |
---|
| 498 | { |
---|
| 499 | #if XML_PARSER_DEBUG |
---|
| 500 | printf(" name = %s\n", str); |
---|
| 501 | #endif |
---|
| 502 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
| 503 | } |
---|
| 504 | else |
---|
| 505 | { |
---|
| 506 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
| 507 | vspace_index, vseg_loc_index); |
---|
| 508 | exit(1); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | /////////// get vbase attribute |
---|
| 512 | value = getIntValue(reader,"vbase", &ok); |
---|
| 513 | if ( ok ) |
---|
| 514 | { |
---|
| 515 | #if XML_PARSER_DEBUG |
---|
| 516 | printf(" vbase = 0x%x\n", value); |
---|
| 517 | #endif |
---|
| 518 | vseg[vseg_index]->vbase = value; |
---|
| 519 | } |
---|
| 520 | else |
---|
| 521 | { |
---|
| 522 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
| 523 | vspace_index, vseg_loc_index); |
---|
| 524 | exit(1); |
---|
| 525 | } |
---|
| 526 | |
---|
[165] | 527 | ////////// get ident attribute (optional : 0 if missing) |
---|
[158] | 528 | value = getIntValue(reader,"ident", &ok); |
---|
| 529 | if ( ok ) |
---|
| 530 | { |
---|
| 531 | #if XML_PARSER_DEBUG |
---|
| 532 | printf(" ident = %d\n", value); |
---|
| 533 | #endif |
---|
| 534 | vseg[vseg_index]->ident = value; |
---|
| 535 | } |
---|
| 536 | else |
---|
| 537 | { |
---|
| 538 | vseg[vseg_index]->ident = 0; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | ////////// get psegname attribute |
---|
| 542 | str = getStringValue(reader,"psegname", &ok); |
---|
| 543 | if ( ok ) |
---|
| 544 | { |
---|
| 545 | int index = getPsegId( str ); |
---|
| 546 | if ( index >= 0 ) |
---|
| 547 | { |
---|
| 548 | #if XML_PARSER_DEBUG |
---|
| 549 | printf(" psegname = %s\n", str); |
---|
| 550 | printf(" psegid = %d\n", index); |
---|
| 551 | #endif |
---|
| 552 | vseg[vseg_index]->psegid = index; |
---|
| 553 | } |
---|
| 554 | else |
---|
| 555 | { |
---|
| 556 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 557 | vseg_loc_index); |
---|
| 558 | exit(1); |
---|
| 559 | } |
---|
| 560 | } |
---|
| 561 | else |
---|
| 562 | { |
---|
| 563 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 564 | vseg_loc_index); |
---|
| 565 | exit(1); |
---|
| 566 | } |
---|
| 567 | |
---|
[165] | 568 | //////// get mode attribute |
---|
[158] | 569 | str = getStringValue(reader,"mode", &ok); |
---|
| 570 | #if XML_PARSER_DEBUG |
---|
| 571 | printf(" mode = %s\n", str); |
---|
| 572 | #endif |
---|
| 573 | if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; |
---|
| 574 | else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; |
---|
| 575 | else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; |
---|
| 576 | else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; |
---|
| 577 | else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; |
---|
| 578 | else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; |
---|
| 579 | else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; |
---|
| 580 | else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; |
---|
| 581 | else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; |
---|
| 582 | else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; |
---|
| 583 | else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; |
---|
| 584 | else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; |
---|
| 585 | else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; |
---|
| 586 | else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; |
---|
| 587 | else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; |
---|
| 588 | else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; |
---|
| 589 | else |
---|
| 590 | { |
---|
| 591 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
| 592 | vspace_index, vseg_loc_index); |
---|
| 593 | exit(1); |
---|
| 594 | } |
---|
| 595 | |
---|
[160] | 596 | ////////// set the length attribute to 0 |
---|
| 597 | vseg[vseg_index]->length = value; |
---|
| 598 | |
---|
| 599 | ////////// get vobjs |
---|
| 600 | int status = xmlTextReaderRead ( reader ); |
---|
| 601 | while ( status == 1 ) |
---|
| 602 | { |
---|
| 603 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 604 | |
---|
| 605 | if ( strcmp(tag,"vobj") == 0 ) vobjNode(reader); |
---|
| 606 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 607 | else if ( strcmp(tag,"vseg") == 0 ) |
---|
| 608 | { |
---|
| 609 | // checking source file consistency? |
---|
[165] | 610 | vseg[vseg_index]->vobjs = vobj_count; |
---|
[160] | 611 | vseg_index++; |
---|
| 612 | vseg_loc_index++; |
---|
| 613 | return; |
---|
| 614 | } |
---|
| 615 | else |
---|
| 616 | { |
---|
| 617 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
| 618 | exit(1); |
---|
| 619 | } |
---|
| 620 | status = xmlTextReaderRead ( reader ); |
---|
| 621 | } |
---|
[158] | 622 | } // end vsegNode() |
---|
| 623 | |
---|
| 624 | ////////////////////////////////////////// |
---|
| 625 | void vspaceNode( xmlTextReaderPtr reader ) |
---|
| 626 | { |
---|
| 627 | char* str; |
---|
| 628 | unsigned int ok; |
---|
[165] | 629 | |
---|
| 630 | vobj_loc_index = 0; |
---|
[160] | 631 | vseg_loc_index = 0; |
---|
| 632 | task_loc_index = 0; |
---|
[158] | 633 | |
---|
| 634 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 635 | |
---|
| 636 | // checking source file consistency |
---|
| 637 | if ( vspace_index >= header->vspaces ) |
---|
| 638 | { |
---|
| 639 | printf("[XML ERROR] The vspace index is too large : %d\n", |
---|
| 640 | vspace_index); |
---|
| 641 | exit(1); |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | #if XML_PARSER_DEBUG |
---|
[165] | 645 | printf("\n vspace %d\n", vspace_index); |
---|
[158] | 646 | #endif |
---|
| 647 | |
---|
| 648 | vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t)); |
---|
| 649 | |
---|
| 650 | ////////// get name attribute |
---|
| 651 | str = getStringValue(reader, "name", &ok); |
---|
| 652 | if ( ok ) |
---|
| 653 | { |
---|
| 654 | #if XML_PARSER_DEBUG |
---|
[165] | 655 | printf(" name = %s\n", str); |
---|
[158] | 656 | #endif |
---|
| 657 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
| 658 | } |
---|
| 659 | else |
---|
| 660 | { |
---|
[165] | 661 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
---|
[158] | 662 | vspace_index); |
---|
| 663 | exit(1); |
---|
| 664 | } |
---|
| 665 | |
---|
[165] | 666 | ////////// set vseg_offset and task_offset attributes |
---|
| 667 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
| 668 | vspace[vspace_index]->vobj_offset = vobj_index; |
---|
| 669 | vspace[vspace_index]->task_offset = task_index; |
---|
| 670 | |
---|
[158] | 671 | #if XML_PARSER_DEBUG |
---|
[165] | 672 | printf(" vseg_offset = %d\n", vseg_index); |
---|
| 673 | printf(" vobj_offset = %d\n", vobj_index); |
---|
| 674 | printf(" task_offset = %d\n", task_index); |
---|
[158] | 675 | #endif |
---|
| 676 | |
---|
[165] | 677 | ////////// get startname attribute |
---|
| 678 | str = getStringValue(reader, "startname", &ok); |
---|
[158] | 679 | if ( ok ) |
---|
| 680 | { |
---|
[165] | 681 | //used after parsing the vobjs |
---|
[158] | 682 | } |
---|
| 683 | else |
---|
| 684 | { |
---|
[165] | 685 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %d\n", |
---|
| 686 | vspace_index); |
---|
[158] | 687 | exit(1); |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | int status = xmlTextReaderRead ( reader ); |
---|
| 691 | while ( status == 1 ) |
---|
| 692 | { |
---|
| 693 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 694 | |
---|
| 695 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
| 696 | else if ( strcmp(tag,"task") == 0 ) taskNode(reader); |
---|
| 697 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 698 | else if ( strcmp(tag,"vspace") == 0 ) |
---|
| 699 | { |
---|
[165] | 700 | vspace[vspace_index]->vobjs = vobj_loc_index; |
---|
[160] | 701 | vspace[vspace_index]->tasks = task_loc_index ; |
---|
| 702 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
---|
[165] | 703 | |
---|
| 704 | // get index of the vobj containing the start vector |
---|
[160] | 705 | int index = getVobjLocId( vspace_index, str ); |
---|
| 706 | if(index == -1) |
---|
[158] | 707 | { |
---|
[165] | 708 | printf("[XML ERROR] vobj containing the start vector not found %s\n",str); |
---|
[160] | 709 | exit(-1); |
---|
[158] | 710 | } |
---|
[165] | 711 | else |
---|
| 712 | { |
---|
| 713 | vspace[vspace_index]->start_offset = index; |
---|
| 714 | #if XML_PARSER_DEBUG |
---|
| 715 | printf(" startname = %s\n", str); |
---|
| 716 | printf(" startid = %d\n", index); |
---|
| 717 | #endif |
---|
| 718 | } |
---|
[160] | 719 | |
---|
[165] | 720 | // checking startid values for all tasks in vspace |
---|
| 721 | int task_id; |
---|
| 722 | int task_min = vspace[vspace_index]->task_offset; |
---|
| 723 | int task_max = task_min + vspace[vspace_index]->tasks; |
---|
| 724 | for ( task_id = task_min ; task_id < task_max ; task_id++ ) |
---|
| 725 | { |
---|
| 726 | if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) |
---|
| 727 | { |
---|
| 728 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
---|
| 729 | vspace_index, task_id ); |
---|
| 730 | exit(1); |
---|
| 731 | } |
---|
| 732 | } |
---|
| 733 | |
---|
[160] | 734 | vspace_index++; |
---|
| 735 | return; |
---|
[158] | 736 | } |
---|
| 737 | else |
---|
| 738 | { |
---|
| 739 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
| 740 | exit(1); |
---|
| 741 | } |
---|
| 742 | status = xmlTextReaderRead ( reader ); |
---|
| 743 | } |
---|
| 744 | } // end vspaceNode() |
---|
| 745 | |
---|
| 746 | ////////////////////////////////////////// |
---|
| 747 | void psegNode ( xmlTextReaderPtr reader ) |
---|
| 748 | { |
---|
| 749 | unsigned int ok; |
---|
| 750 | unsigned int value; |
---|
| 751 | char* str; |
---|
| 752 | |
---|
| 753 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 754 | |
---|
| 755 | if ( pseg_index >= MAX_PSEGS ) |
---|
| 756 | { |
---|
| 757 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 758 | exit(1); |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | #if XML_PARSER_DEBUG |
---|
| 762 | printf(" pseg %d\n", pseg_index); |
---|
| 763 | #endif |
---|
| 764 | |
---|
| 765 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
---|
| 766 | |
---|
| 767 | // get name attribute |
---|
| 768 | str = getStringValue( reader, "name", &ok ); |
---|
| 769 | #if XML_PARSER_DEBUG |
---|
[165] | 770 | printf(" name = %s\n", str); |
---|
[158] | 771 | #endif |
---|
| 772 | if ( ok ) |
---|
| 773 | { |
---|
| 774 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
| 775 | } |
---|
| 776 | else |
---|
| 777 | { |
---|
| 778 | printf("[XML ERROR] illegal or missing <name> for pseg %d\n", pseg_index); |
---|
| 779 | exit(1); |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | // get base attribute |
---|
| 783 | value = getIntValue( reader, "base", &ok ); |
---|
| 784 | #if XML_PARSER_DEBUG |
---|
[165] | 785 | printf(" base = %x\n", value); |
---|
[158] | 786 | #endif |
---|
| 787 | if ( ok ) |
---|
| 788 | { |
---|
| 789 | pseg[pseg_index]->base = value; |
---|
| 790 | } |
---|
| 791 | else |
---|
| 792 | { |
---|
| 793 | printf("[XML ERROR] illegal or missing <base> for pseg %d\n", pseg_index); |
---|
| 794 | exit(1); |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | // get length attribute |
---|
| 798 | value = getIntValue( reader, "length", &ok ); |
---|
| 799 | #if XML_PARSER_DEBUG |
---|
[165] | 800 | printf(" length = %x\n\n", value); |
---|
[158] | 801 | #endif |
---|
| 802 | if ( ok ) |
---|
| 803 | { |
---|
| 804 | pseg[pseg_index]->length = value; |
---|
| 805 | } |
---|
| 806 | else |
---|
| 807 | { |
---|
| 808 | printf("[XML ERROR] illegal or missing <length> for pseg %d\n", pseg_index); |
---|
| 809 | exit(1); |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | pseg_index++; |
---|
| 813 | } // end psegNode() |
---|
| 814 | |
---|
| 815 | ///////////////////////////////////////////// |
---|
| 816 | void clusterNode ( xmlTextReaderPtr reader ) |
---|
| 817 | { |
---|
| 818 | unsigned int ok; |
---|
| 819 | unsigned int value; |
---|
| 820 | |
---|
| 821 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 822 | |
---|
| 823 | // checking source file consistency |
---|
| 824 | if ( cluster_index >= header->clusters ) |
---|
| 825 | { |
---|
| 826 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
| 827 | exit(1); |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | #if XML_PARSER_DEBUG |
---|
| 831 | printf(" cluster %d :\n", cluster_index); |
---|
| 832 | #endif |
---|
| 833 | |
---|
| 834 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
---|
| 835 | |
---|
[165] | 836 | // get index attribute (optional) |
---|
| 837 | value = getIntValue(reader,"index",&ok); |
---|
[158] | 838 | #if XML_PARSER_DEBUG |
---|
[165] | 839 | printf(" index = %d\n", value); |
---|
[158] | 840 | #endif |
---|
[165] | 841 | if ( ok && (value != cluster_index) ) |
---|
[158] | 842 | { |
---|
[165] | 843 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
---|
[158] | 844 | cluster_index); |
---|
[165] | 845 | exit(1); |
---|
[158] | 846 | } |
---|
| 847 | |
---|
[165] | 848 | // get procs attribute |
---|
| 849 | value = getIntValue(reader,"procs",&ok); |
---|
[158] | 850 | #if XML_PARSER_DEBUG |
---|
[165] | 851 | printf(" procs = %d\n", value); |
---|
[158] | 852 | #endif |
---|
| 853 | if ( ok ) |
---|
| 854 | { |
---|
[165] | 855 | cluster[cluster_index]->procs = value; |
---|
[158] | 856 | } |
---|
| 857 | else |
---|
| 858 | { |
---|
[165] | 859 | printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", |
---|
[158] | 860 | cluster_index); |
---|
| 861 | exit(1); |
---|
| 862 | } |
---|
| 863 | |
---|
| 864 | cluster_index++; |
---|
| 865 | } // end clusterNode() |
---|
| 866 | |
---|
| 867 | ////////////////////////////////////////////// |
---|
| 868 | void clusterSetNode( xmlTextReaderPtr reader ) |
---|
| 869 | { |
---|
| 870 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 871 | |
---|
| 872 | #if XML_PARSER_DEBUG |
---|
[165] | 873 | printf("\n clusters set\n"); |
---|
[158] | 874 | #endif |
---|
| 875 | |
---|
| 876 | int status = xmlTextReaderRead ( reader ); |
---|
| 877 | while ( status == 1 ) |
---|
| 878 | { |
---|
| 879 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 880 | |
---|
| 881 | if ( strcmp(tag,"cluster") == 0 ) clusterNode(reader); |
---|
| 882 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 883 | else if ( strcmp(tag,"clusterset") == 0 ) |
---|
| 884 | { |
---|
| 885 | // checking source file consistency |
---|
| 886 | if ( cluster_index != header->clusters ) |
---|
| 887 | { |
---|
| 888 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
| 889 | exit(1); |
---|
| 890 | } |
---|
| 891 | else |
---|
| 892 | { |
---|
| 893 | return; |
---|
| 894 | } |
---|
| 895 | } |
---|
| 896 | else |
---|
| 897 | { |
---|
| 898 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
| 899 | exit(1); |
---|
| 900 | } |
---|
| 901 | status = xmlTextReaderRead ( reader ); |
---|
| 902 | } |
---|
| 903 | } // end clusterSetNode() |
---|
| 904 | |
---|
| 905 | /////////////////////////////////////////// |
---|
| 906 | void psegSetNode( xmlTextReaderPtr reader ) |
---|
| 907 | { |
---|
| 908 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 909 | |
---|
| 910 | #if XML_PARSER_DEBUG |
---|
| 911 | printf(" psegs set\n"); |
---|
| 912 | #endif |
---|
| 913 | |
---|
| 914 | int status = xmlTextReaderRead ( reader ); |
---|
| 915 | while ( status == 1 ) |
---|
| 916 | { |
---|
| 917 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 918 | |
---|
| 919 | if ( strcmp(tag,"pseg") == 0 ) psegNode(reader); |
---|
| 920 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 921 | else if ( strcmp(tag,"psegset") == 0 ) |
---|
| 922 | { |
---|
| 923 | // checking source file consistency |
---|
| 924 | if ( pseg_index != header->psegs ) |
---|
| 925 | { |
---|
| 926 | printf("[XML ERROR] Wrong number of psegs\n"); |
---|
| 927 | exit(1); |
---|
| 928 | } |
---|
| 929 | else |
---|
| 930 | { |
---|
| 931 | return; |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | else |
---|
| 935 | { |
---|
| 936 | printf("[XML ERROR] Unknown tag in psegset node : %s",tag); |
---|
| 937 | exit(1); |
---|
| 938 | } |
---|
| 939 | status = xmlTextReaderRead ( reader ); |
---|
| 940 | } |
---|
| 941 | } // end psegSetNode() |
---|
| 942 | |
---|
| 943 | ///////////////////////////////////////////// |
---|
| 944 | void globalSetNode( xmlTextReaderPtr reader ) |
---|
| 945 | { |
---|
| 946 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 947 | |
---|
| 948 | #if XML_PARSER_DEBUG |
---|
[165] | 949 | printf(" globals set\n"); |
---|
[158] | 950 | #endif |
---|
| 951 | |
---|
| 952 | int status = xmlTextReaderRead ( reader ); |
---|
| 953 | while ( status == 1 ) |
---|
| 954 | { |
---|
| 955 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 956 | |
---|
| 957 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
| 958 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 959 | else if ( strcmp(tag,"globalset") == 0 ) |
---|
| 960 | { |
---|
| 961 | // checking source file consistency |
---|
| 962 | if ( vseg_index != header->globals ) |
---|
| 963 | { |
---|
| 964 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
---|
| 965 | exit(1); |
---|
| 966 | } |
---|
| 967 | else |
---|
| 968 | { |
---|
| 969 | vseg_loc_index = 0; |
---|
| 970 | return; |
---|
| 971 | } |
---|
| 972 | } |
---|
| 973 | else |
---|
| 974 | { |
---|
| 975 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
| 976 | exit(1); |
---|
| 977 | } |
---|
| 978 | status = xmlTextReaderRead ( reader ); |
---|
| 979 | } |
---|
| 980 | } // end globalSetNode() |
---|
| 981 | |
---|
| 982 | ///////////////////////////////////////////// |
---|
| 983 | void vspaceSetNode( xmlTextReaderPtr reader ) |
---|
| 984 | { |
---|
| 985 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 986 | |
---|
| 987 | #if XML_PARSER_DEBUG |
---|
[165] | 988 | printf("\n vspaces set\n"); |
---|
[158] | 989 | #endif |
---|
| 990 | |
---|
| 991 | int status = xmlTextReaderRead ( reader ); |
---|
| 992 | while ( status == 1 ) |
---|
| 993 | { |
---|
| 994 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 995 | |
---|
| 996 | if ( strcmp(tag,"vspace") == 0 ) vspaceNode(reader); |
---|
| 997 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 998 | else if ( strcmp(tag,"vspaceset") == 0 ) |
---|
| 999 | { |
---|
| 1000 | // checking source file consistency |
---|
| 1001 | if ( vspace_index != header->vspaces ) |
---|
| 1002 | { |
---|
| 1003 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
| 1004 | exit(1); |
---|
| 1005 | } |
---|
| 1006 | else |
---|
| 1007 | { |
---|
| 1008 | header->vsegs = vseg_index; |
---|
[160] | 1009 | header->vobjs = vobj_index; |
---|
[158] | 1010 | header->tasks = task_index; |
---|
| 1011 | return; |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | else |
---|
| 1015 | { |
---|
| 1016 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
| 1017 | exit(1); |
---|
| 1018 | } |
---|
| 1019 | status = xmlTextReaderRead ( reader ); |
---|
| 1020 | } |
---|
| 1021 | } // end globalSetNode() |
---|
| 1022 | |
---|
| 1023 | ////////////////////////////////////////// |
---|
| 1024 | void headerNode(xmlTextReaderPtr reader ) |
---|
| 1025 | { |
---|
| 1026 | char* name; |
---|
| 1027 | unsigned int value; |
---|
| 1028 | unsigned int ok; |
---|
| 1029 | |
---|
| 1030 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 1031 | |
---|
| 1032 | #if XML_PARSER_DEBUG |
---|
| 1033 | printf("mapping_info\n"); |
---|
| 1034 | #endif |
---|
| 1035 | |
---|
| 1036 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
---|
| 1037 | |
---|
[165] | 1038 | ////////// get name attribute |
---|
[158] | 1039 | name = getStringValue(reader, "name", &ok); |
---|
| 1040 | if ( ok ) |
---|
| 1041 | { |
---|
| 1042 | #if XML_PARSER_DEBUG |
---|
[165] | 1043 | printf(" name = %s\n", name); |
---|
[158] | 1044 | #endif |
---|
| 1045 | strncpy( header->name, name, 31); |
---|
| 1046 | } |
---|
| 1047 | else |
---|
| 1048 | { |
---|
| 1049 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
| 1050 | exit(1); |
---|
| 1051 | } |
---|
| 1052 | |
---|
[165] | 1053 | /////////// get clusters attribute |
---|
[158] | 1054 | value = getIntValue(reader, "clusters", &ok); |
---|
| 1055 | if ( ok ) |
---|
| 1056 | { |
---|
| 1057 | if ( value >= MAX_CLUSTERS ) |
---|
| 1058 | { |
---|
| 1059 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
| 1060 | exit(1); |
---|
| 1061 | } |
---|
| 1062 | #if XML_PARSER_DEBUG |
---|
[165] | 1063 | printf(" clusters = %d\n", value); |
---|
[158] | 1064 | #endif |
---|
| 1065 | header->clusters = value; |
---|
| 1066 | } |
---|
| 1067 | else |
---|
| 1068 | { |
---|
| 1069 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
---|
| 1070 | exit(1); |
---|
| 1071 | } |
---|
| 1072 | |
---|
[165] | 1073 | ////////// get psegs attribute |
---|
[158] | 1074 | value = getIntValue(reader, "psegs", &ok); |
---|
| 1075 | if ( ok ) |
---|
| 1076 | { |
---|
| 1077 | if ( value >= MAX_PSEGS ) |
---|
| 1078 | { |
---|
| 1079 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 1080 | exit(1); |
---|
| 1081 | } |
---|
| 1082 | #if XML_PARSER_DEBUG |
---|
[165] | 1083 | printf(" psegs = %d\n", value); |
---|
[158] | 1084 | #endif |
---|
| 1085 | header->psegs = value; |
---|
| 1086 | } |
---|
| 1087 | else |
---|
| 1088 | { |
---|
| 1089 | printf("[XML ERROR] illegal or missing <psegs> attribute in header\n"); |
---|
| 1090 | exit(1); |
---|
| 1091 | } |
---|
| 1092 | |
---|
[165] | 1093 | ///////// get ttys attribute |
---|
[158] | 1094 | value = getIntValue(reader, "ttys", &ok); |
---|
| 1095 | if ( ok ) |
---|
| 1096 | { |
---|
| 1097 | #if XML_PARSER_DEBUG |
---|
[165] | 1098 | printf(" ttys = %d\n", value); |
---|
[158] | 1099 | #endif |
---|
| 1100 | header->ttys = value; |
---|
| 1101 | } |
---|
| 1102 | else |
---|
| 1103 | { |
---|
| 1104 | printf("[XML ERROR] illegal or missing <ttys> attribute in header\n"); |
---|
| 1105 | exit(1); |
---|
| 1106 | } |
---|
| 1107 | |
---|
[165] | 1108 | ///////// get fbs attribute |
---|
| 1109 | value = getIntValue(reader, "fbs", &ok); |
---|
| 1110 | if ( ok ) |
---|
| 1111 | { |
---|
| 1112 | #if XML_PARSER_DEBUG |
---|
| 1113 | printf(" fbs = %d\n", value); |
---|
| 1114 | #endif |
---|
| 1115 | header->fbs = value; |
---|
| 1116 | } |
---|
| 1117 | else |
---|
| 1118 | { |
---|
| 1119 | printf("[XML ERROR] illegal or missing <fbs> attribute in header\n"); |
---|
| 1120 | exit(1); |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | ///////// get vspaces attribute |
---|
[158] | 1124 | value = getIntValue(reader, "vspaces", &ok); |
---|
| 1125 | if ( ok ) |
---|
| 1126 | { |
---|
| 1127 | if ( value >= MAX_VSPACES ) |
---|
| 1128 | { |
---|
| 1129 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
| 1130 | exit(1); |
---|
| 1131 | } |
---|
| 1132 | #if XML_PARSER_DEBUG |
---|
[165] | 1133 | printf(" vspaces = %d\n", value); |
---|
[158] | 1134 | #endif |
---|
| 1135 | header->vspaces = value; |
---|
| 1136 | } |
---|
| 1137 | else |
---|
| 1138 | { |
---|
| 1139 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
| 1140 | exit(1); |
---|
| 1141 | } |
---|
| 1142 | |
---|
[165] | 1143 | ////////// get globals attribute |
---|
[158] | 1144 | value = getIntValue(reader, "globals", &ok); |
---|
| 1145 | if ( ok ) |
---|
| 1146 | { |
---|
| 1147 | if ( value >= MAX_VSEGS ) |
---|
| 1148 | { |
---|
| 1149 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
---|
| 1150 | exit(1); |
---|
| 1151 | } |
---|
| 1152 | #if XML_PARSER_DEBUG |
---|
[165] | 1153 | printf(" globals = %d\n", value); |
---|
[158] | 1154 | #endif |
---|
| 1155 | header->globals = value; |
---|
| 1156 | } |
---|
| 1157 | else |
---|
| 1158 | { |
---|
| 1159 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
---|
| 1160 | exit(1); |
---|
| 1161 | } |
---|
| 1162 | |
---|
| 1163 | header->signature = IN_MAPPING_SIGNATURE; |
---|
| 1164 | |
---|
| 1165 | int status = xmlTextReaderRead ( reader ); |
---|
| 1166 | while ( status == 1 ) |
---|
| 1167 | { |
---|
| 1168 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1169 | |
---|
| 1170 | if ( strcmp(tag,"clusterset") == 0 ) clusterSetNode(reader); |
---|
| 1171 | else if ( strcmp(tag,"psegset") == 0 ) psegSetNode(reader); |
---|
| 1172 | else if ( strcmp(tag,"globalset") == 0 ) globalSetNode(reader); |
---|
| 1173 | else if ( strcmp(tag,"vspaceset") == 0 ) vspaceSetNode(reader); |
---|
| 1174 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 1175 | else if ( strcmp(tag,"mapping_info") == 0 ) |
---|
| 1176 | { |
---|
| 1177 | #if XML_PARSER_DEBUG |
---|
| 1178 | printf("end mapping_info\n"); |
---|
| 1179 | #endif |
---|
| 1180 | return; |
---|
| 1181 | } |
---|
| 1182 | else |
---|
| 1183 | { |
---|
[174] | 1184 | printf("[XML ERROR] Unknown tag in header node : %s\n",tag); |
---|
[158] | 1185 | exit(1); |
---|
| 1186 | } |
---|
| 1187 | status = xmlTextReaderRead ( reader ); |
---|
| 1188 | } |
---|
| 1189 | } // end headerNode() |
---|
| 1190 | |
---|
| 1191 | /////////////////////////// |
---|
| 1192 | void buildBin( int fdout ) |
---|
| 1193 | { |
---|
| 1194 | unsigned int cluster_id; |
---|
| 1195 | unsigned int pseg_id; |
---|
| 1196 | unsigned int vspace_id; |
---|
| 1197 | unsigned int vseg_id; |
---|
[160] | 1198 | unsigned int vobj_id; |
---|
[158] | 1199 | unsigned int task_id; |
---|
| 1200 | |
---|
| 1201 | unsigned int length; |
---|
| 1202 | |
---|
| 1203 | // write header to binary file |
---|
| 1204 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
---|
| 1205 | |
---|
| 1206 | #if XML_PARSER_DEBUG |
---|
| 1207 | printf("\n*** write header\n"); |
---|
| 1208 | #endif |
---|
| 1209 | |
---|
| 1210 | if ( length != sizeof(mapping_header_t) ) |
---|
| 1211 | { |
---|
| 1212 | perror("write header"); |
---|
| 1213 | exit(1); |
---|
| 1214 | } |
---|
| 1215 | |
---|
| 1216 | // write clusters |
---|
| 1217 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
---|
| 1218 | { |
---|
| 1219 | length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t)); |
---|
| 1220 | |
---|
| 1221 | #if XML_PARSER_DEBUG |
---|
| 1222 | printf("\n*** write cluster %d\n", cluster_id); |
---|
| 1223 | #endif |
---|
| 1224 | |
---|
| 1225 | if ( length != sizeof(mapping_cluster_t) ) |
---|
| 1226 | { |
---|
| 1227 | perror("write cluster"); |
---|
| 1228 | exit(1); |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | // write psegs |
---|
| 1233 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 1234 | { |
---|
| 1235 | length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t)); |
---|
| 1236 | |
---|
| 1237 | #if XML_PARSER_DEBUG |
---|
| 1238 | printf("write pseg %d\n", pseg_id); |
---|
| 1239 | #endif |
---|
| 1240 | |
---|
| 1241 | if ( length != sizeof(mapping_pseg_t) ) |
---|
| 1242 | { |
---|
| 1243 | perror("write pseg"); |
---|
| 1244 | exit(1); |
---|
| 1245 | } |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | // write vspaces |
---|
| 1249 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 1250 | { |
---|
| 1251 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
---|
| 1252 | |
---|
| 1253 | #if XML_PARSER_DEBUG |
---|
| 1254 | printf("write vspace %d\n", vspace_id); |
---|
[160] | 1255 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
---|
| 1256 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
---|
| 1257 | printf("header->vobjs: %d\n", header->vobjs); |
---|
[158] | 1258 | #endif |
---|
| 1259 | |
---|
| 1260 | if ( length != sizeof(mapping_vspace_t) ) |
---|
| 1261 | { |
---|
| 1262 | perror("write vspace"); |
---|
| 1263 | exit(1); |
---|
| 1264 | } |
---|
| 1265 | } |
---|
| 1266 | |
---|
| 1267 | // write vsegs |
---|
| 1268 | for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ ) |
---|
| 1269 | { |
---|
| 1270 | length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t)); |
---|
| 1271 | |
---|
| 1272 | #if XML_PARSER_DEBUG |
---|
| 1273 | printf("write vseg %d\n", vseg_id); |
---|
| 1274 | #endif |
---|
| 1275 | |
---|
| 1276 | if ( length != sizeof(mapping_vseg_t) ) |
---|
| 1277 | { |
---|
| 1278 | perror("write vseg"); |
---|
| 1279 | exit(1); |
---|
| 1280 | } |
---|
| 1281 | } |
---|
[160] | 1282 | |
---|
| 1283 | // write vobjs |
---|
| 1284 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
---|
| 1285 | { |
---|
| 1286 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
---|
| 1287 | |
---|
| 1288 | #if XML_PARSER_DEBUG |
---|
| 1289 | printf("write vobj %d\n", vobj_id); |
---|
| 1290 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
---|
| 1291 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
---|
| 1292 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
---|
| 1293 | #endif |
---|
[158] | 1294 | |
---|
[160] | 1295 | if ( length != sizeof(mapping_vobj_t) ) |
---|
| 1296 | { |
---|
| 1297 | perror("write vobj"); |
---|
| 1298 | exit(1); |
---|
| 1299 | } |
---|
| 1300 | } |
---|
| 1301 | |
---|
[158] | 1302 | // write tasks |
---|
| 1303 | for ( task_id = 0 ; task_id < header->tasks ; task_id++ ) |
---|
| 1304 | { |
---|
| 1305 | length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t)); |
---|
| 1306 | |
---|
| 1307 | #if XML_PARSER_DEBUG |
---|
| 1308 | printf("write task %d\n", task_id); |
---|
| 1309 | #endif |
---|
| 1310 | |
---|
| 1311 | if ( length != sizeof(mapping_task_t) ) |
---|
| 1312 | { |
---|
| 1313 | perror("write task"); |
---|
| 1314 | exit(1); |
---|
| 1315 | } |
---|
| 1316 | } |
---|
| 1317 | } // end buildBin() |
---|
| 1318 | |
---|
| 1319 | ///////////////////////////////////// |
---|
| 1320 | int main ( int argc, char* argv[] ) |
---|
| 1321 | { |
---|
| 1322 | if ( argc < 3 ) |
---|
| 1323 | { |
---|
| 1324 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
---|
| 1325 | return 1; |
---|
| 1326 | } |
---|
| 1327 | |
---|
| 1328 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
---|
| 1329 | if ( fdout < 0) |
---|
| 1330 | { |
---|
| 1331 | perror("open"); |
---|
| 1332 | exit(1); |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | LIBXML_TEST_VERSION; |
---|
| 1336 | |
---|
| 1337 | int status; |
---|
| 1338 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
---|
| 1339 | |
---|
| 1340 | if ( reader != NULL ) |
---|
| 1341 | { |
---|
| 1342 | status = xmlTextReaderRead ( reader ); |
---|
| 1343 | while ( status == 1 ) |
---|
| 1344 | { |
---|
| 1345 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1346 | if ( strcmp(tag,"mapping_info") == 0 ) |
---|
| 1347 | { |
---|
| 1348 | headerNode( reader ); |
---|
| 1349 | buildBin( fdout ); |
---|
| 1350 | } |
---|
| 1351 | else |
---|
| 1352 | { |
---|
| 1353 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
| 1354 | return 1; |
---|
| 1355 | } |
---|
| 1356 | status = xmlTextReaderRead ( reader ); |
---|
| 1357 | } |
---|
| 1358 | xmlFreeTextReader ( reader ); |
---|
| 1359 | |
---|
| 1360 | if ( status != 0 ) |
---|
| 1361 | { |
---|
| 1362 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
| 1363 | return 1; |
---|
| 1364 | } |
---|
| 1365 | } |
---|
| 1366 | return 0; |
---|
| 1367 | } // end main() |
---|