Module: RCSimCinterface

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

Class Method Summary collapse

Class Method Details

.rcsim_add_behavior_events(behaviorV, eventVs) ⇒ Object

Adds events to a C behavior.



983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 983

VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
    /* Get the C behavior from the Ruby value. */
    Behavior behavior;
    value_to_rcsim(BehaviorS,behaviorV,behavior);
    // printf("rcsim_add_behavior_events with behavior=%p\n",behavior);
    /* Prepare the size for the events. */
    long num = RARRAY_LEN(eventVs);
    long old_num = behavior->num_events;
    behavior->num_events += num;
    // printf("first behavior->events=%p\n",behavior->events); fflush(stdout);
    // behavior->events = realloc(behavior->events,
    //                            sizeof(Event[behavior->num_events]));
    behavior->events = (Event*)my_realloc(behavior->events,
            sizeof(Event[old_num]), sizeof(Event[behavior->num_events]));
    // printf("now behavior->events=%p\n",behavior->events); fflush(stdout);
    // printf("access test: %p\n",behavior->events[0]); fflush(stdout);
    /* Get and add the events from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Event event;
        // show_access(behavior->events,old_num+i);
        value_to_rcsim(EventS,rb_ary_entry(eventVs,i),event);
        behavior->events[old_num + i] = event;
        /* Update the signal of the event to say it activates the behavior. */
        SignalI sig = event->signal;
        switch(event->edge) {
            case ANYEDGE:
                sig->num_any++;
    // printf("first sig->any=%p\n",sig->any); fflush(stdout);
                // sig->any = realloc(sig->any,sizeof(Object[sig->num_any]));
                sig->any = (Object*)my_realloc(sig->any,
                    sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any]));
    // printf("now sig->any=%p\n",sig->any); fflush(stdout);
    // printf("access test: %p\n",sig->any[0]); fflush(stdout);
        // show_access(sig->any,sig->num_any-1);
                // printf("sig->any=%p\n",sig->any);
                sig->any[sig->num_any-1] = (Object)behavior;
                break;
            case POSEDGE:
                sig->num_pos++;
    // printf("first sig->pos=%p\n",sig->pos); fflush(stdout);
                // sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos]));
                sig->pos = (Object*)my_realloc(sig->pos,
                    sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos]));
    // printf("now sig->pos=%p\n",sig->pos); fflush(stdout);
    // printf("access test: %p\n",sig->pos[0]); fflush(stdout);
        // show_access(sig->pos,sig->num_pos-1);
                // printf("sig->pos=%p\n",sig->pos);
                sig->pos[sig->num_pos-1] = (Object)behavior;
                break;
            case NEGEDGE:
                sig->num_neg++;
    // printf("first sig->neg=%p\n",sig->neg); fflush(stdout);
                // sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg]));
                sig->neg = (Object*)my_realloc(sig->neg,
                    sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg]));
    // printf("now sig->neg=%p\n",sig->neg); fflush(stdout);
    // printf("access test: %p\n",sig->neg[0]); fflush(stdout);
        // show_access(sig->neg,sig->num_neg-1);
                // printf("sig->neg=%p\n",sig->neg);
                sig->neg[sig->num_neg-1] = (Object)behavior;
                break;
            default:
                perror("Invalid value for an edge.");
        }
    }
    return behaviorV;
}

.rcsim_add_block_inners(blockV, sigVs) ⇒ Object

Adds inners to a C block.



1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1180

