ruby-vpi 13.0.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/Rakefile +6 -1
  2. data/bin/generate_test_tpl/bench.rb +84 -1
  3. data/bin/generate_test_tpl/bench.v +8 -17
  4. data/bin/generate_test_tpl/proto.rb +1 -1
  5. data/doc/common.css +14 -41
  6. data/doc/common.tpl +1 -1
  7. data/doc/figures/figures.dia +274 -753
  8. data/doc/figures/organization_detailed.png +0 -0
  9. data/doc/figures/ruby_relay.png +0 -0
  10. data/doc/history.html +363 -276
  11. data/doc/history.yml +40 -0
  12. data/doc/intro.inc +37 -15
  13. data/doc/lib/doc_proxy.rb +24 -4
  14. data/doc/manual.doc +345 -196
  15. data/doc/manual.html +741 -497
  16. data/doc/memo.doc +15 -15
  17. data/doc/memo.html +28 -27
  18. data/doc/readme.doc +2 -2
  19. data/doc/readme.html +51 -15
  20. data/doc/rss.erb +1 -1
  21. data/doc/rss.xml +1624 -31
  22. data/ext/Rakefile +1 -6
  23. data/ext/main.c +8 -3
  24. data/ext/main.h +5 -0
  25. data/ext/relay.c +12 -12
  26. data/ext/relay.h +1 -6
  27. data/ext/swig_vpi.i +2 -2
  28. data/ext/swig_wrap.cin +37 -20
  29. data/ext/verilog.h +2 -2
  30. data/ext/vlog.c +10 -3
  31. data/ext/vlog.h +4 -4
  32. data/lib/ruby-vpi/vpi.rb +114 -0
  33. data/lib/ruby-vpi.rb +21 -59
  34. data/ref/c/annotated.html +1 -1
  35. data/ref/c/common_8h.html +1 -1
  36. data/ref/c/files.html +1 -1
  37. data/ref/c/functions.html +1 -1
  38. data/ref/c/functions_vars.html +1 -1
  39. data/ref/c/globals.html +1 -1
  40. data/ref/c/globals_0x63.html +1 -1
  41. data/ref/c/globals_0x65.html +1 -1
  42. data/ref/c/globals_0x66.html +1 -1
  43. data/ref/c/globals_0x6d.html +3 -2
  44. data/ref/c/globals_0x70.html +1 -1
  45. data/ref/c/globals_0x72.html +4 -5
  46. data/ref/c/globals_0x73.html +1 -1
  47. data/ref/c/globals_0x74.html +1 -1
  48. data/ref/c/globals_0x76.html +4 -2
  49. data/ref/c/globals_0x78.html +1 -1
  50. data/ref/c/globals_defs.html +1 -1
  51. data/ref/c/globals_defs_0x65.html +1 -1
  52. data/ref/c/globals_defs_0x70.html +1 -1
  53. data/ref/c/globals_defs_0x76.html +1 -1
  54. data/ref/c/globals_defs_0x78.html +1 -1
  55. data/ref/c/globals_enum.html +1 -1
  56. data/ref/c/globals_eval.html +1 -1
  57. data/ref/c/globals_func.html +8 -7
  58. data/ref/c/globals_type.html +1 -1
  59. data/ref/c/globals_vars.html +3 -2
  60. data/ref/c/index.html +1 -1
  61. data/ref/c/main_8c.html +26 -1
  62. data/ref/c/main_8h.html +26 -1
  63. data/ref/c/relay_8c.html +11 -35
  64. data/ref/c/relay_8h.html +3 -27
  65. data/ref/c/structt__cb__data.html +1 -1
  66. data/ref/c/structt__vpi__delay.html +1 -1
  67. data/ref/c/structt__vpi__error__info.html +1 -1
  68. data/ref/c/structt__vpi__strengthval.html +1 -1
  69. data/ref/c/structt__vpi__systf__data.html +1 -1
  70. data/ref/c/structt__vpi__time.html +1 -1
  71. data/ref/c/structt__vpi__value.html +1 -1
  72. data/ref/c/structt__vpi__vecval.html +1 -1
  73. data/ref/c/structt__vpi__vlog__info.html +1 -1
  74. data/ref/c/verilog_8h.html +5 -5
  75. data/ref/c/vlog_8c.html +44 -6
  76. data/ref/c/vlog_8h.html +7 -8
  77. data/ref/c/vpi__user_8h.html +1 -1
  78. data/ref/ruby/classes/RDoc.html +5 -5
  79. data/ref/ruby/classes/RDoc.src/{M000041.html → M000045.html} +0 -0
  80. data/ref/ruby/classes/RubyVpi.html +10 -28
  81. data/ref/ruby/classes/RubyVpi.src/M000029.html +101 -124
  82. data/ref/ruby/classes/Vpi/Handle.html +56 -56
  83. data/ref/ruby/classes/Vpi/Handle.src/M000034.html +5 -9
  84. data/ref/ruby/classes/Vpi/Handle.src/M000035.html +5 -31
  85. data/ref/ruby/classes/Vpi/Handle.src/M000036.html +5 -74
  86. data/ref/ruby/classes/Vpi/Handle.src/M000037.html +5 -17
  87. data/ref/ruby/classes/Vpi/Handle.src/M000038.html +9 -11
  88. data/ref/ruby/classes/Vpi/Handle.src/M000039.html +44 -0
  89. data/ref/ruby/classes/Vpi/Handle.src/M000040.html +74 -55
  90. data/ref/ruby/classes/Vpi/Handle.src/M000041.html +30 -0
  91. data/ref/ruby/classes/Vpi/Handle.src/M000042.html +24 -0
  92. data/ref/ruby/classes/Vpi/Handle.src/M000044.html +68 -0
  93. data/ref/ruby/classes/Vpi.html +149 -0
  94. data/ref/ruby/classes/Vpi.src/M000030.html +28 -0
  95. data/ref/ruby/classes/Vpi.src/M000031.html +18 -0
  96. data/ref/ruby/classes/Vpi.src/M000032.html +39 -0
  97. data/ref/ruby/classes/Vpi.src/M000033.html +22 -0
  98. data/ref/ruby/created.rid +1 -1
  99. data/ref/ruby/files/lib/ruby-vpi/vpi_rb.html +1 -1
  100. data/ref/ruby/files/lib/ruby-vpi_rb.html +2 -2
  101. data/ref/ruby/fr_method_index.html +18 -14
  102. data/samp/counter/counter_rspec_bench.rb +81 -1
  103. data/samp/counter/counter_rspec_bench.v +5 -12
  104. data/samp/counter/counter_rspec_design.rb +1 -2
  105. data/samp/counter/counter_rspec_proto.rb +1 -1
  106. data/samp/counter/counter_rspec_spec.rb +3 -3
  107. data/samp/counter/counter_xunit_bench.rb +81 -1
  108. data/samp/counter/counter_xunit_bench.v +5 -12
  109. data/samp/counter/counter_xunit_design.rb +1 -2
  110. data/samp/counter/counter_xunit_proto.rb +1 -1
  111. data/samp/counter/counter_xunit_spec.rb +3 -3
  112. data/samp/pipelined_alu/hw5_unit_test_bench.rb +81 -1
  113. data/samp/pipelined_alu/hw5_unit_test_bench.v +11 -18
  114. data/samp/pipelined_alu/hw5_unit_test_design.rb +1 -1
  115. data/samp/pipelined_alu/hw5_unit_test_proto.rb +1 -1
  116. data/samp/pipelined_alu/hw5_unit_test_spec.rb +1 -1
  117. metadata +12 -9
  118. data/doc/figures/ruby_init.png +0 -0
  119. data/ext/swig_vpi.h +0 -924
  120. data/ref/ruby/classes/Vpi/Handle.src/M000030.html +0 -18
  121. data/ref/ruby/classes/Vpi/Handle.src/M000031.html +0 -18
  122. data/ref/ruby/classes/Vpi/Handle.src/M000032.html +0 -18
  123. data/ref/ruby/classes/Vpi/Handle.src/M000033.html +0 -18
