Module: OrigenTesters::Generator
- Extended by:
- ActiveSupport::Concern
- Included in:
- Doc::Generator::Flow, IGXLBasedTester::Base::Flow, IGXLBasedTester::Base::Patgroups, IGXLBasedTester::Base::Patsets, IGXLBasedTester::Base::Patsubrs, IGXLBasedTester::Base::TestInstances, SmartestBasedTester::Base::Flow, SmartestBasedTester::Base::PatternCompiler, SmartestBasedTester::Base::PatternMaster
- Defined in:
- lib/origen_testers/generator.rb,
lib/origen_testers/generator/placeholder.rb,
lib/origen_testers/generator/identity_map.rb,
lib/origen_testers/generator/test_numberer.rb,
lib/origen_testers/generator/flow_control_api.rb
Overview
This module should be included in all test program component generators and provides the required integration with the Flow.create and Resources.create methods
Defined Under Namespace
Modules: ClassMethods, FlowControlAPI
Classes: IdentityMap, Placeholder, TestNumberer
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.execute_source(file) ⇒ Object
The program source files are executed by eval to allow the tester to filter the source contents before executing. For examples the doc tester replaces all comments with a method call containing each comment so that they can be captured.
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/origen_testers/generator.rb', line 22
def self.execute_source(file)
if Origen.interface.respond_to?(:filter_source)
File.open(file) do |f|
src = f.read
src = Origen.interface.filter_source(src)
eval(src, global_binding)
end
else
load file
end
end
|
Instance Method Details
#close(options = {}) ⇒ Object
Expands and inserts all render statements that have been encountered
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/origen_testers/generator.rb', line 45
def close(options = {})
Origen.profile "closing #{filename}" do
base_collection = collection
base_collection.each_with_index do |item, i|
if item.is_a? Placeholder
if item.type == :render
txt = ''
Origen.file_handler.preserve_current_file do
Origen.file_handler.default_extension = file_extension
placeholder = compiler.render(item.file, item.options)
txt = compiler.insert(placeholder).chomp
end
base_collection[i] = txt
else
fail 'Unknown placeholder encountered!'
end
end
end
@collection = base_collection.flatten.compact
on_close(options)
end
end
|
#collection ⇒ Object
All generators must implement a collection method that returns an array containing the generated items
134
135
136
|
# File 'lib/origen_testers/generator.rb', line 134
def collection
@collection ||= []
end
|
#collection=(array) ⇒ Object
138
139
140
|
# File 'lib/origen_testers/generator.rb', line 138
def collection=(array)
@collection = array
end
|
#compiler ⇒ Object
92
93
94
|
# File 'lib/origen_testers/generator.rb', line 92
def compiler
Origen.generator.compiler
end
|
#current_dir ⇒ Object
Returns the directory of the current source file being generated
73
74
75
76
77
78
79
|
# File 'lib/origen_testers/generator.rb', line 73
def current_dir
if file_pipeline.empty?
Origen.file_handler.base_directory
else
Pathname.new(file_pipeline.last).dirname
end
end
|
#dont_diff=(val) ⇒ Object
128
129
130
|
# File 'lib/origen_testers/generator.rb', line 128
def dont_diff=(val)
@dont_diff = val
end
|
#file_extension ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/origen_testers/generator.rb', line 142
def file_extension
if defined? self.class::OUTPUT_EXTENSION
self.class::OUTPUT_EXTENSION
elsif defined? self.class::TEMPLATE
p = Pathname.new(self.class::TEMPLATE)
ext = p.basename('.erb').extname
ext.empty? ? 'txt' : ext
else
'txt'
end
end
|
#file_pipeline ⇒ Object
68
69
70
|
# File 'lib/origen_testers/generator.rb', line 68
def file_pipeline
@@file_pipeline ||= []
end
|
#filename(options = {}) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/origen_testers/generator.rb', line 100
def filename(options = {})
options = {
include_extension: true
}.merge(options)
name = (@filename || Origen.file_handler.current_file.basename('.rb')).to_s
if Origen.config.program_prefix
unless name =~ /^#{Origen.config.program_prefix}/i
name = "#{Origen.config.program_prefix}_#{name}"
end
end
f = Pathname.new(name).basename
ext = f.extname.empty? ? file_extension : f.extname
body = f.basename(".#{ext}").to_s
body.gsub!('_resources', '')
if defined? self.class::OUTPUT_POSTFIX
unless body =~ /#{self.class::OUTPUT_POSTFIX}$/i
body = "#{body}_#{self.class::OUTPUT_POSTFIX}"
end
end
ext = ".#{ext}" unless ext =~ /^\./
if options[:include_extension]
"#{body}#{ext}"
else
"#{body}"
end
end
|
#filename=(name) ⇒ Object
96
97
98
|
# File 'lib/origen_testers/generator.rb', line 96
def filename=(name)
@filename = name
end
|
#finalize(options = {}) ⇒ Object
Redefine this in the parent which includes this module if you want anything to occur after all tests have been generated but before file writing starts.
89
90
|
# File 'lib/origen_testers/generator.rb', line 89
def finalize(options = {})
end
|
#identity_map ⇒ Object
261
262
263
|
# File 'lib/origen_testers/generator.rb', line 261
def identity_map Origen.interface.identity_map
end
|
#import(file, options = {}) ⇒ Object
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/origen_testers/generator.rb', line 228
def import(file, options = {})
file = Pathname.new(file).absolute? ? file : "#{current_dir}/#{file}"
file = Origen.file_handler.clean_path_to_sub_program(file)
base_collection = collection
@collection = []
Origen.generator.option_pipeline << options
file_pipeline << file
::OrigenTesters::Generator.execute_source(file)
file_pipeline.pop
base_collection << @collection
@collection = base_collection.flatten
end
|
#inhibit_output ⇒ Object
When called on a generator no output files will be created from it
35
36
37
|
# File 'lib/origen_testers/generator.rb', line 35
def inhibit_output
@inhibit_output = true
end
|
#on_close(options = {}) ⇒ Object
Redefine this in the parent which includes this module if you want anything to occur after closing the generator (expanding all render/import statements) but before writing to a file.
84
85
|
# File 'lib/origen_testers/generator.rb', line 84
def on_close(options = {})
end
|
#output_file ⇒ Object
214
215
216
217
218
219
220
221
222
|
# File 'lib/origen_testers/generator.rb', line 214
def output_file
if respond_to? :subdirectory
p = Pathname.new("#{Origen.file_handler.output_directory}/#{subdirectory}/#{filename}")
FileUtils.mkdir_p p.dirname.to_s unless p.dirname.exist?
p
else
Pathname.new("#{Origen.file_handler.output_directory}/#{filename}")
end
end
|
#output_inhibited? ⇒ Boolean
Returns true if the output files from this generator will be inhibited
40
41
42
|
# File 'lib/origen_testers/generator.rb', line 40
def output_inhibited?
@inhibit_output
end
|
265
266
267
|
# File 'lib/origen_testers/generator.rb', line 265
def platform
Origen.interface.platform
end
|
#reference_file ⇒ Object
224
225
226
|
# File 'lib/origen_testers/generator.rb', line 224
def reference_file
Pathname.new("#{Origen.file_handler.reference_directory}/#{filename}")
end
|
#render(file, options = {}) ⇒ Object
241
242
243
244
245
246
247
|
# File 'lib/origen_testers/generator.rb', line 241
def render(file, options = {})
if options.delete(:_inline)
super Origen.file_handler.clean_path_to_sub_template(file), options
else
collection << Placeholder.new(:render, file, options)
end
end
|
#set_flow_description(desc) ⇒ Object
257
258
259
|
# File 'lib/origen_testers/generator.rb', line 257
def set_flow_description(desc)
Origen.interface.descriptions.add_for_flow(output_file, desc)
end
|
#stats ⇒ Object
249
250
251
|
# File 'lib/origen_testers/generator.rb', line 249
def stats
Origen.app.stats
end
|
#to_be_written? ⇒ Boolean
253
254
255
|
# File 'lib/origen_testers/generator.rb', line 253
def to_be_written?
true
end
|
#write_from_template(options = {}) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/origen_testers/generator.rb', line 166
def write_from_template(options = {})
options = {
quiet: false,
skip_diff: false
}.merge(options)
unless output_inhibited?
@@opened_files ||= []
if @@opened_files.include?(output_file) && !Origen.tester.is_a?(OrigenTesters::Doc)
@append = true
Origen.file_handler.preserve_state do
File.open(output_file, 'a') do |out|
content = compiler.insert(ERB.new(File.read(self.class::TEMPLATE), 0, Origen.config.erb_trim_mode).result(binding))
out.puts content unless content.empty?
end
end
Origen.log.info "Appending... #{output_file.basename}" unless options[:quiet]
else
@append = false
Origen.file_handler.preserve_state do
if Origen.tester.is_a?(OrigenTesters::Doc)
if options[:return_model]
OrigenTesters::Doc.model.add_flow(filename(include_extension: false), to_yaml)
else
Origen.file_handler.open_for_write(output_file) do |f|
f.puts YAML.dump(to_yaml(include_descriptions: false))
end
end
else
File.open(output_file, 'w') do |out|
out.puts compiler.insert(ERB.new(File.read(self.class::TEMPLATE), 0, Origen.config.erb_trim_mode).result(binding))
end
end
end
@@opened_files << output_file
Origen.log.info "Writing... #{output_file.basename}" unless options[:quiet]
end
if !@dont_diff && !options[:skip_diff] && !options[:quiet]
check_for_changes(output_file, reference_file,
compile_job: true,
comment_char: Origen.app.tester.)
end
end
end
|
#write_to_file(options = {}) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/origen_testers/generator.rb', line 154
def write_to_file(options = {})
c = caller[0]
unless output_inhibited?
if defined? self.class::TEMPLATE || Origen.tester.is_a?(OrigenTesters::Doc)
write_from_template(options)
else
fail "Don't know hot to write without a template!"
end
stats.completed_files += 1
end
end
|