rggen-systemverilog 0.23.0 → 0.23.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f00d208ebd7482486fc99dd9b7fcf787ca74b668c5a4fbbe60879cc6f497607d
4
- data.tar.gz: af34bfc503ddaba18d7e696c14cef77f8979f53aaf05d7b6cd5a2f570dedfa33
3
+ metadata.gz: 0674114b0b928f20b2d1cb809eddac46617f4386d35dd4ef44de793817943fd1
4
+ data.tar.gz: e8afca21a640eff2ce8f6cfc8058b9b96e87bba16351335c610e01e78a28fe91
5
5
  SHA512:
6
- metadata.gz: 65ab0f8c1a60dd50e7d0731491c396b9f4531ec4c1b9d1ed7d8ecebac4d8e57e4e8367763be85660d0ddb373f38371cf4ea373130514763c00e2cf6432928523
7
- data.tar.gz: 4aafce8907c363d82c219d1aae0dbb5d43681d1fc05726e9e877a6b1ee894cbe1d63ddf5c295e152d8cdc1cd9cb2b5154fa470dbce81f75b65211dba8b635e86
6
+ metadata.gz: 52b28ccde37f6a73d570cd7b27fdf6e58c33622c8dce631915c200c272063b19e8c6a513fa286cc6017b96bab8579ac1c6a66d96bf937f45d730cdfa24613e27
7
+ data.tar.gz: daa6d28c95470347433adb1853e1d78c1b28b19722275e1e21523bfe13d19621753d0c11b454e97643fc189b48cfd717d3292beb7003b44a1220ae2c0eeb0cff
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  # RgGen::SystemVerilog
9
9
 
10
- RgGen::SystemVerilog privides SystemVerilog RTL generator and UVM RAL model generator for RgGen.
10
+ RgGen::SystemVerilog provides SystemVerilog RTL and UVM register model (UVM RAL) generators for RgGen.
11
11
 
12
12
  ## Installation
13
13
 
@@ -35,9 +35,9 @@ module RgGen
35
35
  @name.to_s
36
36
  end
37
37
 
38
- def [](array_index_or_lsb, width = nil)
38
+ def [](array_index_or_lsb, lsb_or_width = nil, width = nil)
39
39
  if array_index_or_lsb
40
- __create_new_identifier__(array_index_or_lsb, width)
40
+ __create_new_identifier__(array_index_or_lsb, lsb_or_width, width)
41
41
  else
42
42
  self
43
43
  end
@@ -45,35 +45,38 @@ module RgGen
45
45
 
46
46
  private
47
47
 
48
- def __create_new_identifier__(array_index_or_lsb, width)
49
- select = __create_select__(array_index_or_lsb, width)
48
+ def __create_new_identifier__(array_index_or_lsb, lsb_or_width, width)
49
+ select = __create_select__(array_index_or_lsb, lsb_or_width, width)
50
50
  Identifier.new("#{@name}#{select}") do |identifier|
51
51
  identifier.__sub_identifiers__(@sub_identifiers)
52
52
  end
53
53
  end
54
54
 
55
- def __create_select__(array_index_or_lsb, width)
55
+ def __create_select__(array_index_or_lsb, lsb_or_width, width)
56
56
  if array_index_or_lsb.is_a?(::Array)
57
- __array_select__(array_index_or_lsb)
58
- elsif width
59
- "[#{array_index_or_lsb}+:#{width}]"
57
+ __array_select__(array_index_or_lsb, lsb_or_width, width)
58
+ elsif lsb_or_width
59
+ "[#{array_index_or_lsb}+:#{lsb_or_width}]"
60
60
  else
61
61
  "[#{array_index_or_lsb}]"
62
62
  end
63
63
  end
64
64
 
65
- def __array_select__(array_index)
65
+ def __array_select__(array_index, lsb, width)
66
66
  if @array_format == :serialized
67
- "[#{__serialized_lsb__(array_index)}+:#{@width}]"
67
+ "[#{__serialized_lsb__(array_index, lsb)}+:#{width || @width}]"
68
68
  else
