| [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 | 
|---|
| [160] | 366 | str = getStringValue(reader, "type", &ok); | 
|---|
|  | 367 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 368 | printf("        type = %s\n", str); | 
|---|
| [160] | 369 | #endif | 
|---|
| [165] | 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) | 
|---|
| [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 | } | 
|---|
| [165] | 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; | 
|---|
| [160] | 388 | else | 
|---|
|  | 389 | { | 
|---|
|  | 390 | printf("[XML ERROR] illegal or missing <type> attribute for vobj (%d,%d)\n", | 
|---|
| [165] | 391 | vspace_index, vobj_loc_index); | 
|---|
| [160] | 392 | exit(1); | 
|---|
|  | 393 | } | 
|---|
|  | 394 |  | 
|---|
| [165] | 395 | ////////// get length attribute | 
|---|
| [160] | 396 | value = getIntValue(reader,"length", &ok); | 
|---|
|  | 397 | if ( ok ) | 
|---|
|  | 398 | { | 
|---|
|  | 399 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 400 | printf("        length = %d\n", value); | 
|---|
| [160] | 401 | #endif | 
|---|
|  | 402 | vobj[vobj_index]->length = value; | 
|---|
|  | 403 | } | 
|---|
|  | 404 | else | 
|---|
|  | 405 | { | 
|---|
| [165] | 406 | printf("[XML ERROR] illegal or missing <length> attribute for vobj (%d,%d)\n", | 
|---|
|  | 407 | vspace_index, vobj_loc_index); | 
|---|
|  | 408 | exit(1); | 
|---|
| [160] | 409 | } | 
|---|
|  | 410 |  | 
|---|
| [165] | 411 | ////////// get align attribute (optional : 0 if missing) | 
|---|
| [160] | 412 | value = getIntValue(reader,"align", &ok); | 
|---|
|  | 413 | if ( ok ) | 
|---|
|  | 414 | { | 
|---|
|  | 415 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 416 | printf("        align = %d\n", value); | 
|---|
| [160] | 417 | #endif | 
|---|
|  | 418 | vobj[vobj_index]->align = value; | 
|---|
|  | 419 | } | 
|---|
|  | 420 | else | 
|---|
|  | 421 | { | 
|---|
|  | 422 | vobj[vobj_index]->align = 0; | 
|---|
|  | 423 | } | 
|---|
|  | 424 |  | 
|---|
| [165] | 425 | ////////// get binpath attribute (optional : '\0' if missing) | 
|---|
| [160] | 426 | str = getStringValue(reader, "binpath", &ok); | 
|---|
|  | 427 | if ( ok ) | 
|---|
|  | 428 | { | 
|---|
|  | 429 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 430 | printf("        binpath = %s\n", str); | 
|---|
| [160] | 431 | #endif | 
|---|
|  | 432 | strncpy(vobj[vobj_index]->binpath, str, 63); | 
|---|
|  | 433 | } | 
|---|
|  | 434 | else | 
|---|
|  | 435 | { | 
|---|
|  | 436 | vobj[vobj_index]->binpath[0] = '\0'; | 
|---|
|  | 437 | } | 
|---|
|  | 438 |  | 
|---|
| [165] | 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 |  | 
|---|
| [160] | 453 | vobj_index++; | 
|---|
| [165] | 454 | vobj_count++; | 
|---|
| [160] | 455 | vobj_loc_index++; | 
|---|
| [165] | 456 | } // end vobjNode() | 
|---|
| [160] | 457 |  | 
|---|
| [165] | 458 | ////////////////////////////////////////// | 
|---|
| [158] | 459 | void  vsegNode ( xmlTextReaderPtr reader ) | 
|---|
|  | 460 | { | 
|---|
|  | 461 | unsigned int        ok; | 
|---|
|  | 462 | unsigned int        value; | 
|---|
|  | 463 | char*               str; | 
|---|
|  | 464 |  | 
|---|
| [165] | 465 | vobj_count = 0; | 
|---|
|  | 466 |  | 
|---|
| [158] | 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)); | 
|---|
| [160] | 480 |  | 
|---|
|  | 481 | ////////// set vobj_offset attributes | 
|---|
|  | 482 | vseg[vseg_index]->vobj_offset = vobj_index; | 
|---|
|  | 483 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 484 | printf("      vobj_offset = %d\n", vobj_index); | 
|---|
| [160] | 485 | #endif | 
|---|
| [158] | 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 |  | 
|---|
| [165] | 519 | ////////// get ident attribute (optional : 0 if missing) | 
|---|
| [158] | 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 |  | 
|---|
| [165] | 560 | //////// get mode attribute | 
|---|
| [158] | 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 |  | 
|---|
| [160] | 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? | 
|---|
| [165] | 602 | vseg[vseg_index]->vobjs = vobj_count; | 
|---|
| [160] | 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 | } | 
|---|
| [158] | 614 | } // end vsegNode() | 
|---|
|  | 615 |  | 
|---|
|  | 616 | ////////////////////////////////////////// | 
|---|
|  | 617 | void vspaceNode( xmlTextReaderPtr reader ) | 
|---|
|  | 618 | { | 
|---|
|  | 619 | char*               str; | 
|---|
|  | 620 | unsigned int        ok; | 
|---|
| [165] | 621 |  | 
|---|
|  | 622 | vobj_loc_index = 0; | 
|---|
| [160] | 623 | vseg_loc_index = 0; | 
|---|
|  | 624 | task_loc_index = 0; | 
|---|
| [158] | 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 | 
|---|
| [165] | 637 | printf("\n  vspace %d\n", vspace_index); | 
|---|
| [158] | 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 | 
|---|
| [165] | 647 | printf("  name = %s\n", str); | 
|---|
| [158] | 648 | #endif | 
|---|
|  | 649 | strncpy(vspace[vspace_index]->name, str, 31); | 
|---|
|  | 650 | } | 
|---|
|  | 651 | else | 
|---|
|  | 652 | { | 
|---|
| [165] | 653 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d\n", | 
|---|
| [158] | 654 | vspace_index); | 
|---|
|  | 655 | exit(1); | 
|---|
|  | 656 | } | 
|---|
|  | 657 |  | 
|---|
| [165] | 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 |  | 
|---|
| [158] | 663 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 664 | printf("  vseg_offset = %d\n", vseg_index); | 
|---|
|  | 665 | printf("  vobj_offset = %d\n", vobj_index); | 
|---|
|  | 666 | printf("  task_offset = %d\n", task_index); | 
|---|
| [158] | 667 | #endif | 
|---|
|  | 668 |  | 
|---|
| [165] | 669 | ////////// get startname attribute | 
|---|
|  | 670 | str = getStringValue(reader, "startname", &ok); | 
|---|
| [158] | 671 | if ( ok ) | 
|---|
|  | 672 | { | 
|---|
| [165] | 673 | //used after parsing the vobjs | 
|---|
| [158] | 674 | } | 
|---|
|  | 675 | else | 
|---|
|  | 676 | { | 
|---|
| [165] | 677 | printf("[XML ERROR] illegal or missing <startname> attribute for vspace %d\n", | 
|---|
|  | 678 | vspace_index); | 
|---|
| [158] | 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 | { | 
|---|
| [165] | 692 | vspace[vspace_index]->vobjs = vobj_loc_index; | 
|---|
| [160] | 693 | vspace[vspace_index]->tasks = task_loc_index ; | 
|---|
|  | 694 | vspace[vspace_index]->vsegs = vseg_loc_index ; | 
|---|
| [165] | 695 |  | 
|---|
|  | 696 | // get index of the vobj containing the start vector | 
|---|
| [160] | 697 | int index =  getVobjLocId( vspace_index, str ); | 
|---|
|  | 698 | if(index == -1) | 
|---|
| [158] | 699 | { | 
|---|
| [165] | 700 | printf("[XML ERROR] vobj containing the start vector not found %s\n",str); | 
|---|
| [160] | 701 | exit(-1); | 
|---|
| [158] | 702 | } | 
|---|
| [165] | 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 | } | 
|---|
| [160] | 711 |  | 
|---|
| [165] | 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 |  | 
|---|
| [160] | 726 | vspace_index++; | 
|---|
|  | 727 | return; | 
|---|
| [158] | 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 | 
|---|
| [165] | 762 | printf("    name = %s\n", str); | 
|---|
| [158] | 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 | 
|---|
| [165] | 777 | printf("    base = %x\n", value); | 
|---|
| [158] | 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 | 
|---|
| [165] | 792 | printf("    length = %x\n\n", value); | 
|---|
| [158] | 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_index++; | 
|---|
|  | 805 | } // end psegNode() | 
|---|
|  | 806 |  | 
|---|
|  | 807 | ///////////////////////////////////////////// | 
|---|
|  | 808 | void  clusterNode ( xmlTextReaderPtr reader ) | 
|---|
|  | 809 | { | 
|---|
|  | 810 | unsigned int ok; | 
|---|
|  | 811 | unsigned int value; | 
|---|
|  | 812 |  | 
|---|
|  | 813 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 814 |  | 
|---|
|  | 815 | // checking source file consistency | 
|---|
|  | 816 | if ( cluster_index >= header->clusters ) | 
|---|
|  | 817 | { | 
|---|
|  | 818 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); | 
|---|
|  | 819 | exit(1); | 
|---|
|  | 820 | } | 
|---|
|  | 821 |  | 
|---|
|  | 822 | #if XML_PARSER_DEBUG | 
|---|
|  | 823 | printf("  cluster %d :\n", cluster_index); | 
|---|
|  | 824 | #endif | 
|---|
|  | 825 |  | 
|---|
|  | 826 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); | 
|---|
|  | 827 |  | 
|---|
| [165] | 828 | // get index attribute (optional) | 
|---|
|  | 829 | value = getIntValue(reader,"index",&ok); | 
|---|
| [158] | 830 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 831 | printf("    index = %d\n", value); | 
|---|
| [158] | 832 | #endif | 
|---|
| [165] | 833 | if ( ok && (value != cluster_index) ) | 
|---|
| [158] | 834 | { | 
|---|
| [165] | 835 | printf("[XML ERROR] wrong cluster index / expected value is %d", | 
|---|
| [158] | 836 | cluster_index); | 
|---|
| [165] | 837 | exit(1); | 
|---|
| [158] | 838 | } | 
|---|
|  | 839 |  | 
|---|
| [165] | 840 | // get procs attribute | 
|---|
|  | 841 | value = getIntValue(reader,"procs",&ok); | 
|---|
| [158] | 842 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 843 | printf("    procs = %d\n", value); | 
|---|
| [158] | 844 | #endif | 
|---|
|  | 845 | if ( ok ) | 
|---|
|  | 846 | { | 
|---|
| [165] | 847 | cluster[cluster_index]->procs = value; | 
|---|
| [158] | 848 | } | 
|---|
|  | 849 | else | 
|---|
|  | 850 | { | 
|---|
| [165] | 851 | printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", | 
|---|
| [158] | 852 | cluster_index); | 
|---|
|  | 853 | exit(1); | 
|---|
|  | 854 | } | 
|---|
|  | 855 |  | 
|---|
|  | 856 | cluster_index++; | 
|---|
|  | 857 | } // end clusterNode() | 
|---|
|  | 858 |  | 
|---|
|  | 859 | ////////////////////////////////////////////// | 
|---|
|  | 860 | void clusterSetNode( xmlTextReaderPtr reader ) | 
|---|
|  | 861 | { | 
|---|
|  | 862 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 863 |  | 
|---|
|  | 864 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 865 | printf("\n  clusters set\n"); | 
|---|
| [158] | 866 | #endif | 
|---|
|  | 867 |  | 
|---|
|  | 868 | int status = xmlTextReaderRead ( reader ); | 
|---|
|  | 869 | while ( status == 1 ) | 
|---|
|  | 870 | { | 
|---|
|  | 871 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 872 |  | 
|---|
|  | 873 | if      ( strcmp(tag,"cluster") == 0 ) clusterNode(reader); | 
|---|
|  | 874 | else if ( strcmp(tag,"#text") == 0 ) { } | 
|---|
|  | 875 | else if ( strcmp(tag,"clusterset") == 0 ) | 
|---|
|  | 876 | { | 
|---|
|  | 877 | // checking source file consistency | 
|---|
|  | 878 | if ( cluster_index != header->clusters ) | 
|---|
|  | 879 | { | 
|---|
|  | 880 | printf("[XML ERROR] Wrong number of clusters\n"); | 
|---|
|  | 881 | exit(1); | 
|---|
|  | 882 | } | 
|---|
|  | 883 | else | 
|---|
|  | 884 | { | 
|---|
|  | 885 | return; | 
|---|
|  | 886 | } | 
|---|
|  | 887 | } | 
|---|
|  | 888 | else | 
|---|
|  | 889 | { | 
|---|
|  | 890 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); | 
|---|
|  | 891 | exit(1); | 
|---|
|  | 892 | } | 
|---|
|  | 893 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 894 | } | 
|---|
|  | 895 | } // end clusterSetNode() | 
|---|
|  | 896 |  | 
|---|
|  | 897 | /////////////////////////////////////////// | 
|---|
|  | 898 | void psegSetNode( xmlTextReaderPtr reader ) | 
|---|
|  | 899 | { | 
|---|
|  | 900 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 901 |  | 
|---|
|  | 902 | #if XML_PARSER_DEBUG | 
|---|
|  | 903 | printf("  psegs set\n"); | 
|---|
|  | 904 | #endif | 
|---|
|  | 905 |  | 
|---|
|  | 906 | int status = xmlTextReaderRead ( reader ); | 
|---|
|  | 907 | while ( status == 1 ) | 
|---|
|  | 908 | { | 
|---|
|  | 909 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 910 |  | 
|---|
|  | 911 | if      ( strcmp(tag,"pseg") == 0    ) psegNode(reader); | 
|---|
|  | 912 | else if ( strcmp(tag,"#text") == 0 ) { } | 
|---|
|  | 913 | else if ( strcmp(tag,"psegset") == 0  ) | 
|---|
|  | 914 | { | 
|---|
|  | 915 | // checking source file consistency | 
|---|
|  | 916 | if ( pseg_index != header->psegs ) | 
|---|
|  | 917 | { | 
|---|
|  | 918 | printf("[XML ERROR] Wrong number of psegs\n"); | 
|---|
|  | 919 | exit(1); | 
|---|
|  | 920 | } | 
|---|
|  | 921 | else | 
|---|
|  | 922 | { | 
|---|
|  | 923 | return; | 
|---|
|  | 924 | } | 
|---|
|  | 925 | } | 
|---|
|  | 926 | else | 
|---|
|  | 927 | { | 
|---|
|  | 928 | printf("[XML ERROR] Unknown tag in psegset node : %s",tag); | 
|---|
|  | 929 | exit(1); | 
|---|
|  | 930 | } | 
|---|
|  | 931 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 932 | } | 
|---|
|  | 933 | } // end psegSetNode() | 
|---|
|  | 934 |  | 
|---|
|  | 935 | ///////////////////////////////////////////// | 
|---|
|  | 936 | void globalSetNode( xmlTextReaderPtr reader ) | 
|---|
|  | 937 | { | 
|---|
|  | 938 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 939 |  | 
|---|
|  | 940 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 941 | printf("  globals set\n"); | 
|---|
| [158] | 942 | #endif | 
|---|
|  | 943 |  | 
|---|
|  | 944 | int status = xmlTextReaderRead ( reader ); | 
|---|
|  | 945 | while ( status == 1 ) | 
|---|
|  | 946 | { | 
|---|
|  | 947 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 948 |  | 
|---|
|  | 949 | if      ( strcmp(tag,"vseg") == 0    ) vsegNode(reader); | 
|---|
|  | 950 | else if ( strcmp(tag,"#text"  ) == 0 ) { } | 
|---|
|  | 951 | else if ( strcmp(tag,"globalset") == 0  ) | 
|---|
|  | 952 | { | 
|---|
|  | 953 | // checking source file consistency | 
|---|
|  | 954 | if ( vseg_index != header->globals ) | 
|---|
|  | 955 | { | 
|---|
|  | 956 | printf("[XML ERROR] Wrong number of global vsegs\n"); | 
|---|
|  | 957 | exit(1); | 
|---|
|  | 958 | } | 
|---|
|  | 959 | else | 
|---|
|  | 960 | { | 
|---|
|  | 961 | vseg_loc_index = 0; | 
|---|
|  | 962 | return; | 
|---|
|  | 963 | } | 
|---|
|  | 964 | } | 
|---|
|  | 965 | else | 
|---|
|  | 966 | { | 
|---|
|  | 967 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); | 
|---|
|  | 968 | exit(1); | 
|---|
|  | 969 | } | 
|---|
|  | 970 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 971 | } | 
|---|
|  | 972 | } // end globalSetNode() | 
|---|
|  | 973 |  | 
|---|
|  | 974 | ///////////////////////////////////////////// | 
|---|
|  | 975 | void vspaceSetNode( xmlTextReaderPtr reader ) | 
|---|
|  | 976 | { | 
|---|
|  | 977 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 978 |  | 
|---|
|  | 979 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 980 | printf("\n  vspaces set\n"); | 
|---|
| [158] | 981 | #endif | 
|---|
|  | 982 |  | 
|---|
|  | 983 | int status = xmlTextReaderRead ( reader ); | 
|---|
|  | 984 | while ( status == 1 ) | 
|---|
|  | 985 | { | 
|---|
|  | 986 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 987 |  | 
|---|
|  | 988 | if      ( strcmp(tag,"vspace") == 0    ) vspaceNode(reader); | 
|---|
|  | 989 | else if ( strcmp(tag,"#text"  ) == 0 ) { } | 
|---|
|  | 990 | else if ( strcmp(tag,"vspaceset") == 0  ) | 
|---|
|  | 991 | { | 
|---|
|  | 992 | // checking source file consistency | 
|---|
|  | 993 | if ( vspace_index != header->vspaces ) | 
|---|
|  | 994 | { | 
|---|
|  | 995 | printf("[XML ERROR] Wrong number of vspaces\n"); | 
|---|
|  | 996 | exit(1); | 
|---|
|  | 997 | } | 
|---|
|  | 998 | else | 
|---|
|  | 999 | { | 
|---|
|  | 1000 | header->vsegs = vseg_index; | 
|---|
| [160] | 1001 | header->vobjs = vobj_index; | 
|---|
| [158] | 1002 | header->tasks = task_index; | 
|---|
|  | 1003 | return; | 
|---|
|  | 1004 | } | 
|---|
|  | 1005 | } | 
|---|
|  | 1006 | else | 
|---|
|  | 1007 | { | 
|---|
|  | 1008 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); | 
|---|
|  | 1009 | exit(1); | 
|---|
|  | 1010 | } | 
|---|
|  | 1011 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 1012 | } | 
|---|
|  | 1013 | } // end globalSetNode() | 
|---|
|  | 1014 |  | 
|---|
|  | 1015 | ////////////////////////////////////////// | 
|---|
|  | 1016 | void headerNode(xmlTextReaderPtr reader ) | 
|---|
|  | 1017 | { | 
|---|
|  | 1018 | char*               name; | 
|---|
|  | 1019 | unsigned int        value; | 
|---|
|  | 1020 | unsigned int        ok; | 
|---|
|  | 1021 |  | 
|---|
|  | 1022 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; | 
|---|
|  | 1023 |  | 
|---|
|  | 1024 | #if XML_PARSER_DEBUG | 
|---|
|  | 1025 | printf("mapping_info\n"); | 
|---|
|  | 1026 | #endif | 
|---|
|  | 1027 |  | 
|---|
|  | 1028 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); | 
|---|
|  | 1029 |  | 
|---|
| [165] | 1030 | ////////// get name attribute | 
|---|
| [158] | 1031 | name = getStringValue(reader, "name", &ok); | 
|---|
|  | 1032 | if ( ok ) | 
|---|
|  | 1033 | { | 
|---|
|  | 1034 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1035 | printf("  name = %s\n", name); | 
|---|
| [158] | 1036 | #endif | 
|---|
|  | 1037 | strncpy( header->name, name, 31); | 
|---|
|  | 1038 | } | 
|---|
|  | 1039 | else | 
|---|
|  | 1040 | { | 
|---|
|  | 1041 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); | 
|---|
|  | 1042 | exit(1); | 
|---|
|  | 1043 | } | 
|---|
|  | 1044 |  | 
|---|
| [165] | 1045 | /////////// get clusters attribute | 
|---|
| [158] | 1046 | value = getIntValue(reader, "clusters", &ok); | 
|---|
|  | 1047 | if ( ok ) | 
|---|
|  | 1048 | { | 
|---|
|  | 1049 | if ( value >= MAX_CLUSTERS ) | 
|---|
|  | 1050 | { | 
|---|
|  | 1051 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); | 
|---|
|  | 1052 | exit(1); | 
|---|
|  | 1053 | } | 
|---|
|  | 1054 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1055 | printf("  clusters = %d\n", value); | 
|---|
| [158] | 1056 | #endif | 
|---|
|  | 1057 | header->clusters  = value; | 
|---|
|  | 1058 | } | 
|---|
|  | 1059 | else | 
|---|
|  | 1060 | { | 
|---|
|  | 1061 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); | 
|---|
|  | 1062 | exit(1); | 
|---|
|  | 1063 | } | 
|---|
|  | 1064 |  | 
|---|
| [165] | 1065 | ////////// get psegs attribute | 
|---|
| [158] | 1066 | value = getIntValue(reader, "psegs", &ok); | 
|---|
|  | 1067 | if ( ok ) | 
|---|
|  | 1068 | { | 
|---|
|  | 1069 | if ( value >= MAX_PSEGS ) | 
|---|
|  | 1070 | { | 
|---|
|  | 1071 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); | 
|---|
|  | 1072 | exit(1); | 
|---|
|  | 1073 | } | 
|---|
|  | 1074 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1075 | printf("  psegs = %d\n", value); | 
|---|
| [158] | 1076 | #endif | 
|---|
|  | 1077 | header->psegs = value; | 
|---|
|  | 1078 | } | 
|---|
|  | 1079 | else | 
|---|
|  | 1080 | { | 
|---|
|  | 1081 | printf("[XML ERROR] illegal or missing <psegs> attribute in header\n"); | 
|---|
|  | 1082 | exit(1); | 
|---|
|  | 1083 | } | 
|---|
|  | 1084 |  | 
|---|
| [165] | 1085 | ///////// get ttys attribute | 
|---|
| [158] | 1086 | value = getIntValue(reader, "ttys", &ok); | 
|---|
|  | 1087 | if ( ok ) | 
|---|
|  | 1088 | { | 
|---|
|  | 1089 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1090 | printf("  ttys = %d\n", value); | 
|---|
| [158] | 1091 | #endif | 
|---|
|  | 1092 | header->ttys  = value; | 
|---|
|  | 1093 | } | 
|---|
|  | 1094 | else | 
|---|
|  | 1095 | { | 
|---|
|  | 1096 | printf("[XML ERROR] illegal or missing <ttys> attribute in header\n"); | 
|---|
|  | 1097 | exit(1); | 
|---|
|  | 1098 | } | 
|---|
|  | 1099 |  | 
|---|
| [165] | 1100 | ///////// get fbs attribute | 
|---|
|  | 1101 | value = getIntValue(reader, "fbs", &ok); | 
|---|
|  | 1102 | if ( ok ) | 
|---|
|  | 1103 | { | 
|---|
|  | 1104 | #if XML_PARSER_DEBUG | 
|---|
|  | 1105 | printf("  fbs = %d\n", value); | 
|---|
|  | 1106 | #endif | 
|---|
|  | 1107 | header->fbs  = value; | 
|---|
|  | 1108 | } | 
|---|
|  | 1109 | else | 
|---|
|  | 1110 | { | 
|---|
|  | 1111 | printf("[XML ERROR] illegal or missing <fbs> attribute in header\n"); | 
|---|
|  | 1112 | exit(1); | 
|---|
|  | 1113 | } | 
|---|
|  | 1114 |  | 
|---|
|  | 1115 | ///////// get vspaces attribute | 
|---|
| [158] | 1116 | value = getIntValue(reader, "vspaces", &ok); | 
|---|
|  | 1117 | if ( ok ) | 
|---|
|  | 1118 | { | 
|---|
|  | 1119 | if ( value >= MAX_VSPACES ) | 
|---|
|  | 1120 | { | 
|---|
|  | 1121 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); | 
|---|
|  | 1122 | exit(1); | 
|---|
|  | 1123 | } | 
|---|
|  | 1124 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1125 | printf("  vspaces = %d\n", value); | 
|---|
| [158] | 1126 | #endif | 
|---|
|  | 1127 | header->vspaces  = value; | 
|---|
|  | 1128 | } | 
|---|
|  | 1129 | else | 
|---|
|  | 1130 | { | 
|---|
|  | 1131 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); | 
|---|
|  | 1132 | exit(1); | 
|---|
|  | 1133 | } | 
|---|
|  | 1134 |  | 
|---|
| [165] | 1135 | ////////// get globals attribute | 
|---|
| [158] | 1136 | value = getIntValue(reader, "globals", &ok); | 
|---|
|  | 1137 | if ( ok ) | 
|---|
|  | 1138 | { | 
|---|
|  | 1139 | if ( value >= MAX_VSEGS ) | 
|---|
|  | 1140 | { | 
|---|
|  | 1141 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); | 
|---|
|  | 1142 | exit(1); | 
|---|
|  | 1143 | } | 
|---|
|  | 1144 | #if XML_PARSER_DEBUG | 
|---|
| [165] | 1145 | printf("  globals = %d\n", value); | 
|---|
| [158] | 1146 | #endif | 
|---|
|  | 1147 | header->globals  = value; | 
|---|
|  | 1148 | } | 
|---|
|  | 1149 | else | 
|---|
|  | 1150 | { | 
|---|
|  | 1151 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); | 
|---|
|  | 1152 | exit(1); | 
|---|
|  | 1153 | } | 
|---|
|  | 1154 |  | 
|---|
|  | 1155 | header->signature = IN_MAPPING_SIGNATURE; | 
|---|
|  | 1156 |  | 
|---|
|  | 1157 | int status = xmlTextReaderRead ( reader ); | 
|---|
|  | 1158 | while ( status == 1 ) | 
|---|
|  | 1159 | { | 
|---|
|  | 1160 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 1161 |  | 
|---|
|  | 1162 | if      ( strcmp(tag,"clusterset")   == 0 ) clusterSetNode(reader); | 
|---|
|  | 1163 | else if ( strcmp(tag,"psegset")      == 0 ) psegSetNode(reader); | 
|---|
|  | 1164 | else if ( strcmp(tag,"globalset")   == 0 ) globalSetNode(reader); | 
|---|
|  | 1165 | else if ( strcmp(tag,"vspaceset")    == 0 ) vspaceSetNode(reader); | 
|---|
|  | 1166 | else if ( strcmp(tag,"#text")        == 0 ) { } | 
|---|
|  | 1167 | else if ( strcmp(tag,"mapping_info") == 0 ) | 
|---|
|  | 1168 | { | 
|---|
|  | 1169 | #if XML_PARSER_DEBUG | 
|---|
|  | 1170 | printf("end mapping_info\n"); | 
|---|
|  | 1171 | #endif | 
|---|
|  | 1172 | return; | 
|---|
|  | 1173 | } | 
|---|
|  | 1174 | else | 
|---|
|  | 1175 | { | 
|---|
|  | 1176 | printf("[XML ERROR] Unknown tag in header node : %s",tag); | 
|---|
|  | 1177 | exit(1); | 
|---|
|  | 1178 | } | 
|---|
|  | 1179 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 1180 | } | 
|---|
|  | 1181 | } // end headerNode() | 
|---|
|  | 1182 |  | 
|---|
|  | 1183 | /////////////////////////// | 
|---|
|  | 1184 | void  buildBin( int fdout ) | 
|---|
|  | 1185 | { | 
|---|
|  | 1186 | unsigned int    cluster_id; | 
|---|
|  | 1187 | unsigned int    pseg_id; | 
|---|
|  | 1188 | unsigned int    vspace_id; | 
|---|
|  | 1189 | unsigned int    vseg_id; | 
|---|
| [160] | 1190 | unsigned int    vobj_id; | 
|---|
| [158] | 1191 | unsigned int    task_id; | 
|---|
|  | 1192 |  | 
|---|
|  | 1193 | unsigned int    length; | 
|---|
|  | 1194 |  | 
|---|
|  | 1195 | // write header to binary file | 
|---|
|  | 1196 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); | 
|---|
|  | 1197 |  | 
|---|
|  | 1198 | #if XML_PARSER_DEBUG | 
|---|
|  | 1199 | printf("\n*** write header\n"); | 
|---|
|  | 1200 | #endif | 
|---|
|  | 1201 |  | 
|---|
|  | 1202 | if ( length != sizeof(mapping_header_t) ) | 
|---|
|  | 1203 | { | 
|---|
|  | 1204 | perror("write header"); | 
|---|
|  | 1205 | exit(1); | 
|---|
|  | 1206 | } | 
|---|
|  | 1207 |  | 
|---|
|  | 1208 | // write clusters | 
|---|
|  | 1209 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) | 
|---|
|  | 1210 | { | 
|---|
|  | 1211 | length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t)); | 
|---|
|  | 1212 |  | 
|---|
|  | 1213 | #if XML_PARSER_DEBUG | 
|---|
|  | 1214 | printf("\n*** write cluster %d\n", cluster_id); | 
|---|
|  | 1215 | #endif | 
|---|
|  | 1216 |  | 
|---|
|  | 1217 | if ( length != sizeof(mapping_cluster_t) ) | 
|---|
|  | 1218 | { | 
|---|
|  | 1219 | perror("write cluster"); | 
|---|
|  | 1220 | exit(1); | 
|---|
|  | 1221 | } | 
|---|
|  | 1222 | } | 
|---|
|  | 1223 |  | 
|---|
|  | 1224 | // write psegs | 
|---|
|  | 1225 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) | 
|---|
|  | 1226 | { | 
|---|
|  | 1227 | length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t)); | 
|---|
|  | 1228 |  | 
|---|
|  | 1229 | #if XML_PARSER_DEBUG | 
|---|
|  | 1230 | printf("write pseg %d\n", pseg_id); | 
|---|
|  | 1231 | #endif | 
|---|
|  | 1232 |  | 
|---|
|  | 1233 | if ( length != sizeof(mapping_pseg_t) ) | 
|---|
|  | 1234 | { | 
|---|
|  | 1235 | perror("write pseg"); | 
|---|
|  | 1236 | exit(1); | 
|---|
|  | 1237 | } | 
|---|
|  | 1238 | } | 
|---|
|  | 1239 |  | 
|---|
|  | 1240 | // write vspaces | 
|---|
|  | 1241 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) | 
|---|
|  | 1242 | { | 
|---|
|  | 1243 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); | 
|---|
|  | 1244 |  | 
|---|
|  | 1245 | #if XML_PARSER_DEBUG | 
|---|
|  | 1246 | printf("write vspace %d\n", vspace_id); | 
|---|
| [160] | 1247 | printf("vspace->vobj_offset: %d\n", vspace[vspace_id]->vobj_offset); | 
|---|
|  | 1248 | printf("vspace->vobjs: %d\n", vspace[vspace_id]->vobjs); | 
|---|
|  | 1249 | printf("header->vobjs: %d\n", header->vobjs); | 
|---|
| [158] | 1250 | #endif | 
|---|
|  | 1251 |  | 
|---|
|  | 1252 | if ( length != sizeof(mapping_vspace_t) ) | 
|---|
|  | 1253 | { | 
|---|
|  | 1254 | perror("write vspace"); | 
|---|
|  | 1255 | exit(1); | 
|---|
|  | 1256 | } | 
|---|
|  | 1257 | } | 
|---|
|  | 1258 |  | 
|---|
|  | 1259 | // write vsegs | 
|---|
|  | 1260 | for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ ) | 
|---|
|  | 1261 | { | 
|---|
|  | 1262 | length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t)); | 
|---|
|  | 1263 |  | 
|---|
|  | 1264 | #if XML_PARSER_DEBUG | 
|---|
|  | 1265 | printf("write vseg %d\n", vseg_id); | 
|---|
|  | 1266 | #endif | 
|---|
|  | 1267 |  | 
|---|
|  | 1268 | if ( length != sizeof(mapping_vseg_t) ) | 
|---|
|  | 1269 | { | 
|---|
|  | 1270 | perror("write vseg"); | 
|---|
|  | 1271 | exit(1); | 
|---|
|  | 1272 | } | 
|---|
|  | 1273 | } | 
|---|
| [160] | 1274 |  | 
|---|
|  | 1275 | // write vobjs | 
|---|
|  | 1276 | for ( vobj_id = 0 ; vobj_id < header->vobjs ; vobj_id++ ) | 
|---|
|  | 1277 | { | 
|---|
|  | 1278 | length = write(fdout, (char*)vobj[vobj_id], sizeof(mapping_vobj_t)); | 
|---|
|  | 1279 |  | 
|---|
|  | 1280 | #if XML_PARSER_DEBUG | 
|---|
|  | 1281 | printf("write vobj %d\n", vobj_id); | 
|---|
|  | 1282 | printf("write vobj name %s\n", vobj[vobj_id]->name); | 
|---|
|  | 1283 | printf("write vobj length %x\n", vobj[vobj_id]->length); | 
|---|
|  | 1284 | printf("write vobj type %d\n", vobj[vobj_id]->type); | 
|---|
|  | 1285 | #endif | 
|---|
| [158] | 1286 |  | 
|---|
| [160] | 1287 | if ( length != sizeof(mapping_vobj_t) ) | 
|---|
|  | 1288 | { | 
|---|
|  | 1289 | perror("write vobj"); | 
|---|
|  | 1290 | exit(1); | 
|---|
|  | 1291 | } | 
|---|
|  | 1292 | } | 
|---|
|  | 1293 |  | 
|---|
| [158] | 1294 | // write tasks | 
|---|
|  | 1295 | for ( task_id = 0 ; task_id < header->tasks ; task_id++ ) | 
|---|
|  | 1296 | { | 
|---|
|  | 1297 | length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t)); | 
|---|
|  | 1298 |  | 
|---|
|  | 1299 | #if XML_PARSER_DEBUG | 
|---|
|  | 1300 | printf("write task %d\n", task_id); | 
|---|
|  | 1301 | #endif | 
|---|
|  | 1302 |  | 
|---|
|  | 1303 | if ( length != sizeof(mapping_task_t) ) | 
|---|
|  | 1304 | { | 
|---|
|  | 1305 | perror("write task"); | 
|---|
|  | 1306 | exit(1); | 
|---|
|  | 1307 | } | 
|---|
|  | 1308 | } | 
|---|
|  | 1309 | } // end buildBin() | 
|---|
|  | 1310 |  | 
|---|
|  | 1311 | ///////////////////////////////////// | 
|---|
|  | 1312 | int  main ( int argc, char* argv[] ) | 
|---|
|  | 1313 | { | 
|---|
|  | 1314 | if ( argc < 3 ) | 
|---|
|  | 1315 | { | 
|---|
|  | 1316 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); | 
|---|
|  | 1317 | return 1; | 
|---|
|  | 1318 | } | 
|---|
|  | 1319 |  | 
|---|
|  | 1320 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); | 
|---|
|  | 1321 | if ( fdout < 0) | 
|---|
|  | 1322 | { | 
|---|
|  | 1323 | perror("open"); | 
|---|
|  | 1324 | exit(1); | 
|---|
|  | 1325 | } | 
|---|
|  | 1326 |  | 
|---|
|  | 1327 | LIBXML_TEST_VERSION; | 
|---|
|  | 1328 |  | 
|---|
|  | 1329 | int              status; | 
|---|
|  | 1330 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); | 
|---|
|  | 1331 |  | 
|---|
|  | 1332 | if ( reader != NULL ) | 
|---|
|  | 1333 | { | 
|---|
|  | 1334 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 1335 | while ( status == 1 ) | 
|---|
|  | 1336 | { | 
|---|
|  | 1337 | const char* tag = (const char*)xmlTextReaderConstName(reader); | 
|---|
|  | 1338 | if ( strcmp(tag,"mapping_info") == 0 ) | 
|---|
|  | 1339 | { | 
|---|
|  | 1340 | headerNode( reader ); | 
|---|
|  | 1341 | buildBin( fdout ); | 
|---|
|  | 1342 | } | 
|---|
|  | 1343 | else | 
|---|
|  | 1344 | { | 
|---|
|  | 1345 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); | 
|---|
|  | 1346 | return 1; | 
|---|
|  | 1347 | } | 
|---|
|  | 1348 | status = xmlTextReaderRead ( reader ); | 
|---|
|  | 1349 | } | 
|---|
|  | 1350 | xmlFreeTextReader ( reader ); | 
|---|
|  | 1351 |  | 
|---|
|  | 1352 | if ( status != 0 ) | 
|---|
|  | 1353 | { | 
|---|
|  | 1354 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); | 
|---|
|  | 1355 | return 1; | 
|---|
|  | 1356 | } | 
|---|
|  | 1357 | } | 
|---|
|  | 1358 | return 0; | 
|---|
|  | 1359 | } // end main() | 
|---|