Class: Rhdl::ModuleGenerator
- Inherits:
-
Object
- Object
- Rhdl::ModuleGenerator
- Defined in:
- lib/rhdl/module_generator.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
Instance Method Summary collapse
- #comb_block ⇒ Object
- #generate ⇒ Object
-
#initialize(module_name, component) ⇒ ModuleGenerator
constructor
A new instance of ModuleGenerator.
- #maxlens ⇒ Object
- #params ⇒ Object
- #params_arr ⇒ Object
- #params_stmt ⇒ Object
- #wire_list ⇒ Object
Constructor Details
#initialize(module_name, component) ⇒ ModuleGenerator
Returns a new instance of ModuleGenerator.
5 6 7 8 |
# File 'lib/rhdl/module_generator.rb', line 5 def initialize(module_name, component) @module_name = module_name @component = component end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
3 4 5 |
# File 'lib/rhdl/module_generator.rb', line 3 def component @component end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
3 4 5 |
# File 'lib/rhdl/module_generator.rb', line 3 def module_name @module_name end |
Instance Method Details
#comb_block ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rhdl/module_generator.rb', line 56 def comb_block @comb_block ||= component. comb_block_dsl. statements. map{|x| x.generate}.flatten.map{|x| " #{x}"}. join("\n") end |
#generate ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rhdl/module_generator.rb', line 71 def generate result = " module \#{module_name}\n (\n \#{params_stmt}\n );\n \#{wire_list}\n always @(*) begin\n \#{comb_block}\n end\n \n endmodule\n \n CONTENT\n \n result\nend\n" |
#maxlens ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rhdl/module_generator.rb', line 10 def maxlens @maxlens ||= begin res = {} params.each do |paraminfo| paraminfo.each do |key, val| res[key] ||= 0 len = (val&.length || 0) if res[key] < len res[key] = len end end end res end end |
#params ⇒ Object
27 28 29 30 31 |
# File 'lib/rhdl/module_generator.rb', line 27 def params @params ||= [] + component.inputs.map{|x| x.generate_terms} + component.outputs.map{|x| x.generate_terms} end |
#params_arr ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rhdl/module_generator.rb', line 33 def params_arr @params_arr ||= begin res = [] params.each do |paraminfo| arr = [] paraminfo.each do |key, val| if val.nil? arr << "".ljust(maxlens[key]) next end arr << val.ljust(maxlens[key]) end res << " #{arr.join(' ')}" end res end end |
#params_stmt ⇒ Object
52 53 54 |
# File 'lib/rhdl/module_generator.rb', line 52 def params_stmt @params_stmt ||= params_arr.join(",\n") end |
#wire_list ⇒ Object
64 65 66 67 68 69 |
# File 'lib/rhdl/module_generator.rb', line 64 def wire_list component.wires.map do |x| terms = x.generate_terms "reg #{terms[:bitterm]} #{terms[:name]}; // wire" end.join("\n") end |