class RgGen::DUH::Loader

Constants

SUB_LAYERS

Public Instance Methods

disable_validation() click to toggle source
# File lib/rggen/duh/loader.rb, line 8
def disable_validation
  @disable_validation = true
end

Private Instance Methods

add_parent_and_layer_properties(data, parent, layer) click to toggle source
# File lib/rggen/duh/loader.rb, line 82
def add_parent_and_layer_properties(data, parent, layer)
  data.instance_variable_set(:@parent, parent)
  data.instance_variable_set(:@layer, layer)
  class << data
    attr_reader :parent
    attr_reader :layer
  end
  data
end
collect_address_blocks(read_data) click to toggle source
# File lib/rggen/duh/loader.rb, line 57
def collect_address_blocks(read_data)
  read_data
    .dig('component', 'memoryMaps')
    &.flat_map { |memory_map| memory_map['addressBlocks'] }
    &.compact
end
collect_bit_field_data(read_data) click to toggle source
# File lib/rggen/duh/loader.rb, line 76
def collect_bit_field_data(read_data)
  read_data['fields']&.map do |data|
    add_parent_and_layer_properties(data, read_data, :bit_field)
  end
end
collect_register_block_data(read_data) click to toggle source
# File lib/rggen/duh/loader.rb, line 51
def collect_register_block_data(read_data)
  collect_address_blocks(read_data)
    &.select { |address_block| address_block['usage'] == 'register' }
    &.map { |data| add_parent_and_layer_properties(data, nil, :register_block) }
end
collect_register_data(read_data) click to toggle source
# File lib/rggen/duh/loader.rb, line 70
def collect_register_data(read_data)
  read_data['registers']&.map do |data|
    add_parent_and_layer_properties(data, read_data, :register)
  end
end
collect_register_file_data(read_data) click to toggle source
# File lib/rggen/duh/loader.rb, line 64
def collect_register_file_data(read_data)
  read_data['registerFiles']&.map do |data|
    add_parent_and_layer_properties(data, read_data, :register_file)
  end
end
format_sub_layer_data(read_data, layer, _file) click to toggle source
# File lib/rggen/duh/loader.rb, line 44
def format_sub_layer_data(read_data, layer, _file)
  SUB_LAYERS[layer]&.each_with_object({}) do |sub_layer, sub_layer_data|
    data = __send__("collect_#{sub_layer}_data", read_data)
    data && (sub_layer_data[sub_layer] = data)
  end
end
load_json5(file_name) click to toggle source
# File lib/rggen/duh/loader.rb, line 20
def load_json5(file_name)
  JsonRefs.dereference(RbJSON5.load_file(file_name))
rescue RbJSON5::ParseError => e
  reason = e.parse_failure_cause.ascii_tree.strip
  raise ParseError.new(e.message, file_name, reason)
end
read_file(file_name) click to toggle source
# File lib/rggen/duh/loader.rb, line 14
def read_file(file_name)
  duh = load_json5(file_name)
  validation? && validate(duh, file_name)
  duh
end
validate(duh, file_name) click to toggle source
# File lib/rggen/duh/loader.rb, line 31
def validate(duh, file_name)
  errors = Schema.validate(duh)
  errors.empty? ||
    (raise ValidationError.new('input DUH file is invalid', file_name, errors))
end
validation?() click to toggle source
# File lib/rggen/duh/loader.rb, line 27
def validation?
  !@disable_validation
end