rggen-systemverilog 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rggen/systemverilog/common.rb +2 -2
  3. data/lib/rggen/systemverilog/common/component.rb +2 -6
  4. data/lib/rggen/systemverilog/common/feature.rb +39 -26
  5. data/lib/rggen/systemverilog/common/utility/interface_port.rb +7 -3
  6. data/lib/rggen/systemverilog/common/utility/local_scope.rb +2 -2
  7. data/lib/rggen/systemverilog/common/utility/structure_definition.rb +1 -3
  8. data/lib/rggen/systemverilog/ral.rb +4 -1
  9. data/lib/rggen/systemverilog/ral/bit_field/type.rb +15 -10
  10. data/lib/rggen/systemverilog/ral/bit_field/type/rwe_rwl.rb +1 -11
  11. data/lib/rggen/systemverilog/ral/feature.rb +4 -4
  12. data/lib/rggen/systemverilog/ral/register/type.rb +10 -52
  13. data/lib/rggen/systemverilog/ral/register/type/default.erb +1 -1
  14. data/lib/rggen/systemverilog/ral/register/type/external.rb +6 -10
  15. data/lib/rggen/systemverilog/ral/register/type/indirect.erb +3 -3
  16. data/lib/rggen/systemverilog/ral/register/type/indirect.rb +5 -2
  17. data/lib/rggen/systemverilog/ral/register_block/sv_ral_model.erb +8 -0
  18. data/lib/rggen/systemverilog/ral/register_block/sv_ral_model.rb +36 -0
  19. data/lib/rggen/systemverilog/ral/register_block/sv_ral_package.rb +1 -32
  20. data/lib/rggen/systemverilog/ral/register_common.rb +46 -0
  21. data/lib/rggen/systemverilog/ral/register_file/sv_ral_model.erb +8 -0
  22. data/lib/rggen/systemverilog/ral/register_file/sv_ral_model.rb +57 -0
  23. data/lib/rggen/systemverilog/ral/setup.rb +2 -1
  24. data/lib/rggen/systemverilog/rtl.rb +4 -1
  25. data/lib/rggen/systemverilog/rtl/bit_field/sv_rtl_top.rb +34 -19
  26. data/lib/rggen/systemverilog/rtl/bit_field/type.rb +1 -5
  27. data/lib/rggen/systemverilog/rtl/bit_field/type/rc_w0c_w1c.rb +3 -3
  28. data/lib/rggen/systemverilog/rtl/bit_field/type/ro.rb +1 -1
  29. data/lib/rggen/systemverilog/rtl/bit_field/type/rs_w0s_w1s.rb +2 -2
  30. data/lib/rggen/systemverilog/rtl/bit_field/type/rw_w1_wo_wo1.rb +1 -1
  31. data/lib/rggen/systemverilog/rtl/bit_field/type/rwc.rb +2 -2
  32. data/lib/rggen/systemverilog/rtl/bit_field/type/rwe.rb +2 -2
  33. data/lib/rggen/systemverilog/rtl/bit_field/type/rwl.rb +2 -2
  34. data/lib/rggen/systemverilog/rtl/bit_field/type/rws.rb +3 -3
  35. data/lib/rggen/systemverilog/rtl/bit_field/type/w0crs_w1crs.rb +1 -1
  36. data/lib/rggen/systemverilog/rtl/bit_field/type/w0src_w1src.rb +1 -1
  37. data/lib/rggen/systemverilog/rtl/bit_field/type/w0trg_w1trg.rb +1 -1
  38. data/lib/rggen/systemverilog/rtl/feature.rb +12 -16
  39. data/lib/rggen/systemverilog/rtl/partial_sum.rb +29 -0
  40. data/lib/rggen/systemverilog/rtl/register/sv_rtl_top.rb +10 -47
  41. data/lib/rggen/systemverilog/rtl/register/type.rb +25 -1
  42. data/lib/rggen/systemverilog/rtl/register/type/external.rb +10 -10
  43. data/lib/rggen/systemverilog/rtl/register/type/indirect.rb +2 -2
  44. data/lib/rggen/systemverilog/rtl/register_block/protocol.rb +2 -2
  45. data/lib/rggen/systemverilog/rtl/register_block/protocol/apb.rb +13 -14
  46. data/lib/rggen/systemverilog/rtl/register_block/protocol/axi4lite.rb +23 -25
  47. data/lib/rggen/systemverilog/rtl/register_block/sv_rtl_top.rb +11 -10
  48. data/lib/rggen/systemverilog/rtl/register_file/sv_rtl_top.rb +30 -0
  49. data/lib/rggen/systemverilog/rtl/register_index.rb +112 -0
  50. data/lib/rggen/systemverilog/rtl/setup.rb +1 -0
  51. data/lib/rggen/systemverilog/version.rb +1 -1
  52. metadata +11 -4
  53. data/lib/rggen/systemverilog/ral/register_block/sv_ral_block_model.erb +0 -11
