rggen 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rggen.rb +2 -0
- data/lib/rggen/base/item.rb +2 -2
- data/lib/rggen/base/item_factory.rb +4 -5
- data/lib/rggen/builder/builder.rb +2 -2
- data/lib/rggen/builder/item_store.rb +3 -3
- data/lib/rggen/builder/list_item_entry.rb +2 -2
- data/lib/rggen/builtins/bit_field/type.rb +1 -1
- data/lib/rggen/builtins/loaders/register_map/csv_loader.rb +1 -1
- data/lib/rggen/builtins/register/offset_address.rb +1 -1
- data/lib/rggen/builtins/register/rtl_top.rb +1 -1
- data/lib/rggen/builtins/register/type.rb +2 -2
- data/lib/rggen/builtins/register/types/indirect.rb +4 -6
- data/lib/rggen/builtins/register_block/host_if.rb +1 -1
- data/lib/rggen/builtins/register_block/irq_controller.rb +7 -8
- data/lib/rggen/core_components/c_utility/data_structure_definition.rb +3 -5
- data/lib/rggen/core_components/code_utility.rb +6 -6
- data/lib/rggen/core_components/code_utility/code_block.rb +1 -1
- data/lib/rggen/core_components/code_utility/source_file.rb +4 -4
- data/lib/rggen/core_components/configuration/configuration_factory.rb +1 -1
- data/lib/rggen/core_components/configuration/raise_error.rb +1 -1
- data/lib/rggen/core_components/register_map/loader.rb +2 -4
- data/lib/rggen/core_components/register_map/raise_error.rb +1 -1
- data/lib/rggen/core_components/register_map/register_map_factory.rb +3 -6
- data/lib/rggen/core_components/verilog_utility/structure_definition.rb +3 -3
- data/lib/rggen/generator.rb +5 -154
- data/lib/rggen/input_base/loader.rb +1 -1
- data/lib/rggen/option_switches.rb +60 -0
- data/lib/rggen/options.rb +97 -0
- data/lib/rggen/output_base/component.rb +11 -9
- data/lib/rggen/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cf6420ad53a229357bd8445db927fe2c8c23d32
|
4
|
+
data.tar.gz: 960ab1258d4dc08dc4f79679b7095f5d7a93dd9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3732f7f3ee3826b0594a03b9595172898229a26c0165a3f49a8777582a1fa7f8075a903a0d6ac6f76d89e81bbfca823e9a9e9f128f2ef964bcc0d03334367aa6
|
7
|
+
data.tar.gz: b716700cfe79c466b05edf9f47b56ca6706089e09b613d24f8c29cd03d49b20aa1434c0a93e02982c48d902f6ae9e9562b5663b938ca4b69ef197bd05567b9c9
|
data/lib/rggen.rb
CHANGED
@@ -49,6 +49,8 @@ module RgGen
|
|
49
49
|
require_relative 'rggen/builder/category'
|
50
50
|
require_relative 'rggen/builder/builder'
|
51
51
|
|
52
|
+
require_relative 'rggen/options'
|
53
|
+
require_relative 'rggen/option_switches'
|
52
54
|
require_relative 'rggen/generator'
|
53
55
|
|
54
56
|
require_relative 'rggen/commands'
|
data/lib/rggen/base/item.rb
CHANGED
@@ -13,10 +13,10 @@ module RgGen
|
|
13
13
|
define_method(:available?, &body)
|
14
14
|
end
|
15
15
|
|
16
|
-
def inherit_class_instance_variable(variable_name, klass
|
16
|
+
def inherit_class_instance_variable(variable_name, klass)
|
17
17
|
return unless klass.instance_variable_defined?(variable_name)
|
18
18
|
v = klass.instance_variable_get(variable_name)
|
19
|
-
v =
|
19
|
+
v = yield(v) if block_given?
|
20
20
|
instance_variable_set(variable_name, v)
|
21
21
|
end
|
22
22
|
end
|
@@ -8,12 +8,11 @@ module RgGen
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def create_item(owner, *args
|
11
|
+
def create_item(owner, *args)
|
12
12
|
item = create_item_object(owner, *args)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
return unless item.available?
|
14
|
+
yield item if block_given?
|
15
|
+
owner.add_item(item)
|
17
16
|
end
|
18
17
|
|
19
18
|
def create_item_object(owner, *args)
|
@@ -10,10 +10,10 @@ module RgGen
|
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@stores = Hash.new do |_, component_name|
|
13
|
-
|
13
|
+
raise RgGen::BuilderError, "unknown component: #{component_name}"
|
14
14
|
end
|
15
15
|
@categories = Hash.new do |_, category_name|
|
16
|
-
|
16
|
+
raise RgGen::BuilderError, "unknown category: #{category_name}"
|
17
17
|
end
|
18
18
|
INITIAL_CATEGORIES.each do |category_name|
|
19
19
|
@categories[category_name] = Category.new
|
@@ -32,7 +32,7 @@ module RgGen
|
|
32
32
|
enable_list_item(args[0], args[1])
|
33
33
|
else
|
34
34
|
message = "wrong number of arguments (#{args.size} for 1..2)"
|
35
|
-
|
35
|
+
raise ArgumentError, message
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -65,7 +65,7 @@ module RgGen
|
|
65
65
|
def define_list_item_class(list_name, item_name, context, body)
|
66
66
|
unless @list_item_entries.key?(list_name)
|
67
67
|
message = "undefined list item entry: #{list_name}"
|
68
|
-
|
68
|
+
raise RgGen::BuilderError, message
|
69
69
|
end
|
70
70
|
entry = @list_item_entries[list_name]
|
71
71
|
entry.define_list_item(item_name, context, &body)
|
@@ -76,7 +76,7 @@ module RgGen
|
|
76
76
|
next if @enabled_entries.include?(entry_name)
|
77
77
|
next unless @simple_item_entries.key?(entry_name) ||
|
78
78
|
@list_item_entries.key?(entry_name)
|
79
|
-
@enabled_entries
|
79
|
+
@enabled_entries << entry_name
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -36,7 +36,7 @@ module RgGen
|
|
36
36
|
klass = Class.new(item_base)
|
37
37
|
unless context.nil?
|
38
38
|
if item_base.private_method_defined?(:shared_context)
|
39
|
-
|
39
|
+
raise BuilderError, 'base class already has #shared_context'
|
40
40
|
end
|
41
41
|
set_context(klass, context)
|
42
42
|
end
|
@@ -48,7 +48,7 @@ module RgGen
|
|
48
48
|
Array(item_or_items).each do |item|
|
49
49
|
next unless @items.key?(item)
|
50
50
|
next if @enabled_items.include?(item)
|
51
|
-
@enabled_items
|
51
|
+
@enabled_items << item
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -36,7 +36,7 @@ simple_item :register, :offset_address do
|
|
36
36
|
|
37
37
|
def check_start_end_adderss_relation(cell)
|
38
38
|
return if start_address < end_address
|
39
|
-
return if [configuration.byte_width, byte_size].all? { |v| v == 1}
|
39
|
+
return if [configuration.byte_width, byte_size].all? { |v| v == 1 }
|
40
40
|
error "start address is equal to or greater than end address: #{cell}"
|
41
41
|
end
|
42
42
|
|
@@ -142,7 +142,7 @@ list_item :register, :type do
|
|
142
142
|
factory do
|
143
143
|
define_struct :cell_value, [:type, :options] do
|
144
144
|
def empty?
|
145
|
-
|
145
|
+
type.nil?
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -229,7 +229,7 @@ list_item :register, :type do
|
|
229
229
|
|
230
230
|
def valid_bits_value
|
231
231
|
actual_bit_fields.inject(0) do |bits, bit_field|
|
232
|
-
bits
|
232
|
+
bits | (((1 << bit_field.width) - 1) << bit_field.lsb)
|
233
233
|
end
|
234
234
|
end
|
235
235
|
end
|
@@ -55,9 +55,7 @@ list_item :register, :type, :indirect do
|
|
55
55
|
:check_using_non_existing_index,
|
56
56
|
:check_using_own_bit_field_for_index,
|
57
57
|
:check_using_arrayed_bit_field_for_index
|
58
|
-
].each
|
59
|
-
send(checker, entry)
|
60
|
-
end
|
58
|
+
].each { |checker| send(checker, entry) }
|
61
59
|
end
|
62
60
|
|
63
61
|
def check_using_same_index_more_than_once(entry)
|
@@ -82,7 +80,7 @@ list_item :register, :type, :indirect do
|
|
82
80
|
|
83
81
|
def check_number_of_array_indexes
|
84
82
|
return if array_indexes.size == size_of_dimensions
|
85
|
-
error
|
83
|
+
error 'not match size of array dimensions and number of array indexes'
|
86
84
|
end
|
87
85
|
|
88
86
|
def check_array_index_values
|
@@ -94,7 +92,7 @@ list_item :register, :type, :indirect do
|
|
94
92
|
end
|
95
93
|
|
96
94
|
def check_fixed_value_index_values
|
97
|
-
fixed_value_indexes.
|
95
|
+
fixed_value_indexes.each do |entry|
|
98
96
|
next if entry.value <= max_value(entry.name)
|
99
97
|
error "index value(#{entry.value}) is greater thatn " \
|
100
98
|
"maximum value of #{entry.name}(#{max_value(entry.name)})"
|
@@ -114,7 +112,7 @@ list_item :register, :type, :indirect do
|
|
114
112
|
end
|
115
113
|
|
116
114
|
def fixed_value_indexes
|
117
|
-
indexes.select
|
115
|
+
indexes.select(&:value)
|
118
116
|
end
|
119
117
|
|
120
118
|
def size_of_dimensions
|
@@ -1,6 +1,6 @@
|
|
1
1
|
simple_item :register_block, :irq_controller do
|
2
2
|
rtl do
|
3
|
-
available? {
|
3
|
+
available? { register_block.source.bit_fields.any?(&:irq?) }
|
4
4
|
|
5
5
|
build do
|
6
6
|
output :register_block, :irq, width: 1 , name: 'o_irq'
|
@@ -14,11 +14,6 @@ simple_item :register_block, :irq_controller do
|
|
14
14
|
code << process_template
|
15
15
|
end
|
16
16
|
|
17
|
-
def total_interrupts
|
18
|
-
@total_interrupts ||=
|
19
|
-
register_block.source.bit_fields.count(&:irq?)
|
20
|
-
end
|
21
|
-
|
22
17
|
def assign_ier
|
23
18
|
assign(ier, concat(ier_fields.map(&:value)))
|
24
19
|
end
|
@@ -28,11 +23,11 @@ simple_item :register_block, :irq_controller do
|
|
28
23
|
end
|
29
24
|
|
30
25
|
def isr_fields
|
31
|
-
register_block.bit_fields.select(&:irq?)
|
26
|
+
@isr_fields ||= register_block.bit_fields.select(&:irq?)
|
32
27
|
end
|
33
28
|
|
34
29
|
def ier_fields
|
35
|
-
isr_fields.each_with_object([]) do |isr_field, fields|
|
30
|
+
@ier_fields ||= isr_fields.each_with_object([]) do |isr_field, fields|
|
36
31
|
fields << find_ier_field(isr_field.reference)
|
37
32
|
end
|
38
33
|
end
|
@@ -40,5 +35,9 @@ simple_item :register_block, :irq_controller do
|
|
40
35
|
def find_ier_field(reference)
|
41
36
|
register_block.bit_fields.find_by(name: reference.name)
|
42
37
|
end
|
38
|
+
|
39
|
+
def total_interrupts
|
40
|
+
@total_interrupts ||= isr_fields.sum(0, &:width)
|
41
|
+
end
|
43
42
|
end
|
44
43
|
end
|
@@ -3,10 +3,10 @@ module RgGen
|
|
3
3
|
class DataStructureDefinition
|
4
4
|
include CodeUtility
|
5
5
|
|
6
|
-
def initialize(type_keyword, type_name
|
6
|
+
def initialize(type_keyword, type_name)
|
7
7
|
@type_keyword = type_keyword
|
8
8
|
@type_name = type_name
|
9
|
-
|
9
|
+
yield(self) if block_given?
|
10
10
|
end
|
11
11
|
|
12
12
|
attr_setter :members
|
@@ -34,9 +34,7 @@ module RgGen
|
|
34
34
|
|
35
35
|
def body_code(code)
|
36
36
|
indent(code, 2) do
|
37
|
-
@members.each
|
38
|
-
code << member << semicolon << nl
|
39
|
-
end
|
37
|
+
@members.each { |member| code << member << semicolon << nl }
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -28,24 +28,24 @@ module RgGen
|
|
28
28
|
"\"#{expression}\""
|
29
29
|
end
|
30
30
|
|
31
|
-
def code_block(indent_size = 0
|
31
|
+
def code_block(indent_size = 0)
|
32
32
|
CodeBlock.new.tap do |code|
|
33
33
|
code.indent = indent_size
|
34
|
-
|
34
|
+
yield(code) if block_given?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def indent(code_block, indent_size
|
38
|
+
def indent(code_block, indent_size)
|
39
39
|
code_block << nl unless code_block.last_line_empty?
|
40
40
|
code_block.indent += indent_size
|
41
|
-
|
41
|
+
yield if block_given?
|
42
42
|
code_block << nl unless code_block.last_line_empty?
|
43
43
|
code_block.indent -= indent_size
|
44
44
|
end
|
45
45
|
|
46
|
-
def wrap(code_block, head, tail
|
46
|
+
def wrap(code_block, head, tail)
|
47
47
|
code_block << head
|
48
|
-
|
48
|
+
yield if block_given?
|
49
49
|
code_block << tail
|
50
50
|
end
|
51
51
|
|
@@ -10,9 +10,9 @@ module RgGen
|
|
10
10
|
attr_setter :include_keyword
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(path
|
13
|
+
def initialize(path)
|
14
14
|
@path = path
|
15
|
-
|
15
|
+
yield(self) if block_given?
|
16
16
|
end
|
17
17
|
|
18
18
|
attr_reader :path
|
@@ -62,7 +62,7 @@ module RgGen
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def default_guard_macro(prefix, suffix)
|
65
|
-
|
65
|
+
"#{prefix}#{path.basename.to_s.upcase.gsub(/\W/, '_')}#{suffix}"
|
66
66
|
end
|
67
67
|
|
68
68
|
def include_guard_header
|
@@ -73,7 +73,7 @@ module RgGen
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def include_guard_footer
|
76
|
-
@guard_macro &&
|
76
|
+
@guard_macro && ->(c) { c << self.class.endif_keyword << nl }
|
77
77
|
end
|
78
78
|
|
79
79
|
def include_files_block
|
@@ -3,10 +3,8 @@ module RgGen
|
|
3
3
|
class Loader < InputBase::Loader
|
4
4
|
private
|
5
5
|
|
6
|
-
def create_map(file
|
7
|
-
|
8
|
-
block.call(map) if block_given?
|
9
|
-
map
|
6
|
+
def create_map(file)
|
7
|
+
GenericMap.new(file).tap { |m| yield(m) if block_given? }
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -9,12 +9,9 @@ module RgGen
|
|
9
9
|
|
10
10
|
def load(file)
|
11
11
|
map = load_file(file)
|
12
|
-
if map.is_a?(GenericMap)
|
13
|
-
|
14
|
-
|
15
|
-
message = "GenericMap type required for register map: #{map.class}"
|
16
|
-
fail RgGen::LoadError, message
|
17
|
-
end
|
12
|
+
return map if map.is_a?(GenericMap)
|
13
|
+
message = "GenericMap type required for register map: #{map.class}"
|
14
|
+
raise RgGen::LoadError, message
|
18
15
|
end
|
19
16
|
end
|
20
17
|
end
|
@@ -3,9 +3,9 @@ module RgGen
|
|
3
3
|
class StructureDefinition
|
4
4
|
include CodeUtility
|
5
5
|
|
6
|
-
def initialize(name
|
6
|
+
def initialize(name)
|
7
7
|
@name = name
|
8
|
-
|
8
|
+
yield(self) if block_given?
|
9
9
|
end
|
10
10
|
|
11
11
|
def body(&block)
|
@@ -43,7 +43,7 @@ module RgGen
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def body_code?
|
46
|
-
@bodies
|
46
|
+
!(@bodies.nil? || @bodies.empty?)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/rggen/generator.rb
CHANGED
@@ -1,139 +1,6 @@
|
|
1
1
|
module RgGen
|
2
2
|
class Generator
|
3
|
-
Context = Struct.new(:options, :configuration, :register_map)
|
4
|
-
def initialize
|
5
|
-
super
|
6
|
-
self.options = {}
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Option
|
11
|
-
def initialize(kind)
|
12
|
-
@kind = kind
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_accessor :short
|
16
|
-
attr_accessor :long
|
17
|
-
attr_accessor :class
|
18
|
-
attr_writer :default
|
19
|
-
attr_writer :description
|
20
|
-
attr_writer :body
|
21
|
-
|
22
|
-
def on(parser, options)
|
23
|
-
options[@kind] = default_value if default_value
|
24
|
-
parser.on(*args) do |value|
|
25
|
-
parser.instance_exec(value, options, @kind, &body)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def args
|
30
|
-
[@short, @long, @class, description].compact
|
31
|
-
end
|
32
|
-
|
33
|
-
def description
|
34
|
-
return nil unless @description || default_value
|
35
|
-
d = ''
|
36
|
-
d << @description.to_s
|
37
|
-
d << "(default: #{default_value})" if default_value
|
38
|
-
d
|
39
|
-
end
|
40
|
-
|
41
|
-
def body
|
42
|
-
@body || default_body
|
43
|
-
end
|
44
|
-
|
45
|
-
def default_body
|
46
|
-
proc do |value, options, kind|
|
47
|
-
options[kind] = value
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def default_value
|
52
|
-
return unless @default
|
53
|
-
case @default
|
54
|
-
when Proc
|
55
|
-
@default.call
|
56
|
-
else
|
57
|
-
@default
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class << self
|
63
|
-
def options
|
64
|
-
@options ||= []
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def add_option(kind, &body)
|
70
|
-
options << Option.new(kind)
|
71
|
-
body.call(options.last)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
add_option :setup do |option|
|
76
|
-
option.long = '--setup FILE'
|
77
|
-
option.default = proc do
|
78
|
-
ENV['RGGEN_DEFAULT_SETUP_FILE'] ||
|
79
|
-
File.join(RGGEN_HOME, 'setup', 'default.rb')
|
80
|
-
end
|
81
|
-
option.description = 'Specify a setup file to set up RgGen tool'
|
82
|
-
end
|
83
|
-
|
84
|
-
add_option :configuration do |option|
|
85
|
-
option.short = '-c'
|
86
|
-
option.long = '--configuration FILE'
|
87
|
-
option.default = proc { ENV['RGGEN_DEFAULT_CONFIGURATION_FILE'] }
|
88
|
-
option.description = 'Specify a configuration file ' \
|
89
|
-
'for generated source code'
|
90
|
-
end
|
91
|
-
|
92
|
-
add_option :output do |option|
|
93
|
-
option.short = '-o'
|
94
|
-
option.long = '--output DIR'
|
95
|
-
option.default = '.'
|
96
|
-
option.description = 'Specify output directory'
|
97
|
-
end
|
98
|
-
|
99
|
-
add_option :except do |option|
|
100
|
-
option.long = '--except [TYPE1,TYPE2,...]'
|
101
|
-
option.class = Array
|
102
|
-
option.description = 'Disable the given output file type(s)'
|
103
|
-
option.body = proc do |value, options, kind|
|
104
|
-
options[kind] ||= []
|
105
|
-
options[kind].concat(value.map(&:to_sym))
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
add_option :show_home do |option|
|
110
|
-
option.long = '--show-home'
|
111
|
-
option.description = 'Display the path of RgGen tool home directory'
|
112
|
-
option.body = proc do
|
113
|
-
puts RGGEN_HOME
|
114
|
-
exit
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
add_option :version do |option|
|
119
|
-
option.short = '-v'
|
120
|
-
option.long = '--version'
|
121
|
-
option.description = 'Display the version'
|
122
|
-
option.body = proc do
|
123
|
-
puts ver
|
124
|
-
exit
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
add_option :help do |option|
|
129
|
-
option.short = '-h'
|
130
|
-
option.long = '--help'
|
131
|
-
option.description = 'Display this message'
|
132
|
-
option.body = proc do
|
133
|
-
puts help
|
134
|
-
exit
|
135
|
-
end
|
136
|
-
end
|
3
|
+
Context = Struct.new(:options, :configuration, :register_map)
|
137
4
|
|
138
5
|
def run(argv)
|
139
6
|
Context.new.tap do |context|
|
@@ -150,22 +17,7 @@ module RgGen
|
|
150
17
|
private
|
151
18
|
|
152
19
|
def parse_options(argv, context)
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
def option_parser(options)
|
157
|
-
OptionParser.new do |parser|
|
158
|
-
parser.version = RgGen::VERSION
|
159
|
-
parser.program_name = 'rggen'
|
160
|
-
parser.banner = 'Usage: rggen [options] REGISTER_MAP'
|
161
|
-
add_option_switches(parser, options)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def add_option_switches(parser, options)
|
166
|
-
self.class.options.each do |option|
|
167
|
-
option.on(parser, options)
|
168
|
-
end
|
20
|
+
context.options = Options.parse(argv)
|
169
21
|
end
|
170
22
|
|
171
23
|
def load_setup(context)
|
@@ -195,7 +47,7 @@ module RgGen
|
|
195
47
|
def write_files(context)
|
196
48
|
file_generators(context).each do |generator|
|
197
49
|
generator.write_file(context.options[:output])
|
198
|
-
end
|
50
|
+
end unless context.options[:load_only]
|
199
51
|
end
|
200
52
|
|
201
53
|
def file_generators(context)
|
@@ -207,9 +59,8 @@ module RgGen
|
|
207
59
|
end
|
208
60
|
|
209
61
|
def available_output_components(context)
|
210
|
-
|
211
|
-
|
212
|
-
except.nil? || except.exclude?(component)
|
62
|
+
RgGen.builder.stored_output_components.reject do |component|
|
63
|
+
context.options[:disable].include?(component)
|
213
64
|
end
|
214
65
|
end
|
215
66
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RgGen
|
2
|
+
Options.add_option_switch :setup do
|
3
|
+
long '--setup FILE'
|
4
|
+
description 'Specify a setup file to set up RgGen tool'
|
5
|
+
default { ENV['RGGEN_DEFAULT_SETUP_FILE'] || default_setup }
|
6
|
+
|
7
|
+
def default_setup
|
8
|
+
File.join(RgGen::RGGEN_HOME, 'setup', 'default.rb')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Options.add_option_switch :configuration do
|
13
|
+
short '-c'
|
14
|
+
long '--configuration FILE'
|
15
|
+
description 'Specify a configuration file for generated source code'
|
16
|
+
default { ENV['RGGEN_DEFAULT_CONFIGURATION_FILE'] }
|
17
|
+
end
|
18
|
+
|
19
|
+
Options.add_option_switch :output do
|
20
|
+
short '-o'
|
21
|
+
long '--output DIR'
|
22
|
+
description 'Specify output directory'
|
23
|
+
default '.'
|
24
|
+
end
|
25
|
+
|
26
|
+
Options.add_option_switch :load_only do
|
27
|
+
long '--load-only'
|
28
|
+
option_class TrueClass
|
29
|
+
description 'Load input files only if specified'
|
30
|
+
default false
|
31
|
+
end
|
32
|
+
|
33
|
+
Options.add_option_switch :disable do
|
34
|
+
long '--disable TYPE1[,TYPE2,...]'
|
35
|
+
option_class Array
|
36
|
+
description 'Disable the given output file type(s)'
|
37
|
+
default { [] }
|
38
|
+
body { |v, o, k| o[k].concat(v.map(&:to_sym)) }
|
39
|
+
end
|
40
|
+
|
41
|
+
Options.add_option_switch :show_home do
|
42
|
+
long '--show-home'
|
43
|
+
description 'Display the path of RgGen tool home directory'
|
44
|
+
body { puts RgGen::RGGEN_HOME; exit }
|
45
|
+
end
|
46
|
+
|
47
|
+
Options.add_option_switch :version do
|
48
|
+
short '-v'
|
49
|
+
long '--version'
|
50
|
+
description 'Display the version'
|
51
|
+
body { puts ver; exit }
|
52
|
+
end
|
53
|
+
|
54
|
+
Options.add_option_switch :help do
|
55
|
+
short '-h'
|
56
|
+
long '--help'
|
57
|
+
description 'Display this message'
|
58
|
+
body { puts help; exit }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module RgGen
|
2
|
+
class Options
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
class OptionSwitch
|
6
|
+
def initialize(kind)
|
7
|
+
@kind = kind
|
8
|
+
end
|
9
|
+
|
10
|
+
def on(parser, options)
|
11
|
+
parser.on(*args) do |value|
|
12
|
+
parser.instance_exec(value, options, @kind, &body)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_setter :short
|
17
|
+
attr_setter :long
|
18
|
+
attr_setter :option_class
|
19
|
+
|
20
|
+
def default(value = nil, &block)
|
21
|
+
if block_given?
|
22
|
+
@default = block
|
23
|
+
elsif value
|
24
|
+
@default = proc { value }
|
25
|
+
else
|
26
|
+
@default && @default.call
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def description(value = nil)
|
31
|
+
if value
|
32
|
+
@description = value
|
33
|
+
elsif @description || @default
|
34
|
+
''.tap do |d|
|
35
|
+
d << @description if @description
|
36
|
+
d << "(default: #{default})" if default
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def body(&block)
|
42
|
+
if block_given?
|
43
|
+
@body = block
|
44
|
+
else
|
45
|
+
@body || proc { |v, o, k| o[k] = v }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def args
|
52
|
+
[@short, @long, @option_class, description].compact
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class << self
|
57
|
+
def parse(args)
|
58
|
+
new.tap { |options| options.parse(args) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def option_switches
|
62
|
+
@option_switches ||= {}
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_option_switch(kind, &block)
|
66
|
+
option_switches[kind] = OptionSwitch.new(kind)
|
67
|
+
option_switches[kind].instance_exec(&block)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def_class_delegator :option_switches
|
72
|
+
def_delegator :@options, :[]
|
73
|
+
|
74
|
+
def initialize
|
75
|
+
@options = Hash.new { |h, k| h[k] = option_switches[k].default }
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse(args)
|
79
|
+
option_parser.parse!(args)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def option_parser
|
85
|
+
OptionParser.new do |parser|
|
86
|
+
parser.version = RgGen::VERSION
|
87
|
+
parser.program_name = 'rggen'
|
88
|
+
parser.banner = 'Usage: rggen [options] REGISTER_MAP'
|
89
|
+
define_option_switches(parser)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def define_option_switches(parser)
|
94
|
+
option_switches.each_value { |switch| switch.on(parser, @options) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -49,7 +49,7 @@ module RgGen
|
|
49
49
|
|
50
50
|
def generate_child_code(kind, mode, code)
|
51
51
|
children.inject(code) do |c, child|
|
52
|
-
child.generate_code(kind, mode,
|
52
|
+
child.generate_code(kind, mode, c)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -58,14 +58,16 @@ module RgGen
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def main_code_generator(mode)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
{
|
62
|
+
top_down: [
|
63
|
+
method(:generate_item_code ).curry[:generate_code],
|
64
|
+
method(:generate_child_code)
|
65
|
+
],
|
66
|
+
bottom_up: [
|
67
|
+
method(:generate_child_code),
|
68
|
+
method(:generate_item_code ).curry[:generate_code]
|
69
|
+
]
|
70
|
+
}[mode]
|
69
71
|
end
|
70
72
|
|
71
73
|
def post_code_generator
|
data/lib/rggen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rggen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: baby_erubis
|
@@ -109,8 +109,8 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.35'
|
111
111
|
description: |2
|
112
|
-
RgGen is a code
|
113
|
-
It will automatically generate source code for control registers
|
112
|
+
RgGen is a code generator tool for SoC/IP/FPGA/RTL engineers.
|
113
|
+
It will automatically generate source code for control/status registers, e.g. RTL, UVM RAL model, C header file, from its register map document.
|
114
114
|
Also RgGen is customizable so you can build your specific generate tool.
|
115
115
|
email:
|
116
116
|
- taichi730@gmail.com
|
@@ -266,6 +266,8 @@ files:
|
|
266
266
|
- lib/rggen/input_base/item_factory.rb
|
267
267
|
- lib/rggen/input_base/loader.rb
|
268
268
|
- lib/rggen/input_base/regexp_patterns.rb
|
269
|
+
- lib/rggen/option_switches.rb
|
270
|
+
- lib/rggen/options.rb
|
269
271
|
- lib/rggen/output_base/code_generator.rb
|
270
272
|
- lib/rggen/output_base/component.rb
|
271
273
|
- lib/rggen/output_base/component_factory.rb
|