Changeset d0febca in mainline for uspace/app/sbi/src/rdata.c
- Timestamp:
- 2010-03-13T12:04:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7715994
- Parents:
- 94d484a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/rdata.c
r94d484a rd0febca 64 64 } 65 65 66 rdata_address_t *rdata_address_new(void) 66 rdata_addr_var_t *rdata_addr_var_new(void) 67 { 68 rdata_addr_var_t *addr_var; 69 70 addr_var = calloc(1, sizeof(rdata_addr_var_t)); 71 if (addr_var == NULL) { 72 printf("Memory allocation failed.\n"); 73 exit(1); 74 } 75 76 return addr_var; 77 } 78 79 rdata_aprop_named_t *rdata_aprop_named_new(void) 80 { 81 rdata_aprop_named_t *aprop_named; 82 83 aprop_named = calloc(1, sizeof(rdata_aprop_named_t)); 84 if (aprop_named == NULL) { 85 printf("Memory allocation failed.\n"); 86 exit(1); 87 } 88 89 return aprop_named; 90 } 91 92 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void) 93 { 94 rdata_aprop_indexed_t *aprop_indexed; 95 96 aprop_indexed = calloc(1, sizeof(rdata_aprop_indexed_t)); 97 if (aprop_indexed == NULL) { 98 printf("Memory allocation failed.\n"); 99 exit(1); 100 } 101 102 return aprop_indexed; 103 } 104 105 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc) 106 { 107 rdata_addr_prop_t *addr_prop; 108 109 addr_prop = calloc(1, sizeof(rdata_addr_prop_t)); 110 if (addr_prop == NULL) { 111 printf("Memory allocation failed.\n"); 112 exit(1); 113 } 114 115 addr_prop->apc = apc; 116 return addr_prop; 117 } 118 119 rdata_address_t *rdata_address_new(address_class_t ac) 67 120 { 68 121 rdata_address_t *address; … … 74 127 } 75 128 129 address->ac = ac; 76 130 return address; 77 131 } … … 349 403 } 350 404 351 /** Convert item to value item. 352 * 353 * If @a item is a value, we just return a copy. If @a item is an address, 354 * we read from the address. 405 /** Read data from a variable. 406 * 407 * Return value stored in variable @a var. 355 408 */ 356 void rdata_cvt_value_item(rdata_item_t *item, rdata_item_t **ritem) 357 { 358 rdata_value_t *value; 359 360 /* 361 * This can happen when trying to use output of a function which 362 * does not return a value. 363 */ 364 if (item == NULL) { 365 printf("Error: Sub-expression has no value.\n"); 366 exit(1); 367 } 368 369 /* Address item. Perform read operation. */ 370 if (item->ic == ic_address) { 371 rdata_address_read(item->u.address, ritem); 372 return; 373 } 374 375 /* It already is a value, we can share the @c var. */ 376 value = rdata_value_new(); 377 value->var = item->u.value->var; 378 *ritem = rdata_item_new(ic_value); 379 (*ritem)->u.value = value; 380 } 381 382 /** Return reference to a variable. 383 * 384 * Constructs a reference (value item) pointing to @a var. 385 */ 386 void rdata_reference(rdata_var_t *var, rdata_item_t **res) 387 { 388 rdata_ref_t *ref; 389 rdata_var_t *ref_var; 390 rdata_value_t *ref_value; 391 rdata_item_t *ref_item; 392 393 /* Create reference to the variable. */ 394 ref = rdata_ref_new(); 395 ref_var = rdata_var_new(vc_ref); 396 ref->vref = var; 397 ref_var->u.ref_v = ref; 398 399 /* Construct value of the reference to return. */ 400 ref_item = rdata_item_new(ic_value); 401 ref_value = rdata_value_new(); 402 ref_item->u.value = ref_value; 403 ref_value->var = ref_var; 404 405 *res = ref_item; 406 } 407 408 /** Return address of reference target. 409 * 410 * Takes a reference (address or value) and returns the address (item) of 411 * the target of the reference. 412 */ 413 void rdata_dereference(rdata_item_t *ref, rdata_item_t **ritem) 414 { 415 rdata_item_t *ref_val; 416 rdata_item_t *item; 417 rdata_address_t *address; 418 419 #ifdef DEBUG_RUN_TRACE 420 printf("run_dereference()\n"); 421 #endif 422 rdata_cvt_value_item(ref, &ref_val); 423 assert(ref_val->u.value->var->vc == vc_ref); 424 425 item = rdata_item_new(ic_address); 426 address = rdata_address_new(); 427 item->u.address = address; 428 address->vref = ref_val->u.value->var->u.ref_v->vref; 429 430 if (address->vref == NULL) { 431 printf("Error: Accessing null reference.\n"); 432 exit(1); 433 } 434 435 #ifdef DEBUG_RUN_TRACE 436 printf("vref set to %p\n", address->vref); 437 #endif 438 *ritem = item; 439 } 440 441 /** Read data from an address. 442 * 443 * Return value stored in a variable at the specified address. 444 */ 445 void rdata_address_read(rdata_address_t *address, rdata_item_t **ritem) 409 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem) 446 410 { 447 411 rdata_value_t *value; 448 412 rdata_var_t *rvar; 449 413 450 /* Perform a shallow copy of @ cvar. */451 rdata_var_copy( address->vref, &rvar);414 /* Perform a shallow copy of @a var. */ 415 rdata_var_copy(var, &rvar); 452 416 453 417 value = rdata_value_new(); … … 455 419 *ritem = rdata_item_new(ic_value); 456 420 (*ritem)->u.value = value; 457 }458 459 /** Write data to an address.460 *461 * Store @a value to the variable at @a address.462 */463 void rdata_address_write(rdata_address_t *address, rdata_value_t *value)464 {465 rdata_var_write(address->vref, value);466 421 } 467 422 … … 492 447 } 493 448 449 /** Get item var-class. 450 * 451 * Get var-class of @a item, regardless whether it is a value or address. 452 * (I.e. the var class of the value or variable at the given address). 453 */ 454 var_class_t rdata_item_get_vc(rdata_item_t *item) 455 { 456 var_class_t vc; 457 458 switch (item->ic) { 459 case ic_value: 460 vc = item->u.value->var->vc; 461 break; 462 case ic_address: 463 switch (item->u.address->ac) { 464 case ac_var: 465 vc = item->u.address->u.var_a->vref->vc; 466 break; 467 case ac_prop: 468 printf("Unimplemented: Get property address " 469 "varclass.\n"); 470 exit(1); 471 default: 472 assert(b_false); 473 } 474 break; 475 default: 476 assert(b_false); 477 } 478 479 return vc; 480 } 481 494 482 /** Determine if CSI @a a is derived from CSI described by type item @a tb. */ 495 483 bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb) … … 530 518 static void rdata_address_print(rdata_address_t *address) 531 519 { 532 rdata_var_print(address->vref); 520 switch (address->ac) { 521 case ac_var: 522 rdata_var_print(address->u.var_a->vref); 523 break; 524 case ac_prop: 525 printf("Warning: Unimplemented: Print property address.\n"); 526 break; 527 } 533 528 } 534 529
Note:
See TracChangeset
for help on using the changeset viewer.