rggen 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/c_header/LICENSE +21 -0
  3. data/{c → c_header}/rggen.h +0 -0
  4. data/lib/rggen/builtins.rb +2 -5
  5. data/lib/rggen/builtins/bit_field/type.rb +22 -7
  6. data/lib/rggen/builtins/bit_field/types/ro.erb +2 -2
  7. data/lib/rggen/builtins/bit_field/types/ro.rb +2 -2
  8. data/lib/rggen/builtins/bit_field/types/rw.erb +5 -9
  9. data/lib/rggen/builtins/bit_field/types/rw.rb +5 -5
  10. data/lib/rggen/builtins/bit_field/types/rwl_rwe.erb +3 -7
  11. data/lib/rggen/builtins/bit_field/types/rwl_rwe.rb +6 -7
  12. data/lib/rggen/builtins/bit_field/types/w0c_w1c.erb +8 -12
  13. data/lib/rggen/builtins/bit_field/types/w0c_w1c.rb +5 -2
  14. data/lib/rggen/builtins/bit_field/types/w0s_w1s.erb +8 -12
  15. data/lib/rggen/builtins/bit_field/types/w0s_w1s.rb +3 -6
  16. data/lib/rggen/builtins/register/array.rb +0 -93
  17. data/lib/rggen/builtins/register/reg_model.rb +1 -1
  18. data/lib/rggen/builtins/register/rtl_top.rb +68 -0
  19. data/lib/rggen/builtins/register/type.rb +74 -0
  20. data/lib/rggen/builtins/register/types/default.erb +10 -0
  21. data/lib/rggen/builtins/register/types/external.erb +11 -0
  22. data/lib/rggen/builtins/register/types/external.rb +11 -0
  23. data/lib/rggen/builtins/register/types/indirect.erb +13 -0
  24. data/lib/rggen/builtins/register/types/indirect.rb +43 -0
  25. data/lib/rggen/builtins/register_block/clock_reset.rb +2 -2
  26. data/lib/rggen/builtins/register_block/host_if.rb +11 -12
  27. data/lib/rggen/builtins/register_block/host_ifs/apb.erb +7 -25
  28. data/lib/rggen/builtins/register_block/host_ifs/apb.rb +4 -13
  29. data/lib/rggen/builtins/register_block/host_ifs/axi4lite.erb +6 -34
  30. data/lib/rggen/builtins/register_block/host_ifs/axi4lite.rb +8 -30
  31. data/lib/rggen/builtins/register_block/irq_controller.rb +4 -4
  32. data/lib/rggen/builtins/register_block/rtl_top.erb +7 -0
  33. data/lib/rggen/builtins/register_block/rtl_top.rb +28 -0
  34. data/lib/rggen/core_components.rb +3 -0
  35. data/lib/rggen/core_components/ral/item.rb +2 -6
  36. data/lib/rggen/core_components/rtl/component.rb +8 -8
  37. data/lib/rggen/core_components/rtl/item.rb +41 -38
  38. data/lib/rggen/core_components/verilog_utility.rb +23 -4
  39. data/lib/rggen/core_components/verilog_utility/declaration.rb +14 -4
  40. data/lib/rggen/core_components/verilog_utility/identifier.rb +19 -0
  41. data/lib/rggen/core_components/verilog_utility/interface_instantiation.rb +33 -0
  42. data/lib/rggen/core_components/verilog_utility/interface_port_declaration.rb +29 -0
  43. data/lib/rggen/core_components/verilog_utility/local_scope.rb +64 -0
  44. data/lib/rggen/core_extensions/facets.rb +1 -1
  45. data/lib/rggen/core_extensions/forwardable.rb +1 -1
  46. data/lib/rggen/version.rb +2 -2
  47. data/ral/LICENSE +21 -0
  48. data/ral/rggen_ral_macros.svh +1 -4
  49. data/ral/rggen_ral_reg.svh +35 -3
  50. data/rtl/LICENSE +21 -0
  51. data/rtl/compile.f +21 -6
  52. data/rtl/rggen_address_decoder.sv +23 -0
  53. data/rtl/rggen_apb_if.sv +41 -0
  54. data/rtl/rggen_axi4lite_if.sv +68 -0
  55. data/rtl/rggen_bit_field_if.sv +28 -0
  56. data/rtl/rggen_bit_field_ro.sv +9 -0
  57. data/rtl/rggen_bit_field_rw.sv +25 -0
  58. data/rtl/rggen_bit_field_rwl_rwe.sv +29 -0
  59. data/rtl/rggen_bit_field_w01s_w01c.sv +55 -0
  60. data/rtl/rggen_bus_if.sv +43 -0
  61. data/rtl/rggen_bus_splitter.sv +87 -0
  62. data/rtl/rggen_default_register.sv +15 -0
  63. data/rtl/rggen_external_register.sv +83 -0
  64. data/rtl/rggen_host_if_apb.sv +29 -0
  65. data/rtl/rggen_host_if_axi4lite.sv +14 -0
  66. data/rtl/rggen_indirect_register.sv +21 -0
  67. data/rtl/{register_block/rggen_irq_controller.sv → rggen_irq_controller.sv} +0 -0
  68. data/rtl/rggen_register_base.sv +57 -0
  69. data/rtl/rggen_register_if.sv +42 -0
  70. data/rtl/rggen_rtl_pkg.sv +23 -0
  71. data/sample/LICENSE +21 -0
  72. data/sample/sample_0.sv +315 -444
  73. data/sample/sample_0_ral_pkg.sv +7 -7
  74. data/sample/sample_1.sv +104 -162
  75. data/sample/sample_1_ral_pkg.sv +3 -3
  76. data/sample/sample_setup.rb +2 -2
  77. data/setup/default.rb +3 -3
  78. metadata +35 -23
  79. data/lib/rggen/builtins/register/address_decoder.erb +0 -12
  80. data/lib/rggen/builtins/register/address_decoder.rb +0 -82
  81. data/lib/rggen/builtins/register/bus_exporter.erb +0 -28
  82. data/lib/rggen/builtins/register/bus_exporter.rb +0 -52
  83. data/lib/rggen/builtins/register/read_data.rb +0 -61
  84. data/lib/rggen/builtins/register_block/response_mux.erb +0 -18
  85. data/lib/rggen/builtins/register_block/response_mux.rb +0 -47
  86. data/lib/rggen/builtins/register_block/top_module.rb +0 -20
  87. data/rtl/bit_field/rggen_bit_field_common.svh +0 -15
  88. data/rtl/bit_field/rggen_bit_field_ro.sv +0 -8
  89. data/rtl/bit_field/rggen_bit_field_rw.sv +0 -27
  90. data/rtl/bit_field/rggen_bit_field_rwl_rwe.sv +0 -49
  91. data/rtl/bit_field/rggen_bit_field_w01s_w01c.sv +0 -67
  92. data/rtl/register/rggen_address_decoder.sv +0 -37
  93. data/rtl/register/rggen_bus_exporter.sv +0 -96
  94. data/rtl/register_block/rggen_host_if_apb.sv +0 -42
  95. data/rtl/register_block/rggen_host_if_axi4lite.sv +0 -257
  96. data/rtl/register_block/rggen_host_if_common.svh +0 -9
  97. data/rtl/register_block/rggen_response_mux.sv +0 -113
