Changeset fa36f29 in mainline for uspace/app/sbi/src/rdata.c
- Timestamp:
- 2010-02-27T17:59:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 94d484a
- Parents:
- 09ababb7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/rdata.c
r09ababb7 rfa36f29 100 100 } 101 101 102 rdata_ref_t *rdata_ref_new(void) 103 { 104 rdata_ref_t *ref; 105 106 ref = calloc(1, sizeof(rdata_ref_t)); 107 if (ref == NULL) { 108 printf("Memory allocation failed.\n"); 109 exit(1); 110 } 111 112 return ref; 113 } 114 102 115 rdata_deleg_t *rdata_deleg_new(void) 103 116 { … … 111 124 112 125 return deleg; 126 } 127 128 rdata_object_t *rdata_object_new(void) 129 { 130 rdata_object_t *object; 131 132 object = calloc(1, sizeof(rdata_object_t)); 133 if (object == NULL) { 134 printf("Memory allocation failed.\n"); 135 exit(1); 136 } 137 138 return object; 113 139 } 114 140 … … 181 207 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest) 182 208 { 183 printf("Unimplemented: Copy reference.\n");184 exit(1);209 *dest = rdata_ref_new(); 210 (*dest)->vref = src->vref; 185 211 } 186 212 187 213 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest) 188 214 { 215 (void) src; (void) dest; 189 216 printf("Unimplemented: Copy delegate.\n"); 190 217 exit(1); … … 193 220 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest) 194 221 { 222 (void) src; (void) dest; 195 223 printf("Unimplemented: Copy object.\n"); 196 224 exit(1); 225 } 226 227 /** Convert item to value item. 228 * 229 * If @a item is a value, we just return a copy. If @a item is an address, 230 * we read from the address. 231 */ 232 void rdata_cvt_value_item(rdata_item_t *item, rdata_item_t **ritem) 233 { 234 rdata_value_t *value; 235 236 /* 237 * This can happen when trying to use output of a function which 238 * does not return a value. 239 */ 240 if (item == NULL) { 241 printf("Error: Sub-expression has no value.\n"); 242 exit(1); 243 } 244 245 /* Address item. Perform read operation. */ 246 if (item->ic == ic_address) { 247 rdata_address_read(item->u.address, ritem); 248 return; 249 } 250 251 /* It already is a value, we can share the @c var. */ 252 value = rdata_value_new(); 253 value->var = item->u.value->var; 254 *ritem = rdata_item_new(ic_value); 255 (*ritem)->u.value = value; 256 } 257 258 /** Return reference to a variable. 259 * 260 * Constructs a reference (value item) pointing to @a var. 261 */ 262 void rdata_reference(rdata_var_t *var, rdata_item_t **res) 263 { 264 rdata_ref_t *ref; 265 rdata_var_t *ref_var; 266 rdata_value_t *ref_value; 267 rdata_item_t *ref_item; 268 269 /* Create reference to the variable. */ 270 ref = rdata_ref_new(); 271 ref_var = rdata_var_new(vc_ref); 272 ref->vref = var; 273 ref_var->u.ref_v = ref; 274 275 /* Construct value of the reference to return. */ 276 ref_item = rdata_item_new(ic_value); 277 ref_value = rdata_value_new(); 278 ref_item->u.value = ref_value; 279 ref_value->var = ref_var; 280 281 *res = ref_item; 282 } 283 284 /** Return address of reference target. 285 * 286 * Takes a reference (address or value) and returns the address (item) of 287 * the target of the reference. 288 */ 289 void rdata_dereference(rdata_item_t *ref, rdata_item_t **ritem) 290 { 291 rdata_item_t *ref_val; 292 rdata_item_t *item; 293 rdata_address_t *address; 294 295 #ifdef DEBUG_RUN_TRACE 296 printf("run_dereference()\n"); 297 #endif 298 rdata_cvt_value_item(ref, &ref_val); 299 assert(ref_val->u.value->var->vc == vc_ref); 300 301 item = rdata_item_new(ic_address); 302 address = rdata_address_new(); 303 item->u.address = address; 304 address->vref = ref_val->u.value->var->u.ref_v->vref; 305 306 if (address->vref == NULL) { 307 printf("Error: Accessing null reference.\n"); 308 exit(1); 309 } 310 311 #ifdef DEBUG_RUN_TRACE 312 printf("vref set to %p\n", address->vref); 313 #endif 314 *ritem = item; 315 } 316 317 /** Read data from an address. 318 * 319 * Return value stored in a variable at the specified address. 320 */ 321 void rdata_address_read(rdata_address_t *address, rdata_item_t **ritem) 322 { 323 rdata_value_t *value; 324 rdata_var_t *rvar; 325 326 /* Perform a shallow copy of @c var. */ 327 rdata_var_copy(address->vref, &rvar); 328 329 value = rdata_value_new(); 330 value->var = rvar; 331 *ritem = rdata_item_new(ic_value); 332 (*ritem)->u.value = value; 333 } 334 335 /** Write data to an address. 336 * 337 * Store @a value to the variable at @a address. 338 */ 339 void rdata_address_write(rdata_address_t *address, rdata_value_t *value) 340 { 341 rdata_var_t *nvar; 342 rdata_var_t *orig_var; 343 344 /* Perform a shallow copy of @c value->var. */ 345 rdata_var_copy(value->var, &nvar); 346 orig_var = address->vref; 347 348 /* XXX do this in a prettier way. */ 349 350 orig_var->vc = nvar->vc; 351 switch (nvar->vc) { 352 case vc_int: orig_var->u.int_v = nvar->u.int_v; break; 353 case vc_ref: orig_var->u.ref_v = nvar->u.ref_v; break; 354 case vc_deleg: orig_var->u.deleg_v = nvar->u.deleg_v; break; 355 case vc_object: orig_var->u.object_v = nvar->u.object_v; break; 356 default: assert(b_false); 357 } 358 359 /* XXX We should free some stuff around here. */ 197 360 } 198 361 … … 232 395 printf("int(%d)", var->u.int_v->value); 233 396 break; 397 case vc_string: 398 printf("string(\"%s\")", var->u.string_v->value); 399 break; 234 400 case vc_ref: 235 401 printf("ref"); … … 242 408 break; 243 409 default: 410 printf("print(%d)\n", var->vc); 244 411 assert(b_false); 245 412 }
Note:
See TracChangeset
for help on using the changeset viewer.