rggen-c-header 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bde50cf30f12147cac1bbe3b5d13ba5a1fadf7714d24f64a3fbe339708eadae4
4
+ data.tar.gz: e88709a2d9362c0d326e732a59ad910df61176d61a9acf55e2463e7505f44d3f
5
+ SHA512:
6
+ metadata.gz: ff93ca1e266012860248b3df4a63c3fd1789ba6937761bd077c6bf53b456eded67b0a0fa19529910a36aea4843c44408941a0a4bb97fc6124ea71d5063a1644c
7
+ data.tar.gz: 97f87c1eed64dba48287b0645a5f93a0e4b34d3b14921f85fc7737825c86cbb3c7467e8c53fb59e68e21741ff24243cc863a51fc42a5c5f4029510108c45f6cf
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at taichi730@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 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,59 @@
1
+ [![Gem Version](https://badge.fury.io/rb/rggen-c-header.svg)](https://badge.fury.io/rb/rggen-c-header)
2
+ [![CI](https://github.com/rggen/rggen-c-header/actions/workflows/ci.yml/badge.svg)](https://github.com/rggen/rggen-c-header/actions/workflows/ci.yml)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/abc9b4eea884c4b32805/maintainability)](https://codeclimate.com/github/rggen/rggen-c-header/maintainability)
4
+ [![codecov](https://codecov.io/gh/rggen/rggen-c-header/branch/master/graph/badge.svg?token=kUhLlLvtv6)](https://codecov.io/gh/rggen/rggen-c-header)
5
+ [![Gitter](https://badges.gitter.im/rggen/rggen.svg)](https://gitter.im/rggen/rggen?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
6
+
7
+ # RgGen::CHeader
8
+
9
+ RgGen::CHeader is a RgGen plugin to generate C header file.
10
+
11
+ ## Installation
12
+
13
+ To install RgGen::CHeader, use the following command:
14
+
15
+ ```
16
+ $ gem install rggen-c-header
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ You need to tell RgGen to load RgGen::CHeader plugin. There are two ways.
22
+
23
+ ### Using `--plugin` runtime option
24
+
25
+ ```
26
+ $ rggen --plugin rggen-c-header your_register_map.yml
27
+ ```
28
+
29
+ ### Using `RGGEN_PLUGINS` environment variable
30
+
31
+ ```
32
+ $ export RGGEN_PLUGINS=${RGGEN_PLUGINS}:rggen-c-header
33
+ $ rggen your_register_map.yml
34
+ ```
35
+
36
+ ## Example
37
+
38
+ You can find sample C header files generated from sample register map specifications from [this repository](https://github.com/rggen/rggen-sample).
39
+
40
+ * https://github.com/rggen/rggen-sample/blob/master/block_0.h
41
+ * https://github.com/rggen/rggen-sample/blob/master/block_1.h
42
+
43
+ ## Contact
44
+
45
+ Feedbacks, bus reports, questions and etc. are welcome! You can post them bu using following ways:
46
+
47
+ * [GitHub Issue Tracker](https://github.com/rggen/rggen/issues)
48
+ * [GitHub Discussions](https://github.com/rggen/rggen/discussions)
49
+ * [Chat Room](https://gitter.im/rggen/rggen)
50
+ * [Mailing List](https://groups.google.com/d/forum/rggen)
51
+ * [Mail](mailto:rggen@googlegroups.com)
52
+
53
+ ## Copyright & License
54
+
55
+ Copyright © 2022 Taichi Ishitani. RgGen::CHeader is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the RgGen::CHeader project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rggen/rggen-c-header/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:bit_field, :c_header) do
4
+ c_header do
5
+ build do
6
+ define_macro("#{full_name}_bit_width", width)
7
+ define_macro("#{full_name}_bit_mask", mask)
8
+ define_offset_macro
9
+ end
10
+
11
+ private
12
+
13
+ def width
14
+ bit_field.width
15
+ end
16
+
17
+ def mask
18
+ hex((1 << width) - 1)
19
+ end
20
+
21
+ def define_offset_macro
22
+ if bit_field.sequential?
23
+ bit_field.sequence_size.times do |i|
24
+ define_macro("#{full_name}_bit_offset_#{i}", bit_field.lsb(i))
25
+ end
26
+ else
27
+ define_macro("#{full_name}_bit_offset", bit_field.lsb)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ class Component < Core::OutputBase::Component
6
+ def macro_definitions
7
+ [
8
+ @features.each_value.map(&:macro_definitions),
9
+ @children.map(&:macro_definitions)
10
+ ].flatten
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ class ComponentFactory < Core::OutputBase::SourceFileComponentFactory
6
+ end
7
+
8
+ class FeatureFactory < Core::OutputBase::FeatureFactory
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ class Feature < Core::OutputBase::Feature
6
+ include Utility
7
+
8
+ def macro_definitions
9
+ @macro_definitions ||= []
10
+ end
11
+
12
+ private
13
+
14
+ def define_macro(name, value = nil)
15
+ macro_definitions <<
16
+ Utility::MacroDefinition.new(name.upcase, value)
17
+ end
18
+
19
+ def full_name(separator = '_')
20
+ [register_block.name, component.full_name(separator)].join(separator)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:register, :c_header) do
4
+ c_header do
5
+ pre_build do
6
+ if register.width > 64
7
+ message =
8
+ 'register of which width is wider than 64 bits is not allowed: ' \
9
+ "#{full_name('.')} width #{register.width}"
10
+ raise RgGen::Core::RegisterMap::RegisterMapError.new(message)
11
+ end
12
+ end
13
+
14
+ build do
15
+ define_macro("#{full_name}_byte_width", byte_width)
16
+ define_macro("#{full_name}_byte_size", byte_size)
17
+ define_array_macros if array?
18
+ define_offset_address_macros
19
+ end
20
+
21
+ private
22
+
23
+ def byte_width
24
+ register.byte_width
25
+ end
26
+
27
+ def byte_size
28
+ array_size_upper_layer.inject(1, :*) * register.byte_size
29
+ end
30
+
31
+ def array?
32
+ register_files.any?(&:array?) || register.array?
33
+ end
34
+
35
+ def define_array_macros
36
+ size_list = array_size
37
+ define_macro("#{full_name}_array_dimension", size_list.size)
38
+ size_list.each_with_index do |size, i|
39
+ define_macro("#{full_name}_array_size_#{i}", size)
40
+ end
41
+ end
42
+
43
+ def define_offset_address_macros
44
+ if array?
45
+ address_list.zip(array_suffix) do |address, suffix|
46
+ define_macro("#{full_name}_byte_offset_#{suffix}", hex(address))
47
+ end
48
+ else
49
+ define_macro("#{full_name}_byte_offset", hex(address_list.first))
50
+ end
51
+ end
52
+
53
+ def address_list
54
+ upper_address_list = register_file&.expanded_offset_addresses || [0]
55
+ upper_address_list.product(local_address_list).map(&:sum)
56
+ end
57
+
58
+ def local_address_list
59
+ Array.new(register.count) do |i|
60
+ if register.settings[:support_shared_address]
61
+ register.offset_address
62
+ else
63
+ register.offset_address + register.byte_width * i
64
+ end
65
+ end
66
+ end
67
+
68
+ def array_suffix
69
+ index_list = array_size.map { |size| size.times.to_a }
70
+ index_list.first.product(*index_list[1..]).map { |index| index.join('_') }
71
+ end
72
+
73
+ def array_size_upper_layer
74
+ register_files.flat_map(&:array_size).compact
75
+ end
76
+
77
+ def array_size
78
+ [*register_files, register].flat_map(&:array_size).compact
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:register_block, :c_header) do
4
+ c_header do
5
+ write_file '<%= register_block.name %>.h' do |f|
6
+ f.include_guard
7
+ f.body do |code|
8
+ register_block.macro_definitions.each do |macro|
9
+ code << macro << nl
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rggen/c_header'
4
+
5
+ RgGen.register_plugin RgGen::CHeader do |builder|
6
+ builder.enable :register_block, [:c_header]
7
+ builder.enable :register, [:c_header]
8
+ builder.enable :bit_field, [:c_header]
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ module Utility
6
+ class MacroDefinition
7
+ def initialize(name, value = nil)
8
+ @name = name
9
+ @value = value
10
+ end
11
+
12
+ def to_s
13
+ @value && "#define #{@name} #{@value}" || "#define #{@name}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ class SourceFile < Core::Utility::CodeUtility::SourceFile
6
+ ifndef_keyword '#ifndef'
7
+ endif_keyword '#endif'
8
+ define_keyword '#define'
9
+ include_keyword '#include'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ module Utility
6
+ include Core::Utility::CodeUtility
7
+
8
+ def create_blank_file(path)
9
+ SourceFile.new(path)
10
+ end
11
+
12
+ private
13
+
14
+ def hex(value)
15
+ format('0x%x', value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module CHeader
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'c_header/version'
4
+ require_relative 'c_header/utility/macro_definition'
5
+ require_relative 'c_header/utility/source_file'
6
+ require_relative 'c_header/utility'
7
+ require_relative 'c_header/feature'
8
+ require_relative 'c_header/component'
9
+ require_relative 'c_header/factories'
10
+
11
+ module RgGen
12
+ module CHeader
13
+ extend Core::Plugin
14
+
15
+ setup_plugin :'rggen-c-header' do |plugin|
16
+ plugin.register_component :c_header do
17
+ component Component, ComponentFactory
18
+ feature Feature, FeatureFactory
19
+ end
20
+
21
+ plugin.files [
22
+ 'c_header/bit_field/c_header',
23
+ 'c_header/register/c_header',
24
+ 'c_header/register_block/c_header'
25
+ ]
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rggen-c-header
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: 2022-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: C header file writer plugin for RgGen
28
+ email:
29
+ - rggen@googlegroups.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CODE_OF_CONDUCT.md
35
+ - LICENSE
36
+ - README.md
37
+ - lib/rggen/c_header.rb
38
+ - lib/rggen/c_header/bit_field/c_header.rb
39
+ - lib/rggen/c_header/component.rb
40
+ - lib/rggen/c_header/factories.rb
41
+ - lib/rggen/c_header/feature.rb
42
+ - lib/rggen/c_header/register/c_header.rb
43
+ - lib/rggen/c_header/register_block/c_header.rb
44
+ - lib/rggen/c_header/setup.rb
45
+ - lib/rggen/c_header/utility.rb
46
+ - lib/rggen/c_header/utility/macro_definition.rb
47
+ - lib/rggen/c_header/utility/source_file.rb
48
+ - lib/rggen/c_header/version.rb
49
+ homepage: https://github.com/rggen/rggen-c-header
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ bug_tracker_uri: https://github.com/rggen/rggen-c-header/issues
54
+ mailing_list_uri: https://groups.google.com/d/forum/rggen
55
+ rubygems_mfa_required: 'true'
56
+ source_code_uri: https://github.com/rggen/rggen-c-header
57
+ wiki_uri: https://github.com/rggen/rggen/wiki
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.6.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.3.3
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: rggen-c-header-0.1.0
77
+ test_files: []