VALUE rcsim_add_block_inners(VALUE mod, VALUE blockV, VALUE sigVs) {
    /* Get the C block from the Ruby value. */
    Block block;
    value_to_rcsim(BlockS,blockV,block);
    // printf("rcsim_add_block_inners with block=%p\n",block);
    /* Prepare the size for the inners. */
    long num = RARRAY_LEN(sigVs);
    long old_num = block->num_inners;
    block->num_inners += num;
    // printf("first block->inners=%p\n",block->inners); fflush(stdout);
    // block->inners = realloc(block->inners,
    //         sizeof(SignalI[block->num_inners]));
    block->inners = (SignalI*)my_realloc(block->inners,
            sizeof(SignalI[old_num]), sizeof(SignalI[block->num_inners]));
    // printf("now block->inners=%p\n",block->inners); fflush(stdout);
    // printf("access test: %p\n",block->inners[0]); fflush(stdout);
    /* Get and add the signals from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SignalI sig;
        // show_access(block->inners,old_num+i);
        value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
        block->inners[old_num + i] = sig;
    }
    return blockV;
}

.rcsim_add_block_statements(blockV, stmntVs) ⇒ Object

Adds statements to a C block.



1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1207

VALUE rcsim_add_block_statements(VALUE mod, VALUE blockV, VALUE stmntVs) {
    /* Get the C block from the Ruby value. */
    Block block;
    value_to_rcsim(BlockS,blockV,block);
    // printf("rcsim_add_block_statements with block=%p\n",block);
    /* Prepare the size for the statements. */
    long num = RARRAY_LEN(stmntVs);
    long old_num = block->num_stmnts;
    block->num_stmnts += num;
    // printf("first block->stmnts=%p\n",block->stmnts); fflush(stdout);
    // block->stmnts = realloc(block->stmnts,
    //         sizeof(Statement[block->num_stmnts]));
    block->stmnts = (Statement*)my_realloc(block->stmnts,
            sizeof(Statement[old_num]), sizeof(Statement[block->num_stmnts]));
    // printf("now block->stmnts=%p\n",block->stmnts); fflush(stdout);
    // printf("access test: %p\n",block->stmnts[0]); fflush(stdout);
    /* Get and add the statements from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Statement stmnt;
        // show_access(block->stmnts,old_num+i);
        value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
        block->stmnts[old_num + i] = stmnt;
    }
    return blockV;
}

.rcsim_add_concat_expressions(concatV, exprVs) ⇒ Object

Adds expressions to a C concat.



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1261

VALUE rcsim_add_concat_expressions(VALUE mod, VALUE concatV, VALUE exprVs) {
    /* Get the C concat from the Ruby value. */
    Concat concat;
    value_to_rcsim(ConcatS,concatV,concat);
    // printf("rcsim_add_concat_expressions with concat=%p\n",concat);
    /* Prepare the size for the expressions. */
    long num = RARRAY_LEN(exprVs);
    long old_num = concat->num_exprs;
    // printf("add_concat_expressions with num=%li old_num=%li\n",num,old_num);
    concat->num_exprs += num;
    // printf("first concat->exprs=%p\n",concat->exprs); fflush(stdout);
    // concat->exprs = realloc(concat->exprs,
    //         sizeof(Expression[concat->num_exprs]));
    concat->exprs = (Expression*)my_realloc(concat->exprs,
            sizeof(Expression[old_num]), sizeof(Expression[concat->num_exprs]));
    // printf("now concat->exprs=%p\n",concat->exprs); fflush(stdout);
    // printf("access test: %p\n",concat->exprs[0]); fflush(stdout);
    /* Get and add the expressions from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression expr;
        // show_access(concat->exprs,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(exprVs,i),expr);
        concat->exprs[old_num + i] = expr;
    }
    return concatV;
}

.rcsim_add_hcase_whens(hcaseV, matchVs, stmntVs) ⇒ Object

Adds whens to a C hardware case.



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1142

VALUE rcsim_add_hcase_whens(VALUE mod, VALUE hcaseV, VALUE matchVs, VALUE stmntVs) {
    /* Get the C hardware case from the Ruby value. */
    HCase hcase;
    value_to_rcsim(HCaseS,hcaseV,hcase);
    // printf("rcsim_add_hcase_whens with hcase=%p\n",hcase);
    /* Prepare the size for the noifs. */
    long num = RARRAY_LEN(matchVs);
    long old_num = hcase->num_whens;
    hcase->num_whens += num;
    // printf("first hcase->matches=%p\n",hcase->matches); fflush(stdout);
    // printf("first hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
    // hcase->matches = realloc(hcase->matches,
    //                          sizeof(Expression[hcase->num_whens]));
    hcase->matches = (Expression*)my_realloc(hcase->matches,
            sizeof(Expression[old_num]), sizeof(Expression[hcase->num_whens]));
    // printf("now hcase->matches=%p\n",hcase->matches); fflush(stdout);
    // printf("access test: %p\n",hcase->matches[0]); fflush(stdout);
    // hcase->stmnts = realloc(hcase->stmnts,
    //                         sizeof(Statement[hcase->num_whens]));
    hcase->stmnts = (Statement*)my_realloc(hcase->stmnts,
            sizeof(Statement[old_num]), sizeof(Statement[hcase->num_whens]));
    // printf("now hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
    // printf("access test: %p\n",hcase->stmnts[0]); fflush(stdout);
    /* Get and add the whens from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression match;
        Statement stmnt;
        // show_access(hcase->matches,old_num+i);
        // show_access(hcase->stmnts,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(matchVs,i),match);
        hcase->matches[old_num + i] = match;
        value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
        hcase->stmnts[old_num + i] = stmnt;
    }
    return hcaseV;
}

.rcsim_add_hif_noifs(hifV, condVs, stmntVs) ⇒ Object

Adds noifs to a C hardware if.



1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1106

VALUE rcsim_add_hif_noifs(VALUE mod, VALUE hifV, VALUE condVs, VALUE stmntVs) {
    /* Get the C hardware if from the Ruby value. */
    HIf hif;
    value_to_rcsim(HIfS,hifV,hif);
    // printf("rcsim_add_hif_noifs with hif=%p\n",hif);
    /* Prepare the size for the noifs. */
    long num = RARRAY_LEN(condVs);
    long old_num = hif->num_noifs;
    hif->num_noifs += num;
    // printf("first hif->noconds=%p\n",hif->noconds); fflush(stdout);
    // printf("first hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
    // hif->noconds = realloc(hif->noconds,sizeof(Expression[hif->num_noifs]));
    hif->noconds = (Expression*)my_realloc(hif->noconds,
            sizeof(Expression[old_num]),sizeof(Expression[hif->num_noifs]));
    // printf("now hif->noconds=%p\n",hif->noconds); fflush(stdout);
    // printf("access test: %p\n",hif->noconds[0]); fflush(stdout);
    // hif->nostmnts = realloc(hif->nostmnts,sizeof(Statement[hif->num_noifs]));
    hif->nostmnts = (Statement*)my_realloc(hif->nostmnts,
            sizeof(Statement[old_num]),sizeof(Statement[hif->num_noifs]));
    // printf("now hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
    // printf("access test: %p\n",hif->nostmnts[0]); fflush(stdout);
    /* Get and add the noifs from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression cond;
        Statement stmnt;
        // show_access(hif->noconds,old_num+i);
        // show_access(hif->nostmnts,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(condVs,i),cond);
        hif->noconds[old_num + i] = cond;
        value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
        hif->nostmnts[old_num + i] = stmnt;
    }
    return hifV;
}

.rcsim_add_print_args(printV, argVs) ⇒ Object

Adds arguments to a C print.



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1079

VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
    /* Get the C print from the Ruby value. */
    Print print;
    value_to_rcsim(PrintS,printV,print);
    // printf("rcsim_add_print_args with print=%p\n",print);
    /* Prepare the size for the arguments. */
    long num = RARRAY_LEN(argVs);
    long old_num = print->num_args;
    print->num_args += num;
    // printf("first print->args=%p\n",print->args); fflush(stdout);
    // print->args = realloc(print->args,
    //                       sizeof(Expression[print->num_args]));
    print->args = (Expression*)my_realloc(print->args,
            sizeof(Expression[old_num]), sizeof(Expression[print->num_args]));
    // printf("now print->args=%p\n",print->args); fflush(stdout);
    // printf("access test: %p\n",print->args[0]); fflush(stdout);
    /* Get and add the arguments from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression arg;
        // show_access(print->args,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(argVs,i),arg);
        print->args[old_num + i] = arg;
    }
    return printV;
}

.rcsim_add_refConcat_refs(refConcatV, refVs) ⇒ Object

Adds references to a C ref concat.



1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1289

VALUE rcsim_add_refConcat_refs(VALUE mod, VALUE refConcatV, VALUE refVs) {
    /* Get the C refConcat from the Ruby value. */
    RefConcat refConcat;
    value_to_rcsim(RefConcatS,refConcatV,refConcat);
    // printf("rcsim_add_refConcat_refs with refConcat=%p\n",refConcat);
    /* Prepare the size for the references. */
    long num = RARRAY_LEN(refVs);
    long old_num = refConcat->num_refs;
    refConcat->num_refs += num;
    // printf("first refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
    // refConcat->refs = realloc(refConcat->refs,
    //         sizeof(Reference[refConcat->num_refs]));
    refConcat->refs = (Reference*)my_realloc(refConcat->refs,
            sizeof(Reference[old_num]), sizeof(Reference[refConcat->num_refs]));
    // printf("now refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
    // printf("access test: %p\n",refConcat->refs[0]); fflush(stdout);
    /* Get and add the references from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Reference ref;
        // show_access(refConcat->refs,old_num+i);
        value_to_rcsim(ReferenceS,rb_ary_entry(refVs,i),ref);
        refConcat->refs[old_num + i] = ref;
        // printf("ref=%p ref &type=%p type=%p width=%llu\n",ref,&(ref->type),ref->type,type_width(ref->type));
    }
    return refConcatV;
}

.rcsim_add_scope_behaviors(scopeV, behVs) ⇒ Object

Adds behaviors to a C scope.



899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 899

VALUE rcsim_add_scope_behaviors(VALUE mod, VALUE scopeV, VALUE behVs) {
    // printf("rcsim_add_scope_behaviors\n");
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_behaviors with scope=%p\n",scope);
    /* Prepare the size for the behaviors. */
    long num = RARRAY_LEN(behVs);
    long old_num = scope->num_behaviors;
    // printf("num=%lu old_num=%lu\n",num,old_num);
    // printf("scope->behaviors=%p\n",scope->behaviors);
    scope->num_behaviors += num;
    // printf("first scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
    // scope->behaviors = realloc(scope->behaviors,
    //                            sizeof(Behavior[scope->num_behaviors]));
    scope->behaviors = (Behavior*)my_realloc(scope->behaviors,
            sizeof(Behavior[old_num]), sizeof(Behavior[scope->num_behaviors]));
    // printf("now scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
    // printf("access test: %p\n",scope->behaviors[0]); fflush(stdout);
    /* Get and add the behaviors from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Behavior beh;
        // show_access(scope->behaviors,old_num+i);
        value_to_rcsim(BehaviorS,rb_ary_entry(behVs,i),beh);
        scope->behaviors[old_num + i] = beh;
    }
    return scopeV;
}

.rcsim_add_scope_inners(scopeV, sigVs) ⇒ Object

Adds inners to a C scope.



872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 872

VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_inners with scope=%p\n",scope);
    /* Prepare the size for the inners. */
    long num = RARRAY_LEN(sigVs);
    long old_num = scope->num_inners;
    scope->num_inners += num;
    // printf("first scope->inners=%p\n",scope->inners); fflush(stdout);
    // scope->inners = realloc(scope->inners,
    //         sizeof(SignalI[scope->num_inners]));
    scope->inners = (SignalI*)my_realloc(scope->inners,
            sizeof(SignalI[old_num]), sizeof(SignalI[scope->num_inners]));
    // printf("now scope->inners=%p\n",scope->inners); fflush(stdout);
    // printf("access test: %p\n",scope->inners[0]); fflush(stdout);
    /* Get and add the signals from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SignalI sig;
        // show_access(scope->inners,old_num+i);
        value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
        scope->inners[old_num + i] = sig;
    }
    return scopeV;
}

.rcsim_add_scope_scopes(scopeV, scpVs) ⇒ Object

Adds sub scopes to a C scope.



956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 956

VALUE rcsim_add_scope_scopes(VALUE mod, VALUE scopeV, VALUE scpVs) {
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_scopes with scope=%p\n",scope);
    /* Prepare the size for the sub scopes. */
    long num = RARRAY_LEN(scpVs);
    long old_num = scope->num_scopes;
    scope->num_scopes += num;
    // printf("first scope->scopes=%p\n",scope->scopes); fflush(stdout);
    // scope->scopes = realloc(scope->scopes,
    //                         sizeof(Scope[scope->num_scopes]));
    scope->scopes = (Scope*)my_realloc(scope->scopes,
            sizeof(Scope[old_num]), sizeof(Scope[scope->num_scopes]));
    // printf("now scope->scopes=%p\n",scope->scopes); fflush(stdout);
    // printf("access test: %p\n",scope->scopes[0]); fflush(stdout);
    /* Get and add the sub scopes from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Scope scp;
        // show_access(scope->scopes,old_num+i);
        value_to_rcsim(ScopeS,rb_ary_entry(scpVs,i),scp);
        scope->scopes[old_num + i] = scp;
    }
    return scopeV;
}

.rcsim_add_scope_systemIs(scopeV, sysVs) ⇒ Object

Adds system instances to a C scope.



929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 929

VALUE rcsim_add_scope_systemIs(VALUE mod, VALUE scopeV, VALUE sysVs) {
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_systemIs with scope=%p\n",scope);
    /* Prepare the size for the system instances. */
    long num = RARRAY_LEN(sysVs);
    long old_num = scope->num_systemIs;
    scope->num_systemIs += num;
    // printf("first scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
    // scope->systemIs = realloc(scope->systemIs,
    //                            sizeof(SystemI[scope->num_systemIs]));
    scope->systemIs = (SystemI*)my_realloc(scope->systemIs,
            sizeof(SystemI[old_num]), sizeof(SystemI[scope->num_systemIs]));
    // printf("now scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
    // printf("access test: %p\n",scope->systemIs[0]); fflush(stdout);
    /* Get and add the system instances from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SystemI sys;
        // show_access(scope->systemIs,old_num+i);
        value_to_rcsim(SystemIS,rb_ary_entry(sysVs,i),sys);
        scope->systemIs[old_num + i] = sys;
    }
    return scopeV;
}

.rcsim_add_select_choices(selectV, choiceVs) ⇒ Object

Adds choices to a C select.



1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1234

VALUE rcsim_add_select_choices(VALUE mod, VALUE selectV, VALUE choiceVs) {
    /* Get the C select from the Ruby value. */
    Select select;
    value_to_rcsim(SelectS,selectV,select);
    // printf("rcsim_add_select_choices with select=%p\n",select);
    /* Prepare the size for the choices. */
    long num = RARRAY_LEN(choiceVs);
    long old_num = select->num_choices;
    select->num_choices += num;
    // printf("first select->choices=%p\n",select->choices); fflush(stdout);
    // select->choices = realloc(select->choices,
    //         sizeof(Expression[select->num_choices]));
    select->choices = (Expression*)my_realloc(select->choices,
            sizeof(Expression[old_num]),sizeof(Expression[select->num_choices]));
    // printf("now select->choices=%p\n",select->choices); fflush(stdout);
    // printf("access test: %p\n",select->choices[0]); fflush(stdout);
    /* Get and add the choices from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression choice;
        // show_access(select->choices,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(choiceVs,i),choice);
        select->choices[old_num + i] = choice;
    }
    return selectV;
}

.rcsim_add_systemI_systemTs(systemIV, sysVs) ⇒ Object

Adds alternate system types to a C system instance.



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1052

VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
    /* Get the C systemI from the Ruby value. */
    SystemI systemI;
    value_to_rcsim(SystemIS,systemIV,systemI);
    // printf("rcsim_add_systemI_systemTs with systemI=%p\n",systemI);
    /* Prepare the size for the alternate system types. */
    long num = RARRAY_LEN(sysVs);
    long old_num = systemI->num_systems;
    systemI->num_systems += num;
    // printf("first systemI->systems=%p\n",systemI->systems); fflush(stdout);
    // systemI->systems=realloc(systemI->systems,
    //         sizeof(SystemT[systemI->num_systems]));
    systemI->systems = (SystemT*)my_realloc(systemI->systems,
            sizeof(SystemT[old_num]), sizeof(SystemT[systemI->num_systems]));
    // printf("now systemI->systems=%p\n",systemI->systems); fflush(stdout);
    // printf("access test: %p\n",systemI->systems[0]); fflush(stdout);
    /* Get and add the alternate system types from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SystemT sys;
        // show_access(systemI->systems,old_num+i);
        value_to_rcsim(SystemTS,rb_ary_entry(sysVs,i),sys);
        systemI->systems[old_num + i] = sys;
    }
    return systemIV;
}

.rcsim_add_systemT_inouts(systemTV, sigVs) ⇒ Object

Adds inouts to a C systemT.



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 845

VALUE rcsim_add_systemT_inouts(VALUE mod, VALUE systemTV, VALUE sigVs) {
    /* Get the C systemT from the Ruby value. */
    SystemT systemT;
    value_to_rcsim(SystemTS,systemTV,systemT);
    // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
    /* Prepare the size for the inouts. */
    long num = RARRAY_LEN(sigVs);
    long old_num = systemT->num_inouts;
    systemT->num_inouts += num;
    // printf("first systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
    // systemT->inouts =realloc(systemT->inouts,
    //         sizeof(SignalI[systemT->num_inouts]));
    systemT->inouts =(SignalI*)my_realloc(systemT->inouts,
            sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inouts]));
    // printf("now systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
    // printf("access test: %p\n",systemT->inouts[0]); fflush(stdout);
    /* Get and add the signals from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SignalI sig;
        // show_access(systemT->inouts,old_num+i);
        value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
        systemT->inouts[old_num + i] = sig;
    }
    return systemTV;
}

.rcsim_add_systemT_inputs(systemTV, sigVs) ⇒ Object

Adds inputs to a C systemT.



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 790

VALUE rcsim_add_systemT_inputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
    /* Get the C systemT from the Ruby value. */
    SystemT systemT;
    value_to_rcsim(SystemTS,systemTV,systemT);
    // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
    // printf("Adding to systemT with kind=%d and name=%s\n",systemT->kind, systemT->name);
    /* Prepare the size for the inputs. */
    long num = RARRAY_LEN(sigVs);
    long old_num = systemT->num_inputs;
    systemT->num_inputs += num;
    // printf("first systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
    // systemT->inputs=realloc(systemT->inputs,
    //         sizeof(SignalI[systemT->num_inputs]));
    systemT->inputs=(SignalI*)my_realloc(systemT->inputs,
            sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inputs]));
    // printf("now systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
    // printf("access test: %p\n",systemT->inputs[0]); fflush(stdout);
    /* Get and add the signals from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SignalI sig;
        // show_access(systemT->inputs,old_num+i);
        value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
        systemT->inputs[old_num + i] = sig;
    }
    return systemTV;
}

.rcsim_add_systemT_outputs(systemTV, sigVs) ⇒ Object

Adds outputs to a C systemT.



818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 818

VALUE rcsim_add_systemT_outputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
    /* Get the C systemT from the Ruby value. */
    SystemT systemT;
    value_to_rcsim(SystemTS,systemTV,systemT);
    // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
    /* Prepare the size for the outputs. */
    long num = RARRAY_LEN(sigVs);
    long old_num = systemT->num_outputs;
    systemT->num_outputs += num;
    // printf("first systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
    // systemT->outputs =realloc(systemT->outputs,
    //         sizeof(SignalI[systemT->num_outputs]));
    systemT->outputs =(SignalI*)my_realloc(systemT->outputs,
            sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_outputs]));
    // printf("now systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
    // printf("access test: %p\n",systemT->outputs[0]); fflush(stdout);
    /* Get and add the signals from the Ruby value. */
    for(long i=0; i< num; ++i) {
        SignalI sig;
        // show_access(systemT->outputs,old_num+i);
        value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
        systemT->outputs[old_num + i] = sig;
    }
    return systemTV;
}