@@ -4,10 +4,10 @@ endfunction
4
4
  function void build();
5
5
  <% field_model_constructors.each do |constructor| %>
6
6
  <%= constructor %>
7
- <% end%>
7
+ <% end %>
8
8
  endfunction
9
9
  function void setup_index_fields();
10
- <% index_properties.each do |reg_name, field_name, value| %>
11
- setup_index_field("<%= reg_name %>", "<%= field_name%>", <%= value %>);
10
+ <% index_properties.each do |field_name, value| %>
11
+ setup_index_field("<%= field_name %>", <%= value %>);
12
12
  <% end %>
13
13
  endfunction
@@ -2,7 +2,6 @@
2
2
 
3
3
  RgGen.define_list_item_feature(:register, :type, :indirect) do
4
4
  sv_ral do
5
- unmapped
6
5
  offset_address { register.offset_address }
7
6
 
8
7
  main_code :ral_package do
@@ -24,12 +23,16 @@ RgGen.define_list_item_feature(:register, :type, :indirect) do
24
23
  else
25
24
  "array_index[#{array_position += 1}]"
26
25
  end
27
- [field.register.name, field.name, value]
26
+ [field_full_name(field), value]
28
27
  end
29
28
  end
30
29
 
31
30
  def index_fields
32
31
  register.collect_index_fields(register_block.bit_fields)
33
32
  end
33
+
34
+ def field_full_name(field)
35
+ [field.register.full_name('.'), field.name].join('.')
36
+ end
34
37
  end
35
38
  end
@@ -0,0 +1,8 @@
1
+ function new(string name);
2
+ super.new(name, <%= byte_width %>, 0);
3
+ endfunction
4
+ function void build();
5
+ <% child_model_constructors.each do |constructor| %>
6
+ <%= constructor %>
7
+ <% end %>
8
+ endfunction
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:register_block, :sv_ral_model) do
4
+ sv_ral do
5
+ main_code :ral_package do
6
+ class_definition(model_name) do |sv_class|
7
+ sv_class.base 'rggen_ral_block'
8
+ sv_class.parameters parameters
9
+ sv_class.variables variables
10
+ sv_class.body { process_template }
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def model_name
17
+ "#{register_block.name}_block_model"
18
+ end
19
+
20
+ def parameters
21
+ register_block.declarations[:parameter]
22
+ end
23
+
24
+ def variables
25
+ register_block.declarations[:variable]
26
+ end
27
+
28
+ def byte_width
29
+ configuration.byte_width
30
+ end
31
+
32
+ def child_model_constructors
33
+ register_block.children.flat_map(&:constructors)
34
+ end
35
+ end
36
+ end
@@ -8,23 +8,12 @@ RgGen.define_simple_feature(:register_block, :sv_ral_package) do
8
8
  package.package_imports packages
9
9
  package.include_files include_files
10
10
  package.body do |code|
