rggen 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rggen/builtins.rb +2 -1
  3. data/lib/rggen/builtins/bit_field/type.rb +3 -5
  4. data/lib/rggen/builtins/bit_field/types/ro.rb +5 -3
  5. data/lib/rggen/builtins/bit_field/types/rw.rb +5 -3
  6. data/lib/rggen/builtins/bit_field/types/rwl_rwe.rb +5 -3
  7. data/lib/rggen/builtins/bit_field/types/w0c_w1c.erb +1 -1
  8. data/lib/rggen/builtins/bit_field/types/w0c_w1c.rb +11 -5
  9. data/lib/rggen/builtins/bit_field/types/w0s_w1s.rb +10 -6
  10. data/lib/rggen/builtins/global/array_port_format.rb +15 -0
  11. data/lib/rggen/builtins/global/unfold_sv_interface_port.rb +22 -0
  12. data/lib/rggen/builtins/register/type.rb +10 -4
  13. data/lib/rggen/builtins/register/types/external.rb +56 -5
  14. data/lib/rggen/builtins/register_block/clock_reset.rb +2 -2
  15. data/lib/rggen/builtins/register_block/host_if.rb +1 -1
  16. data/lib/rggen/builtins/register_block/host_ifs/apb.rb +44 -4
  17. data/lib/rggen/builtins/register_block/host_ifs/axi4lite.rb +76 -7
  18. data/lib/rggen/builtins/register_block/rtl_top.rb +17 -7
  19. data/lib/rggen/core_components.rb +3 -3
  20. data/lib/rggen/core_components/ral/item.rb +16 -15
  21. data/lib/rggen/core_components/rtl/component.rb +0 -4
  22. data/lib/rggen/core_components/rtl/item.rb +27 -32
  23. data/lib/rggen/core_components/verilog_utility.rb +6 -6
  24. data/lib/rggen/core_components/verilog_utility/class_definition.rb +11 -11
  25. data/lib/rggen/core_components/verilog_utility/identifier.rb +49 -17
  26. data/lib/rggen/core_components/verilog_utility/{interface_instantiation.rb → interface_instance.rb} +7 -3
  27. data/lib/rggen/core_components/verilog_utility/{interface_port_declaration.rb → interface_port.rb} +7 -3
  28. data/lib/rggen/core_components/verilog_utility/local_scope.rb +8 -4
  29. data/lib/rggen/core_components/verilog_utility/module_definition.rb +20 -9
  30. data/lib/rggen/core_components/verilog_utility/package_definition.rb +15 -23
  31. data/lib/rggen/core_components/verilog_utility/structure_definition.rb +7 -6
  32. data/lib/rggen/core_components/verilog_utility/variable.rb +115 -0
  33. data/lib/rggen/version.rb +2 -2
  34. data/rtl/compile.f +0 -3
  35. data/rtl/rggen_address_decoder.sv +2 -2
  36. data/rtl/rggen_bus_splitter.sv +2 -2
  37. data/rtl/rggen_external_register.sv +2 -2
  38. data/rtl/rggen_host_if_apb.sv +2 -2
  39. data/rtl/rggen_indirect_register.sv +3 -3
  40. data/sample/sample.json +3 -1
  41. data/sample/sample.yaml +2 -0
  42. data/sample/sample_0.sv +30 -42
  43. data/sample/sample_1.sv +13 -13
  44. data/sample/sample_setup.rb +2 -2
  45. data/setup/default.rb +2 -2
  46. metadata +7 -9
  47. data/lib/rggen/builtins/register_block/irq_controller.erb +0 -9
  48. data/lib/rggen/builtins/register_block/irq_controller.rb +0 -43
  49. data/lib/rggen/builtins/register_block/rtl_top.erb +0 -7
  50. data/lib/rggen/core_components/verilog_utility/declaration.rb +0 -76
  51. data/rtl/rggen_irq_controller.sv +0 -21
@@ -6,9 +6,9 @@ define_simple_item :register_block, :rtl_top do
6
6
 
7
7
  def source_file_body
8
8
  module_definition register_block.name do |m|
9
- m.parameters register_block.parameter_declarations(:register_block)
10
- m.ports register_block.port_declarations(:register_block)
11
- m.signals register_block.signal_declarations(:register_block)
9
+ m.parameters register_block.parameter_declarations(:register_block)
10
+ m.ports register_block.port_declarations(:register_block)
11
+ m.signals register_block.signal_declarations(:register_block)
12
12
  m.body { |code| module_body(code) }