@@ -8,10 +8,13 @@ require_relative 'core_components/code_utility'
8
8
  require_relative 'core_components/verilog_utility/identifier'
9
9
  require_relative 'core_components/verilog_utility/declaration'
10
10
  require_relative 'core_components/verilog_utility/structure_definition'
11
+ require_relative 'core_components/verilog_utility/local_scope'
11
12
  require_relative 'core_components/verilog_utility/module_definition'
12
13
  require_relative 'core_components/verilog_utility/package_definition'
13
14
  require_relative 'core_components/verilog_utility/class_definition'
14
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'
15
18
  require_relative 'core_components/verilog_utility/source_file'
16
19
  require_relative 'core_components/verilog_utility'
17
20
 
@@ -49,12 +49,8 @@ module RgGen
49
49
  end
50
50
 
51
51
  def add_declaration(type, domain, attributes)
52
- create_declaration(type, attributes).tap do |d|
53
- declarations = {
54
- variable: @variable_declarations,
55
- parameter: @parameter_declarations
56
- }.fetch(type)
57
- declarations[domain] << d
52
+ instance_variable_get("@#{type}_declarations").tap do |list|
53
+ list[domain] << __send__("#{type}_declaration", attributes)
58
54
  end
59
55
  end
60
56
  end
@@ -8,20 +8,20 @@ module RgGen
8
8
  end
