| 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> |
|---|
| 14 | #include <sys/types.h> |
|---|
| 15 | #include <sys/stat.h> |
|---|
| 16 | #include <unistd.h> |
|---|
| 17 | #include <stdio.h> |
|---|
| 18 | #include <string.h> |
|---|
| 19 | #include <libxml/xmlreader.h> |
|---|
| 20 | #include <mapping_info.h> |
|---|
| 21 | |
|---|
| 22 | #define MAX_CLUSTERS 1024 |
|---|
| 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 |
|---|
| 28 | #define MAX_VOBJS 8192 |
|---|
| 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 |
|---|
| 41 | mapping_vobj_t* vobj[MAX_VOBJS]; // vobj array |
|---|
| 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; |
|---|
| 52 | unsigned int vobj_index = 0; |
|---|
| 53 | unsigned int vobj_loc_index = 0; |
|---|
| 54 | unsigned int vobj_count = 0; |
|---|
| 55 | |
|---|
| 56 | unsigned int tty_index = 1; |
|---|
| 57 | unsigned int fb_index = 0; |
|---|
| 58 | |
|---|
| 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 | ////////////////////////////////////////// |
|---|
| 142 | int getVobjLocId( unsigned int vspace_id, |
|---|
| 143 | char* str ) |
|---|
| 144 | { |
|---|
| 145 | unsigned int vobj_id; |
|---|
| 146 | unsigned int vobj_min = vspace[vspace_id]->vobj_offset; |
|---|
| 147 | unsigned int vobj_max = vobj_min + vobj_loc_index; |
|---|
| 148 | |
|---|
| 149 | for ( vobj_id = vobj_min ; vobj_id < vobj_max ; vobj_id++ ) |
|---|
| 150 | { |
|---|
| 151 | if ( strcmp(vobj[vobj_id]->name, str) == 0 ) |
|---|
| 152 | { |
|---|
| 153 | return (vobj_id - vobj_min); |
|---|
| 154 | } |
|---|
| 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 |
|---|
| 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 | } |
|---|
| 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 |
|---|
| 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 | } |
|---|
| 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 | { |
|---|
| 243 | int index = getVobjLocId( vspace_index, str ); |
|---|
| 244 | if ( index >= 0 ) |
|---|
| 245 | { |
|---|
| 246 | #if XML_PARSER_DEBUG |
|---|
| 247 | printf(" stackname = %s\n", str); |
|---|
| 248 | printf(" stackid = %d\n", index); |
|---|
| 249 | #endif |
|---|
| 250 | task[task_index]->vobjlocid = index; |
|---|
| 251 | } |
|---|
| 252 | else |
|---|
| 253 | { |
|---|
| 254 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
|---|
| 255 | vspace_index, task_loc_index); |
|---|
| 256 | exit(1); |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | else |
|---|
| 260 | { |
|---|
| 261 | printf("[XML ERROR] illegal or missing <stackname> for task (%d,%d)\n", |
|---|
| 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 | |
|---|
| 282 | /////////// get use_tty attribute (optionnal : 0 if missing) |
|---|
| 283 | value = getIntValue(reader,"usetty", &ok); |
|---|
| 284 | if ( ok ) |
|---|
| 285 | { |
|---|
| 286 | #if XML_PARSER_DEBUG |
|---|
| 287 | printf(" usetty = %x\n", value); |
|---|
| 288 | #endif |
|---|
| 289 | if ( (value != 0) && (tty_index >= header->ttys) ) |
|---|
| 290 | { |
|---|
| 291 | printf("[XML ERROR] The tty index is too large for task (%d,%d)\n", |
|---|
| 292 | vspace_index, task_loc_index); |
|---|
| 293 | exit(1); |
|---|
| 294 | } |
|---|
| 295 | task[task_index]->use_tty = value; |
|---|
| 296 | if (value != 0) tty_index++; |
|---|
| 297 | } |
|---|
| 298 | else |
|---|
| 299 | { |
|---|
| 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", |
|---|
| 313 | vspace_index, task_loc_index); |
|---|
| 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; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | task_index++; |
|---|
| 325 | task_loc_index++; |
|---|
| 326 | } // end taskNode() |
|---|
| 327 | |
|---|
| 328 | ////////////////////////////////////////// |
|---|
| 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 |
|---|
| 344 | printf(" vobj %d\n", vobj_loc_index); |
|---|
| 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 |
|---|
| 354 | printf(" name = %s\n", str); |
|---|
| 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 | |
|---|
| 365 | //////// get type attribute |
|---|
| 366 | str = getStringValue(reader, "type", &ok); |
|---|
| 367 | #if XML_PARSER_DEBUG |
|---|
| 368 | printf(" type = %s\n", str); |
|---|
| 369 | #endif |
|---|
| 370 | if (ok && (strcmp(str, "ELF") == 0)) |
|---|
| 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) |
|---|
| 376 | { |
|---|
| 377 | printf("[XML ERROR] an ELF vobj must be alone in a vseg (%d,%d)\n", |
|---|
| 378 | vspace_index, vobj_loc_index); |
|---|
| 379 | exit(1); |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | else if (ok && (strcmp(str, "PTAB") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PTAB; |
|---|
| 383 | else if (ok && (strcmp(str, "PERI") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_PERI; |
|---|
| 384 | else if (ok && (strcmp(str, "MWMR") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_MWMR; |
|---|
| 385 | else if (ok && (strcmp(str, "LOCK") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_LOCK; |
|---|
| 386 | else if (ok && (strcmp(str, "BUFFER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BUFFER; |
|---|
| 387 | else if (ok && (strcmp(str, "BARRIER") == 0)) vobj[vobj_index]->type = VOBJ_TYPE_BARRIER; |
|---|
| 388 | else |
|---|
| 389 | { |
|---|
| 390 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", |
|---|
| 391 | vspace_index, vobj_loc_index); |
|---|
| 392 | exit(1); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | ////////// get length attribute |
|---|
| 396 | value = getIntValue(reader,"length", &ok); |
|---|
| 397 | if ( ok ) |
|---|
| 398 | { |
|---|
| 399 | #if XML_PARSER_DEBUG |
|---|
| 400 | printf(" length = %d\n", value); |
|---|
| 401 | #endif |
|---|
| 402 | vobj[vobj_index]->length = value; |
|---|
| 403 | } |
|---|
| 404 | else |
|---|
| 405 | { |
|---|
| 406 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", |
|---|
| 407 | vspace_index, vobj_loc_index); |
|---|
| 408 | exit(1); |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | ////////// get align attribute (optional : 0 if missing) |
|---|
| 412 | value = getIntValue(reader,"align", &ok); |
|---|
| 413 | if ( ok ) |
|---|
| 414 | { |
|---|
| 415 | #if XML_PARSER_DEBUG |
|---|
| 416 | printf(" align = %d\n", value); |
|---|
| 417 | #endif |
|---|
| 418 | vobj[vobj_index]->align = value; |
|---|
| 419 | } |
|---|
| 420 | else |
|---|
| 421 | { |
|---|
| 422 | vobj[vobj_index]->align = 0; |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | ////////// get binpath attribute (optional : '\0' if missing) |
|---|
| 426 | str = getStringValue(reader, "binpath", &ok); |
|---|
| 427 | if ( ok ) |
|---|
| 428 | { |
|---|
| 429 | #if XML_PARSER_DEBUG |
|---|
| 430 | printf(" binpath = %s\n", str); |
|---|
| 431 | #endif |
|---|
| 432 | strncpy(vobj[vobj_index]->binpath, str, 63); |
|---|
| 433 | } |
|---|
| 434 | else |
|---|
| 435 | { |
|---|
| 436 | vobj[vobj_index]->binpath[0] = '\0'; |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | ////////// get init attribute (optional : 0 if missing) |
|---|
| 440 | value = getIntValue(reader,"init", &ok); |
|---|
| 441 | if ( ok ) |
|---|
| 442 | { |
|---|
| 443 | #if XML_PARSER_DEBUG |
|---|
| 444 | printf(" init = %d\n", value); |
|---|
| 445 | #endif |
|---|
| 446 | vobj[vobj_index]->init = value; |
|---|
| 447 | } |
|---|
| 448 | else |
|---|
| 449 | { |
|---|
| 450 | vobj[vobj_index]->init = 0; |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | vobj_index++; |
|---|
| 454 | vobj_count++; |
|---|
| 455 | vobj_loc_index++; |
|---|
| 456 | } // end vobjNode() |
|---|
| 457 | |
|---|
| 458 | ////////////////////////////////////////// |
|---|
| 459 | void vsegNode ( xmlTextReaderPtr reader ) |
|---|
| 460 | { |
|---|
| 461 | unsigned int ok; |
|---|
| 462 | unsigned int value; |
|---|
| 463 | char* str; |
|---|
| 464 | |
|---|
| 465 | vobj_count = 0; |
|---|
| 466 | |
|---|
| 467 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 468 | |
|---|
| 469 | if ( vseg_index >= MAX_VSEGS ) |
|---|
| 470 | { |
|---|
| 471 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
|---|
| 472 | exit(1); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | #if XML_PARSER_DEBUG |
|---|
| 476 | printf(" vseg %d\n", vseg_loc_index); |
|---|
| 477 | #endif |
|---|
| 478 | |
|---|
| 479 | vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t)); |
|---|
| 480 | |
|---|
| 481 | ////////// set vobj_offset attributes |
|---|
| 482 | vseg[vseg_index]->vobj_offset = vobj_index; |
|---|
| 483 | #if XML_PARSER_DEBUG |
|---|
| 484 | printf(" vobj_offset = %d\n", vobj_index); |
|---|
| 485 | #endif |
|---|
| 486 | |
|---|
| 487 | ///////// get name attribute |
|---|
| 488 | str = getStringValue(reader, "name", &ok); |
|---|
| 489 | if ( ok ) |
|---|
| 490 | { |
|---|
| 491 | #if XML_PARSER_DEBUG |
|---|
| 492 | printf(" name = %s\n", str); |
|---|
| 493 | #endif |
|---|
| 494 | strncpy( vseg[vseg_index]->name, str, 31); |
|---|
| 495 | } |
|---|
| 496 | else |
|---|
| 497 | { |
|---|
| 498 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
|---|
| 499 | vspace_index, vseg_loc_index); |
|---|
| 500 | exit(1); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | /////////// get vbase attribute |
|---|
| 504 | value = getIntValue(reader,"vbase", &ok); |
|---|
| 505 | if ( ok ) |
|---|
| 506 | { |
|---|
| 507 | #if XML_PARSER_DEBUG |
|---|
| 508 | printf(" vbase = 0x%x\n", value); |
|---|
| 509 | #endif |
|---|
| 510 | vseg[vseg_index]->vbase = value; |
|---|
| 511 | } |
|---|
| 512 | else |
|---|
| 513 | { |
|---|
| 514 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
|---|
| 515 | vspace_index, vseg_loc_index); |
|---|
| 516 | exit(1); |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | ////////// get ident attribute (optional : 0 if missing) |
|---|
| 520 | value = getIntValue(reader,"ident", &ok); |
|---|
| 521 | if ( ok ) |
|---|
| 522 | { |
|---|
| 523 | #if XML_PARSER_DEBUG |
|---|
| 524 | printf(" ident = %d\n", value); |
|---|
| 525 | #endif |
|---|
| 526 | vseg[vseg_index]->ident = value; |
|---|
| 527 | } |
|---|
| 528 | else |
|---|
| 529 | { |
|---|
| 530 | vseg[vseg_index]->ident = 0; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | ////////// get psegname attribute |
|---|
| 534 | str = getStringValue(reader,"psegname", &ok); |
|---|
| 535 | if ( ok ) |
|---|
| 536 | { |
|---|
| 537 | int index = getPsegId( str ); |
|---|
| 538 | if ( index >= 0 ) |
|---|
| 539 | { |
|---|
| 540 | #if XML_PARSER_DEBUG |
|---|
| 541 | printf(" psegname = %s\n", str); |
|---|
| 542 | printf(" psegid = %d\n", index); |
|---|
| 543 | #endif |
|---|
| 544 | vseg[vseg_index]->psegid = index; |
|---|
| 545 | } |
|---|
| 546 | else |
|---|
| 547 | { |
|---|
| 548 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
|---|
| 549 | vseg_loc_index); |
|---|
| 550 | exit(1); |
|---|
| 551 | } |
|---|
| 552 | } |
|---|
| 553 | else |
|---|
| 554 | { |
|---|
| 555 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
|---|
| 556 | vseg_loc_index); |
|---|
| 557 | exit(1); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | //////// get mode attribute |
|---|
| 561 | str = getStringValue(reader,"mode", &ok); |
|---|
| 562 | #if XML_PARSER_DEBUG |
|---|
| 563 | printf(" mode = %s\n", str); |
|---|
| 564 | #endif |
|---|
| 565 | if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; |
|---|
| 566 | else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; |
|---|
| 567 | else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; |
|---|
| 568 | else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; |
|---|
| 569 | else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; |
|---|
| 570 | else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; |
|---|
| 571 | else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; |
|---|
| 572 | else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; |
|---|
| 573 | else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; |
|---|
| 574 | else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; |
|---|
| 575 | else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; |
|---|
| 576 | else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; |
|---|
| 577 | else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; |
|---|
| 578 | else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; |
|---|
| 579 | else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; |
|---|
| 580 | else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; |
|---|
| 581 | else |
|---|
| 582 | { |
|---|
| 583 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
|---|
| 584 | vspace_index, vseg_loc_index); |
|---|
| 585 | exit(1); |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | ////////// set the length attribute to 0 |
|---|
| 589 | vseg[vseg_index]->length = value; |
|---|
| 590 | |
|---|
| 591 | ////////// get vobjs |
|---|
| 592 | int status = xmlTextReaderRead ( reader ); |
|---|
| 593 | while ( status == 1 ) |
|---|
| 594 | { |
|---|
| 595 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 596 | |
|---|
| 597 | if ( strcmp(tag,"vobj") == 0 ) vobjNode(reader); |
|---|
| 598 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
|---|
| 599 | else if ( strcmp(tag,"vseg") == 0 ) |
|---|
| 600 | { |
|---|
| 601 | // checking source file consistency? |
|---|
| 602 | vseg[vseg_index]->vobjs = vobj_count; |
|---|
| 603 | vseg_index++; |
|---|
| 604 | vseg_loc_index++; |
|---|
| 605 | return; |
|---|
| 606 | } |
|---|
| 607 | else |
|---|
| 608 | { |
|---|
| 609 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 610 | exit(1); |
|---|
| 611 | } |
|---|
| 612 | status = xmlTextReaderRead ( reader ); |
|---|
| 613 | } |
|---|
| 614 | } // end vsegNode() |
|---|
| 615 | |
|---|
| 616 | ////////////////////////////////////////// |
|---|
| 617 | void vspaceNode( xmlTextReaderPtr reader ) |
|---|
| 618 | { |
|---|
| 619 | char* str; |
|---|
| 620 | unsigned int ok; |
|---|
| 621 | |
|---|
| 622 | vobj_loc_index = 0; |
|---|
| 623 | vseg_loc_index = 0; |
|---|
| 624 | task_loc_index = 0; |
|---|
| 625 | |
|---|
| 626 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 627 | |
|---|
| 628 | // checking source file consistency |
|---|
| 629 | if ( vspace_index >= header->vspaces ) |
|---|
| 630 | { |
|---|
| 631 | printf("[XML ERROR] The vspace index is too large : %d\n", |
|---|
| 632 | vspace_index); |
|---|
| 633 | exit(1); |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | #if XML_PARSER_DEBUG |
|---|
| 637 | printf("\n vspace %d\n", vspace_index); |
|---|
| 638 | #endif |
|---|
| 639 | |
|---|
| 640 | vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t)); |
|---|
| 641 | |
|---|
| 642 | ////////// get name attribute |
|---|
| 643 | str = getStringValue(reader, "name", &ok); |
|---|
| 644 | if ( ok ) |
|---|
| 645 | { |
|---|
| 646 | #if XML_PARSER_DEBUG |
|---|
| 647 | printf(" name = %s\n", str); |
|---|
| 648 | #endif |
|---|
| 649 | strncpy(vspace[vspace_index]->name, str, 31); |
|---|
| 650 | } |
|---|
| 651 | else |
|---|
| 652 | { |
|---|
| 653 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", |
|---|
| 654 | vspace_index); |
|---|
| 655 | exit(1); |
|---|
| 656 | } |
|---|
| 657 | |
|---|
| 658 | ////////// set vseg_offset and task_offset attributes |
|---|
| 659 | vspace[vspace_index]->vseg_offset = vseg_index; |
|---|
| 660 | vspace[vspace_index]->vobj_offset = vobj_index; |
|---|
| 661 | vspace[vspace_index]->task_offset = task_index; |
|---|
| 662 | |
|---|
| 663 | #if XML_PARSER_DEBUG |
|---|
| 664 | printf(" vseg_offset = %d\n", vseg_index); |
|---|
| 665 | printf(" vobj_offset = %d\n", vobj_index); |
|---|
| 666 | printf(" task_offset = %d\n", task_index); |
|---|
| 667 | #endif |
|---|
| 668 | |
|---|
| 669 | ////////// get startname attribute |
|---|
| 670 | str = getStringValue(reader, "startname", &ok); |
|---|
| 671 | if ( ok ) |
|---|
| 672 | { |
|---|
| 673 | //used after parsing the vobjs |
|---|
| 674 | } |
|---|
| 675 | else |
|---|
| 676 | { |
|---|
| 677 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %d\n", |
|---|
| 678 | vspace_index); |
|---|
| 679 | exit(1); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | int status = xmlTextReaderRead ( reader ); |
|---|
| 683 | while ( status == 1 ) |
|---|
| 684 | { |
|---|
| 685 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 686 | |
|---|
| 687 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
|---|
| 688 | else if ( strcmp(tag,"task") == 0 ) taskNode(reader); |
|---|
| 689 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
|---|
| 690 | else if ( strcmp(tag,"vspace") == 0 ) |
|---|
| 691 | { |
|---|
| 692 | vspace[vspace_index]->vobjs = vobj_loc_index; |
|---|
| 693 | vspace[vspace_index]->tasks = task_loc_index ; |
|---|
| 694 | vspace[vspace_index]->vsegs = vseg_loc_index ; |
|---|
| 695 | |
|---|
| 696 | // get index of the vobj containing the start vector |
|---|
| 697 | int index = getVobjLocId( vspace_index, str ); |
|---|
| 698 | if(index == -1) |
|---|
| 699 | { |
|---|
| 700 | printf("[XML ERROR] vobj containing the start vector not found %s\n",str); |
|---|
| 701 | exit(-1); |
|---|
| 702 | } |
|---|
| 703 | else |
|---|
| 704 | { |
|---|
| 705 | vspace[vspace_index]->start_offset = index; |
|---|
| 706 | #if XML_PARSER_DEBUG |
|---|
| 707 | printf(" startname = %s\n", str); |
|---|
| 708 | printf(" startid = %d\n", index); |
|---|
| 709 | #endif |
|---|
| 710 | } |
|---|
| 711 | |
|---|
| 712 | // checking startid values for all tasks in vspace |
|---|
| 713 | int task_id; |
|---|
| 714 | int task_min = vspace[vspace_index]->task_offset; |
|---|
| 715 | int task_max = task_min + vspace[vspace_index]->tasks; |
|---|
| 716 | for ( task_id = task_min ; task_id < task_max ; task_id++ ) |
|---|
| 717 | { |
|---|
| 718 | if ( task[task_id]->startid >= vspace[vspace_index]->tasks ) |
|---|
| 719 | { |
|---|
| 720 | printf("[XML ERROR] <startid> too large for task (%d,%d)\n", |
|---|
| 721 | vspace_index, task_id ); |
|---|
| 722 | exit(1); |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | vspace_index++; |
|---|
| 727 | return; |
|---|
| 728 | } |
|---|
| 729 | else |
|---|
| 730 | { |
|---|
| 731 | printf("[XML ERROR] Unknown tag %s",tag); |
|---|
| 732 | exit(1); |
|---|
| 733 | } |
|---|
| 734 | status = xmlTextReaderRead ( reader ); |
|---|
| 735 | } |
|---|
| 736 | } // end vspaceNode() |
|---|
| 737 | |
|---|
| 738 | ////////////////////////////////////////// |
|---|
| 739 | void psegNode ( xmlTextReaderPtr reader ) |
|---|
| 740 | { |
|---|
| 741 | unsigned int ok; |
|---|
| 742 | unsigned int value; |
|---|
| 743 | char* str; |
|---|
| 744 | |
|---|
| 745 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 746 | |
|---|
| 747 | if ( pseg_index >= MAX_PSEGS ) |
|---|
| 748 | { |
|---|
| 749 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
|---|
| 750 | exit(1); |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | #if XML_PARSER_DEBUG |
|---|
| 754 | printf(" pseg %d\n", pseg_index); |
|---|
| 755 | #endif |
|---|
| 756 | |
|---|
| 757 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
|---|
| 758 | |
|---|
| 759 | // get name attribute |
|---|
| 760 | str = getStringValue( reader, "name", &ok ); |
|---|
| 761 | #if XML_PARSER_DEBUG |
|---|
| 762 | printf(" name = %s\n", str); |
|---|
| 763 | #endif |
|---|
| 764 | if ( ok ) |
|---|
| 765 | { |
|---|
| 766 | strncpy(pseg[pseg_index]->name, str, 31); |
|---|
| 767 | } |
|---|
| 768 | else |
|---|
| 769 | { |
|---|
| 770 | printf("[XML ERROR] illegal or missing <name> for pseg %d\n", pseg_index); |
|---|
| 771 | exit(1); |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | // get base attribute |
|---|
| 775 | value = getIntValue( reader, "base", &ok ); |
|---|
| 776 | #if XML_PARSER_DEBUG |
|---|
| 777 | printf(" base = %x\n", value); |
|---|
| 778 | #endif |
|---|
| 779 | if ( ok ) |
|---|
| 780 | { |
|---|
| 781 | pseg[pseg_index]->base = value; |
|---|
| 782 | } |
|---|
| 783 | else |
|---|
| 784 | { |
|---|
| 785 | printf("[XML ERROR] illegal or missing <base> for pseg %d\n", pseg_index); |
|---|
| 786 | exit(1); |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | // get length attribute |
|---|
| 790 | value = getIntValue( reader, "length", &ok ); |
|---|
| 791 | #if XML_PARSER_DEBUG |
|---|
| 792 | printf(" length = %x\n\n", value); |
|---|
| 793 | #endif |
|---|
| 794 | if ( ok ) |
|---|
| 795 | { |
|---|
| 796 | pseg[pseg_index]->length = value; |
|---|
| 797 | } |
|---|
| 798 | else |
|---|
| 799 | { |
|---|
| 800 | printf("[XML ERROR] illegal or missing <length> for pseg %d\n", pseg_index); |
|---|
| 801 | exit(1); |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | pseg[pseg_index]->next_free_page = 0; |
|---|
| 805 | pseg_index++; |
|---|
| 806 | } // end psegNode() |
|---|
| 807 | |
|---|
| 808 | ///////////////////////////////////////////// |
|---|
| 809 | void clusterNode ( xmlTextReaderPtr reader ) |
|---|
| 810 | { |
|---|
| 811 | unsigned int ok; |
|---|
| 812 | unsigned int value; |
|---|
| 813 | |
|---|
| 814 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 815 | |
|---|
| 816 | // checking source file consistency |
|---|
| 817 | if ( cluster_index >= header->clusters ) |
|---|
| 818 | { |
|---|
| 819 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
|---|
| 820 | exit(1); |
|---|
| 821 | } |
|---|
| 822 | |
|---|
| 823 | #if XML_PARSER_DEBUG |
|---|
| 824 | printf(" cluster %d :\n", cluster_index); |
|---|
| 825 | #endif |
|---|
| 826 | |
|---|
| 827 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
|---|
| 828 | |
|---|
| 829 | // get index attribute (optional) |
|---|
| 830 | value = getIntValue(reader,"index",&ok); |
|---|
| 831 | #if XML_PARSER_DEBUG |
|---|
| 832 | printf(" index = %d\n", value); |
|---|
| 833 | #endif |
|---|
| 834 | if ( ok && (value != cluster_index) ) |
|---|
| 835 | { |
|---|
| 836 | printf("[XML ERROR] wrong cluster index / expected value is %d", |
|---|
| 837 | cluster_index); |
|---|
| 838 | exit(1); |
|---|
| 839 | } |
|---|
| 840 | |
|---|
| 841 | // get procs attribute |
|---|
| 842 | value = getIntValue(reader,"procs",&ok); |
|---|
| 843 | #if XML_PARSER_DEBUG |
|---|
| 844 | printf(" procs = %d\n", value); |
|---|
| 845 | #endif |
|---|
| 846 | if ( ok ) |
|---|
| 847 | { |
|---|
| 848 | cluster[cluster_index]->procs = value; |
|---|
| 849 | } |
|---|
| 850 | else |
|---|
| 851 | { |
|---|
| 852 | printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", |
|---|
| 853 | cluster_index); |
|---|
| 854 | exit(1); |
|---|
| 855 | } |
|---|
| 856 | |
|---|
| 857 | cluster_index++; |
|---|
| 858 | } // end clusterNode() |
|---|
| 859 | |
|---|
| 860 | ////////////////////////////////////////////// |
|---|
| 861 | void clusterSetNode( xmlTextReaderPtr reader ) |
|---|
| 862 | { |
|---|
| 863 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 864 | |
|---|
| 865 | #if XML_PARSER_DEBUG |
|---|
| 866 | printf("\n clusters set\n"); |
|---|
| 867 | #endif |
|---|
| 868 | |
|---|
| 869 | int status = xmlTextReaderRead ( reader ); |
|---|
| 870 | while ( status == 1 ) |
|---|
| 871 | { |
|---|
| 872 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 873 | |
|---|
| 874 | if ( strcmp(tag,"cluster") == 0 ) clusterNode(reader); |
|---|
| 875 | else if ( strcmp(tag,"#text") == 0 ) { } |
|---|
| 876 | else if ( strcmp(tag,"clusterset") == 0 ) |
|---|
| 877 | { |
|---|
| 878 | // checking source file consistency |
|---|
| 879 | if ( cluster_index != header->clusters ) |
|---|
| 880 | { |
|---|
| 881 | printf("[XML ERROR] Wrong number of clusters\n"); |
|---|
| 882 | exit(1); |
|---|
| 883 | } |
|---|
| 884 | else |
|---|
| 885 | { |
|---|
| 886 | return; |
|---|
| 887 | } |
|---|
| 888 | } |
|---|
| 889 | else |
|---|
| 890 | { |
|---|
| 891 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
|---|
| 892 | exit(1); |
|---|
| 893 | } |
|---|
| 894 | status = xmlTextReaderRead ( reader ); |
|---|
| 895 | } |
|---|
| 896 | } // end clusterSetNode() |
|---|
| 897 | |
|---|
| 898 | /////////////////////////////////////////// |
|---|
| 899 | void psegSetNode( xmlTextReaderPtr reader ) |
|---|
| 900 | { |
|---|
| 901 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 902 | |
|---|
| 903 | #if XML_PARSER_DEBUG |
|---|
| 904 | printf(" psegs set\n"); |
|---|
| 905 | #endif |
|---|
| 906 | |
|---|
| 907 | int status = xmlTextReaderRead ( reader ); |
|---|
| 908 | while ( status == 1 ) |
|---|
| 909 | { |
|---|
| 910 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 911 | |
|---|
| 912 | if ( strcmp(tag,"pseg") == 0 ) psegNode(reader); |
|---|
| 913 | else if ( strcmp(tag,"#text") == 0 ) { } |
|---|
| 914 | else if ( strcmp(tag,"psegset") == 0 ) |
|---|
| 915 | { |
|---|
| 916 | // checking source file consistency |
|---|
| 917 | if ( pseg_index != header->psegs ) |
|---|
| 918 | { |
|---|
| 919 | printf("[XML ERROR] Wrong number of psegs\n"); |
|---|
| 920 | exit(1); |
|---|
| 921 | } |
|---|
| 922 | else |
|---|
| 923 | { |
|---|
| 924 | return; |
|---|
| 925 | } |
|---|
| 926 | } |
|---|
| 927 | else |
|---|
| 928 | { |
|---|
| 929 | printf("[XML ERROR] Unknown tag in psegset node : %s",tag); |
|---|
| 930 | exit(1); |
|---|
| 931 | } |
|---|
| 932 | status = xmlTextReaderRead ( reader ); |
|---|
| 933 | } |
|---|
| 934 | } // end psegSetNode() |
|---|
| 935 | |
|---|
| 936 | ///////////////////////////////////////////// |
|---|
| 937 | void globalSetNode( xmlTextReaderPtr reader ) |
|---|
| 938 | { |
|---|
| 939 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 940 | |
|---|
| 941 | #if XML_PARSER_DEBUG |
|---|
| 942 | printf(" globals set\n"); |
|---|
| 943 | #endif |
|---|
| 944 | |
|---|
| 945 | int status = xmlTextReaderRead ( reader ); |
|---|
| 946 | while ( status == 1 ) |
|---|
| 947 | { |
|---|
| 948 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 949 | |
|---|
| 950 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
|---|
| 951 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
|---|
| 952 | else if ( strcmp(tag,"globalset") == 0 ) |
|---|
| 953 | { |
|---|
| 954 | // checking source file consistency |
|---|
| 955 | if ( vseg_index != header->globals ) |
|---|
| 956 | { |
|---|
| 957 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
|---|
| 958 | exit(1); |
|---|
| 959 | } |
|---|
| 960 | else |
|---|
| 961 | { |
|---|
| 962 | vseg_loc_index = 0; |
|---|
| 963 | return; |
|---|
| 964 | } |
|---|
| 965 | } |
|---|
| 966 | else |
|---|
| 967 | { |
|---|
| 968 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
|---|
| 969 | exit(1); |
|---|
| 970 | } |
|---|
| 971 | status = xmlTextReaderRead ( reader ); |
|---|
| 972 | } |
|---|
| 973 | } // end globalSetNode() |
|---|
| 974 | |
|---|
| 975 | ///////////////////////////////////////////// |
|---|
| 976 | void vspaceSetNode( xmlTextReaderPtr reader ) |
|---|
| 977 | { |
|---|
| 978 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 979 | |
|---|
| 980 | #if XML_PARSER_DEBUG |
|---|
| 981 | printf("\n vspaces set\n"); |
|---|
| 982 | #endif |
|---|
| 983 | |
|---|
| 984 | int status = xmlTextReaderRead ( reader ); |
|---|
| 985 | while ( status == 1 ) |
|---|
| 986 | { |
|---|
| 987 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 988 | |
|---|
| 989 | if ( strcmp(tag,"vspace") == 0 ) vspaceNode(reader); |
|---|
| 990 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
|---|
| 991 | else if ( strcmp(tag,"vspaceset") == 0 ) |
|---|
| 992 | { |
|---|
| 993 | // checking source file consistency |
|---|
| 994 | if ( vspace_index != header->vspaces ) |
|---|
| 995 | { |
|---|
| 996 | printf("[XML ERROR] Wrong number of vspaces\n"); |
|---|
| 997 | exit(1); |
|---|
| 998 | } |
|---|
| 999 | else |
|---|
| 1000 | { |
|---|
| 1001 | header->vsegs = vseg_index; |
|---|
| 1002 | header->vobjs = vobj_index; |
|---|
| 1003 | header->tasks = task_index; |
|---|
| 1004 | return; |
|---|
| 1005 | } |
|---|
| 1006 | } |
|---|
| 1007 | else |
|---|
| 1008 | { |
|---|
| 1009 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
|---|
| 1010 | exit(1); |
|---|
| 1011 | } |
|---|
| 1012 | status = xmlTextReaderRead ( reader ); |
|---|
| 1013 | } |
|---|
| 1014 | } // end globalSetNode() |
|---|
| 1015 | |
|---|
| 1016 | ////////////////////////////////////////// |
|---|
| 1017 | void headerNode(xmlTextReaderPtr reader ) |
|---|
| 1018 | { |
|---|
| 1019 | char* name; |
|---|
| 1020 | unsigned int value; |
|---|
| 1021 | unsigned int ok; |
|---|
| 1022 | |
|---|
| 1023 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
|---|
| 1024 | |
|---|
| 1025 | #if XML_PARSER_DEBUG |
|---|
| 1026 | printf("mapping_info\n"); |
|---|
| 1027 | #endif |
|---|
| 1028 | |
|---|
| 1029 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
|---|
| 1030 | |
|---|
| 1031 | ////////// get name attribute |
|---|
| 1032 | name = getStringValue(reader, "name", &ok); |
|---|
| 1033 | if ( ok ) |
|---|
| 1034 | { |
|---|
| 1035 | #if XML_PARSER_DEBUG |
|---|
| 1036 | printf(" name = %s\n", name); |
|---|
| 1037 | #endif |
|---|
| 1038 | strncpy( header->name, name, 31); |
|---|
| 1039 | } |
|---|
| 1040 | else |
|---|
| 1041 | { |
|---|
| 1042 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
|---|
| 1043 | exit(1); |
|---|
| 1044 | } |
|---|
| 1045 | |
|---|
| 1046 | /////////// get clusters attribute |
|---|
| 1047 | value = getIntValue(reader, "clusters", &ok); |
|---|
| 1048 | if ( ok ) |
|---|
| 1049 | { |
|---|
| 1050 | if ( value >= MAX_CLUSTERS ) |
|---|
| 1051 | { |
|---|
| 1052 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
|---|
| 1053 | exit(1); |
|---|
| 1054 | } |
|---|
| 1055 | #if XML_PARSER_DEBUG |
|---|
| 1056 | printf(" clusters = %d\n", value); |
|---|
| 1057 | #endif |
|---|
| 1058 | header->clusters = value; |
|---|
| 1059 | } |
|---|
| 1060 | else |
|---|
| 1061 | { |
|---|
| 1062 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
|---|
| 1063 | exit(1); |
|---|
| 1064 | } |
|---|
| 1065 | |
|---|
| 1066 | ////////// get psegs attribute |
|---|
| 1067 | value = getIntValue(reader, "psegs", &ok); |
|---|
| 1068 | if ( ok ) |
|---|
| 1069 | { |
|---|
| 1070 | if ( value >= MAX_PSEGS ) |
|---|
| 1071 | { |
|---|
| 1072 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
|---|
| 1073 | exit(1); |
|---|
| 1074 | } |
|---|
| 1075 | #if XML_PARSER_DEBUG |
|---|
| 1076 | printf(" psegs = %d\n", value); |
|---|
| 1077 | #endif |
|---|
| 1078 | header->psegs = value; |
|---|
| 1079 | } |
|---|
| 1080 | else |
|---|
| 1081 | { |
|---|
| 1082 | printf("[XML ERROR] illegal or missing <psegs> attribute in header\n"); |
|---|
| 1083 | exit(1); |
|---|
| 1084 | } |
|---|
| 1085 | |
|---|
| 1086 | ///////// get ttys attribute |
|---|
| 1087 | value = getIntValue(reader, "ttys", &ok); |
|---|
| 1088 | if ( ok ) |
|---|
| 1089 | { |
|---|
| 1090 | #if XML_PARSER_DEBUG |
|---|
| 1091 | printf(" ttys = %d\n", value); |
|---|
| 1092 | #endif |
|---|
| 1093 | header->ttys = value; |
|---|
| 1094 | } |
|---|
| 1095 | else |
|---|
| 1096 | { |
|---|
| 1097 | printf("[XML ERROR] illegal or missing <ttys> attribute in header\n"); |
|---|
| 1098 | exit(1); |
|---|
| 1099 | } |
|---|
| 1100 | |
|---|
| 1101 | ///////// get fbs attribute |
|---|
| 1102 | value = getIntValue(reader, "fbs", &ok); |
|---|
| 1103 | if ( ok ) |
|---|
| 1104 | { |
|---|
| 1105 | #if XML_PARSER_DEBUG |
|---|
| 1106 | printf(" fbs = %d\n", value); |
|---|
| 1107 | #endif |
|---|
| 1108 | header->fbs = value; |
|---|
| 1109 | } |
|---|
| 1110 | else |
|---|
| 1111 | { |
|---|
| 1112 | printf("[XML ERROR] illegal or missing <fbs> attribute in header\n"); |
|---|
| 1113 | exit(1); |
|---|
| 1114 | } |
|---|
| 1115 | |
|---|
| 1116 | ///////// get vspaces attribute |
|---|
| 1117 | value = getIntValue(reader, "vspaces", &ok); |
|---|
| 1118 | if ( ok ) |
|---|
| 1119 | { |
|---|
| 1120 | if ( value >= MAX_VSPACES ) |
|---|
| 1121 | { |
|---|
| 1122 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
|---|
| 1123 | exit(1); |
|---|
| 1124 | } |
|---|
| 1125 | #if XML_PARSER_DEBUG |
|---|
| 1126 | printf(" vspaces = %d\n", value); |
|---|
| 1127 | #endif |
|---|
| 1128 | header->vspaces = value; |
|---|
| 1129 | } |
|---|
| 1130 | else |
|---|
| 1131 | { |
|---|
| 1132 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
|---|
| 1133 | exit(1); |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | ////////// get globals attribute |
|---|
| 1137 | value = getIntValue(reader, "globals", &ok); |
|---|
| 1138 | if ( ok ) |
|---|
| 1139 | { |
|---|
| 1140 | if ( value >= MAX_VSEGS ) |
|---|
| 1141 | { |
|---|
| 1142 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
|---|
| 1143 | exit(1); |
|---|
| 1144 | } |
|---|
| 1145 | #if XML_PARSER_DEBUG |
|---|
| 1146 | printf(" globals = %d\n", value); |
|---|
| 1147 | #endif |
|---|
| 1148 | header->globals = value; |
|---|
| 1149 | } |
|---|
| 1150 | else |
|---|
| 1151 | { |
|---|
| 1152 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
|---|
| 1153 | exit(1); |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | header->signature = IN_MAPPING_SIGNATURE; |
|---|
| 1157 | |
|---|
| 1158 | int status = xmlTextReaderRead ( reader ); |
|---|
| 1159 | while ( status == 1 ) |
|---|
| 1160 | { |
|---|
| 1161 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1162 | |
|---|
| 1163 | if ( strcmp(tag,"clusterset") == 0 ) clusterSetNode(reader); |
|---|
| 1164 | else if ( strcmp(tag,"psegset") == 0 ) psegSetNode(reader); |
|---|
| 1165 | else if ( strcmp(tag,"globalset") == 0 ) globalSetNode(reader); |
|---|
| 1166 | else if ( strcmp(tag,"vspaceset") == 0 ) vspaceSetNode(reader); |
|---|
| 1167 | else if ( strcmp(tag,"#text") == 0 ) { } |
|---|
| 1168 | else if ( strcmp(tag,"mapping_info") == 0 ) |
|---|
| 1169 | { |
|---|
| 1170 | #if XML_PARSER_DEBUG |
|---|
| 1171 | printf("end mapping_info\n"); |
|---|
| 1172 | #endif |
|---|
| 1173 | return; |
|---|
| 1174 | } |
|---|
| 1175 | else |
|---|
| 1176 | { |
|---|
| 1177 | printf("[XML ERROR] Unknown tag in header node : %s",tag); |
|---|
| 1178 | exit(1); |
|---|
| 1179 | } |
|---|
| 1180 | status = xmlTextReaderRead ( reader ); |
|---|
| 1181 | } |
|---|
| 1182 | } // end headerNode() |
|---|
| 1183 | |
|---|
| 1184 | /////////////////////////// |
|---|
| 1185 | void buildBin( int fdout ) |
|---|
| 1186 | { |
|---|
| 1187 | unsigned int cluster_id; |
|---|
| 1188 | unsigned int pseg_id; |
|---|
| 1189 | unsigned int vspace_id; |
|---|
| 1190 | unsigned int vseg_id; |
|---|
| 1191 | unsigned int vobj_id; |
|---|
| 1192 | unsigned int task_id; |
|---|
| 1193 | |
|---|
| 1194 | unsigned int length; |
|---|
| 1195 | |
|---|
| 1196 | // write header to binary file |
|---|
| 1197 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
|---|
| 1198 | |
|---|
| 1199 | #if XML_PARSER_DEBUG |
|---|
| 1200 | printf("\n*** write header\n"); |
|---|
| 1201 | #endif |
|---|
| 1202 | |
|---|
| 1203 | if ( length != sizeof(mapping_header_t) ) |
|---|
| 1204 | { |
|---|
| 1205 | perror("write header"); |
|---|
| 1206 | exit(1); |
|---|
| 1207 | } |
|---|
| 1208 | |
|---|
| 1209 | // write clusters |
|---|
| 1210 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
|---|
| 1211 | { |
|---|
| 1212 | length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t)); |
|---|
| 1213 | |
|---|
| 1214 | #if XML_PARSER_DEBUG |
|---|
| 1215 | printf("\n*** write cluster %d\n", cluster_id); |
|---|
| 1216 | #endif |
|---|
| 1217 | |
|---|
| 1218 | if ( length != sizeof(mapping_cluster_t) ) |
|---|
| 1219 | { |
|---|
| 1220 | perror("write cluster"); |
|---|
| 1221 | exit(1); |
|---|
| 1222 | } |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | // write psegs |
|---|
| 1226 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
|---|
| 1227 | { |
|---|
| 1228 | length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t)); |
|---|
| 1229 | |
|---|
| 1230 | #if XML_PARSER_DEBUG |
|---|
| 1231 | printf("write pseg %d\n", pseg_id); |
|---|
| 1232 | #endif |
|---|
| 1233 | |
|---|
| 1234 | if ( length != sizeof(mapping_pseg_t) ) |
|---|
| 1235 | { |
|---|
| 1236 | perror("write pseg"); |
|---|
| 1237 | exit(1); |
|---|
| 1238 | } |
|---|
| 1239 | } |
|---|
| 1240 | |
|---|
| 1241 | // write vspaces |
|---|
| 1242 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
|---|
| 1243 | { |
|---|
| 1244 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
|---|
| 1245 | |
|---|
| 1246 | #if XML_PARSER_DEBUG |
|---|
| 1247 | printf("write vspace %d\n", vspace_id); |
|---|
| 1248 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); |
|---|
| 1249 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); |
|---|
| 1250 | printf("header->vobjs: %d\n", header->vobjs); |
|---|
| 1251 | #endif |
|---|
| 1252 | |
|---|
| 1253 | if ( length != sizeof(mapping_vspace_t) ) |
|---|
| 1254 | { |
|---|
| 1255 | perror("write vspace"); |
|---|
| 1256 | exit(1); |
|---|
| 1257 | } |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | // write vsegs |
|---|
| 1261 | for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ ) |
|---|
| 1262 | { |
|---|
| 1263 | length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t)); |
|---|
| 1264 | |
|---|
| 1265 | #if XML_PARSER_DEBUG |
|---|
| 1266 | printf("write vseg %d\n", vseg_id); |
|---|
| 1267 | #endif |
|---|
| 1268 | |
|---|
| 1269 | if ( length != sizeof(mapping_vseg_t) ) |
|---|
| 1270 | { |
|---|
| 1271 | perror("write vseg"); |
|---|
| 1272 | exit(1); |
|---|
| 1273 | } |
|---|
| 1274 | } |
|---|
| 1275 | |
|---|
| 1276 | // write vobjs |
|---|
| 1277 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) |
|---|
| 1278 | { |
|---|
| 1279 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); |
|---|
| 1280 | |
|---|
| 1281 | #if XML_PARSER_DEBUG |
|---|
| 1282 | printf("write vobj %d\n", vobj_id); |
|---|
| 1283 | printf("write vobj name %s\n", vobj[vobj_id]->name); |
|---|
| 1284 | printf("write vobj length %x\n", vobj[vobj_id]->length); |
|---|
| 1285 | printf("write vobj type %d\n", vobj[vobj_id]->type); |
|---|
| 1286 | #endif |
|---|
| 1287 | |
|---|
| 1288 | if ( length != sizeof(mapping_vobj_t) ) |
|---|
| 1289 | { |
|---|
| 1290 | perror("write vobj"); |
|---|
| 1291 | exit(1); |
|---|
| 1292 | } |
|---|
| 1293 | } |
|---|
| 1294 | |
|---|
| 1295 | // write tasks |
|---|
| 1296 | for ( task_id = 0 ; task_id < header->tasks ; task_id++ ) |
|---|
| 1297 | { |
|---|
| 1298 | length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t)); |
|---|
| 1299 | |
|---|
| 1300 | #if XML_PARSER_DEBUG |
|---|
| 1301 | printf("write task %d\n", task_id); |
|---|
| 1302 | #endif |
|---|
| 1303 | |
|---|
| 1304 | if ( length != sizeof(mapping_task_t) ) |
|---|
| 1305 | { |
|---|
| 1306 | perror("write task"); |
|---|
| 1307 | exit(1); |
|---|
| 1308 | } |
|---|
| 1309 | } |
|---|
| 1310 | } // end buildBin() |
|---|
| 1311 | |
|---|
| 1312 | ///////////////////////////////////// |
|---|
| 1313 | int main ( int argc, char* argv[] ) |
|---|
| 1314 | { |
|---|
| 1315 | if ( argc < 3 ) |
|---|
| 1316 | { |
|---|
| 1317 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
|---|
| 1318 | return 1; |
|---|
| 1319 | } |
|---|
| 1320 | |
|---|
| 1321 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
|---|
| 1322 | if ( fdout < 0) |
|---|
| 1323 | { |
|---|
| 1324 | perror("open"); |
|---|
| 1325 | exit(1); |
|---|
| 1326 | } |
|---|
| 1327 | |
|---|
| 1328 | LIBXML_TEST_VERSION; |
|---|
| 1329 | |
|---|
| 1330 | int status; |
|---|
| 1331 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
|---|
| 1332 | |
|---|
| 1333 | if ( reader != NULL ) |
|---|
| 1334 | { |
|---|
| 1335 | status = xmlTextReaderRead ( reader ); |
|---|
| 1336 | while ( status == 1 ) |
|---|
| 1337 | { |
|---|
| 1338 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
|---|
| 1339 | if ( strcmp(tag,"mapping_info") == 0 ) |
|---|
| 1340 | { |
|---|
| 1341 | headerNode( reader ); |
|---|
| 1342 | buildBin( fdout ); |
|---|
| 1343 | } |
|---|
| 1344 | else |
|---|
| 1345 | { |
|---|
| 1346 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
|---|
| 1347 | return 1; |
|---|
| 1348 | } |
|---|
| 1349 | status = xmlTextReaderRead ( reader ); |
|---|
| 1350 | } |
|---|
| 1351 | xmlFreeTextReader ( reader ); |
|---|
| 1352 | |
|---|
| 1353 | if ( status != 0 ) |
|---|
| 1354 | { |
|---|
| 1355 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
|---|
| 1356 | return 1; |
|---|
| 1357 | } |
|---|
| 1358 | } |
|---|
| 1359 | return 0; |
|---|
| 1360 | } // end main() |
|---|