13
13
  end
14
14
  end
@@ -17,12 +17,22 @@ define_simple_item :register_block, :rtl_top do
17
17
  register_block.generate_code(:register_block, :top_down, code)
18
18
  end
19
19
 
20
- generate_pre_code :register_block do
21
- process_template
20
+ generate_pre_code :register_block do |code|
21
+ [
22
+ '`define rggen_connect_bit_field_if(RIF, FIF, MSB, LSB) \\',
23
+ 'assign FIF.read_access = RIF.read_access; \\',
24
+ 'assign FIF.write_access = RIF.write_access; \\',
25
+ 'assign FIF.write_data = RIF.write_data[MSB:LSB]; \\',
26
+ 'assign FIF.write_mask = RIF.write_mask[MSB:LSB]; \\',
27
+ 'assign RIF.value[MSB:LSB] = FIF.value; \\',
28
+ 'assign RIF.read_data[MSB:LSB] = FIF.read_data;'
29
+ ].each do |line|
30
+ code << line << nl
31
+ end
22
32
  end
23
33
 
24
- generate_post_code :register_block do
25
- :'`undef rggen_connect_bit_field_if'
34
+ generate_post_code :register_block do |code|
35
+ code << :'`undef rggen_connect_bit_field_if' << nl
26
36
  end
27
37
  end
28
38
  end
@@ -6,15 +6,15 @@ require_relative 'core_components/code_utility/source_file'
6
6
  require_relative 'core_components/code_utility'
7
7
 
8
8
  require_relative 'core_components/verilog_utility/identifier'
9
- require_relative 'core_components/verilog_utility/declaration'
9
+ require_relative 'core_components/verilog_utility/variable'
10
10
  require_relative 'core_components/verilog_utility/structure_definition'
11
11
  require_relative 'core_components/verilog_utility/local_scope'
12
12
  require_relative 'core_components/verilog_utility/module_definition'
13
13
  require_relative 'core_components/verilog_utility/package_definition'
14
14
  require_relative 'core_components/verilog_utility/class_definition'
15
15
  require_relative 'core_components/verilog_utility/subroutine_definition'
16
- require_relative 'core_components/verilog_utility/interface_instantiation'
17
- require_relative 'core_components/verilog_utility/interface_port_declaration'
16
+ require_relative 'core_components/verilog_utility/interface_instance'
17
+ require_relative 'core_components/verilog_utility/interface_port'
18
18
  require_relative 'core_components/verilog_utility/source_file'
19
19
  require_relative 'core_components/verilog_utility'
20
20
 
@@ -15,12 +15,12 @@ module RgGen
15
15
 
16
16
  class << self
17
17
  private
18
-
19
18
  def define_declaration_method(method_name)
20
19
  define_method(method_name) do |domain, handle_name, attributes = {}|
21
20
  attributes[:name] ||= handle_name
22
- add_identifier(handle_name, attributes[:name])
23
- add_declaration(method_name, domain, attributes)
21
+ declaration = create_declaration(method_name, attributes)
22
+ add_declaration(method_name, domain, declaration)
23
+ add_identifier(handle_name, declaration.identifier)
24
24
  end
25
25
  end
26
26
  end
@@ -29,29 +29,30 @@ module RgGen
29
29
  define_declaration_method :parameter
30
30
 
31
31
  def variable_declarations(domain = nil)
32
- return @variable_declarations if domain.nil?
32
+ domain || (return @variable_declarations)
33
33
  @variable_declarations[domain]
34
34
  end
35
35
 
36
36
  def parameter_declarations(domain = nil)
37
- return @parameter_declarations if domain.nil?
37
+ domain || (return @parameter_declarations)
38
38
  @parameter_declarations[domain]
39
39
  end
40
40
 
41
41
  private
42
42
 
43
- def add_identifier(handle_name, name)
44
- create_identifier(name).tap do |i|
45
- instance_variable_set(handle_name.variablize, i)
46
- attr_singleton_reader(handle_name)
47
- identifiers << handle_name
48
- end
43
+ def create_declaration(type, attributes)
44
+ __send__("#{type}_declaration", attributes)
49
45
  end
