rggen 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +7 -0
  3. data/.rubocop_todo.yml +91 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +31 -0
  7. data/bin/rggen +6 -0
  8. data/lib/rggen/base/component.rb +27 -0
  9. data/lib/rggen/base/component_factory.rb +46 -0
  10. data/lib/rggen/base/hierarchical_accessors.rb +87 -0
  11. data/lib/rggen/base/hierarchical_item_accessors.rb +79 -0
  12. data/lib/rggen/base/item.rb +24 -0
  13. data/lib/rggen/base/item_factory.rb +20 -0
  14. data/lib/rggen/builder/builder.rb +69 -0
  15. data/lib/rggen/builder/category.rb +52 -0
  16. data/lib/rggen/builder/component_entry.rb +50 -0
  17. data/lib/rggen/builder/component_store.rb +42 -0
  18. data/lib/rggen/builder/input_component_store.rb +25 -0
  19. data/lib/rggen/builder/item_store.rb +89 -0
  20. data/lib/rggen/builder/list_item_entry.rb +81 -0
  21. data/lib/rggen/builder/output_component_store.rb +13 -0
  22. data/lib/rggen/builder/simple_item_entry.rb +33 -0
  23. data/lib/rggen/builtins/bit_field/bit_assignment.rb +39 -0
  24. data/lib/rggen/builtins/bit_field/field_model_creation.rb +25 -0
  25. data/lib/rggen/builtins/bit_field/field_model_declaration.rb +9 -0
  26. data/lib/rggen/builtins/bit_field/initial_value.rb +36 -0
  27. data/lib/rggen/builtins/bit_field/name.rb +26 -0
  28. data/lib/rggen/builtins/bit_field/reference.rb +42 -0
  29. data/lib/rggen/builtins/bit_field/reserved.rb +9 -0
  30. data/lib/rggen/builtins/bit_field/ro.rb +19 -0
  31. data/lib/rggen/builtins/bit_field/rw.erb +13 -0
  32. data/lib/rggen/builtins/bit_field/rw.rb +25 -0
  33. data/lib/rggen/builtins/bit_field/type.rb +205 -0
  34. data/lib/rggen/builtins/bit_field/wo.rb +5 -0
  35. data/lib/rggen/builtins/global/address_width.rb +17 -0
  36. data/lib/rggen/builtins/global/data_width.rb +20 -0
  37. data/lib/rggen/builtins/loaders/configuration/json_loader.rb +7 -0
  38. data/lib/rggen/builtins/loaders/configuration/yaml_loader.rb +7 -0
  39. data/lib/rggen/builtins/loaders/register_map/csv_loader.rb +14 -0
  40. data/lib/rggen/builtins/loaders/register_map/xls_loader.rb +19 -0
  41. data/lib/rggen/builtins/loaders/register_map/xlsx_ods_loader.rb +24 -0
  42. data/lib/rggen/builtins/register/accessibility.rb +23 -0
  43. data/lib/rggen/builtins/register/address_decoder.erb +16 -0
  44. data/lib/rggen/builtins/register/address_decoder.rb +92 -0
  45. data/lib/rggen/builtins/register/array.rb +133 -0
  46. data/lib/rggen/builtins/register/field_model_creator.rb +10 -0
  47. data/lib/rggen/builtins/register/field_model_declarations.rb +7 -0
  48. data/lib/rggen/builtins/register/name.rb +26 -0
  49. data/lib/rggen/builtins/register/offset_address.rb +55 -0
  50. data/lib/rggen/builtins/register/read_data.rb +36 -0
  51. data/lib/rggen/builtins/register/reg_model_constructor.rb +17 -0
  52. data/lib/rggen/builtins/register/reg_model_creation.rb +64 -0
  53. data/lib/rggen/builtins/register/reg_model_declaration.rb +13 -0
  54. data/lib/rggen/builtins/register/reg_model_definition.rb +22 -0
  55. data/lib/rggen/builtins/register/shadow.rb +130 -0
  56. data/lib/rggen/builtins/register/shadow_index_configurator.rb +53 -0
  57. data/lib/rggen/builtins/register/uniqueness_validator.rb +48 -0
  58. data/lib/rggen/builtins/register_block/apb.erb +27 -0
  59. data/lib/rggen/builtins/register_block/apb.rb +20 -0
  60. data/lib/rggen/builtins/register_block/base_address.rb +64 -0
  61. data/lib/rggen/builtins/register_block/block_model_constructor.rb +14 -0
  62. data/lib/rggen/builtins/register_block/block_model_default_map_creator.rb +39 -0
  63. data/lib/rggen/builtins/register_block/block_model_definition.rb +18 -0
  64. data/lib/rggen/builtins/register_block/byte_size.rb +37 -0
  65. data/lib/rggen/builtins/register_block/clock_reset.rb +8 -0
  66. data/lib/rggen/builtins/register_block/host_if.rb +46 -0
  67. data/lib/rggen/builtins/register_block/module_definition.rb +13 -0
  68. data/lib/rggen/builtins/register_block/name.rb +26 -0
  69. data/lib/rggen/builtins/register_block/ral_package_definition.rb +19 -0
  70. data/lib/rggen/builtins/register_block/reg_model_creator.rb +14 -0
  71. data/lib/rggen/builtins/register_block/reg_model_declarations.rb +7 -0
  72. data/lib/rggen/builtins/register_block/response_mux.erb +14 -0
  73. data/lib/rggen/builtins/register_block/response_mux.rb +16 -0
  74. data/lib/rggen/builtins/register_block/signal_declarations.rb +9 -0
  75. data/lib/rggen/builtins.rb +52 -0
  76. data/lib/rggen/commands.rb +23 -0
  77. data/lib/rggen/core_components/configuration/configuration_factory.rb +23 -0
  78. data/lib/rggen/core_components/configuration/item_factory.rb +13 -0
  79. data/lib/rggen/core_components/configuration/raise_error.rb +11 -0
  80. data/lib/rggen/core_components/configuration/setup.rb +14 -0
  81. data/lib/rggen/core_components/ral/item.rb +16 -0
  82. data/lib/rggen/core_components/ral/setup.rb +19 -0
  83. data/lib/rggen/core_components/register_map/bit_field_factory.rb +11 -0
  84. data/lib/rggen/core_components/register_map/component.rb +12 -0
  85. data/lib/rggen/core_components/register_map/generic_map.rb +69 -0
  86. data/lib/rggen/core_components/register_map/item.rb +22 -0
  87. data/lib/rggen/core_components/register_map/item_factory.rb +13 -0
  88. data/lib/rggen/core_components/register_map/loader.rb +13 -0
  89. data/lib/rggen/core_components/register_map/raise_error.rb +17 -0
  90. data/lib/rggen/core_components/register_map/register_block_factory.rb +29 -0
  91. data/lib/rggen/core_components/register_map/register_factory.rb +18 -0
  92. data/lib/rggen/core_components/register_map/register_map_factory.rb +21 -0
  93. data/lib/rggen/core_components/register_map/setup.rb +33 -0
  94. data/lib/rggen/core_components/rtl/component.rb +28 -0
  95. data/lib/rggen/core_components/rtl/item.rb +83 -0
  96. data/lib/rggen/core_components/rtl/setup.rb +19 -0
  97. data/lib/rggen/core_components.rb +23 -0
  98. data/lib/rggen/core_extensions/facets.rb +17 -0
  99. data/lib/rggen/core_extensions/forwardable.rb +26 -0
  100. data/lib/rggen/core_extensions/integer.rb +5 -0
  101. data/lib/rggen/core_extensions/math.rb +7 -0
  102. data/lib/rggen/exceptions.rb +22 -0
  103. data/lib/rggen/generator.rb +185 -0
  104. data/lib/rggen/input_base/component.rb +19 -0
  105. data/lib/rggen/input_base/component_factory.rb +58 -0
  106. data/lib/rggen/input_base/item.rb +170 -0
  107. data/lib/rggen/input_base/item_factory.rb +13 -0
  108. data/lib/rggen/input_base/loader.rb +14 -0
  109. data/lib/rggen/input_base/regexp_patterns.rb +29 -0
  110. data/lib/rggen/output_base/code_block.rb +72 -0
  111. data/lib/rggen/output_base/code_utility.rb +44 -0
  112. data/lib/rggen/output_base/component.rb +88 -0
  113. data/lib/rggen/output_base/component_factory.rb +32 -0
  114. data/lib/rggen/output_base/item.rb +175 -0
  115. data/lib/rggen/output_base/item_factory.rb +6 -0
  116. data/lib/rggen/output_base/line.rb +28 -0
  117. data/lib/rggen/output_base/template_utility.rb +29 -0
  118. data/lib/rggen/output_base/verilog_utility/class_definition.rb +23 -0
  119. data/lib/rggen/output_base/verilog_utility/declaration.rb +70 -0
  120. data/lib/rggen/output_base/verilog_utility/identifier.rb +29 -0
  121. data/lib/rggen/output_base/verilog_utility/module_definition.rb +47 -0
  122. data/lib/rggen/output_base/verilog_utility/package_definition.rb +67 -0
  123. data/lib/rggen/output_base/verilog_utility/structure_definition.rb +52 -0
  124. data/lib/rggen/output_base/verilog_utility/subroutine_definition.rb +43 -0
  125. data/lib/rggen/output_base/verilog_utility.rb +66 -0
  126. data/lib/rggen/version.rb +6 -0
  127. data/lib/rggen.rb +65 -0
  128. data/ral/compile.f +4 -0
  129. data/ral/rggen_ral_block.svh +84 -0
  130. data/ral/rggen_ral_field.svh +47 -0
  131. data/ral/rggen_ral_macros.svh +22 -0
  132. data/ral/rggen_ral_map.svh +124 -0
  133. data/ral/rggen_ral_pkg.sv +14 -0
  134. data/ral/rggen_ral_reg.svh +52 -0
  135. data/ral/rggen_ral_shadow_reg.svh +188 -0
  136. data/rggen.gemspec +45 -0
  137. data/rtl/bit_field/rggen_bit_field_rw.sv +28 -0
  138. data/rtl/register/rggen_address_decoder.sv +49 -0
  139. data/rtl/register_block/rggen_host_if_apb.sv +40 -0
  140. data/rtl/register_block/rggen_response_mux.sv +82 -0
  141. data/sample/sample.csv +14 -0
  142. data/sample/sample.json +4 -0
  143. data/sample/sample.xls +0 -0
  144. data/sample/sample.xlsx +0 -0
  145. data/sample/sample.yaml +2 -0
  146. data/sample/sample_0.sv +285 -0
  147. data/sample/sample_0_ral_pkg.sv +99 -0
  148. data/sample/sample_1.sv +172 -0
  149. data/sample/sample_1_ral_pkg.sv +53 -0
  150. data/sample/sample_setup.rb +21 -0
  151. data/setup/default.rb +11 -0
  152. metadata +296 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0dee9380fac0315414a76aa4bdf305528fe30335
