Method: RCSimCinterface.rcsim_make_code

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_make_code(lang, funcname) ⇒ Object

Creating a system code C object. Note: HDLRuby Code object are actually refactored to Program object, but the low-level simulation still use Code as data structure. Hence, it may change in the future.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 395

VALUE rcsim_make_code(VALUE mod, VALUE lang, VALUE funcname) {
    // printf("rcsim_make_code\n");
    /* Allocates the code. */
    Code code = (Code)malloc(sizeof(CodeS));
    // printf("code=%p\n",code);
    /* Set it up. */
    code->kind  = CODE;
    code->owner = NULL;
    code->name = strdup(StringValueCStr(funcname));
    // printf("code->name=%p\n",code->name);
    code->num_events = 0;
    code->events = NULL;
    code->function = NULL;
    char* langStr = StringValueCStr(lang);
    if(strncmp(langStr,"ruby",4) == 0) {
        /* Ruby function. */
        code->function = ruby_function_wrap;
    } else if (strncmp(langStr,"c",1) == 0) {
        /* C or C-compatible dynamically compiled code: it will be loaded
         * afterward */
        code->function = NULL;
    } else {
        /* Other language function. */
        fprintf(stderr,"Unsupported language.");
        exit(-1);
    }
    code->enabled = 0;
    code->activated = 0;
    /* Returns the C code embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(CodeS,code,res);
    return res;
}