data/ext/Rakefile CHANGED
@@ -54,12 +54,7 @@ file 'swig_wrap.cin' => 'swig_vpi.i' do |t|
54
54
  sh %w{swig -ruby -o}, t.name, t.prerequisites[0]
55
55
  end
56
56
 
57
- file 'swig_vpi.i' => 'swig_vpi.h'
58
-
59
- file 'swig_vpi.h' => 'vpi_user.h' do |t|
60
- # avoid problems with SWIG-generated wrapper for VPI vprintf functions which use va_list
61
- ruby %{-pe 'gsub /\\bva_list\\b/, "int"' #{t.prerequisites[0]} > #{t.name}}
62
- end
57
+ file 'swig_vpi.i' => 'vpi_user.h'
63
58
 
64
59
  # NOTE: since SWIG is not a requirement for users, we should not clobber these generated files
65
60
  #CLOBBER.include 'swig_wrap.cin', 'swig_vpi.h'
data/ext/main.c CHANGED
@@ -36,20 +36,21 @@ void main_init() {
36
36
  // load the VPI interface for Ruby
37
37
  Init_vpi();
38
38
  rb_define_module_function(mVpi, "relay_verilog", main_relay_verilog, 0);
39
+ rb_define_module_function(mVpi, "relay_ruby_reason", main_relay_ruby_reason, 0);
40
+
39
41
 
40
42
  // initialize the Ruby bench
41
43
  char* benchFile = getenv("RUBY_VPI__RUBY_BENCH_FILE");
42
44
 
43
45
  if (benchFile != NULL) {
46
+ ruby_script(benchFile);
44
47
  rb_load_file(benchFile);
45
48
  }
46
49
  else {
47
- common_printf("error: environment variable RUBY_VPI__RUBY_BENCH_FILE is not set.");
50
+ common_printf("error: environment variable RUBY_VPI__RUBY_BENCH_FILE is uninitialized.");
48
51
  exit(EXIT_FAILURE);
49
52
  }
50
53
 
51
- ruby_script(benchFile);
52
-
53
54
  // run the test bench
54
55
  ruby_run();
55
56
 
@@ -60,3 +61,7 @@ VALUE main_relay_verilog(VALUE arSelf) {
60
61
  relay_verilog();
61
62
  return arSelf;
62
63
  }
64
+
65
+ VALUE main_relay_ruby_reason(VALUE arSelf) {
66
+ return SWIG_NewPointerObj(vlog_relay_ruby_reason(), SWIGTYPE_p_t_cb_data, 0);
67
+ }
data/ext/main.h CHANGED
@@ -37,4 +37,9 @@
37
37
  */
38
38
  VALUE main_relay_verilog(VALUE arSelf);
39
39
 
40
+ /**
41
+ Gets the reason (Vpi::S_cb_data) why Verilog relayed to Ruby.
42
+ */
43
+ VALUE main_relay_ruby_reason(VALUE arSelf);
44
+
40
45
  #endif
data/ext/relay.c CHANGED
@@ -28,11 +28,23 @@ pthread_t relay__rubyThread;
28
28
  pthread_mutex_t relay__rubyLock;
29
29
  pthread_mutex_t relay__verilogLock;
30
30
 
31
+ // Body of the ruby thread.
32
+ void* relay_ruby_thread(void* dummy) {
33
+ main_init();
34
+ return NULL;
35
+ }
36
+
31
37
  void relay_init() {
32
38
  pthread_mutex_init(&relay__rubyLock, NULL);
33
39
  pthread_mutex_lock(&relay__rubyLock);
34
40
  pthread_mutex_init(&relay__verilogLock, NULL);
35
41
  pthread_mutex_lock(&relay__verilogLock);
42
+
43
+ // start the ruby thread
44
+ pthread_create(&relay__rubyThread, 0, relay_ruby_thread, NULL);
45
+
46
+ // XXX: freezee verilog because RubyVpi.init_bench will call relay_verilog (which assumes that verilog is frozen)
47
+ pthread_mutex_lock(&relay__verilogLock);
36
48
  }
37
49
 
38
50
  void relay_ruby() {
@@ -44,15 +56,3 @@ void relay_verilog() {
44
56
  pthread_mutex_unlock(&relay__verilogLock);
45
57
  pthread_mutex_lock(&relay__rubyLock);
46
58
  }
47
-
48
- void* relay_main_handshake(void* aDummy) {
49
- main_init();
50
- return NULL;
51
- }
52
-
53
- void relay_main() {
54
- pthread_create(&relay__rubyThread, 0, relay_main_handshake, NULL);
55
-
56
- // XXX: freezee verilog because RubyVpi.init_bench will call relay_verilog (which assumes that verilog is frozen)
57
- pthread_mutex_lock(&relay__verilogLock);
58
- }
data/ext/relay.h CHANGED
@@ -28,7 +28,7 @@
28
28
  #include "common.h"
29
29
 
30
30
  /**
31
- Initialize the relay mechanism, which enables Verilog to transfer control to Ruby and vice versa.
31
+ Initialize the relay mechanism, which enables Verilog to transfer control to Ruby and vice versa, and start Ruby.
32
32
  */
33
33
  void relay_init();
34
34
 
@@ -42,9 +42,4 @@
42
42
  */
43
43
  void relay_verilog();
44
44
 
45
- /**
46
- Transfers control to the main layer.
47
- */
48
- void relay_main();
49
-
50
45
  #endif
data/ext/swig_vpi.i CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  /* Parse the header file to generate wrappers */
5
5
  %{
6
- #include "swig_vpi.h"
6
+ #include "vpi_user.h"
7
7
  %}
8
- %include "swig_vpi.h"
8
+ %include "vpi_user.h"
9
9
 
10
10
 
11
11
  /* allows us to set S_cb_data.cb_rtn = Vpi::Vlog_relay_ruby from Ruby */
data/ext/swig_wrap.cin CHANGED
@@ -1491,9 +1491,10 @@ SWIG_Ruby_SetModule(swig_module_info *pointer)
1491
1491
  #define SWIGTYPE_p_unsigned_char swig_types[17]
1492
1492
  #define SWIGTYPE_p_unsigned_int swig_types[18]
1493
1493
  #define SWIGTYPE_p_unsigned_short swig_types[19]
1494
- #define SWIGTYPE_p_void swig_types[20]
1495
- static swig_type_info *swig_types[22];
1496
- static swig_module_info swig_module = {swig_types, 21, 0, 0, 0, 0};
1494
+ #define SWIGTYPE_p_va_list swig_types[20]
1495
+ #define SWIGTYPE_p_void swig_types[21]
1496
+ static swig_type_info *swig_types[23];
1497
+ static swig_module_info swig_module = {swig_types, 22, 0, 0, 0, 0};
1497
1498
  #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
1498
1499
  #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
1499
1500
 
@@ -1511,7 +1512,7 @@ static VALUE mVpi;
1511
1512
  #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a))
1512
1513
 
1513
1514
 
1514
- #include "swig_vpi.h"
1515
+ #include "vpi_user.h"
1515
1516
 
1516
1517
 
1517
1518
  #include <limits.h>
@@ -5943,13 +5944,13 @@ fail:
5943
5944
  SWIGINTERN VALUE
5944
5945
  _wrap_vpi_vprintf(int argc, VALUE *argv, VALUE self) {
5945
5946
  PLI_BYTE8 *arg1 = (PLI_BYTE8 *) 0 ;
5946
- int arg2 ;
5947
+ va_list arg2 ;
5947
5948
  PLI_INT32 result;
5948
5949
  int res1 ;
5949
5950
  char *buf1 = 0 ;
5950
5951
  int alloc1 = 0 ;
5951
- int val2 ;
5952
- int ecode2 = 0 ;
5952
+ void *argp2 ;
5953
+ int res2 = 0 ;
5953
5954
  VALUE vresult = Qnil;
5954
5955
 
5955
5956
  if ((argc < 2) || (argc > 2)) {
@@ -5960,11 +5961,17 @@ _wrap_vpi_vprintf(int argc, VALUE *argv, VALUE self) {
5960
5961
  SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "vpi_vprintf" "', argument " "1"" of type '" "PLI_BYTE8 *""'");
5961
5962
  }
5962
5963
  arg1 = buf1;
5963
- ecode2 = SWIG_AsVal_int(argv[1], &val2);
5964
- if (!SWIG_IsOK(ecode2)) {
5965
- SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "vpi_vprintf" "', argument " "2"" of type '" "int""'");
5966
- }
5967
- arg2 = (int)(val2);
5964
+ {
5965
+ res2 = SWIG_ConvertPtr(argv[1], &argp2, SWIGTYPE_p_va_list, 0 );
5966
+ if (!SWIG_IsOK(res2)) {
5967
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "vpi_vprintf" "', argument " "2"" of type '" "va_list""'");
5968
+ }
5969
+ if (!argp2) {
5970
+ SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "vpi_vprintf" "', argument " "2"" of type '" "va_list""'");
5971
+ } else {
5972
+ arg2 = *((va_list *)(argp2));
5973
+ }
5974
+ }
5968
5975
  result = (PLI_INT32)vpi_vprintf(arg1,arg2);
5969
5976
 
5970
5977
  vresult = SWIG_From_int((int)(result));
@@ -5980,15 +5987,15 @@ SWIGINTERN VALUE
5980
5987
  _wrap_vpi_mcd_vprintf(int argc, VALUE *argv, VALUE self) {
5981
5988
  PLI_UINT32 arg1 ;
5982
5989
  PLI_BYTE8 *arg2 = (PLI_BYTE8 *) 0 ;
5983
- int arg3 ;
5990
+ va_list arg3 ;
5984
5991
  PLI_INT32 result;
5985
5992
  unsigned int val1 ;
5986
5993
  int ecode1 = 0 ;
5987
5994
  int res2 ;
5988
5995
  char *buf2 = 0 ;
5989
5996
  int alloc2 = 0 ;
5990
- int val3 ;
5991
- int ecode3 = 0 ;
5997
+ void *argp3 ;
5998
+ int res3 = 0 ;
5992
5999
  VALUE vresult = Qnil;
5993
6000
 
5994
6001
  if ((argc < 3) || (argc > 3)) {
@@ -6004,11 +6011,17 @@ _wrap_vpi_mcd_vprintf(int argc, VALUE *argv, VALUE self) {
6004
6011
  SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "vpi_mcd_vprintf" "', argument " "2"" of type '" "PLI_BYTE8 *""'");
6005
6012
  }
6006
6013
  arg2 = buf2;
6007
- ecode3 = SWIG_AsVal_int(argv[2], &val3);
6008
- if (!SWIG_IsOK(ecode3)) {
6009
- SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "vpi_mcd_vprintf" "', argument " "3"" of type '" "int""'");
6010
- }
6011
- arg3 = (int)(val3);
6014
+ {
6015
+ res3 = SWIG_ConvertPtr(argv[2], &argp3, SWIGTYPE_p_va_list, 0 );
6016
+ if (!SWIG_IsOK(res3)) {
6017
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "vpi_mcd_vprintf" "', argument " "3"" of type '" "va_list""'");
6018
+ }
6019
+ if (!argp3) {
6020
+ SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "vpi_mcd_vprintf" "', argument " "3"" of type '" "va_list""'");
6021
+ } else {
6022
+ arg3 = *((va_list *)(argp3));
6023
+ }
6024
+ }
6012
6025
  result = (PLI_INT32)vpi_mcd_vprintf(arg1,arg2,arg3);