50
46
 
51
- def add_declaration(type, domain, attributes)
52
- instance_variable_get("@#{type}_declarations").tap do |list|
53
- list[domain] << __send__("#{type}_declaration", attributes)
54
- end
47
+ def add_identifier(handle_name, identifier)
48
+ instance_variable_set(handle_name.variablize, identifier)
49
+ attr_singleton_reader(handle_name)
50
+ identifiers << handle_name
51
+ end
52
+
53
+ def add_declaration(type, domain, declaration)
54
+ list = instance_variable_get("@#{type}_declarations")
55
+ list[domain] << declaration
55
56
  end
56
57
  end
57
58
  end
@@ -19,10 +19,6 @@ module RgGen
19
19
  def parameter_declarations(domain)
20
20
  [*@items, *@children].flat_map { |o| o.parameter_declarations(domain) }
21
21
  end
22
-
23
- def localparam_declarations(domain)
24
- [*@items, *@children].flat_map { |o| o.localparam_declarations(domain) }
25
- end
26
22
  end
27
23
  end
28
24
  end
@@ -10,15 +10,13 @@ module RgGen
10
10
  @signal_declarations = Hash.new { |h, d| h[d] = [] }
11
11
  @port_declarations = Hash.new { |h, d| h[d] = [] }
12
12
  @parameter_declarations = Hash.new { |h, d| h[d] = [] }
13
- @localparam_declarations = Hash.new { |h, d| h[d] = [] }
14
13
  end
15
14
 
16
15
  attr_reader :identifiers
17
16
 
18
- def_delegator :@signal_declarations , :[], :signal_declarations
19
- def_delegator :@port_declarations , :[], :port_declarations
20
- def_delegator :@parameter_declarations , :[], :parameter_declarations
21
- def_delegator :@localparam_declarations, :[], :localparam_declarations
17
+ def_delegator :@signal_declarations , :[], :signal_declarations
18
+ def_delegator :@port_declarations , :[], :port_declarations
19
+ def_delegator :@parameter_declarations, :[], :parameter_declarations
22
20
 
23
21
  class << self
24
22
  private
@@ -26,8 +24,9 @@ module RgGen
26
24
  def define_declaration_method(method_name)
27
25
  define_method(method_name) do |domain, handle_name, attributes = {}|
28
26
  attributes[:name] ||= handle_name
29
- add_identifier(handle_name, attributes[:name])
30
- add_declaration(method_name, domain, attributes)
27
+ declaration = create_declaration(method_name, attributes)
28
+ add_declaration(method_name, domain, declaration)
29
+ add_identifier(handle_name, declaration.identifier)
31
30
  end
32
31
  private method_name
33
32
  end
@@ -45,41 +44,37 @@ module RgGen
45
44
 
46
45
  private
47
46
 
48
- def add_declaration(type, domain, attributes)
47
+ def create_declaration(type, attributes)
49
48
  case type
50
49
  when :wire, :reg, :logic
51
- @signal_declarations[domain] << variable_declaration(type, attributes)
50
+ variable_declaration(attributes.merge(data_type: type))
52
51
  when :interface
53
- @signal_declarations[domain] << interface_instantiation(attributes)
52
+ interface_instance(attributes)
54
53
  when :input, :output
55
- @port_declarations[domain] << port_declaration(type, attributes)
54
+ port_declaration(attributes.merge(direction: type))
56
55
  when :interface_port
57
- @port_declarations[domain] << interface_port_declaration(attributes)
58
- when :parameter
59
- @parameter_declarations[domain] << parameter_declaration(type, attributes)
60
- when :localparam
61
- @localparam_declarations[domain] << parameter_declaration(type, attributes)
56
+ interface_port_declaration(attributes)
57
+ when :parameter, :localparam
58
+ parameter_declaration(attributes.merge(parameter_type: type))
62
59
  end
63
60
  end
64
61
 
