Module: UdbGen::CfgHeaderBase
- Extended by:
- T::Helpers, T::Sig
- Included in:
- GenCfgCHeaderOptions, GenCfgSvhHeaderOptions
- Defined in:
- lib/udb-gen/cfg_header_base.rb
Overview
Shared logic for generating config header files across languages (C, SystemVerilog, etc.). Including classes must include TTY::Exit, inherit from SubcommandWithCommonOptions, and include this module; SubcommandWithCommonOptions provides cfg_arch, params, parse, help, and exit_with.
Instance Method Summary collapse
- #cfg_arch ⇒ Object
- #command_name ⇒ Object
- #define_directive ⇒ Object
- #exit_with(exit_code, message = nil) ⇒ Object
- #file_type_name ⇒ Object
- #format_integer(value) ⇒ Object
- #generate_header ⇒ Object
- #guard_begin(guard_name) ⇒ Object
- #guard_end(guard_name) ⇒ Object
- #guard_suffix ⇒ Object
- #header_comment(text_lines) ⇒ Object
- #help ⇒ Object
- #params ⇒ Object
- #parse(argv) ⇒ Object
- #run_generator(argv) ⇒ Object
- #section_comment(text) ⇒ Object
Instance Method Details
#cfg_arch ⇒ Object
25 |
# File 'lib/udb-gen/cfg_header_base.rb', line 25 def cfg_arch; end |
#command_name ⇒ Object
40 |
# File 'lib/udb-gen/cfg_header_base.rb', line 40 def command_name; end |
#define_directive ⇒ Object
44 |
# File 'lib/udb-gen/cfg_header_base.rb', line 44 def define_directive; end |
#exit_with(exit_code, message = nil) ⇒ Object
37 |
# File 'lib/udb-gen/cfg_header_base.rb', line 37 def exit_with(exit_code, = nil); end |
#file_type_name ⇒ Object
68 |
# File 'lib/udb-gen/cfg_header_base.rb', line 68 def file_type_name; end |
#format_integer(value) ⇒ Object
72 |
# File 'lib/udb-gen/cfg_header_base.rb', line 72 def format_integer(value); end |
#generate_header ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/udb-gen/cfg_header_base.rb', line 75 def generate_header unless cfg_arch.fully_configured? exit_with(:data_err, "Config '#{cfg_arch.name}' is not fully configured. Only fully configured configs are supported.\n") end lines = [] guard_name = "UDB_CFG_#{cfg_arch.name.upcase.gsub(/[^A-Z0-9]/, "_")}#{guard_suffix}" convention_lines = [ "SPDX-License-Identifier: BSD-3-Clause-Clear", "", "Auto-generated by riscv-unified-db (udb-gen #{command_name})", "Config: #{cfg_arch.name}", "", "Define conventions:", " Extensions: #{define_directive} NAME_SUPPORTED and #{define_directive} NAMEverPver_SUPPORTED", " Boolean params: #{define_directive} UDB_NAME (present when true, absent when false)", " Integer params: #{define_directive} UDB_NAME value and #{define_directive} UDB_NAME_<value>", " Enum (string) params: #{define_directive} UDB_NAME_VALUE (value sanitized to uppercase identifier)", " Boolean arrays: #{define_directive} UDB_NAME_<index> (one per true element)", " Integer arrays: #{define_directive} UDB_NAME_<value> (one per unique element, sorted)", " String arrays: #{define_directive} UDB_NAME_<VALUE> (one per unique element, sanitized)" ] lines.concat(header_comment(convention_lines)) lines << "" lines << guard_begin(guard_name) lines << "#{define_directive} #{guard_name}" lines << "" lines << section_comment("Implemented extensions") emit_extension_defines(lines) lines << "" lines << section_comment("Configuration parameters") emit_param_defines(lines) lines << "" lines << guard_end(guard_name) lines << "" lines.join("\n") end |
#guard_begin(guard_name) ⇒ Object
48 |
# File 'lib/udb-gen/cfg_header_base.rb', line 48 def guard_begin(guard_name); end |
#guard_end(guard_name) ⇒ Object
52 |
# File 'lib/udb-gen/cfg_header_base.rb', line 52 def guard_end(guard_name); end |
#guard_suffix ⇒ Object
56 |
# File 'lib/udb-gen/cfg_header_base.rb', line 56 def guard_suffix; end |
#header_comment(text_lines) ⇒ Object
64 |
# File 'lib/udb-gen/cfg_header_base.rb', line 64 def header_comment(text_lines); end |
#help ⇒ Object
34 |
# File 'lib/udb-gen/cfg_header_base.rb', line 34 def help; end |
#params ⇒ Object
28 |
# File 'lib/udb-gen/cfg_header_base.rb', line 28 def params; end |
#parse(argv) ⇒ Object
31 |
# File 'lib/udb-gen/cfg_header_base.rb', line 31 def parse(argv); end |
#run_generator(argv) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/udb-gen/cfg_header_base.rb', line 120 def run_generator(argv) parse(argv) if params[:help] Kernel.print help exit_with(:success) end if params.errors.any? exit_with(:usage_error, "#{params.errors.summary}\n\n#{help}") end unless params.remaining.empty? exit_with(:usage_error, "Unknown arguments: #{params.remaining}\n") end header = generate_header if params[:output].nil? $stdout.write(header) else FileUtils.mkdir_p(params[:output].dirname) File.write(params[:output], header) Udb.logger.info "Generated #{file_type_name}: #{params[:output]}" end exit_with(:success) end |
#section_comment(text) ⇒ Object
60 |
# File 'lib/udb-gen/cfg_header_base.rb', line 60 def section_comment(text); end |