.rcsim_get_type_bitObject

Get the bit type.



163
164
165
166
167
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 163

VALUE rcsim_get_type_bit(VALUE mod) {
    VALUE res;
    rcsim_to_value(TypeS,get_type_bit(),res);
    return res;
}

.rcsim_get_type_signedObject

Get the signed type.



170
171
172
173
174
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 170

VALUE rcsim_get_type_signed(VALUE mod) {
    VALUE res;
    rcsim_to_value(TypeS,get_type_signed(),res);
    return res;
}

.rcsim_get_type_vector(baseV, numV) ⇒ Object

Get a vector type.



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 177

VALUE rcsim_get_type_vector(VALUE mod, VALUE baseV, VALUE numV) {
    /* Get the base type. */
    Type base;
    value_to_rcsim(TypeS,baseV,base);
    /* Get the number of elements. */
    unsigned long long num = NUM2LL(numV);
    /* Get the type. */
    Type type = get_type_vector(base,num);
    /* Return it as a Ruby VALUE. */
    VALUE res;
    rcsim_to_value(TypeS,type,res);
    return res;
}

.rcsim_main(systemTV, name, outmodeV) ⇒ Object

Starts the C-Ruby hybrid simulation. @param systemTV the top system type. @param name the name of the simulation. @param outmode tells which output mode is used: 0: standard 1: mute 2: vcd