69
- array_index
70
- .map { |index| "[#{index}]" }
71
- .join
69
+ [
70
+ *array_index.map { |index| "[#{index}]" },
71
+ lsb && __create_select__(lsb, width, nil)
72
+ ].compact.join
72
73
  end
73
74
  end
74
75
 
75
- def __serialized_lsb__(array_index)
76
- __reduce_array__([@width, __serialized_index__(array_index)], :*, 1)
76
+ def __serialized_lsb__(array_index, lsb)
77
+ serialized_index = __serialized_index__(array_index)
78
+ array_lsb = __reduce_array__([@width, serialized_index], :*, 1)
79
+ __reduce_array__([array_lsb, lsb], :+, 0)
77
80
  end
78
81
 
79
82
  def __serialized_index__(array_index)
@@ -97,6 +100,7 @@ module RgGen
97
100
  end
98
101
 
99
102
  def __reduce_array__(array, operator, initial_value)
103
+ array = array.compact
100
104
  if array.all?(&method(:integer?))
101
105
  array.reduce(initial_value, &operator)
102
106
  else
@@ -4,6 +4,9 @@ require_relative 'common'
4
4
  require_relative 'rtl/feature'
5
5
  require_relative 'rtl/partial_sum'
6
6
  require_relative 'rtl/register_index'
7
+ require_relative 'rtl/register_type'
8
+ require_relative 'rtl/indirect_index'
9
+ require_relative 'rtl/bit_field_index'
7
10
 
8
11
  module RgGen
9
12
  module SystemVerilog
@@ -2,10 +2,8 @@
2
2
 
3
3
  RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
4
4
  sv_rtl do
5
- export :local_index
6
- export :local_indices
7
- export :loop_variables
8
- export :array_size
5
+ include RgGen::SystemVerilog::RTL::BitFieldIndex
6
+
9
7
  export :value
10
8
 
11
9
  build do
@@ -13,13 +11,13 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
13
11
  localparam :initial_value, {
14
12
  name: initial_value_name, data_type: :bit, width: bit_field.width,
15
13
  array_size: initial_value_size, array_format: initial_value_format,
16
- default: initial_value_lhs
14
+ default: initial_value_rhs
17
15
  }
18
16
  elsif initial_value?
19
17
  parameter :initial_value, {
20
18
  name: initial_value_name, data_type: :bit, width: bit_field.width,
21
19
  array_size: initial_value_size, array_format: initial_value_format,
22
- default: initial_value_lhs
20
+ default: initial_value_rhs
23
21
  }
24
22
  end
