Class: PrmGenerator::Generator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/udb/prm_generator.rb

Overview

Main PRM generation coordinator

The Generator class orchestrates the PRM (Processor Reference Manual) generation process. It validates input parameters, loads PRM configuration, and coordinates the creation of AsciiDoc and PDF documentation files. Usage involves initializing with required paths and resolver, then calling ‘generate_adoc` and/or `generate_pdf` to produce documentation. Key responsibilities:

- Validating inputs and configuration
- Loading PRM data and processor configuration
- Generating component documentation (CSRs, instructions, extensions, non-ISA specs)
- Assembling and exporting the main PRM document in AsciiDoc and PDF formats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prm_name, resolver:, output_dir:, template_dir:, root_dir:) ⇒ Generator

Returns a new instance of Generator.



60
61
62
63
64
65
66
67
68
# File 'lib/udb/prm_generator.rb', line 60

def initialize(prm_name, resolver:, output_dir:, template_dir:, root_dir:)
  @prm_name = prm_name
  @resolver = resolver
  @output_dir = Pathname.new(output_dir)
  @template_dir = Pathname.new(template_dir)
  @root_dir = Pathname.new(root_dir)

  validate_inputs
end

Instance Attribute Details

#output_dirObject (readonly)

Returns the value of attribute output_dir.



58
59
60
# File 'lib/udb/prm_generator.rb', line 58

def output_dir
  @output_dir
end

#prm_nameObject (readonly)

Returns the value of attribute prm_name.



58
59
60
# File 'lib/udb/prm_generator.rb', line 58

def prm_name
  @prm_name
end

#resolverObject (readonly)

Returns the value of attribute resolver.



58
59
60
# File 'lib/udb/prm_generator.rb', line 58

def resolver
  @resolver
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



58
59
60
# File 'lib/udb/prm_generator.rb', line 58

def root_dir
  @root_dir
end

#template_dirObject (readonly)

Returns the value of attribute template_dir.



58
59
60
# File 'lib/udb/prm_generator.rb', line 58

def template_dir
  @template_dir
end

Instance Method Details

#generate_adocObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/udb/prm_generator.rb', line 70

def generate_adoc
  puts "[INFO] Generating AsciiDoc files for #{prm_name}..."

  prm = load_prm
  processor_config = prm.processor_config
  adoc_output_dir = @output_dir / prm_name / "adoc"

  # Clean and create output directory
  FileUtils.rm_rf(adoc_output_dir)
  FileUtils.mkdir_p(adoc_output_dir)

  # Generate individual component files
  ComponentGenerator.new(processor_config, prm_name, adoc_output_dir, @template_dir).generate_all

  puts "[INFO] AsciiDoc generation complete for #{prm_name}"
end

#generate_pdfObject



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
# File 'lib/udb/prm_generator.rb', line 87

def generate_pdf
  puts "[INFO] Generating PDF for #{prm_name}..."

  prm = load_prm
  pdf_output_dir = @output_dir / prm_name / "pdf"
  FileUtils.mkdir_p(pdf_output_dir)

  # Generate main document
  main_generator = MainDocumentGenerator.new(
    prm,
    @resolver,
    @output_dir / prm_name,
    @template_dir,
    @root_dir
  )

  main_adoc_path = pdf_output_dir / "_prm_main.adoc"
  main_content = main_generator.generate

  File.write(main_adoc_path, main_content)
  puts "[INFO] Generated main AsciiDoc: #{main_adoc_path}"

  # Generate PDF
  pdf_path = pdf_output_dir / "#{prm_name}-specification.pdf"
  PdfGenerator.new(@template_dir, @root_dir).generate(main_adoc_path, pdf_path)

  puts "[INFO] PDF generation complete: #{pdf_path}"
end