11
- register_block.generate_code(:ral_package, :bottom_up, code)
11
+ register_block.generate_code(code, :ral_package, :bottom_up)
12
12
  end
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- main_code :ral_package do
18
- class_definition(model_name) do |sv_class|
19
- sv_class.base 'rggen_ral_block'
20
- sv_class.parameters parameters
21
- sv_class.variables variables
22
- sv_class.body do
23
- process_template(File.join(__dir__, 'sv_ral_block_model.erb'))
24
- end
25
- end
26
- end
27
-
28
17
  private
29
18
 
30
19
  def package_name
@@ -41,25 +30,5 @@ RgGen.define_simple_feature(:register_block, :sv_ral_package) do
41
30
  def include_files
42
31
  ['uvm_macros.svh', 'rggen_ral_macros.svh']
43
32
  end
44
-
45
- def model_name
46
- "#{register_block.name}_block_model"
47
- end
48
-
49
- def parameters
50
- register_block.declarations(:register_block, :parameter)
51
- end
52
-
53
- def variables
54
- register_block.declarations(:register_block, :variable)
55
- end
56
-
57
- def reg_model_constructors
58
- register_block.registers.flat_map(&:constructors)
59
- end
60
-
61
- def byte_width
62
- configuration.byte_width
63
- end
64
33
  end
65
34
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SystemVerilog
5
+ module RAL
6
+ module RegisterCommon
7
+ private
8
+
9
+ def array_indices
10
+ if component.array?
11
+ index_table = component.array_size.map { |size| (0...size).to_a }
12
+ index_table[0].product(*index_table[1..-1])
13
+ else
14
+ [nil]
15
+ end
16
+ end
17
+
18
+ def offset_address(index)
19
+ address =
20
+ if register? && helper.offset_address
21
+ instance_exec(index, &helper.offset_address)
22
+ else
23
+ default_offset_address(index)
24
+ end
25
+ hex(address, register_block.local_address_width)
26
+ end
27
+
28
+ def default_offset_address(index)
29
+ component.offset_address + component.byte_size(false) * index
30
+ end
31
+
32
+ def hdl_path(array_index)
33
+ [
34
+ "g_#{component.name}",
35
+ *Array(array_index).map { |i| "g[#{i}]" },
36
+ *unit_instance_name
37
+ ].join('.')
38
+ end
39
+
40
+ def unit_instance_name
41
+ register? && 'u_register' || nil
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ function new(string name);
2
+ super.new(name, <%= byte_width %>, 0);
3
+ endfunction
4
+ function void build();
5
+ <% child_model_constructors.each do |constructor| %>
6
+ <%= constructor %>
7
+ <% end %>
8
+ endfunction
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:register_file, :sv_ral_model) do
4
+ sv_ral do
5
+ include RgGen::SystemVerilog::RAL::RegisterCommon
6
+
7
+ export :constructors
8
+
9
+ build do
10
+ variable :ral_model, {
11
+ name: register_file.name, data_type: model_name,
12
+ array_size: register_file.array_size, random: true
13
+ }
14
+ end
15
+
16
+ def constructors
17
+ array_indices.map.with_index(&method(:constructor_code))
18
+ end
19
+
20
+ main_code :ral_package do
21
+ class_definition(model_name) do |sv_class|
22
+ sv_class.base 'rggen_ral_reg_file'
23
+ sv_class.variables variables
24
+ sv_class.body { process_template }
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def model_name
31
+ "#{register_file.full_name('_')}_reg_file_model"
32
+ end
33
+
34
+ def constructor_code(array_index, index)
35
+ macro_call(:rggen_ral_create_reg_file, arguments(array_index, index))
36
+ end
37
+
38
+ def arguments(array_index, index)
39
+ [
40
+ ral_model[array_index], array(array_index), offset_address(index),
41
+ string(hdl_path(array_index))
42
+ ]
43
+ end
44
+
45
+ def variables
46
+ register_file.declarations[:variable]
47
+ end
48
+
49
+ def byte_width
50
+ configuration.byte_width
51
+ end
52
+
53
+ def child_model_constructors
54
+ register_file.children.flat_map(&:constructors)
55
+ end
56
+ end
57
+ end
@@ -3,5 +3,6 @@
3
3
  require 'rggen/systemverilog/ral'