65
- def variable_declaration(data_type, attributes)
66
- super(attributes.merge(data_type: data_type))
67
- end
68
-
69
- def port_declaration(direction, attributes)
70
- super(attributes.merge(direction: direction))
71
- end
72
-
73
- def parameter_declaration(parameter_type, attributes)
74
- super(attributes.merge(parameter_type: parameter_type))
62
+ def add_declaration(type, domain, declaration)
63
+ declarations =
64
+ case type
65
+ when :wire, :reg, :logic, :interface
66
+ @signal_declarations[domain]
67
+ when :input, :output, :interface_port
68
+ @port_declarations[domain]
69
+ when :parameter, :localparam
70
+ @parameter_declarations[domain]
71
+ end
72
+ declarations << declaration
75
73
  end
76
74
 
77
- def add_identifier(handle_name, name)
78
- identifier = create_identifier(name)
79
- instance_exec do
80
- instance_variable_set(handle_name.variablize, identifier)
81
- attr_singleton_reader(handle_name)
82
- end
75
+ def add_identifier(handle_name, identifier)
76
+ instance_variable_set(handle_name.variablize, identifier)
77
+ attr_singleton_reader(handle_name)
83
78
  identifiers << handle_name
84
79
  end
85
80
  end
@@ -13,23 +13,23 @@ module RgGen
13
13
  end
14
14
 
15
15
  def variable_declaration(attributes)
16
- Declaration.new(:variable, attributes)
16
+ Variable.new(:variable, attributes)
17
17
  end
18
18
 
19
- def interface_instantiation(attributes)
20
- InterfaceInstantiation.new(attributes)
19
+ def interface_instance(attributes)
20
+ InterfaceInstance.new(attributes)
21
21
  end
22
22
 
23
23
  def port_declaration(attributes)
24
- Declaration.new(:port, attributes)
24
+ Variable.new(:port, attributes)
25
25
  end
26
26
 
27
27
  def interface_port_declaration(attributes)
28
- InterfacePortDeclaration.new(attributes)
28
+ InterfacePort.new(attributes)
29
29
  end
30
30
 
31
31
  def parameter_declaration(attributes)
32
- Declaration.new(:parameter, attributes)
32
+ Variable.new(:parameter, attributes)
33
33
  end
34
34
 
35
35
  def module_definition(name, &body)
@@ -5,22 +5,24 @@ module RgGen
5
5
  attr_setter :parameters
6
6
  attr_setter :variables
7
7
 
8
- def to_code
9
- bodies.unshift(variables_declarations) if variables?
10
- super
11
- end
12
-
13
8
  private
14
9
 
15
10
  def header_code
16
11
  code_block do |code|
17
- code << :class << space << @name
18
- paraemter_declarations(code) if parameters?
19
- code << space <<:extends << space << @base unless @base.nil?
12
+ code << :class << space << @name
13
+ parameters? && paraemter_declarations(code)
14
+ @base && (code << space <<:extends << space << @base)
20
15
  code << semicolon
21
16
  end
22
17
  end
23
18
 
19
+ def body_code_blocks
20
+ blocks = []
21
+ variables? && (blocks << variables_declarations)
22
+ blocks.concat(super)
23
+ blocks
24
+ end
25
+
24
26
  def footer_code
25
27
  :endclass
26
28
  end
@@ -46,9 +48,7 @@ module RgGen
46
48
 
47
49
  def variables_declarations
48
50
  lambda do |code|
49
- variables.each do |variable|
50
- code << variable << semicolon << nl
51
- end
51
+ variables.each { |variable| code << variable << semicolon << nl }
52
52
  end
53
53
  end
54
54
  end
@@ -3,25 +3,30 @@ module RgGen
3
3
  class Identifier
4
4
  include InputBase::RegxpPatterns
5
5
 
6
- def initialize(name)
7
- @name = name
6
+ def initialize(name, width = nil, array_dimensions = nil, array_format = nil)
7
+ @name = name
8
+ @width = width
9
+ @array_dimensions = array_dimensions
10
+ @array_format = array_format || :unpacked
8
11
  end
9
12
 
10
13
  def to_s
11
14
  @name.to_s
12
15
  end
13
16
 
14
- def [](indexes_or_msb, lsb = indexes_or_msb)
15
- if indexes_or_msb.nil?
17
+ def [](array_index_or_msb, lsb = array_index_or_msb)
18
+ if array_index_or_msb.nil?
16
19
  self
17
- elsif indexes_or_msb.is_a?(Array)
18
- indexes_or_msb.inject(self) do |identifer, index|
19
- identifer[index]
20
- end
21
- elsif indexes_or_msb == lsb
22
- Identifier.new("#{@name}[#{indexes_or_msb}]")
23
20
  else