9
9
  end
10
10
 
11
- def signal_declarations
12
- [*@items, *@children].flat_map(&:signal_declarations)
11
+ def signal_declarations(domain)
12
+ [*@items, *@children].flat_map { |o| o.signal_declarations(domain) }
13
13
  end
14
14
 
15
- def port_declarations
16
- [*@items, *@children].flat_map(&:port_declarations)
15
+ def port_declarations(domain)
16
+ [*@items, *@children].flat_map { |o| o.port_declarations(domain) }
17
17
  end
18
18
 
19
- def parameter_declarations
20
- [*@items, *@children].flat_map(&:parameter_declarations)
19
+ def parameter_declarations(domain)
20
+ [*@items, *@children].flat_map { |o| o.parameter_declarations(domain) }
21
21
  end
22
22
 
23
- def localparam_declarations
24
- [*@items, *@children].flat_map(&:localparam_declarations)
23
+ def localparam_declarations(domain)
24
+ [*@items, *@children].flat_map { |o| o.localparam_declarations(domain) }
25
25
  end
26
26
  end
27
27
  end
@@ -7,28 +7,27 @@ module RgGen
7
7
  def initialize(owner)
8
8
  super(owner)
9
9
  @identifiers = []
10
- @signal_declarations = []
11
- @port_declarations = []
12
- @parameter_declarations = []
13
- @localparam_declarations = []
10
+ @signal_declarations = Hash.new { |h, d| h[d] = [] }
11
+ @port_declarations = Hash.new { |h, d| h[d] = [] }
12
+ @parameter_declarations = Hash.new { |h, d| h[d] = [] }
13
+ @localparam_declarations = Hash.new { |h, d| h[d] = [] }
14
14
  end
15
15
 
16
16
  attr_reader :identifiers
17
- attr_reader :signal_declarations
18
- attr_reader :port_declarations
19
- attr_reader :parameter_declarations
20
- attr_reader :localparam_declarations
21
17
 
22
- private
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
23
22
 
24
23
  class << self
25
24
  private
26
25
 
27
26
  def define_declaration_method(method_name)
28
- define_method(method_name) do |handle_name, attributes = {}|
27
+ define_method(method_name) do |domain, handle_name, attributes = {}|
29
28
  attributes[:name] ||= handle_name
30
29
  add_identifier(handle_name, attributes[:name])
31
- add_declaration(method_name, attributes)
30
+ add_declaration(method_name, domain, attributes)
32
31
  end
33
32
  private method_name
34
33
  end
@@ -37,47 +36,51 @@ module RgGen
37
36
  define_declaration_method :wire
38
37
  define_declaration_method :reg
39
38
  define_declaration_method :logic
39
+ define_declaration_method :interface
40
40
  define_declaration_method :input
41
41
  define_declaration_method :output
42
+ define_declaration_method :interface_port
42
43
  define_declaration_method :parameter
43
44
  define_declaration_method :localparam
44
45
 
45
- def group(group_name, &body)
46
- create_group(group_name)
47
- instance_exec(&body)
48
- @group = nil
46
+ private
47
+
48
+ def add_declaration(type, domain, attributes)
49
+ case type
50
+ when :wire, :reg, :logic
51
+ @signal_declarations[domain] << variable_declaration(type, attributes)
52
+ when :interface
53
+ @signal_declarations[domain] << interface_instantiation(attributes)
54
+ when :input, :output
55
+ @port_declarations[domain] << port_declaration(type, attributes)
56
+ 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)
62
+ end
49
63
  end
50
64
 
51
- def add_declaration(type, attributes)
52
- attribute_key, declaration_type, declarations =
53
- case type
54
- when :wire, :reg, :logic
55
- [:data_type, :variable, signal_declarations]
56
- when :input, :output
57
- [:direction, :port, port_declarations]
58
- when :parameter
59
- [:parameter_type, :parameter, parameter_declarations]
60
- when :localparam
61
- [:parameter_type, :parameter, localparam_declarations]
62
- end
63
- attributes[attribute_key] = type
64
- declarations << create_declaration(declaration_type, attributes)
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))
65
75
  end
66
76
 
67
77
  def add_identifier(handle_name, name)
68
78
  identifier = create_identifier(name)