4
4
 
5
5
  RgGen.setup :'rggen-sv-ral', RgGen::SystemVerilog::RAL do |builder|
6
- builder.enable :register_block, [:sv_ral_package]
6
+ builder.enable :register_block, [:sv_ral_model, :sv_ral_package]
7
+ builder.enable :register_file, [:sv_ral_model]
7
8
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative 'common'
4
4
  require_relative 'rtl/feature'
5
+ require_relative 'rtl/partial_sum'
6
+ require_relative 'rtl/register_index'
5
7
 
6
8
  module RgGen
7
9
  module SystemVerilog
@@ -31,7 +33,8 @@ module RgGen
31
33
  'rtl/register_block/protocol',
32
34
  'rtl/register_block/protocol/apb',
33
35
  'rtl/register_block/protocol/axi4lite',
34
- 'rtl/register_block/sv_rtl_top'
36
+ 'rtl/register_block/sv_rtl_top',
37
+ 'rtl/register_file/sv_rtl_top'
35
38
  ].freeze
36
39
 
37
40
  def self.version
@@ -3,25 +3,26 @@
3
3
  RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
4
4
  sv_rtl do
5
5
  export :local_index
6
+ export :local_indices
6
7
  export :loop_variables
7
8
  export :array_size
8
9
  export :value
9
10
 
10
11
  build do
11
12
  if fixed_initial_value?