25
23
  interface :bit_field_sub_if, {
@@ -42,31 +40,8 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
42
40
  code << bit_field_if_connection << nl
43
41
  end
44
42
 
45
- def local_index
46
- (index_name = local_index_name) &&
47
- create_identifier(index_name)
48
- end
49
-
50
- def local_indices
51
- [*register.local_indices, local_index_name]
52
- end
53
-
54
- def loop_variables
55
- (inside_loop? || nil) &&
56
- [*register.loop_variables, local_index].compact
57
- end
58
-
59
- def array_size
60
- (inside_loop? || nil) &&
61
- [
62
- *register_files.flat_map(&:array_size),
63
- *register.array_size,
64
- *bit_field.sequence_size
65
- ].compact
66
- end
67
-
68
43
  def value(offsets = nil, width = nil)
69
- value_lsb = bit_field.lsb(offsets&.last || local_index_name)
44
+ value_lsb = bit_field.lsb(offsets&.last || local_index)
70
45
  value_width = width || bit_field.width
71
46
  register_if(offsets&.slice(0..-2)).value[value_lsb, value_width]
72
47
  end
@@ -77,14 +52,6 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
77
52
  define_method(m) { bit_field.__send__(__method__) }
78
53
  end
79
54
 
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
55
  def register_if(offsets)
89
56
  index = register.index(offsets || register.local_indices)
90
57
  register_block.register_if[index]
@@ -106,11 +73,11 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
106
73
  configuration.array_port_format
107
74
  end
108
75
 
109
- def initial_value_lhs
110
- initial_value_array? && initial_value_array_lhs || sized_initial_value
76
+ def initial_value_rhs
77
+ initial_value_array? && initial_value_array_rhs || sized_initial_value
111
78
  end
112
79
 
113
- def initial_value_array_lhs
80
+ def initial_value_array_rhs
114
81
  if fixed_initial_value?
115
82
  array(sized_initial_values)
116
83
  elsif initial_value_format == :unpacked
@@ -129,12 +96,9 @@ RgGen.define_simple_feature(:bit_field, :sv_rtl_top) do
129
96
  bit_field.initial_values&.map { |v| hex(v, bit_field.width) }
130
97
  end
131
98
 
132
- def inside_loop?
133
- register.array? || bit_field.sequential?
134
- end
135
-
136
99
  def loop_size
137
- (loop_variable = local_index_name) &&
100
+ loop_variable = local_index
101
+ loop_variable &&
138
102
  { loop_variable => bit_field.sequence_size }
139
103
  end
140
104
 
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SystemVerilog
5
+ module RTL
6
+ module BitFieldIndex
7
+ EXPORTED_METHODS = [
8
+ :local_index, :local_indices, :loop_variables, :array_size
9
+ ].freeze
10
+
11
+ def self.included(feature)
12
+ feature.module_eval do
13
+ EXPORTED_METHODS.each { |m| export m }
14
+ end
15
+ end
16
+
17
+ def local_index
18
+ index_name = local_index_name
19
+ index_name && create_identifier(index_name)
20
+ end
21
+
22
+ def local_indices
23
+ [*register.local_indices, local_index_name]
24
+ end
25
+
26
+ def loop_variables
27
+ (inside_loop? || nil) &&
28
+ [*register.loop_variables, local_index].compact
29
+ end
30
+
31
+ def array_size
32
+ (inside_loop? || nil) &&
33
+ [
34
+ *register_files.flat_map(&:array_size),
35
+ *register.array_size,
36
+ *bit_field.sequence_size
37
+ ].compact
38
+ end
39
+
40
+ private
41
+
42
+ def local_index_name
43
+ (bit_field.sequential? || nil) &&
44
+ loop_index((register.loop_variables&.size || 0) + 1)
45
+ end
46
+
47
+ def inside_loop?
48
+ register.inside_loop? || bit_field.sequential?
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SystemVerilog
5
+ module RTL
6
+ module IndirectIndex
7
+ private
8
+
9
+ def index_fields
10
+ @index_fields ||=
11
+ register.collect_index_fields(register_block.bit_fields)
12
+ end
13
+
14
+ def index_width
15
+ @index_width ||= index_fields.sum(&:width)
16
+ end
17
+
18
+ def index_values
19
+ loop_variables = register.local_loop_variables
20
+ register.index_entries.zip(index_fields).map do |entry, field|
21
+ if entry.array_index?
22
+ loop_variables.shift[0, field.width]
23
+ else
24
+ hex(entry.value, field.width)
25
+ end
26
+ end
27
+ end
28
+
29
+ def indirect_index_assignment
30
+ assign(indirect_index, concat(index_fields.map(&:value)))
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,65 +3,10 @@
3
3
  RgGen.define_list_feature(:register, :type) do
4
4
  sv_rtl do
5
5
  base_feature do
6
- include RgGen::SystemVerilog::RTL::PartialSum
6
+ include RgGen::SystemVerilog::RTL::RegisterType
7
7
 
8
8
  private
9
9
 
10
- def readable
11
- register.readable? && 1 || 0
12
- end
13
-
14
- def writable
15
- register.writable? && 1 || 0
16
- end
17
-
18
- def bus_width
19
- configuration.bus_width
20
- end
21
-
22
- def address_width
23
- register_block.local_address_width
24
- end
25
-
26
- def offset_address
27
- offsets = [*register_files, register].flat_map(&method(:collect_offsets))
28
- offsets = partial_sums(offsets)
29
- format_offsets(offsets)
30
- end
31
-
32
- def collect_offsets(component)
33
- if component.register_file? && component.array?
34
- [component.offset_address, byte_offset(component)]
35
- else
36
- component.offset_address
37
- end
38
- end
39
-
40
- def byte_offset(component)
41
- "#{component.byte_size(false)}*(#{component.local_index})"
42
- end
43
-
44
- def format_offsets(offsets)
45
- offsets.map(&method(:format_offset)).join('+')
46
- end
47
-
48
- def format_offset(offset)
49
- offset.is_a?(Integer) ? hex(offset, address_width) : offset
50
- end
51
-
52
- def width
53
- register.width
54
- end
55
-
56
- def valid_bits
57
- bits = register.bit_fields.map(&:bit_map).inject(:|)
58
- hex(bits, register.width)
59
- end
60
-
61
- def register_index
62
- register.local_index || 0
63
- end
64
-
65
10
  def register_if
66
11
  register_block.register_if[register.index]
67
12
  end
@@ -71,10 +71,6 @@ RgGen.define_list_item_feature(:register, :type, :external) do
71
71
 
72
72
  private
73
73
 
74
- def address_width
75
- register_block.local_address_width
76
- end
77
-
78
74
  def byte_width
79
75
  configuration.byte_width
80
76
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  RgGen.define_list_item_feature(:register, :type, :indirect) do
4
4
  sv_rtl do
5
+ include RgGen::SystemVerilog::RTL::IndirectIndex
6
+
5
7
  build do
6
8
  logic :indirect_index, { width: index_width }
7
9
  end
@@ -10,31 +12,5 @@ RgGen.define_list_item_feature(:register, :type, :indirect) do
10
12
  code << indirect_index_assignment << nl
11
13
  code << process_template
12
14
  end
13
-
14
- private
15
-
16
- def index_fields
17
- @index_fields ||=
18
- register.collect_index_fields(register_block.bit_fields)
19
- end
20
-
21
- def index_width
22
- @index_width ||= index_fields.sum(&:width)
23
- end
24
-
25
- def index_values
26
- loop_variables = register.local_loop_variables
27
- register.index_entries.zip(index_fields).map do |entry, field|
28
- if entry.array_index?
29
- loop_variables.shift[0, field.width]
30
- else
31
- hex(entry.value, field.width)
32
- end
33
- end
34
- end
35
-
36
- def indirect_index_assignment
37
- assign(indirect_index, concat(index_fields.map(&:value)))
38
- end
39
15
  end
40
16
  end
@@ -2,19 +2,25 @@
2
2
 
3
3
  RgGen.define_list_feature(:register_block, :protocol) do
4
4
  shared_context do
5
- def feature_registry(registry = nil)
6
- @registry = registry if registry
7
- @registry
5
+ def feature_registry(registry)
6
+ feature_registries << registry
8
7
  end
9
8
 
10
9
  def available_protocols
11
- feature_registry
12
- .enabled_features(:protocol)
13
- .select(&method(:valid_protocol?))
10
+ feature_registries
11
+ .map(&method(:collect_available_protocols)).inject(:&)
14
12
  end
15
13
 
16
- def valid_protocol?(protocol)
17
- feature_registry.feature?(:protocol, protocol)
14
+ private
15
+
16
+ def feature_registries
17
+ @feature_registries ||= []
18
+ end
19
+
20
+ def collect_available_protocols(registry)
21
+ registry
22
+ .enabled_features(:protocol)
23
+ .select { |protocol| registry.feature?(:protocol, protocol) }
18
24
  end
19
25
  end
20
26
 
@@ -9,7 +9,7 @@ module RgGen
9
9
  EXPORTED_METHODS = [
10
10
  :loop_variables, :local_loop_variables,
11
11
  :local_index, :local_indices,
12
- :index, :inside_roop?
12
+ :index, :inside_loop?
13
13
  ].freeze
14
14
 
15
15
  def self.included(feature)
@@ -23,7 +23,7 @@ module RgGen
23
23
  end
24
24
 
25
25
  def loop_variables
26
- (inside_roop? || nil) &&
26
+ (inside_loop? || nil) &&
27
27
  [*upper_register_file&.loop_variables, *local_loop_variables]
28
28
  end
29
29
 
@@ -59,8 +59,8 @@ module RgGen
59
59
  end
60
60
  end
61
61
 
62
- def inside_roop?
63
- component.array? || upper_register_file&.inside_roop? || false
62
+ def inside_loop?
63
+ component.array? || upper_register_file&.inside_loop? || false
64
64
  end
65
65
 
66
66
  private
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module SystemVerilog
5
+ module RTL
6
+ module RegisterType
7
+ include PartialSum
8
+
9
+ private
10
+
11
+ def readable
12
+ register.readable? && 1 || 0
13
+ end
14
+
15
+ def writable
16
+ register.writable? && 1 || 0
17
+ end
18
+
19
+ def bus_width
20
+ configuration.bus_width
21
+ end
22
+
23
+ def address_width
24
+ register_block.local_address_width
25
+ end
26
+
27
+ def offset_address
28
+ offsets = [*register_files, register].flat_map(&method(:collect_offsets))
29
+ offsets = partial_sums(offsets)
30
+ format_offsets(offsets)
31
+ end
32
+
33
+ def collect_offsets(component)
34
+ if component.register_file? && component.array?
35
+ [component.offset_address, byte_offset(component)]
36
+ else
37
+ component.offset_address
38
+ end
39
+ end
40
+
41
+ def byte_offset(component)
42
+ "#{component.byte_size(false)}*(#{component.local_index})"
43
+ end
44
+
45
+ def format_offsets(offsets)
46
+ offsets.map(&method(:format_offset)).join('+')
47
+ end
48
+
49
+ def format_offset(offset)
50
+ offset.is_a?(Integer) ? hex(offset, address_width) : offset
51
+ end
52
+
53
+ def width
54
+ register.width
55
+ end
56
+
57
+ def valid_bits
58
+ bits = register.bit_fields.map(&:bit_map).inject(:|)
59
+ hex(bits, register.width)
60
+ end
61
+
62
+ def register_index
63
+ register.local_index || 0
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RgGen
4
4
  module SystemVerilog
5
- VERSION = '0.23.0'
5
+ VERSION = '0.23.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rggen-systemverilog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -133,9 +133,11 @@ files:
133
133
  - lib/rggen/systemverilog/rtl/bit_field/type/w0trg_w1trg.rb
134
134
  - lib/rggen/systemverilog/rtl/bit_field/type/wrc_wrs.erb
135
135
  - lib/rggen/systemverilog/rtl/bit_field/type/wrc_wrs.rb
136
+ - lib/rggen/systemverilog/rtl/bit_field_index.rb
136
137
  - lib/rggen/systemverilog/rtl/feature.rb
137
138
  - lib/rggen/systemverilog/rtl/global/array_port_format.rb
138
139
  - lib/rggen/systemverilog/rtl/global/fold_sv_interface_port.rb
140
+ - lib/rggen/systemverilog/rtl/indirect_index.rb
139
141
  - lib/rggen/systemverilog/rtl/partial_sum.rb
140
142
  - lib/rggen/systemverilog/rtl/register/sv_rtl_top.rb
141
143
  - lib/rggen/systemverilog/rtl/register/type.rb
@@ -153,6 +155,7 @@ files:
153
155
  - lib/rggen/systemverilog/rtl/register_block/sv_rtl_top.rb
154
156
  - lib/rggen/systemverilog/rtl/register_file/sv_rtl_top.rb
155
157
  - lib/rggen/systemverilog/rtl/register_index.rb
158
+ - lib/rggen/systemverilog/rtl/register_type.rb
156
159
  - lib/rggen/systemverilog/rtl/setup.rb
157
160
  - lib/rggen/systemverilog/version.rb
158
161
  homepage: https://github.com/rggen/rggen-systemverilog
@@ -181,5 +184,5 @@ requirements: []
181
184
  rubygems_version: 3.1.2
182
185
  signing_key:
183
186
  specification_version: 4
184
- summary: rggen-systemverilog-0.23.0
187
+ summary: rggen-systemverilog-0.23.1
185
188
  test_files: []