69
- (@group || self).instance_exec do
79
+ instance_exec do
70
80
  instance_variable_set(handle_name.variablize, identifier)
71
81
  attr_singleton_reader(handle_name)
72
82
  end
73
- identifiers << handle_name if @group.nil?
74
- end
75
-
76
- def create_group(group_name)
77
- instance_variable_set(group_name.variablize, Object.new)
78
- attr_singleton_reader(group_name)
79
- identifiers << group_name
80
- @group = __send__(group_name)
83
+ identifiers << handle_name
81
84
  end
82
85
  end
83
86
  end
@@ -12,8 +12,24 @@ module RgGen
12
12
  Identifier.new(name)
13
13
  end
14
14
 
15
- def create_declaration(declaration_type, attributes)
16
- Declaration.new(declaration_type, attributes)
15
+ def variable_declaration(attributes)
16
+ Declaration.new(:variable, attributes)
17
+ end
18
+
19
+ def interface_instantiation(attributes)
20
+ InterfaceInstantiation.new(attributes)
21
+ end
22
+
23
+ def port_declaration(attributes)
24
+ Declaration.new(:port, attributes)
25
+ end
26
+
27
+ def interface_port_declaration(attributes)
28
+ InterfacePortDeclaration.new(attributes)
29
+ end
30
+
31
+ def parameter_declaration(attributes)
32
+ Declaration.new(:parameter, attributes)
17
33
  end
18
34
 
19
35
  def module_definition(name, &body)
@@ -32,9 +48,12 @@ module RgGen
32
48
  SubroutineDefinition.new(:function, name, &body).to_code
33
49
  end
34
50
 
51
+ def local_scope(block_name, &body)
52
+ LocalScope.new(block_name, &body).to_code
53
+ end
54
+
35
55
  def argument(name, attributes)
36
- attributes[:name] = name
37
- create_declaration(:port, attributes)
56
+ port_declaration(attributes.merge(name: name))
38
57
  end
39
58
 
40
59
  def assign(lhs, rhs)
@@ -36,6 +36,7 @@ module RgGen
36
36
 
37
37
  def width
38
38
  return unless vector?
39
+ return "[#{@attributes[:width]}-1:0]" unless numerical_width?
39
40
  "[#{(@attributes[:width] || 1) - 1}:0]"
40
41
  end
41
42
 
@@ -44,12 +45,12 @@ module RgGen
44
45
  end
45
46
 
46
47
  def dimensions
47
- return if @attributes[:dimensions].nil?
48
+ return unless @attributes[:dimensions]
48
49
  @attributes[:dimensions].map { |dimension| "[#{dimension}]" }.join
49
50
  end
50
51
 
51
52
  def default_value_assignment
52
- return if @attributes[:default].nil?
53
+ return unless @attributes[:default]
53
54
  "= #{@attributes[:default]}"
54
55
  end
55
56
 
@@ -58,8 +59,17 @@ module RgGen
58
59
  end
59
60
 
60
61
  def vector?
61
- return true if @attributes[:vector]
62
- @attributes[:width] && (parameter? || (@attributes[:width] > 1))
62
+ return true if @attributes[:vector]
63
+ return false unless @attributes[:width]
64
+ return true unless numerical_width?
65
+ return true if parameter?
66
+ @attributes[:width] > 1
67
+ end
68
+
69
+ def numerical_width?
70
+ return true unless @attributes[:width]
71
+ return true if Integer === @attributes[:width]
72
+ false
63
73
  end
64
74
  end
65
75
  end
@@ -1,6 +1,8 @@
1
1
  module RgGen
2
2
  module VerilogUtility
3
3
  class Identifier
4
+ include InputBase::RegxpPatterns
5
+
4
6
  def initialize(name)
5
7
  @name = name
6
8
  end
@@ -22,6 +24,23 @@ module RgGen
22
24
  Identifier.new("#{@name}[#{indexes_or_msb}:#{lsb}]")
23
25
  end
24
26
  end
27
+
28
+ TYPE_CONVERSIONS = [
29
+ :to_a, :to_ary, :to_hash, :to_int, :to_io, :to_proc, :to_regexp, :to_str
30
+ ].freeze
31
+
32
+ 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}")
37
+ end
38
+
39
+ def respond_to_missing?(symbol, include_private)
40
+ return super if TYPE_CONVERSIONS.include?(symbol)
41
+ return super unless symbol =~ variable_name
42
+ true
43
+ end
25
44
  end