1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1385

VALUE rcsim_main(VALUE mod, VALUE systemTV, VALUE name, VALUE outmodeV) {
    /* Get the C system type from the Ruby value. */
    SystemT systemT;
    value_to_rcsim(SystemTS,systemTV,systemT);
    /* Set it as the top of the simulator. */
    top_system = systemT;
    /* Enable it. */
    set_enable_system(systemT,1);
    /* Get the output mode. */
    int outmode = NUM2INT(outmodeV);
    /* Starts the simulation. */
    switch(outmode) { 
        case 0: hruby_sim_core(StringValueCStr(name),init_default_visualizer,-1);
                break;
        case 1: hruby_sim_core(StringValueCStr(name),init_mute_visualizer,-1);
                break;
        case 2: hruby_sim_core(StringValueCStr(name),init_vcd_visualizer,-1);
                break;
        default:hruby_sim_core(StringValueCStr(name),init_default_visualizer,-1);
    }
    return systemTV;
}

.rcsim_make_behavior(timed) ⇒ Object

Creating a behavior C object.



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 249

VALUE rcsim_make_behavior(VALUE mod, VALUE timed) {
    // printf("rcsim_make_behavior\n");
    /* Allocates the behavior. */
    Behavior behavior = (Behavior)malloc(sizeof(BehaviorS));
    // printf("behavior=%p\n",behavior);
    /* Set it up. */
    behavior->kind = BEHAVIOR;
    behavior->owner = NULL;
    behavior->num_events = 0;
    behavior->events = NULL;
    behavior->block = NULL;
    behavior->enabled = 0;
    behavior->activated = 0;
    if (TYPE(timed) == T_TRUE) {
        /* The behavior is timed, set it up and register it. */
        behavior->timed = 1;
        register_timed_behavior(behavior);
    } else {
        /* The behavior is not timed. */
        behavior->timed = 0;
        /* It must be initialized though. */
        register_init_behavior(behavior);
    }
    behavior->active_time = 0;
    behavior->thread = NULL;
    /* Returns the C behavior embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(BehaviorS,behavior,res);
    return res;
}

.rcsim_make_binary(type, operator, left, right) ⇒ Object

Creating a binary value C object.



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 640

VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE right) {
    // printf("rcsim_make_binary\n");
    /* Allocates the binary. */
    Binary binary = (Binary)malloc(sizeof(BinaryS));
    // printf("binary=%p\n",binary);
    /* Set it up. */
    binary->kind = BINARY;
    binary->owner = NULL;
    value_to_rcsim(TypeS,type,binary->type);
    switch(sym_to_char(operator)) {
        case (unsigned char)'+':         binary->oper = add_value; break;
        case (unsigned char)'-':         binary->oper = sub_value; break;
        case (unsigned char)'*':         binary->oper = mul_value; break;
        case (unsigned char)'/':         binary->oper = div_value; break;
        case (unsigned char)'%':         binary->oper = mod_value; break;
        case (unsigned char)'&':         binary->oper = and_value; break;
        case (unsigned char)'|':         binary->oper = or_value; break;
        case (unsigned char)'^':         binary->oper = xor_value; break;
        case (unsigned char)('<'+'<'*2): binary->oper = shift_left_value; break;
        case (unsigned char)('>'+'>'*2): binary->oper = shift_right_value; break;
        case (unsigned char)('='+'='*2): binary->oper = equal_value_c; break;
        case (unsigned char)('!'+'='*2): binary->oper = not_equal_value_c; break;
        case (unsigned char)'<':         binary->oper = lesser_value; break;
        case (unsigned char)('<'+'='*2): binary->oper = lesser_equal_value; break;
        case (unsigned char)'>':         binary->oper = greater_value; break;
        case (unsigned char)('>'+'='*2): binary->oper = greater_equal_value; break;
        default: perror("Invalid operator for binary.");
    }
    value_to_rcsim(ExpressionS,left,binary->left);
    value_to_rcsim(ExpressionS,right,binary->right);
    /* Returns the C binary embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(BinaryS,binary,res);
    return res;
}

.rcsim_make_block(modeV) ⇒ Object

Creating a block C object.



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 531

VALUE rcsim_make_block(VALUE mod, VALUE modeV) {
    // printf("rcsim_make_block\n");
    /* Allocates the block. */
    Block block = (Block)malloc(sizeof(BlockS));
    // printf("block=%p\n",block);
    /* Set it up. */
    block->kind = BLOCK;
    block->owner = NULL;
    block->name = NULL;
    block->num_inners = 0;
    block->inners = NULL;
    block->num_stmnts = 0;
    block->stmnts = NULL;
    block->mode = SYM2ID(modeV) == id_PAR ? PAR : SEQ;
    /* Returns the C block embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(BlockS,block,res);
    return res;
}

.rcsim_make_cast(type, child) ⇒ Object

Creating a cast C object.



601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 601

VALUE rcsim_make_cast(VALUE mod, VALUE type, VALUE child) {
    // printf("rcsim_make_cast\n");
    /* Allocates the cast. */
    Cast cast = (Cast)malloc(sizeof(CastS));
    // printf("cast=%p\n",cast);
    /* Set it up. */
    cast->kind = CAST;
    cast->owner = NULL;
    value_to_rcsim(TypeS,type,cast->type);
    value_to_rcsim(ExpressionS,child,cast->child);
    /* Returns the C cast embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(CastS,cast,res);
    return res;
}

.rcsim_make_concat(type, dirV) ⇒ Object

Creating a concat C object.



696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 696

VALUE rcsim_make_concat(VALUE mod, VALUE type, VALUE dirV) {
    // printf("rcsim_make_concat\n");
    /* Allocates the concat. */
    Concat concat = (Concat)malloc(sizeof(ConcatS));
    // printf("concat=%p\n",concat);
    /* Set it up. */
    concat->kind = CONCAT;
    concat->owner = NULL;
    value_to_rcsim(TypeS,type,concat->type);
    concat->num_exprs = 0;
    concat->exprs = NULL;
    concat->dir = rb_id2name(SYM2ID(dirV))[0]=='l' ? 1 : 0;
    /* Returns the C concat embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(ConcatS,concat,res);
    return res;
}

.rcsim_make_event(typeV, sigV) ⇒ Object

Creating an event C object.



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 282

VALUE rcsim_make_event(VALUE mod, VALUE typeV, VALUE sigV) {
    // printf("rcsim_make_event\n");
    /* Allocates the event. */
    Event event = (Event)malloc(sizeof(EventS));
    // printf("event=%p\n",event);
    /* Set it up. */
    event->kind = EVENT;
    event->owner = NULL;
    /* Its type. */
    ID id_edge = SYM2ID(typeV);
    if      (id_edge == id_POSEDGE) { event->edge = POSEDGE; }
    else if (id_edge == id_NEGEDGE) { event->edge = NEGEDGE; }
    else if (id_edge == id_ANYEDGE) { event->edge = ANYEDGE; }
    else  { perror("Invalid edge type."); }
    /* Its signal. */
    value_to_rcsim(SignalIS,sigV,event->signal);
    /* Returns the C event embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(EventS,event,res);
    return res;
}

.rcsim_make_hcase(valueV, defoltV) ⇒ Object

Creating a hardware case C object.



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 507

VALUE rcsim_make_hcase(VALUE mod, VALUE valueV, VALUE defoltV) {
    // printf("rcsim_make_hcase\n");
    /* Allocates the hardware case. */
    HCase hcase = (HCase)malloc(sizeof(HCaseS));
    // printf("hcase=%p\n",hcase);
    /* Set it up. */
    hcase->kind = HCASE;
    hcase->owner = NULL;
    value_to_rcsim(ExpressionS,valueV,hcase->value);
    hcase->num_whens = 0;
    hcase->matches = NULL;
    hcase->stmnts = NULL;
    if (TYPE(defoltV) == T_NIL)
        hcase->defolt = NULL;
    else
        value_to_rcsim(StatementS,defoltV,hcase->defolt);
    /* Returns the C hardware case embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(HCaseS,hcase,res);
    return res;
}

.rcsim_make_hif(conditionV, yesV, noV) ⇒ Object

Creating a hardware if C object.



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 482

VALUE rcsim_make_hif(VALUE mod, VALUE conditionV, VALUE yesV, VALUE noV) {
    // printf("rcsim_make_hif\n");
    /* Allocates the hardware if. */
    HIf hif = (HIf)malloc(sizeof(HIfS));
    // printf("hif=%p\n",hif);
    /* Set it up. */
    hif->kind = HIF;
    hif->owner = NULL;
    value_to_rcsim(ExpressionS,conditionV,hif->condition);
    value_to_rcsim(StatementS,yesV,hif->yes);
    if (TYPE(noV) == T_NIL)
        hif->no = NULL;
    else
        value_to_rcsim(StatementS,noV,hif->no);
    hif->num_noifs = 0;
    hif->noconds = NULL;
    hif->nostmnts = NULL;
    /* Returns the C hardware if embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(HIfS,hif,res);
    return res;
}

.rcsim_make_printObject

Creating a print C object.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 395

VALUE rcsim_make_print(VALUE mod) {
    // printf("rcsim_make_print\n");
    /* Allocates the print. */
    Print print = (Print)malloc(sizeof(PrintS));
    // printf("print=%p\n",print);
    /* Set it up. */
    print->kind = PRINT;
    print->owner = NULL;
    print->num_args = 0;
    print->args = NULL;
    /* Returns the C print embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(PrintS,print,res);
    return res;
}

.rcsim_make_refConcat(type, dirV) ⇒ Object

Creating a ref concat C object.



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 715

VALUE rcsim_make_refConcat(VALUE mod, VALUE type, VALUE dirV) {
    // printf("rcsim_make_refConcat\n");
    /* Allocates the ref concat. */
    RefConcat refConcat = (RefConcat)malloc(sizeof(RefConcatS));
    // printf("refConcat=%p\n",refConcat);
    /* Set it up. */
    refConcat->kind = REF_CONCAT;
    refConcat->owner = NULL;
    value_to_rcsim(TypeS,type,refConcat->type);
    refConcat->num_refs = 0;
    refConcat->refs = NULL;
    refConcat->dir = rb_id2name(SYM2ID(dirV))[0]=='l' ? 0 : 1;
    /* Returns the C ref concat embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(RefConcatS,refConcat,res);
    return res;
}

.rcsim_make_refIndex(type, index, ref) ⇒ Object

Creating a ref index C object.



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 734

VALUE rcsim_make_refIndex(VALUE mod, VALUE type, VALUE index, VALUE ref) {
    // printf("rcsim_make_refIndex\n");
    /* Allocates the ref index. */
    RefIndex refIndex = (RefIndex)malloc(sizeof(RefIndexS));
    // printf("refIndex=%p\n",refIndex);
    /* Set it up. */
    refIndex->kind = REF_INDEX;
    refIndex->owner = NULL;
    value_to_rcsim(TypeS,type,refIndex->type);
    value_to_rcsim(ExpressionS,index,refIndex->index);
    value_to_rcsim(ReferenceS,ref,refIndex->ref);
    /* Returns the C ref index embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(RefIndexS,refIndex,res);
    return res;
}

.rcsim_make_refRange(type, first, last, ref) ⇒ Object

Creating a ref range C object.



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 752

VALUE rcsim_make_refRange(VALUE mod, VALUE type, VALUE first, VALUE last, VALUE ref) {
    // printf("rcsim_make_refRange\n");
    /* Allocates the ref range. */
    RefRangeE refRange = (RefRangeE)malloc(sizeof(RefRangeES));
    // printf("refRange=%p\n",refRange);
    /* Set it up. */
    refRange->kind = REF_RANGE;
    refRange->owner = NULL;
    value_to_rcsim(TypeS,type,refRange->type);
    value_to_rcsim(ExpressionS,first,refRange->first);
    value_to_rcsim(ExpressionS,last,refRange->last);
    value_to_rcsim(ReferenceS,ref,refRange->ref);
    /* Returns the C ref range embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(RefRangeES,refRange,res);
    return res;
}

.rcsim_make_scope(name) ⇒ Object

Creating a scope C object.



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 221

VALUE rcsim_make_scope(VALUE mod, VALUE name) {
    // printf("rcsim_make_scope\n");
    /* Allocates the scope. */
    Scope scope = (Scope)malloc(sizeof(ScopeS));
    // printf("scope=%p\n",scope);
    /* Set it up. */
    scope->kind = SCOPE;
    scope->owner = NULL;
    scope->name = strdup(StringValueCStr(name));
    // printf("scope->name=%p\n",scope->name);
    scope->num_systemIs = 0;
    scope->systemIs = NULL;
    scope->num_inners = 0;
    scope->inners = NULL;
    scope->num_scopes = 0;
    scope->scopes = NULL;
    scope->num_behaviors = 0;
    scope->behaviors = NULL;
    scope->num_codes = 0;
    scope->codes = NULL;
    /* Returns the C scope embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(ScopeS,scope,res);
    return res;
}

.rcsim_make_select(type, sel) ⇒ Object

Creating a select C object.



677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 677

VALUE rcsim_make_select(VALUE mod, VALUE type, VALUE sel) {
    // printf("rcsim_make_select\n");
    /* Allocates the select. */
    Select select = (Select)malloc(sizeof(SelectS));
    // printf("select=%p\n",select);
    /* Set it up. */
    select->kind = SELECT;
    select->owner = NULL;
    value_to_rcsim(TypeS,type,select->type);
    value_to_rcsim(ExpressionS,sel,select->select);
    select->num_choices = 0;
    select->choices = NULL;
    /* Returns the C select embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(SelectS,select,res);
    return res;
}

.rcsim_make_signal(name, type) ⇒ Object

Creating a signal C object.



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 308

VALUE rcsim_make_signal(VALUE mod, VALUE name, VALUE type) {
    // printf("rcsim_make_signal\n");
    /* Allocates the signal. */
    SignalI signal = (SignalI)malloc(sizeof(SignalIS));
    signal->id = last_signal_id++;
    // printf("signal=%p\n",signal);
    /* Set it up. */
    signal->kind = SIGNALI;
    signal->owner = NULL;
    signal->name = strdup(StringValueCStr(name));
    // printf("signal->name=%p\n",signal->name);
    // printf("Creating signal named=%s\n",signal->name);
    value_to_rcsim(TypeS,type,signal->type);
    // printf("&type=%p type=%p width=%llu\n",&(signal->type),signal->type,type_width(signal->type));
    signal->c_value = make_value(signal->type,0);
    // printf("signal->c_value=%p\n",signal->c_value);
    signal->c_value->signal = signal;
    // printf("c_value=%p type=%p\n",signal->c_value,signal->c_value->type);
    // printf("c_value type width=%llu\n",type_width(signal->c_value->type));
    signal->f_value = make_value(signal->type,0);
    // printf("signal->f_value=%p\n",signal->f_value);
    signal->f_value->signal = signal;
    signal->fading = 1; /* Initially the signal can be overwritten by anything.*/
    signal->num_any = 0;
    signal->any = NULL;
    // signal->any = (SignalI*)calloc(32,sizeof(SignalI));
    signal->num_pos = 0;
    signal->pos = NULL;
    // signal->pos = (SignalI*)calloc(32,sizeof(SignalI));
    signal->num_neg = 0;
    signal->neg = NULL;
    // signal->neg = (SignalI*)calloc(32,sizeof(SignalI));
    /* Register the signal. */
    register_signal(signal);
    /* Returns the C signal embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(SignalIS,signal,res);
    return res;
}

.rcsim_make_stringE(strV) ⇒ Object

Creating a character string C object.



772
773
774
775
776
777
778
779
780
781
782
783
784
785
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 772

VALUE rcsim_make_stringE(VALUE mod, VALUE strV) {
    // printf("rcsim_make_stringE\n");
    /* Allocates the string. */
    StringE stringE = (StringE)malloc(sizeof(StringES));
    // printf("stringE=%p\n",stringE);
    /* Set it up. */
    stringE->kind = STRINGE;
    stringE->owner = NULL;
    stringE->str   = strdup(StringValueCStr(strV));
    /* Returns the C character string embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(StringES,stringE,res);
    return res;
}

.rcsim_make_systemI(name, systemT) ⇒ Object

Creating a system instance C object.



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 350

VALUE rcsim_make_systemI(VALUE mod, VALUE name, VALUE systemT) {
    // printf("rcsim_make_systemI\n");
    /* Allocates the system instance. */
    SystemI systemI = (SystemI)malloc(sizeof(SystemIS));
    // printf("systemI=%p\n",systemI);
    /* Set it up. */
    systemI->kind = SYSTEMI;
    systemI->owner = NULL;
    systemI->name = strdup(StringValueCStr(name));
    // printf("systemI->name=%p\n",systemI->name);
    // /* Name is made empty since redundant with Eigen system. */
    // systemI->name = "";
    value_to_rcsim(SystemTS,systemT,systemI->system);
    systemI->num_systems = 1;
    systemI->systems = (SystemT*)malloc(sizeof(SystemT[1]));
    // printf("systemI->systems=%p\n",systemI->systems); fflush(stdout);
    systemI->systems[0] = systemI->system;
    /* Configure the systemI to execute the default systemT. */
    configure(systemI,0);
    /* Returns the C system instance embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(SystemIS,systemI,res);
    return res;
}

.rcsim_make_systemT(name) ⇒ Object

Creating a systemT C object.



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 195

VALUE rcsim_make_systemT(VALUE mod, VALUE name) {
    // printf("rcsim_make_systemT\n");
    /* Allocates the systemT. */
    SystemT systemT = (SystemT)malloc(sizeof(SystemTS));
    // printf("systemT=%p\n",systemT);
    /* Set it up. */
    systemT->kind = SYSTEMT;
    systemT->owner = NULL;
    systemT->name = strdup(StringValueCStr(name));
    // printf("systemT->name=%p\n",systemT->name);
    systemT->num_inputs = 0;
    systemT->inputs = NULL;
    systemT->num_outputs = 0;
    systemT->outputs = NULL;
    systemT->num_inouts = 0;
    systemT->inouts = NULL;
    systemT->scope = NULL;
    // printf("Created systemT with kind=%d and name=%s\n",systemT->kind,systemT->name);
    /* Returns the C systemT embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(SystemTS,systemT,res);
    return res;
}

.rcsim_make_timeRepeat(numberV, statementV) ⇒ Object

Creating a time repeat C object.



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 443

VALUE rcsim_make_timeRepeat(VALUE mod, VALUE numberV, VALUE statementV) {
    // printf("rcsim_make_timeRepeat\n"); fflush(stdout);
    /* Allocates the time repeat. */
    TimeRepeat timeRepeat = (TimeRepeat)malloc(sizeof(TimeRepeatS));
    // printf("timeRepeat=%p\n",timeRepeat); fflush(stdout);
    /* Set it up. */
    timeRepeat->kind = TIME_REPEAT;
    timeRepeat->owner = NULL;
    /* Get and set the number of repeatition. */
    long long number;
    number = NUM2LL(numberV);
    // printf("number=%lld\n",number); fflush(stdout);
    timeRepeat->number = number;
    /* Get and set the statement. */
    value_to_rcsim(StatementS,statementV,timeRepeat->statement);
    /* Returns the C time wait embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(TimeRepeatS,timeRepeat,res);
    return res;
}

.rcsim_make_timeTerminateObject

Creating a time terminate C object.



466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 466

VALUE rcsim_make_timeTerminate(VALUE mod) {
    // printf("rcsim_make_timeTerminate\n");
    /* Allocates the time terminate. */
    TimeTerminate timeTerminate = (TimeTerminate)malloc(sizeof(TimeTerminateS));
    // printf("timeTerminate=%p\n",timeTerminate);
    /* Set it up. */
    timeTerminate->kind = TIME_TERMINATE;
    timeTerminate->owner = NULL;
    /* Returns the C time terminate embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(TimeTerminateS,timeTerminate,res);
    return res;
}

.rcsim_make_timeWait(unitV, delayV) ⇒ Object

Creating a time wait C object.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 413

VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
    // printf("rcsim_make_timeWait\n");
    /* Allocates the time wait. */
    TimeWait timeWait = (TimeWait)malloc(sizeof(TimeWaitS));
    // printf("timeWait=%p\n",timeWait);
    /* Set it up. */
    timeWait->kind = TIME_WAIT;
    timeWait->owner = NULL;
    /* Compute the delay. */
    unsigned long long delay;
    delay = NUM2LL(delayV);
    /* Adjust the delay depending on the unit. */
    const char* unit = rb_id2name(SYM2ID(unitV));
    switch(unit[0]) {
        case 'p': /* Ok as is. */         break;
        case 'n': delay *= 1000;          break;
        case 'u': delay *= 1000000;       break;
        case 'm': delay *= 1000000000;    break;
        case 's': delay *= 1000000000000; break;
        default:
                  perror("Invalid delay unit.");
    }
    timeWait->delay = delay;
    /* Returns the C time wait embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(TimeWaitS,timeWait,res);
    return res;
}

.rcsim_make_transmit(left, right) ⇒ Object

Creating a transmit C object.



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 377

VALUE rcsim_make_transmit(VALUE mod, VALUE left, VALUE right) {
    // printf("rcsim_make_transmit\n");
    /* Allocates the transmit. */
    Transmit transmit = (Transmit)malloc(sizeof(TransmitS));
    // printf("transmit=%p\n",transmit);
    /* Set it up. */
    transmit->kind = TRANSMIT;
    transmit->owner = NULL;
    value_to_rcsim(ReferenceS,left,transmit->left);
    value_to_rcsim(ExpressionS,right,transmit->right);
    /* Returns the C transmit embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(TransmitS,transmit,res);
    return res;
}

.rcsim_make_unary(type, operator, child) ⇒ Object

Creating a unary value C object.



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 618

VALUE rcsim_make_unary(VALUE mod, VALUE type, VALUE operator, VALUE child) {
    // printf("rcsim_make_unary\n");
    /* Allocates the unary. */
    Unary unary= (Unary)malloc(sizeof(UnaryS));
    // printf("unary=%p\n",unary);
    /* Set it up. */
    unary->kind = UNARY;
    unary->owner = NULL;
    value_to_rcsim(TypeS,type,unary->type);
    switch(sym_to_char(operator)) {
        case (unsigned char)'~':         unary->oper = not_value; break;
        case (unsigned char)('-'+'@'*2): unary->oper = neg_value; break;
        default: perror("Invalid operator for unary.");
    }
    value_to_rcsim(ExpressionS,child,unary->child);
    /* Returns the C unary embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(UnaryS,unary,res);
    return res;
}

.rcsim_make_value_bitstring(typeV, contentV) ⇒ Object

Creating a bitstring value C object.



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 575

VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
    // printf("rcsim_make_value_bitstring\n");
    /* Get the type. */
    Type type;
    value_to_rcsim(TypeS,typeV,type);
    /* Create the value. */
    Value value = make_value(type,0);
    // printf("value=%p\n",value);
    // printf("Created from bitstring value=%p with type=%p\n",value,value->type);
    // printf("and width=%llu\n",type_width(value->type));
    /* Set it to bitstring. */
    value->numeric = 0;
    /* Generate the string of the content. */
    char* str = StringValueCStr(contentV);
    value->capacity = strlen(str)+1;
    value->data_str = calloc(value->capacity,sizeof(char));
    // printf("value->data_str=%p\n",value->data_str);
    strcpy(value->data_str,str);
    /* Returns the C value embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(ValueS,value,res);
    return res;
}

.rcsim_make_value_numeric(typeV, contentV) ⇒ Object

Creating a numeric value C object.



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 553

VALUE rcsim_make_value_numeric(VALUE mod, VALUE typeV, VALUE contentV) {
    // printf("rcsim_make_value_numeric\n");
    /* Get the type. */
    Type type;
    value_to_rcsim(TypeS,typeV,type);
    /* Create the value. */
    Value value = make_value(type,0);
    // printf("value=%p\n",value);
    /* Set it to numeric. */
    value->numeric = 1;
    value->capacity = 0;
    value->data_str = NULL;
    value->data_int = NUM2LL(contentV);
    // printf("value->data_int=%lld\n",value->data_int);
    /* Returns the C value embedded into a ruby VALUE. */
    VALUE res;
    rcsim_to_value(ValueS,value,res);
    return res;
}