4
+ data.tar.gz: 82cba15bcfa8788bb719d703ae549e32e5b381d2
5
+ SHA512:
6
+ metadata.gz: 552c1a13e87dcb9d97d472268f026392bb16d2e40cba50b7f5b5f12c10b2b7867f86d0118fb432c7307d1fde1078d7d9273b2be902355810380e8d289fa5c8e2
7
+ data.tar.gz: e72990eab0ef33aa739d915b83949756feb45278e2cc17a463426e9a17e6365fcd4013b18bd5dbe60c795108ac791ae99d2e7ddf12d27b6a7e3142945e2d9c63
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'sample/*'
6
+ - 'setup/*'
7
+ - 'spec/**/*'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,91 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-12-27 19:46:19 +0900 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Lint/FormatParameterMismatch:
11
+ Exclude:
12
+ - 'lib/rgen/core_components/rtl/item.rb'
13
+
14
+ # Offense count: 3
15
+ Metrics/AbcSize:
16
+ Max: 18
17
+
18
+ # Offense count: 1
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 7
21
+
22
+ # Offense count: 8
23
+ # Configuration parameters: AllowURI, URISchemes.
24
+ Metrics/LineLength:
25
+ Max: 142
26
+
27
+ # Offense count: 1
28
+ # Configuration parameters: CountComments.
29
+ Metrics/MethodLength:
30
+ Max: 11
31
+
32
+ # Offense count: 72
33
+ # Configuration parameters: Exclude.
34
+ Style/Documentation:
35
+ Enabled: false
36
+
37
+ # Offense count: 56
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: AllowForAlignment.
40
+ Style/ExtraSpacing:
41
+ Enabled: false
42
+
43
+ # Offense count: 2
44
+ # Cop supports --auto-correct.
45
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
46
+ Style/HashSyntax:
47
+ Enabled: false
48
+
49
+ # Offense count: 33
50
+ # Cop supports --auto-correct.
51
+ Style/SingleSpaceBeforeFirstArg:
52
+ Exclude:
53
+ - 'lib/rgen/builtins/register_block/apb.rb'
54
+ - 'lib/rgen/core_components/configuration/setup.rb'
55
+ - 'lib/rgen/core_components/register_map/generic_map.rb'
56
+ - 'lib/rgen/core_components/register_map/setup.rb'
57
+ - 'lib/rgen/core_components/rtl/setup.rb'
58
+ - 'lib/rgen/output_base/line.rb'
59
+
60
+ # Offense count: 28
61
+ # Cop supports --auto-correct.
62
+ # Configuration parameters: MultiSpaceAllowedForOperators.
63
+ Style/SpaceAroundOperators:
64
+ Enabled: false
65
+
66
+ # Offense count: 42
67
+ # Cop supports --auto-correct.
68
+ Style/SpaceBeforeComma:
69
+ Exclude:
70
+ - 'lib/rgen/builder/list_item_entry.rb'
71
+ - 'lib/rgen/builtins/bit_field/type.rb'
72
+ - 'lib/rgen/builtins/register_block/apb.rb'
73
+ - 'lib/rgen/builtins/register_block/clock_reset.rb'
74
+ - 'lib/rgen/builtins/register_block/host_if.rb'
75
+ - 'lib/rgen/builtins/register_block/response_mux.rb'
76
+ - 'lib/rgen/commands.rb'
77
+ - 'lib/rgen/core_extensions/forwardable.rb'
78
+ - 'rgen.gemspec'
79
+
80
+ # Offense count: 5
81
+ # Cop supports --auto-correct.
82
+ Style/SpaceInsideBrackets:
83
+ Exclude:
84
+ - 'lib/rgen/commands.rb'
85
+
86
+ # Offense count: 2
87
+ # Cop supports --auto-correct.
88
+ Style/SpaceInsideParens:
89
+ Exclude:
90
+ - 'lib/rgen/builder/category.rb'
91
+
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at taichi730@jf6.so-net.ne.jp. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Taichi Ishitani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ [![Build Status](https://travis-ci.org/taichi-ishitani/rggen.svg?branch=master)](https://travis-ci.org/taichi-ishitani/rggen)
2
+ [![Code Climate](https://codeclimate.com/github/taichi-ishitani/rggen/badges/gpa.svg)](https://codeclimate.com/github/taichi-ishitani/rggen)
3
+ [![Test Coverage](https://codeclimate.com/github/taichi-ishitani/rggen/badges/coverage.svg)](https://codeclimate.com/github/taichi-ishitani/rggen/coverage)
4
+
5
+ # RgGen
6
+
7
+ RgGen is a code generation tool for SoC designers. You can automatically generate soruce code for control registers in a SoC design, e.g. RTL, UVM RAL model, from its register map document. You can also customize RgGen, so you can build your specific generation tool.
8
+
9
+ ## Installation
10
+
11
+ TODO: Write installation command here
12
+
13
+ ## Usage
14
+
15
+ TODO: Write usage instructions here
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
20
+
21
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/taichi-ishitani/rggen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
26
+
27
+
28
+ ## License
29
+
30
+ Copyright © 2015-2016 [Taichi Ishitani](mailto:taichi730@gmail.com).
31
+ RgGen is available as open source under the terms of the [MIT License](LICENSE.txt).
data/bin/rggen ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(__dir__, '../lib'))
4
+
5
+ require 'rggen'
6
+ RgGen::Generator.new.run(ARGV)
@@ -0,0 +1,27 @@
1
+ module RgGen
2
+ module Base
3
+ class Component
4
+ include SingleForwardable
5
+
6
+ def initialize(parent)
7
+ @parent = parent
8
+ @children = []
9
+ @level = (parent && parent.level + 1) || 0
10
+ @items = []
11
+ end
12
+
13
+ attr_reader :parent
14
+ attr_reader :children
15
+ attr_reader :level
16
+ attr_reader :items
17
+
18
+ def add_child(child)
19
+ @children << child
20
+ end
21
+
22
+ def add_item(item)
23
+ items << item
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ module RgGen
2
+ module Base
3
+ class ComponentFactory
4
+ def initialize
5
+ @root_factory = false
6
+ end
7
+
8
+ attr_writer :target_component
9
+ attr_writer :item_factories
10
+ attr_writer :child_factory
11
+
12
+ def create(*args)
13
+ parent = (child_factory? && args.shift) || nil
14
+ sources = args
15
+ create_component(parent, *sources).tap do |component|
16
+ create_items(component, *sources) if @item_factories
17
+ parent.add_child(component) unless @root_factory
18
+ create_children(component, *sources) if @child_factory
19
+ end
20
+ end
21
+
22
+ def root_factory
23
+ @root_factory = true
24
+ end
25
+
26
+ private
27
+
28
+ def child_factory?
29
+ !@root_factory
30
+ end
31
+
32
+ def create_component(parent, *_sources)
33
+ @target_component.new(parent)
34
+ end
35
+
36
+ def create_item(item_factory, component, *sources)
37
+ item = item_factory.create(component, *sources)
38
+ component.add_item(item)
39
+ end
40
+
41
+ def create_child(component, *sources)
42
+ @child_factory.create(component, *sources)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,87 @@
1
+ module RgGen
2
+ module Base
3
+ module HierarchicalAccessors
4
+ module RegisterMap
5
+ def hierarchy
6
+ :register_map
7
+ end
8
+
9
+ def register_blocks
10
+ children
11
+ end
12
+
13
+ def registers
14
+ register_blocks.flat_map(&:children)
15
+ end
16
+
17
+ def bit_fields
18
+ registers.flat_map(&:children)
19
+ end
20
+ end
21
+
22
+ module RegisterBlock
23
+ def hierarchy
24
+ :register_block
25
+ end
26
+
27
+ def register_map
28
+ parent
29
+ end
30
+
31
+ def registers
32
+ children
33
+ end
34
+
35
+ def bit_fields
36
+ registers.flat_map(&:children)
37
+ end
38
+ end
39
+
40
+ module Register
41
+ def hierarchy
42
+ :register
43
+ end
44
+
45
+ def register_map
46
+ register_block.parent
47
+ end
48
+
49
+ def register_block
50
+ parent
51
+ end
52
+
53
+ def bit_fields
54
+ children
55
+ end
56
+ end
57
+
58
+ module BitField
59
+ def hierarchy
60
+ :bit_field
61
+ end
62
+
63
+ def register_map
64
+ register_block.parent
65
+ end
66
+
67
+ def register_block
68
+ register.parent
69
+ end
70
+
71
+ def register
72
+ parent
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ EXTENSIONS = [
79
+ RegisterMap, RegisterBlock, Register, BitField
80
+ ].freeze
81
+
82
+ def define_hierarchical_accessors
83
+ extend EXTENSIONS[level]
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,79 @@
1
+ module RgGen
2
+ module Base
3
+ module HierarchicalItemAccessors
4
+ module RegisterMap
5
+ def hierarchy
6
+ :register_map
7
+ end
8
+
9
+ def register_map
10
+ @owner
11
+ end
12
+ end
13
+
14
+ module RegisterBlock
15
+ def hierarchy
16
+ :register_block
17
+ end
18
+
19
+ def register_map
20
+ register_block.parent
21
+ end
22
+
23
+ def register_block
24
+ @owner
25
+ end
26
+ end
27
+
28
+ module Register
29
+ def hierarchy
30
+ :register
31
+ end
32
+
33
+ def register_map
34
+ register_block.parent
35
+ end
36
+
37
+ def register_block
38
+ register.parent
39
+ end
40
+
41
+ def register
42
+ @owner
43
+ end
44
+ end
45
+
46
+ module BitField
47
+ def hierarchy
48
+ :bit_field
49
+ end
50
+
51
+ def register_map
52
+ register_block.parent
53
+ end
54
+
55
+ def register_block
56
+ register.parent
57
+ end
58
+
59
+ def register
60
+ bit_field.parent
61
+ end
62
+
63
+ def bit_field
64
+ @owner
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ EXTENSIONS = [
71
+ RegisterMap, RegisterBlock, Register, BitField
72
+ ].freeze
73
+
74
+ def define_hierarchical_item_accessors
75
+ extend EXTENSIONS[@owner.level]
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,24 @@
1
+ module RgGen
2
+ module Base
3
+ class Item
4
+ extend Forwardable
5
+
6
+ def initialize(owner)
7
+ @owner = owner
8
+ end
9
+
10
+ attr_reader :owner
11
+
12
+ def self.define_helpers(&body)
13
+ singleton_class.class_exec(&body) if block_given?
14
+ end
15
+
16
+ def self.inherit_class_instance_variable(variable_name, parent_class, &block)
17
+ return unless parent_class.instance_variable_defined?(variable_name)
18
+ v = parent_class.instance_variable_get(variable_name)
19
+ v = block.call(v) if block_given?
20
+ instance_variable_set(variable_name, v)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module RgGen
2
+ module Base
3
+ class ItemFactory
4
+ attr_writer :target_items
5
+ attr_writer :target_item
6
+
7
+ def create(owner, *args)
8
+ create_item(owner, *args)
9
+ end
10
+
11
+ private
12
+
13
+ def create_item(owner, *args)
14
+ klass ||= @target_items && select_target_item(*args)
15
+ klass ||= @target_item
16
+ klass.new(owner)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,69 @@
1
+ module RgGen
2
+ module Builder
3
+ class Builder
4
+ INITIAL_CATEGORIES = [
5
+ :global,
6
+ :register_block,
7
+ :register,
8
+ :bit_field
9
+ ].freeze
10
+
11
+ def initialize
12
+ @stores = Hash.new do |_, component_name|
13
+ fail RgGen::BuilderError, "unknown component: #{component_name}"
14
+ end
15
+ @categories = Hash.new do |_, category_name|
16
+ fail RgGen::BuilderError, "unknown category: #{category_name}"
17
+ end
18
+ INITIAL_CATEGORIES.each do |category_name|
19
+ @categories[category_name] = Category.new
20
+ end
21
+ end
22
+
23
+ attr_reader :categories
24
+
25
+ def input_component_store(component_name, &body)
26
+ component_store(InputComponentStore, component_name, body)
27
+ end
28
+
29
+ def output_component_store(component_name, &body)
30
+ component_store(OutputComponentStore, component_name, body)
31
+ end
32
+
33
+ def stored_output_components
34
+ @stores.keys.select do |component_name|
35
+ @stores[component_name].is_a?(OutputComponentStore)
36
+ end
37
+ end
38
+
39
+ def define_loader(component_name, type_or_types, &body)
40
+ @stores[component_name].define_loader(type_or_types, &body)
41
+ end
42
+
43
+ def build_factory(component_name)
44
+ @stores[component_name].build_factory
45
+ end
46
+
47
+ def define_simple_item(category_name, item_name, &body)
48
+ @categories[category_name].define_simple_item(item_name, &body)
49
+ end
50
+
51
+ def define_list_item(category_name, list_name, item_name = nil, &body)
52
+ @categories[category_name].define_list_item(list_name, item_name, &body)
53
+ end
54
+
55
+ def enable(category_name, *args)
56
+ @categories[category_name].enable(*args)
57
+ end
58
+
59
+ private
60
+
61
+ def component_store(klass, component_name, body)
62
+ unless @stores.key?(component_name)
63
+ @stores[component_name] = klass.new(self, component_name)
64
+ end
65
+ @stores[component_name].instance_exec(&body)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ module RgGen
2
+ module Builder
3
+ class Category
4
+ def initialize
5
+ @item_stores = {}
6
+ end
7
+
8
+ def add_item_store(component_name, item_store)
9
+ return if @item_stores.key?(component_name)
10
+ @item_stores[component_name] = item_store
11
+ define_definition_method(component_name)
12
+ end
13
+
14
+ def define_simple_item(item_name, &body)
15
+ do_definition(:define_simple_item, item_name, &body)
16
+ end
17
+
18
+ def define_list_item(list_name, item_name = nil, &body)
19
+ do_definition(:define_list_item, list_name, item_name, &body)
20
+ end
21
+
22
+ def shared_context(&body)
23
+ @shared_context ||= Object.new
24
+ @shared_context.singleton_class.class_exec(&body) if block_given?
25
+ end
26
+
27
+ def enable(*args)
28
+ @item_stores.each_value do |item_registry|
29
+ item_registry.enable(*args)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def define_definition_method(component_name)
36
+ define_singleton_method(component_name) do |&body|
37
+ item_store = @item_stores[component_name]
38
+ item_store.__send__(@definition_method, @shared_context, *@arguments, &body)
39
+ end
40
+ end
41
+
42
+ def do_definition(register_method, *arguments, &body)
43
+ @definition_method = register_method
44
+ @arguments = arguments
45
+ instance_exec(&body)
46
+ remove_instance_variable(:@definition_method)
47
+ remove_instance_variable(:@arguments )
48
+ remove_instance_variable(:@shared_context ) if @shared_context
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ module RgGen
2
+ module Builder
3
+ class ComponentEntry
4
+ class << self
5
+ private
6
+
7
+ def rggen_class_setter(class_type)
8
+ variable_name = class_type.variablize
9
+ define_method(class_type) do |base_class = nil, options = {}, &body|
10
+ if base_class && !instance_variable_defined?(variable_name)
11
+ klass = define_rggen_class(base_class, options, body)
12
+ instance_variable_set(variable_name, klass)
13
+ end
14
+ instance_variable_get(variable_name)
15
+ end
16
+ end
17
+ end
18
+
19
+ rggen_class_setter :component_class
20
+ rggen_class_setter :component_factory
21
+ rggen_class_setter :item_base
22
+ rggen_class_setter :item_factory
23
+
24
+ def item_store
25
+ return nil unless item_base && item_factory
26
+ @item_store ||= ItemStore.new(item_base, item_factory)
27
+ end
28
+
29
+ def build_factory
30
+ component_factory.new.tap do |f|
31
+ f.target_component = component_class
32
+ f.item_factories = item_store.build_factories if item_store
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def define_rggen_class(base_class, options, body)
39
+ if options.key?(:include) || body
40
+ Class.new(base_class) do
41
+ include(*Array(options[:include])) if options.key?(:include)
42
+ class_exec(&body) if body
43
+ end
44
+ else
45
+ base_class
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end