Class: UdbGen::InstTableOptions

Inherits:
SubcommandWithCommonOptions show all
Includes:
TTY::Exit
Defined in:
lib/udb-gen/generators/inst_table/generator.rb

Constant Summary collapse

NAME =
"inst-table"

Instance Attribute Summary

Attributes inherited from Subcommand

#desc, #name

Instance Method Summary collapse

Methods inherited from SubcommandWithCommonOptions

#cfg_arch, #resolve_cfg_arg, #resolver

Constructor Details

#initializeInstTableOptions

Returns a new instance of InstTableOptions.



23
24
25
# File 'lib/udb-gen/generators/inst_table/generator.rb', line 23

def initialize
  super(name: NAME, desc: "Generate an instruction table")
end

Instance Method Details

#gen_inst_tableObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/udb-gen/generators/inst_table/generator.rb', line 47

def gen_inst_table
  target_file = params[:output_file]
  builder = InstTable::TableBuilder.new(cfg_arch, target_file&.basename&.to_s)

  if target_file.nil?
    $stdout.write(builder.generate)
  else
    File.write(target_file, builder.generate)
  end
end

#run(argv) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/udb-gen/generators/inst_table/generator.rb', line 59

def run(argv)
  parse(argv)

  if params[:help]
    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

  gen_inst_table

  exit_with(:success)
end