12
- localparam :bit_field, :initial_value, {
13
+ localparam :initial_value, {
13
14
  name: initial_value_name, data_type: :bit, width: bit_field.width,
14
15
  array_size: initial_value_size, array_format: initial_value_format,
15
16
  default: initial_value_lhs
16
17
  }
17
18
  elsif initial_value?
18
- parameter :register_block, :initial_value, {
19
+ parameter :initial_value, {
19
20
  name: initial_value_name, data_type: :bit, width: bit_field.width,
20
21
  array_size: initial_value_size, array_format: initial_value_format,
21
22
  default: initial_value_lhs
22
23
  }
23
24
  end
24
- interface :bit_field, :bit_field_sub_if, {
25
+ interface :bit_field_sub_if, {
25
26
  name: 'bit_field_sub_if',
26
27
  interface_type: 'rggen_bit_field_if',
27
28
  parameter_values: [bit_field.width]
@@ -42,13 +43,12 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
42
43
  end
43
44
 
44
45
  def local_index
45
- (bit_field.sequential? || nil) &&
46
+ (index_name = local_index_name) &&
46
47
  create_identifier(index_name)
47
48
  end
48
49
 
49
- def index_name
50
- depth = (register.loop_variables&.size || 0) + 1
51
- loop_index(depth)
50
+ def local_indices
51
+ [*register.local_indices, local_index_name]
52
52
  end
53
53
 
54
54
  def loop_variables
@@ -58,15 +58,17 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
58
58
 
59
59
  def array_size
60
60
  (inside_loop? || nil) &&
61
- [*register.array_size, bit_field.sequence_size].compact
61
+ [
62
+ *register_files.flat_map(&:array_size),
63
+ *register.array_size,
64
+ *bit_field.sequence_size
65
+ ].compact
62
66
  end
63
67
 
64
- def value(register_offset = nil, bit_field_offset = nil, width = nil)
65
- bit_field_offset ||= local_index
66
- width ||= bit_field.width
67
- register_block
68
- .register_if[register.index(register_offset)]
69
- .value[bit_field.lsb(bit_field_offset), width]
68
+ def value(offsets = nil, width = nil)
69
+ value_lsb = bit_field.lsb(offsets&.last || local_index_name)
70
+ value_width = width || bit_field.width
71
+ register_if(offsets&.slice(0..-2)).value[value_lsb, value_width]
70
72
  end
71
73
 
72
74
  private
@@ -75,6 +77,19 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
75
77
  define_method(m) { bit_field.__send__(__method__) }
76
78
  end
77
79
 
80
+ def local_index_name
81
+ (bit_field.sequential? || nil) &&
82
+ begin
83
+ depth = (register.loop_variables&.size || 0) + 1
84
+ loop_index(depth)
85
+ end
86
+ end
87
+
88
+ def register_if(offsets)
89
+ index = register.index(offsets || register.local_indices)
90
+ register_block.register_if[index]
91
+ end
92
+
78
93
  def initial_value_name
79
94
  identifiers = []
80
95
  identifiers << bit_field.full_name('_') unless fixed_initial_value?
@@ -119,20 +134,20 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
119
134
  end
120
135
 
121
136
  def loop_size
122
- (bit_field.sequential? || nil) &&
123
- { index_name => bit_field.sequence_size }
137
+ (loop_variable = local_index_name) &&
138
+ { loop_variable => bit_field.sequence_size }
124
139
  end
125
140
 
126
141
  def parameters
127
- bit_field.declarations(:bit_field, :parameter)
142
+ bit_field.declarations[:parameter]
128
143
  end
129
144
 
130
145
  def variables
131
- bit_field.declarations(:bit_field, :variable)
146
+ bit_field.declarations[:variable]
132
147
  end
133
148
 
134
149
  def body_code(code)
135
- bit_field.generate_code(:bit_field, :top_down, code)
150
+ bit_field.generate_code(code, :bit_field, :top_down)
136
151
  end
137
152
 
138
153
  def bit_field_if_connection
@@ -43,11 +43,7 @@ RgGen.define_list_feature(:bit_field, :type) do
43
43
  bit_field.reference? &&
44
44
  bit_field
45
45
  .find_reference(register_block.bit_fields)
46
- .value(
47
- register.local_index,
48
- bit_field.local_index,
49
- bit_field.reference_width
50
- )
46
+ .value(bit_field.local_indices, bit_field.reference_width)
51
47
  end
52
48
 
53
49
  def bit_field_if
@@ -3,16 +3,16 @@
3
3
  RgGen.define_list_item_feature(:bit_field, :type, [:rc, :w0c, :w1c]) do
4
4
  sv_rtl do
5
5
  build do
6
- input :register_block, :set, {
6
+ input :set, {
7
7
  name: "i_#{full_name}_set", data_type: :logic, width: width,
8
8
  array_size: array_size, array_format: array_port_format
9
9
  }
10
- output :register_block, :value_out, {
10
+ output :value_out, {
11
11
  name: "o_#{full_name}", data_type: :logic, width: width,
12
12
  array_size: array_size, array_format: array_port_format
13
13
  }
14
14
  if bit_field.reference?
15
- output :register_block, :value_unmasked, {
15
+ output :value_unmasked, {
16
16
  name: "o_#{full_name}_unmasked", data_type: :logic, width: width,
17
17
  array_size: array_size, array_format: array_port_format
18
18
  }
@@ -4,7 +4,7 @@ RgGen.define_list_item_feature(:bit_field, :type, :ro) do
4
4
  sv_rtl do
5
5
  build do
6
6
  unless bit_field.reference?
7
- input :register_block, :value_in, {
7
+ input :value_in, {
8
8
  name: "i_#{full_name}", data_type: :logic, width: width,
9
9
  array_size: array_size, array_format: array_port_format
10
10
  }
@@ -3,11 +3,11 @@
3
3
  RgGen.define_list_item_feature(:bit_field, :type, [:rs, :w0s, :w1s]) do
4
4
  sv_rtl do
5
5
  build do
6
- input :register_block, :clear, {
6
+ input :clear, {
7
7
  name: "i_#{full_name}_clear", data_type: :logic, width: width,
8
8
  array_size: array_size, array_format: array_port_format
9
9
  }
10
- output :register_block, :value_out, {
10
+ output :value_out, {
11
11
  name: "o_#{full_name}", data_type: :logic, width: width,
12
12
  array_size: array_size, array_format: array_port_format
13
13
  }