6013
6026
 
6014
6027
  vresult = SWIG_From_int((int)(result));
@@ -6170,6 +6183,7 @@ static swig_type_info _swigt__p_t_vpi_vlog_info = {"_p_t_vpi_vlog_info", "struct
6170
6183
  static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|PLI_UBYTE8 *", 0, 0, (void*)0, 0};
6171
6184
  static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "unsigned int *|vpiHandle", 0, 0, (void*)0, 0};
6172
6185
  static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|PLI_UINT16 *", 0, 0, (void*)0, 0};
6186
+ static swig_type_info _swigt__p_va_list = {"_p_va_list", "va_list *", 0, 0, (void*)0, 0};
6173
6187
  static swig_type_info _swigt__p_void = {"_p_void", "void *", 0, 0, (void*)0, 0};
6174
6188
 
6175
6189
  static swig_type_info *swig_type_initial[] = {
@@ -6193,6 +6207,7 @@ static swig_type_info *swig_type_initial[] = {
6193
6207
  &_swigt__p_unsigned_char,
6194
6208
  &_swigt__p_unsigned_int,
6195
6209
  &_swigt__p_unsigned_short,
6210
+ &_swigt__p_va_list,
6196
6211
  &_swigt__p_void,
6197
6212
  };
6198
6213
 
@@ -6216,6 +6231,7 @@ static swig_cast_info _swigc__p_t_vpi_vlog_info[] = { {&_swigt__p_t_vpi_vlog_in
6216
6231
  static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}};
6217
6232
  static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}};
