rggen-vhdl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +84 -0
  3. data/LICENSE +21 -0
  4. data/README.md +74 -0
  5. data/lib/rggen/vhdl.rb +50 -0
  6. data/lib/rggen/vhdl/bit_field/type.rb +85 -0
  7. data/lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.erb +27 -0
  8. data/lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.rb +51 -0
  9. data/lib/rggen/vhdl/bit_field/type/ro.erb +24 -0
  10. data/lib/rggen/vhdl/bit_field/type/ro.rb +21 -0
  11. data/lib/rggen/vhdl/bit_field/type/rof.erb +24 -0
  12. data/lib/rggen/vhdl/bit_field/type/rof.rb +7 -0
  13. data/lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.erb +27 -0
  14. data/lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.rb +42 -0
  15. data/lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.erb +26 -0
  16. data/lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.rb +23 -0
  17. data/lib/rggen/vhdl/bit_field/type/rwc.erb +25 -0
  18. data/lib/rggen/vhdl/bit_field/type/rwc.rb +24 -0
  19. data/lib/rggen/vhdl/bit_field/type/rwe_rwl.erb +25 -0
  20. data/lib/rggen/vhdl/bit_field/type/rwe_rwl.rb +33 -0
  21. data/lib/rggen/vhdl/bit_field/type/rws.erb +24 -0
  22. data/lib/rggen/vhdl/bit_field/type/rws.rb +27 -0
  23. data/lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.erb +26 -0
  24. data/lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.rb +36 -0
  25. data/lib/rggen/vhdl/bit_field/type/w0t_w1t.erb +25 -0
  26. data/lib/rggen/vhdl/bit_field/type/w0t_w1t.rb +22 -0
  27. data/lib/rggen/vhdl/bit_field/type/w0trg_w1trg.erb +17 -0
  28. data/lib/rggen/vhdl/bit_field/type/w0trg_w1trg.rb +19 -0
  29. data/lib/rggen/vhdl/bit_field/type/wrc_wrs.erb +25 -0
  30. data/lib/rggen/vhdl/bit_field/type/wrc_wrs.rb +22 -0
  31. data/lib/rggen/vhdl/bit_field/vhdl_top.rb +93 -0
  32. data/lib/rggen/vhdl/component.rb +7 -0
  33. data/lib/rggen/vhdl/factories.rb +11 -0
  34. data/lib/rggen/vhdl/feature.rb +31 -0
  35. data/lib/rggen/vhdl/register/default.erb +29 -0
  36. data/lib/rggen/vhdl/register/type.rb +109 -0
  37. data/lib/rggen/vhdl/register/type/default.erb +31 -0
  38. data/lib/rggen/vhdl/register/type/external.erb +29 -0
  39. data/lib/rggen/vhdl/register/type/external.rb +44 -0
  40. data/lib/rggen/vhdl/register/type/indirect.erb +35 -0
  41. data/lib/rggen/vhdl/register/type/indirect.rb +34 -0
  42. data/lib/rggen/vhdl/register/vhdl_top.rb +40 -0
  43. data/lib/rggen/vhdl/register_block/protocol.rb +48 -0
  44. data/lib/rggen/vhdl/register_block/protocol/apb.erb +34 -0
  45. data/lib/rggen/vhdl/register_block/protocol/apb.rb +20 -0
  46. data/lib/rggen/vhdl/register_block/protocol/axi4lite.erb +49 -0
  47. data/lib/rggen/vhdl/register_block/protocol/axi4lite.rb +42 -0
  48. data/lib/rggen/vhdl/register_block/vhdl_top.erb +26 -0
  49. data/lib/rggen/vhdl/register_block/vhdl_top.rb +103 -0
  50. data/lib/rggen/vhdl/register_file/vhdl_top.rb +25 -0
  51. data/lib/rggen/vhdl/setup.rb +11 -0
  52. data/lib/rggen/vhdl/utility.rb +28 -0
  53. data/lib/rggen/vhdl/utility/data_object.rb +91 -0
  54. data/lib/rggen/vhdl/utility/identifier.rb +38 -0
  55. data/lib/rggen/vhdl/utility/local_scope.rb +66 -0
  56. data/lib/rggen/vhdl/version.rb +7 -0
  57. metadata +130 -0
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:register_file, :vhdl_top) do
4
+ vhdl do
5
+ include RgGen::SystemVerilog::RTL::RegisterIndex
6
+
7
+ main_code :register_file do
8
+ local_scope("g_#{register_file.name}") do |scope|
9
+ scope.loop_size loop_size
10
+ scope.body(&method(:body_code))
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def loop_size
17
+ (register_file.array? || nil) &&
18
+ local_loop_variables.zip(register_file.array_size).to_h
19
+ end
20
+
21
+ def body_code(code)
22
+ register_file.generate_code(code, :register_file, :top_down, 1)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rggen/vhdl'
4
+
5
+ RgGen.register_plugin RgGen::VHDL do |builder|
6
+ builder.load_plugin 'rggen/systemverilog/rtl/setup'
7
+ builder.enable :register_block, [:vhdl_top]
8
+ builder.enable :register_file, [:vhdl_top]
9
+ builder.enable :register, [:vhdl_top]
10
+ builder.enable :bit_field, [:vhdl_top]
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ module Utility
6
+ include Core::Utility::CodeUtility
7
+
8
+ private
9
+
10
+ def assign(lhs, rhs)
11
+ "#{lhs} <= #{rhs};"
12
+ end
13
+
14
+ def bin(value, width = nil)
15
+ width && format("\"%0*b\"", width, value) || "'#{value[0]}'"
16
+ end
17
+
18
+ def hex(value, width)
19
+ print_width = (width + 3) / 4
20
+ format("x\"%0*x\"", print_width, value)
21
+ end
22
+
23
+ def local_scope(scope_name, attributes = {}, &block)
24
+ LocalScope.new(attributes.merge(name: scope_name), &block).to_code
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ module Utility
6
+ class DataObject
7
+ include Core::Utility::AttributeSetter
8
+
9
+ def initialize(object_type, default_attributes = {})
10
+ @object_type = object_type
11
+ apply_attributes(**default_attributes)
12
+ block_given? && yield(self)
13
+ end
14
+
15
+ define_attribute :name
16
+ define_attribute :direction
17
+ define_attribute :type
18
+ define_attribute :width
19
+ define_attribute :array_size
20
+ define_attribute :default
21
+
22
+ def declaration
23
+ declaration_snippets
24
+ .compact
25
+ .reject(&:empty?)
26
+ .join(' ')
27
+ end
28
+
29
+ def identifier
30
+ Identifier.new(name) do |identifier|
31
+ identifier.__width__(width)
32
+ identifier.__array_size__(array_size)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def declaration_snippets
39
+ [
40
+ object_type_keyword,
41
+ "#{name}:",
42
+ direction_keyword,
43
+ type_declaration,
44
+ default_value
45
+ ]
46
+ end
47
+
48
+ def object_type_keyword
49
+ [:signal].include?(@object_type) && @object_type || nil
50
+ end
51
+
52
+ def direction_keyword
53
+ @object_type == :port && direction || nil
54
+ end
55
+
56
+ def type_declaration
57
+ if @object_type == :generic && type
58
+ type
59
+ else
60
+ msb = calc_msb
61
+ msb && "#{default_vector_type}(#{msb} downto 0)" || default_type
62
+ end
63
+ end
64
+
65
+ def calc_msb
66
+ width = calc_actual_width
67
+ width && (width.is_a?(Integer) && width - 1 || "#{width}-1")
68
+ end
69
+
70
+ def calc_actual_width
71
+ return width if array_size.nil? || array_size.empty?
72
+ size = [width, *array_size].compact
73
+ size.all? { |s| s.is_a?(Integer) } && size.inject(:*) || size.join('*')
74
+ end
75
+
76
+ def default_vector_type
77
+ @object_type == :generic && 'unsigned' || 'std_logic_vector'
78
+ end
79
+
80
+ def default_type
81
+ @object_type == :generic && 'unsigned' || 'std_logic'
82
+ end
83
+
84
+ def default_value
85
+ return nil if @object_type != :generic || default.nil?
86
+ ":= #{default}"
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ module Utility
6
+ class Identifier < SystemVerilog::Common::Utility::Identifier
7
+ def __create_select__(array_index_or_lsb, lsb_or_width, width)
8
+ if array_index_or_lsb.is_a?(Array)
9
+ __array_select__(array_index_or_lsb, lsb_or_width, width)
10
+ elsif lsb_or_width
11
+ __array_slice__(array_index_or_lsb, lsb_or_width)
12
+ else
13
+ "(#{array_index_or_lsb})"
14
+ end
15
+ end
16
+
17
+ def __array_select__(array_index, lsb, width)
18
+ if @width
19
+ lsb = __serialized_lsb__(array_index, lsb)
20
+ __array_slice__(lsb, width || @width)
21
+ else
22
+ "(#{__serialized_index__(array_index)})"
23
+ end
24
+ end
25
+
26
+ def __array_slice__(lsb, width)
27
+ msb =
28
+ if integer?(width)
29
+ __reduce_array__([lsb, width - 1], :+, 0)
30
+ else
31
+ __reduce_array__([lsb, width, -1], :+, 0)
32
+ end
33
+ "(#{msb} downto #{lsb})"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ module Utility
6
+ class LocalScope < SystemVerilog::Common::Utility::StructureDefinition
7
+ define_attribute :name
8
+ define_attribute :loop_size
9
+ define_attribute :signals
10
+
11
+ private
12
+
13
+ def header_code(code)
14
+ block_header_code(code)
15
+ generate_for_header(code)
16
+ end
17
+
18
+ def block_header_code(code)
19
+ code << "#{name}: block" << nl
20
+ header_begin(code, no_loop?)
21
+ end
22
+
23
+ def no_loop?
24
+ loop_size.nil? || loop_size.empty?
25
+ end
26
+
27
+ def generate_for_header(code)
28
+ loop_size&.each_with_index do |(loop_variable, size), i|
29
+ code.indent += 2
30
+ generate_for(code, loop_variable, size, i)
31
+ end
32
+ end
33
+
34
+ def generate_for(code, loop_variable, size, loop_depth)
35
+ code << "g: for #{loop_variable} in 0 to #{size - 1} generate" << nl
36
+ header_begin(code, last_loop?(loop_depth))
37
+ end
38
+
39
+ def last_loop?(loop_depth)
40
+ loop_depth == (loop_size.size - 1)
41
+ end
42
+
43
+ def header_begin(code, include_declarations)
44
+ signal_declarations(code) if include_declarations
45
+ code << 'begin' << nl
46
+ end
47
+
48
+ def signal_declarations(code)
49
+ indent(code, 2) do
50
+ add_declarations_to_body(code, Array(signals))
51
+ end
52
+ end
53
+
54
+ def footer_code(code)
55
+ loop_size&.each { footer(code, 'generate', true) }
56
+ footer(code, 'block', false)
57
+ end
58
+
59
+ def footer(code, kind, decrease_indent)
60
+ code << "end #{kind};" << nl
61
+ code.indent -= 2 if decrease_indent
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rggen-vhdl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taichi Ishitani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rggen-systemverilog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.25.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.25.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: VHDL writer plugin for RgGen
42
+ email:
43
+ - rggen@googlegroups.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CODE_OF_CONDUCT.md
49
+ - LICENSE
50
+ - README.md
51
+ - lib/rggen/vhdl.rb
52
+ - lib/rggen/vhdl/bit_field/type.rb
53
+ - lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.erb
54
+ - lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.rb
55
+ - lib/rggen/vhdl/bit_field/type/ro.erb
56
+ - lib/rggen/vhdl/bit_field/type/ro.rb
57
+ - lib/rggen/vhdl/bit_field/type/rof.erb
58
+ - lib/rggen/vhdl/bit_field/type/rof.rb
59
+ - lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.erb
60
+ - lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.rb
61
+ - lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.erb
62
+ - lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.rb
63
+ - lib/rggen/vhdl/bit_field/type/rwc.erb
64
+ - lib/rggen/vhdl/bit_field/type/rwc.rb
65
+ - lib/rggen/vhdl/bit_field/type/rwe_rwl.erb
66
+ - lib/rggen/vhdl/bit_field/type/rwe_rwl.rb
67
+ - lib/rggen/vhdl/bit_field/type/rws.erb
68
+ - lib/rggen/vhdl/bit_field/type/rws.rb
69
+ - lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.erb
70
+ - lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.rb
71
+ - lib/rggen/vhdl/bit_field/type/w0t_w1t.erb
72
+ - lib/rggen/vhdl/bit_field/type/w0t_w1t.rb
73
+ - lib/rggen/vhdl/bit_field/type/w0trg_w1trg.erb
74
+ - lib/rggen/vhdl/bit_field/type/w0trg_w1trg.rb
75
+ - lib/rggen/vhdl/bit_field/type/wrc_wrs.erb
76
+ - lib/rggen/vhdl/bit_field/type/wrc_wrs.rb
77
+ - lib/rggen/vhdl/bit_field/vhdl_top.rb
78
+ - lib/rggen/vhdl/component.rb
79
+ - lib/rggen/vhdl/factories.rb
80
+ - lib/rggen/vhdl/feature.rb
81
+ - lib/rggen/vhdl/register/default.erb
82
+ - lib/rggen/vhdl/register/type.rb
83
+ - lib/rggen/vhdl/register/type/default.erb
84
+ - lib/rggen/vhdl/register/type/external.erb
85
+ - lib/rggen/vhdl/register/type/external.rb
86
+ - lib/rggen/vhdl/register/type/indirect.erb
87
+ - lib/rggen/vhdl/register/type/indirect.rb
88
+ - lib/rggen/vhdl/register/vhdl_top.rb
89
+ - lib/rggen/vhdl/register_block/protocol.rb
90
+ - lib/rggen/vhdl/register_block/protocol/apb.erb
91
+ - lib/rggen/vhdl/register_block/protocol/apb.rb
92
+ - lib/rggen/vhdl/register_block/protocol/axi4lite.erb
93
+ - lib/rggen/vhdl/register_block/protocol/axi4lite.rb
94
+ - lib/rggen/vhdl/register_block/vhdl_top.erb
95
+ - lib/rggen/vhdl/register_block/vhdl_top.rb
96
+ - lib/rggen/vhdl/register_file/vhdl_top.rb
97
+ - lib/rggen/vhdl/setup.rb
98
+ - lib/rggen/vhdl/utility.rb
99
+ - lib/rggen/vhdl/utility/data_object.rb
100
+ - lib/rggen/vhdl/utility/identifier.rb
101
+ - lib/rggen/vhdl/utility/local_scope.rb
102
+ - lib/rggen/vhdl/version.rb
103
+ homepage: https://github.com/rggen/rggen-vhdl
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ bug_tracker_uri: https://github.com/rggen/rggen-vhdl/issues
108
+ mailing_list_uri: https://groups.google.com/d/forum/rggen
109
+ source_code_uri: https://github.com/rggen/rggen-vhdl
110
+ wiki_uri: https://github.com/rggen/rggen/wiki
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.5.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.2.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: rggen-vhdl-0.1.0
130
+ test_files: []