26
45
  end
27
46
  end
@@ -0,0 +1,33 @@
1
+ module RgGen
2
+ module VerilogUtility
3
+ class InterfaceInstantiation
4
+ def initialize(attributes)
5
+ @attributes = attributes
6
+ end
7
+
8
+ def to_s
9
+ "#{interface_type} #{identifier}()"
10
+ end
11
+
12
+ private
13
+
14
+ def interface_type
15
+ return @attributes[:type] unless @attributes[:parameters]
16
+ "#{@attributes[:type]} #{parameters}"
17
+ end
18
+
19
+ def parameters
20
+ "#(#{@attributes[:parameters].join(', ')})"
21
+ end
22
+
23
+ def identifier
24
+ "#{@attributes[:name]}#{dimensions}"
25
+ end
26
+
27
+ def dimensions
28
+ return unless @attributes[:dimensions]
29
+ @attributes[:dimensions].map { |d| "[#{d}]" }.join
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module RgGen
2
+ module VerilogUtility
3
+ class InterfacePortDeclaration
4
+ def initialize(attributes)
5
+ @attributes = attributes
6
+ end
7
+
8
+ def to_s
9
+ "#{interface_type} #{identifier}"
10
+ end
11
+
12
+ private
13
+
14
+ def interface_type
15
+ return @attributes[:type] unless @attributes[:modport]
16
+ "#{@attributes[:type]}.#{@attributes[:modport]}"
17
+ end
18
+
19
+ def identifier
20
+ "#{@attributes[:name]}#{dimensions}"
21
+ end
22
+
23
+ def dimensions
24
+ return unless @attributes[:dimensions]
25
+ @attributes[:dimensions].map { |d| "[#{d}]" }.join
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ module RgGen
2
+ module VerilogUtility
3
+ class LocalScope < StructureDefinition
4
+ attr_setter :signals
5
+ attr_setter :loops
6
+
7
+ def to_code
8
+ bodies.unshift(signal_declarations) if signals?
9
+ code_block do |c|
10
+ header_code(c)
11
+ body_code(c)
12
+ footer_code(c)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def header_code(code)
19
+ code << :'generate if (1) begin : ' << @name << nl
20
+ loops? && generate_for_header(code)
21
+ end
22
+
23
+ def footer_code(code)
24
+ loops? && generate_for_footer(code)
25
+ code << :'end endgenerate' << nl
26
+ end
27
+
28
+ def loops?
29
+ !(@loops.nil? || @loops.empty?)
30
+ end
31
+
32
+ def generate_for_header(code)
33
+ loops.each do |genvar, size|
34
+ code.indent += 2
35
+ code << "genvar #{genvar}" << semicolon << nl
36
+ code << generate_for(genvar, size) << nl
37
+ end
38
+ end
39
+
40
+ def generate_for(genvar, size)
41
+ "for (#{genvar} = 0;#{genvar} < #{size};++#{genvar}) begin : g"
42
+ end
43
+
44
+ def generate_for_footer(code)
45
+ loops.size.times do
46
+ code << :end << nl
47
+ code.indent -= 2
48
+ end
49
+ end
50
+
51
+ def signals?
52
+ !(@signals.nil? || @signals.empty?)
53
+ end
54
+
55
+ def signal_declarations
56
+ lambda do |code|
57
+ signals.each do |signal|
58
+ code << signal << semicolon << nl
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,6 +1,6 @@
1
1
  require 'facets/enumerable/exclude'
2
2
  require 'facets/enumerable/find_yield'
3
- require 'facets/enumerable/sum'
3
+ require 'facets/enumerable/sum' unless Enumerable.public_method_defined?(:sum)
4
4
  require 'facets/file/ext'
5
5
  require 'facets/hash/symbolize_keys'
6
6
  require 'facets/integer/multiple'
@@ -24,7 +24,7 @@ module SingleForwardable
24
24
  end
25
25
  end
26
26
 
27
- if ['2.2.5', '2.3.1'].include?(RUBY_VERSION)
27
+ if ['2.2.5', '2.2.6', '2.3.1'].include?(RUBY_VERSION)
28
28
  # https://bugs.ruby-lang.org/issues/12478
29
29
  def def_single_delegator(accessor, method, ali = method)
30
30
  accessor = accessor.to_s