6218
6233
  static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}};
6234
+ static swig_cast_info _swigc__p_va_list[] = { {&_swigt__p_va_list, 0, 0, 0},{0, 0, 0, 0}};
6219
6235
  static swig_cast_info _swigc__p_void[] = { {&_swigt__p_void, 0, 0, 0},{0, 0, 0, 0}};
6220
6236
 
6221
6237
  static swig_cast_info *swig_cast_initial[] = {
@@ -6239,6 +6255,7 @@ static swig_cast_info *swig_cast_initial[] = {
6239
6255
  _swigc__p_unsigned_char,
6240
6256
  _swigc__p_unsigned_int,
6241
6257
  _swigc__p_unsigned_short,
6258
+ _swigc__p_va_list,
6242
6259
  _swigc__p_void,
6243
6260
  };
6244
6261
 
data/ext/verilog.h CHANGED
@@ -55,7 +55,7 @@
55
55
  #define verilog_tf_funcPtr verilog_tf_funcPtr_strict
56
56
 
57
57
  #define verilog_tf_funcSig(aFuncName) \
58
- PLI_INT32 aFuncName(PLI_BYTE8* aArg)
58
+ PLI_INT32 aFuncName(PLI_BYTE8* aCallbackData)
59
59
 
60
60
  #define verilog_tf_funcReturn(aReturnVal) \
61
61
  return aReturnVal
@@ -66,7 +66,7 @@
66
66
  PLI_INT32 (*aPtrName)(p_cb_data)
67
67
 
68
68
  #define verilog_cb_funcSig(aFuncName) \
69
- PLI_INT32 aFuncName(p_cb_data aArg)
69
+ PLI_INT32 aFuncName(p_cb_data aCallbackData)
70
70
 
71
71
  #define verilog_cb_funcReturn(aReturnVal) \
72
72
  return aReturnVal
data/ext/vlog.c CHANGED
@@ -23,17 +23,24 @@
23
23
  #include "relay.h"
24
24
 
25
25
 
26
- verilog_cb_funcSig(vlog_relay_main) {
26
+ s_cb_data* vlog__relayReason = NULL;
27
+
28
+ verilog_cb_funcSig(vlog_relay_init) {
27
29
  relay_init();
28
- relay_main();
29
30
  verilog_cb_funcReturn(0);
30
31
  }
31
32
 
32
33
  verilog_cb_funcSig(vlog_relay_ruby) {
34
+ vlog__relayReason = aCallbackData;
33
35
  relay_ruby();
36
+
34
37
  verilog_cb_funcReturn(0);
35
38
  }
36
39
 
40
+ s_cb_data* vlog_relay_ruby_reason() {
41
+ return vlog__relayReason;
42
+ }
43
+
37
44
 
38
45
  /**
39
46
  Registers a callback at start of simulation to vlog_relay_main();
@@ -42,7 +49,7 @@ void vlog_startup() {
42
49
  s_cb_data call;
43
50
 
44
51
  call.reason = cbStartOfSimulation;
45
- call.cb_rtn = vlog_relay_main;
52
+ call.cb_rtn = vlog_relay_init;
46
53
  call.obj = NULL;
47
54
  call.time = NULL;
48
55
  call.value = NULL;
data/ext/vlog.h CHANGED
@@ -28,13 +28,13 @@
28
28
  #include "verilog.h"
29
29
 
30
30
  /**
31
- Relays control to the main layer.
31
+ Relays control from Verilog to Ruby.
32
32
  */
33
- verilog_cb_funcSig(vlog_relay_main);
33
+ verilog_cb_funcSig(vlog_relay_ruby);
34
34
 
35
35
  /**
36
- Relays control from Verilog to Ruby.
36
+ Returns the data corresponding to the callback that caused the relay from Verilog to Ruby.
37
37
  */
38
- verilog_cb_funcSig(vlog_relay_ruby);
38
+ s_cb_data* vlog_relay_ruby_reason();
39
39
 
40
40
  #endif
data/lib/ruby-vpi/vpi.rb CHANGED
@@ -21,6 +21,18 @@
21
21
  =end
22
22
 
23
23
  module Vpi
24
+ # Number of bits in PLI_INT32.
25
+ INTEGER_BITS = 32
26
+
27
+ # Lowest upper bound of PLI_INT32.
28
+ INTEGER_LIMIT = 2 ** INTEGER_BITS
29
+
30
+ # Bit-mask capable of capturing PLI_INT32.
31
+ INTEGER_MASK = INTEGER_LIMIT - 1
32
+
33
+
34
+ ## handles
35
+
24
36
  Handle = SWIG::TYPE_p_unsigned_int
25
37
 
26
38
  # An object inside a Verilog simulation (see *vpiHandle* in IEEE Std. 1364-2005).
@@ -214,6 +226,8 @@ module Vpi
214
226
  alias to_s inspect
215
227
 
216
228
 
229
+ ## properties
230
+
217
231
  @@propCache = Hash.new {|h, k| h[k] = Property.resolve(k)}
218
232
 
219
233
  # Provides access to this handle's
@@ -354,4 +368,104 @@ module Vpi
354
368
  end
355
369
  end
356
370
  end
371
+
372
+
373
+ ## callbacks
374
+
375
+ Callback = Struct.new :handler, :token #:nodoc:
376
+ @@callbacks = {}
377
+
378
+ alias vpi_register_cb_old vpi_register_cb
379
+
380
+ # This is a Ruby version of the vpi_register_cb C function. It is identical to the C function, except for the following differences:
381
+ # * This method accepts a block (callback handler) which is executed whenever the callback occurs.
382
+ # * This method overwrites the +cb_rtn+ and +user_data+ fields of the given +S_cb_data+ object.
383
+ def vpi_register_cb aData, &aHandler # :yields: Vpi::S_cb_data
384
+ raise ArgumentError, "block must be given" unless block_given?
385
+
386
+ key = aHandler.object_id.to_s
387
+
388
+ # register the callback with Verilog
389
+ aData.user_data = key
390
+ aData.cb_rtn = Vlog_relay_ruby
391
+ token = vpi_register_cb_old(aData)
392
+
393
+ @@callbacks[key] = Callback.new(aHandler, token)
394
+ token
395
+ end
396
+
397
+ alias vpi_remove_cb_old vpi_remove_cb
398
+
399
+ def vpi_remove_cb aData # :nodoc:
400
+ key = aData.user_data
401
+
402
+ if c = @@callbacks[key]
403
+ vpi_remove_cb_old c.token
404
+ @@callbacks.delete key
405
+ end
406
+ end
407
+
408
+ # Proxy for relay_verilog which supports callbacks.
409
+ # This method should NOT be invoked from callback handlers (see vpi_register_cb) and threads -- otherwise the situation will be like seven remote controls changing the channel on a single television set!
410
+ def relay_verilog_proxy # :nodoc:
411
+ loop do
412
+ relay_verilog
413
+
414
+ if reason = relay_ruby_reason # might be nil
415
+ dst = reason.user_data
416
+
417
+ if c = @@callbacks[dst]
418
+ c.handler.call reason
419
+ else
420
+ break # main thread is receiver
421
+ end
422
+ end
423
+ end
424
+ end
425
+
426
+
427
+ ## simulation control
428
+
429
+ # Simulates the design under test according to RubyVpi.init_bench.
430
+ def simulate
431
+ # this is a dummy method!
432
+ end
433
+
434
+ # Advances the simulation by the given number of steps.
435
+ def advance_time aNumSteps = 1
436
+ # schedule wake-up callback from verilog
437
+ time = S_vpi_time.new
438
+ time.low = aNumSteps & INTEGER_MASK
439
+ time.high = (aNumSteps >> INTEGER_BITS) & INTEGER_MASK
440
+ time.type = VpiSimTime
441
+
442
+ value = S_vpi_value.new
443
+ value.format = VpiSuppressVal
444
+
445
+ alarm = S_cb_data.new
446
+ alarm.reason = CbAfterDelay
447
+ alarm.cb_rtn = Vlog_relay_ruby
448
+ alarm.obj = nil
449
+ alarm.time = time
450
+ alarm.value = value
451
+ alarm.index = 0
452
+ alarm.user_data = nil
453
+
454
+ vpi_free_object(vpi_register_cb_old(alarm))
455
+
456
+ # relay to verilog
457
+ relay_verilog_proxy
458
+ end
459
+
460
+
461
+ ## utility
462
+
463
+ # Returns the current simulation time as a 64-bit integer.
464
+ def simulation_time
465
+ t = S_vpi_time.new
466
+ t.type = VpiSimTime
467
+
468
+ vpi_get_time nil, t
469
+ (t.high << INTEGER_BITS) | t.low
470
+ end
357
471
  end
data/lib/ruby-vpi.rb CHANGED
@@ -19,44 +19,32 @@
19
19
  =end
20
20
 
21
21
  module RubyVpi
22
- # Initializes the bench by loading:
23
- # 1. the design.rb file
24
- # 2. the proto.rb file if prototyping is enabled
25
- # 3. the spec.rb file
22
+ # Initializes the bench by setting up code coverage, the interactive debugger, and so on:
23
+ # 1. loads the design.rb file
24
+ # 2. loads the proto.rb file if prototyping is enabled
25
+ # 3. loads the spec.rb file
26
26
  #
27
- # aDesignId:: The name of the Ruby design object.
28
- # aSpecFormat:: The format being used by the specification.
29
- # aClockTrigger:: When the return value of this block is +true+, then the relay_verilog method returns. This block is given one argument: a handle to the clock signal that drives the design under test. If this block is not specified, relay_verilog will always return upon the next positive edge of the clock signal.
27
+ # aDesignId:: The name of the Ruby object which gives access to the design under test.
28
+ # aSpecFormat:: The name of the format being used by the specification.
29
+ # aSimulationCycle:: A block that simulates the design under test by, for example, toggling the clock signal.
30
30
  #
31
- # # return upon positive edge
32
- # RubyVpi.init_bench ... |clk|
33
- # clk.intVal == 1
34
- # end
35
- #
36
- # # return upon negative edge
37
- # RubyVpi.init_bench ... do |clk|
38
- # clk.intVal == 0
39
- # end
40
- #
41
- # # return whenever clock changes
42
- # RubyVpi.init_bench ... do |clk|
43
- # true
44
- # end
45
- #
46
- def RubyVpi.init_bench aDesignId, aSpecFormat, &aClockTrigger # :yields: clock_signal
31
+ def RubyVpi.init_bench aDesignId, aSpecFormat, &aSimulationCycle
32
+ raise ArgumentError, "block must be given" unless block_given?
33
+
47
34
  if caller.find {|s| s =~ /^(.*?)_bench.rb:/}
48
35
  testName = $1
49
36
  else
50
37
  raise 'Unable to determine name of test.'
51
38
  end
52
39
 
53
- aClockTrigger ||= lambda {|clk| clk.intVal == 1}
54
-
55
40
  useDebugger = !(ENV['DEBUG'] || '').empty?
56
41
  useCoverage = !(ENV['COVERAGE'] || '').empty?
57
42
  usePrototype = !(ENV['PROTOTYPE'] || '').empty?
58
43
 
59
44
  # set up code coverage analysis
45
+ # XXX: this is loaded *before* RCov to prevent coverage statistics about it
46
+ require 'ruby-vpi/vpi'
47
+
60
48
  if useCoverage
61
49
  require 'ruby-vpi/rcov'
62
50
 
@@ -104,8 +92,6 @@ module RubyVpi
104
92
  end
105
93
 
106
94
  # set up the VPI utility layer
107
- require 'ruby-vpi/vpi'
108
-
109
95
  Object.class_eval do
110
96
  include Vpi
111
97
  end
@@ -123,48 +109,24 @@ module RubyVpi
123
109
  require "#{testName}_proto.rb"
124
110
 
125
111
  Vpi.module_eval do
126
- define_method :relay_verilog do
112
+ define_method :simulate do
127
113
  design.simulate!
128
114
  end
115
+
116
+ define_method :vpi_register_cb do
117
+ warn "vpi_register_cb: callbacks not allowed when prototyping"
118
+ end
129
119
  end
130
120
 
131
121
  Vpi::vpi_printf "#{Config::PROJECT_NAME}: prototype is enabled for test #{testName.inspect}\n"
132
122
 
133
- # trigger relay_verilog according to aClockTrigger
134
123
  else
135
- regs = design[VpiReg].sort_by {|h| h.lineNo}
136
- clock = regs.first
137
-
138
124
  Vpi.module_eval do
139
- # register callback for relay_verilog
140
- time = S_vpi_time.new
141
- time.type = VpiSuppressTime
142
-
143
- value = S_vpi_value.new
144
- value.format = VpiSuppressVal
145
-
146
- alarm = S_cb_data.new
147
- alarm.reason = CbValueChange
148
- alarm.cb_rtn = Vlog_relay_ruby
149
- alarm.obj = clock
150
- alarm.time = time
151
- alarm.value = value
152
- alarm.index = 0
153
- alarm.user_data = nil
154
-
155
- vpi_free_object(vpi_register_cb(alarm))
156
-
157
- alias_method :relay_verilog_old, :relay_verilog
158
-
159
- define_method :relay_verilog do
160
- begin
161
- relay_verilog_old
162
- end until aClockTrigger.call(clock)
163
- end
125
+ define_method :simulate, &aSimulationCycle
164
126
  end
165
127
 
166
- # XXX: this completes the handshake with pthread_mutex_lock() in relay_main() in the C extension
167
- relay_verilog_old
128
+ # XXX: this completes the handshake, by calling relay_verilog, with pthread_mutex_lock() in relay_main() in the C extension
129
+ advance_time
168
130
  end
169
131
 
170
132
  # load the design's specification
data/ref/c/annotated.html CHANGED
@@ -27,7 +27,7 @@
27
27
  <tr><td class="indexkey"><a class="el" href="structt__vpi__vecval.html">t_vpi_vecval</a></td><td class="indexvalue"></td></tr>
28
28
  <tr><td class="indexkey"><a class="el" href="structt__vpi__vlog__info.html">t_vpi_vlog_info</a></td><td class="indexvalue"></td></tr>
29
29
  </table>
30
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
30
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
31
31
  <a href="http://www.doxygen.org/index.html">
32
32
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
33
33
  </body>
data/ref/c/common_8h.html CHANGED
@@ -140,7 +140,7 @@ Pass aroung this value instead of zero and non-zero integers. <dl compact><dt><b
140
140
 
141
141
  </div>
142
142
  </div><p>
143
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
143
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:25 2006 for Ruby-VPI by&nbsp;
144
144
  <a href="http://www.doxygen.org/index.html">
145
145
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
146
146
  </body>
data/ref/c/files.html CHANGED
@@ -27,7 +27,7 @@
27
27
  <tr><td class="indexkey"><a class="el" href="vlog_8h.html">vlog.h</a></td><td class="indexvalue">Interface between C and Verilog code </td></tr>
28
28
  <tr><td class="indexkey"><a class="el" href="vpi__user_8h.html">vpi_user.h</a></td><td class="indexvalue"></td></tr>
29
29
  </table>
30
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
30
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
31
31
  <a href="http://www.doxygen.org/index.html">
32
32
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
33
33
  </body>
data/ref/c/functions.html CHANGED
@@ -125,7 +125,7 @@ Here is a list of all struct and union fields with links to the structures/union
125
125
  : <a class="el" href="structt__cb__data.html#5039bb34ac75410ff93cbe44515b3543">t_cb_data</a>, <a class="el" href="structt__vpi__value.html#73c4197b95dc5a8f4e8f0754e776d796">t_vpi_value</a><li>vector
126
126
  : <a class="el" href="structt__vpi__value.html#b363de5e581f84f9da4610dade8136df">t_vpi_value</a><li>version
127
127
  : <a class="el" href="structt__vpi__vlog__info.html#3ff076199159904aa9869e0fb1476bad">t_vpi_vlog_info</a></ul>
128
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
128
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
129
129
  <a href="http://www.doxygen.org/index.html">
130
130
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
131
131
  </body>
@@ -125,7 +125,7 @@
125
125
  : <a class="el" href="structt__cb__data.html#5039bb34ac75410ff93cbe44515b3543">t_cb_data</a>, <a class="el" href="structt__vpi__value.html#73c4197b95dc5a8f4e8f0754e776d796">t_vpi_value</a><li>vector
126
126
  : <a class="el" href="structt__vpi__value.html#b363de5e581f84f9da4610dade8136df">t_vpi_value</a><li>version
127
127
  : <a class="el" href="structt__vpi__vlog__info.html#3ff076199159904aa9869e0fb1476bad">t_vpi_vlog_info</a></ul>
128
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
128
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
129
129
  <a href="http://www.doxygen.org/index.html">
130
130
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
131
131
  </body>
data/ref/c/globals.html CHANGED
@@ -49,7 +49,7 @@ Here is a list of all functions, variables, defines, enums, and typedefs with li
49
49
  <h3><a class="anchor" name="index_b">- b -</a></h3><ul>
50
50
  <li>bool
51
51
  : <a class="el" href="common_8h.html#f6a258d8f3ee5206d682d799316314b1">common.h</a></ul>
52
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
52
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
53
53
  <a href="http://www.doxygen.org/index.html">
54
54
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
55
55
  </body>
@@ -80,7 +80,7 @@ Here is a list of all functions, variables, defines, enums, and typedefs with li
80
80
  : <a class="el" href="common_8h.html#f30d3fc89fbb3ed2aab2f5904ab76815">common.h</a><li>common_debug
81
81
  : <a class="el" href="common_8h.html#fcdad79cb06a5c61737b2f434218dc95">common.h</a><li>common_printf
82
82
  : <a class="el" href="common_8h.html#88235e5f8aab82571d68045e9f73fe81">common.h</a></ul>
83
- <hr size="1"><address style="align: right;"><small>Generated on Wed Dec 27 22:29:46 2006 for Ruby-VPI by&nbsp;
83
+ <hr size="1"><address style="align: right;"><small>Generated on Sat Dec 30 19:26:26 2006 for Ruby-VPI by&nbsp;
84
84
  <a href="http://www.doxygen.org/index.html">
85
85
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
86
86
  </body>