24
- Identifier.new("#{@name}[#{indexes_or_msb}:#{lsb}]")
21
+ new_name =
22
+ if array_index_or_msb.is_a?(Array)
23
+ "#{@name}#{array_selection(array_index_or_msb)}"
24
+ elsif array_index_or_msb == lsb
25
+ "#{@name}[#{array_index_or_msb}]"
26
+ else
27
+ "#{@name}[#{array_index_or_msb}:#{lsb}]"
28
+ end
29
+ Identifier.new(new_name, nil, nil, nil)
25
30
  end
26
31
  end
27
32
 
@@ -30,17 +35,44 @@ module RgGen
30
35
  ].freeze
31
36
 
32
37
  def method_missing(name, *args)
33
- return super if args.size > 0
34
- return super if TYPE_CONVERSIONS.include?(name)
35
- return super unless name =~ variable_name
36
- Identifier.new("#{@name}.#{name}")
38
+ args.size.zero? || (return super)
39
+ TYPE_CONVERSIONS.include?(name) && (return super)
40
+ (name =~ variable_name) || (return super)
41
+ Identifier.new("#{@name}.#{name}", nil, nil, nil)
37
42
  end
38
43
 
39
44
  def respond_to_missing?(symbol, include_private)
40
- return super if TYPE_CONVERSIONS.include?(symbol)
41
- return super unless symbol =~ variable_name
45
+ TYPE_CONVERSIONS.include?(symbol) && (return super)
46
+ symbol =~ variable_name || (return super)
42
47
  true
43
48
  end
49
+
50
+ private
51
+
52
+ def array_selection(array_index)
53
+ if @array_format == :unpacked
54
+ array_index.map { |i| "[#{i}]" }.join
55
+ else
56
+ "[#{@width}*(#{vector_index(array_index)})+:#{@width}]"
57
+ end
58
+ end
59
+
60
+ def vector_index(array_index)
61
+ index = []
62
+ array_index.zip(index_factors).reverse_each do |i, f|
63
+ index << ((index.size.zero? && i.to_s) || "#{f}*#{i}")
64
+ end
65
+ index.reverse.join('+')
66
+ end
67
+
68
+ def index_factors
69
+ factors = []
70
+ @array_dimensions.reverse.inject(1) do |elements, dimension|
71
+ factors.unshift(elements)
72
+ elements * dimension
73
+ end
74
+ factors
75
+ end
44
76
  end
45
77
  end
46
78
  end
@@ -1,12 +1,16 @@
1
1
  module RgGen
2
2
  module VerilogUtility
3
- class InterfaceInstantiation
3
+ class InterfaceInstance
4
4
  def initialize(attributes)
5
5
  @attributes = attributes
6
6
  end
7
7
 
8
8
  def to_s
9
- "#{interface_type} #{identifier}()"
9
+ "#{interface_type} #{instance_identifier}()"
10
+ end
11
+
12
+ def identifier
13
+ Identifier.new(@attributes[:name], nil, nil, nil)
10
14
  end
11
15
 
12
16
  private
@@ -20,7 +24,7 @@ module RgGen
20
24
  "#(#{@attributes[:parameters].join(', ')})"
21
25
  end
22
26
 
23
- def identifier
27
+ def instance_identifier
24
28
  "#{@attributes[:name]}#{dimensions}"
25
29
  end
26
30
 
@@ -1,12 +1,16 @@
1
1
  module RgGen
2
2
  module VerilogUtility
3
- class InterfacePortDeclaration
3
+ class InterfacePort
4
4
  def initialize(attributes)
5
5
  @attributes = attributes
6
6
  end
7
7
 
8
8
  def to_s
9
- "#{interface_type} #{identifier}"
9
+ "#{interface_type} #{port_identifier}"
10
+ end
11
+
12
+ def identifier
13
+ Identifier.new(@attributes[:name], nil, nil, nil)
10
14
  end
11
15
 
12
16
  private
@@ -16,7 +20,7 @@ module RgGen
16
20
  "#{@attributes[:type]}.#{@attributes[:modport]}"
17
21
  end
18
22
 
19
- def identifier
23
+ def port_identifier
20
24
  "#{@attributes[:name]}#{dimensions}"
21
25
  end
22
26