.rcsim_set_behavior_block(behaviorV, blockV) ⇒ Object

Sets the block for a C behavior.



1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1346

VALUE rcsim_set_behavior_block(VALUE mod, VALUE behaviorV, VALUE blockV) {
    /* Get the C behavior from the Ruby value. */
    Behavior behavior;
    value_to_rcsim(BehaviorS,behaviorV,behavior);
    /* Get the C block from the Ruby value. */
    Block block;
    value_to_rcsim(BlockS,blockV,block);
    /* Set the block. */
    behavior->block = block;
    return behaviorV;
}

.rcsim_set_owner(objV, ownerV) ⇒ Object

Sets the owner for a C simulation object.



1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1320

VALUE rcsim_set_owner(VALUE mod, VALUE objV, VALUE ownerV) {
    /* Get the C object from the Ruby value. */
    Object obj;
    value_to_rcsim(ObjectS,objV,obj);
    /* Get the C owner from the Ruby value. */
    Object owner;
    value_to_rcsim(ObjectS,ownerV,owner);
    /* Set the owner. */
    obj->owner = owner;
    return objV;
}

.rcsim_set_signal_value(signalV, exprV) ⇒ Object

Sets the value for a C signal.



1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1359

VALUE rcsim_set_signal_value(VALUE mod, VALUE signalV, VALUE exprV) {
    /* Get the C signal from the Ruby value. */
    SignalI signal;
    value_to_rcsim(SignalIS,signalV,signal);
    // printf("rc_sim_set_signal_value for signal=%s\n",signal->name);
    /* Get the C expression from the Ruby value. */
    Expression expr;
    value_to_rcsim(ExpressionS,exprV,expr);
    /* Compute the value from it. */
    Value value = get_value();
    value = calc_expression(expr,value);
    /* Copies the value. */
    signal->f_value = copy_value(value,signal->f_value);
    signal->c_value = copy_value(value,signal->c_value);
    free_value();
    return signalV;
}

.rcsim_set_systemT_scope(systemTV, scopeV) ⇒ Object

Sets the scope for a C system type.



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1333

VALUE rcsim_set_systemT_scope(VALUE mod, VALUE systemTV, VALUE scopeV) {
    /* Get the C system type from the Ruby value. */
    SystemT systemT;
    value_to_rcsim(SystemTS,systemTV,systemT);
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    /* Set the scope. */
    systemT->scope = scope;
    return systemTV;
}