Class: OrigenSim::Simulator::UserDetails

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_sim/simulator/user_details.rb

Direct Known Subclasses

SnapshotDetails

Constant Summary collapse

DETAIL_NAMES_NET =
'_AVAILABLE_DETAILS_'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(simulator:, cache: true) ⇒ UserDetails

Returns a new instance of UserDetails.



9
10
11
12
13
14
# File 'lib/origen_sim/simulator/user_details.rb', line 9

def initialize(simulator:, cache: true)
  @simulator = simulator
  @fetch_error_message = "OrigenSim was unable to find net #{detail_names_net} in the snapshot! Unable to retrieve snapshot details!"
  @details = fetch
  @cache = cache
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



22
23
24
# File 'lib/origen_sim/simulator/user_details.rb', line 22

def method_missing(method, *args, &block)
  self[method]
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



6
7
8
# File 'lib/origen_sim/simulator/user_details.rb', line 6

def cache
  @cache
end

#detailsObject (readonly)

Returns the value of attribute details.



7
8
9
# File 'lib/origen_sim/simulator/user_details.rb', line 7

def details
  @details
end

Instance Method Details

#[](d) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/origen_sim/simulator/user_details.rb', line 26

def [](d)
  _d = d.to_s.upcase
  if cache
    if details
      if details.key?(_d)
        details[_d]
      else
        Origen.log.error(_missing_detail_message(_d))
        nil
      end
    else
      # if detail fetching failed, but the user is still trying to query
      # details, re-print the fetch error message
      Origen.log.error(@fetch_error_message)
      nil
    end
  else
    details = fetch
    if details
      if details.key?(_d)
        details[_d]
      else
        Origen.log.error(_missing_detail_message(_d))
        nil
      end
    end
  end
end

#_missing_detail_message(d) ⇒ Object



55
56
57
# File 'lib/origen_sim/simulator/user_details.rb', line 55

def _missing_detail_message(d)
  "Detail '#{d}' was not provided in this snapshot!"
end

#available_detailsObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/origen_sim/simulator/user_details.rb', line 85

def available_details
  if details
    details.keys
  else
    details = fetch
    @details = details if cache
    if details
      details.keys
    end
  end
end

#detail_names_netObject



101
102
103
# File 'lib/origen_sim/simulator/user_details.rb', line 101

def detail_names_net
  detail_to_net(DETAIL_NAMES_NET)
end

#detail_to_net(d) ⇒ Object



97
98
99
# File 'lib/origen_sim/simulator/user_details.rb', line 97

def detail_to_net(d)
  "#{@simulator.testbench_top}.debug.snapshot_details.user_details.#{d}"
end

#fetchObject

Note:

This requires the details origen.debug.AVAILABLE_DETAILS to be defined. This should be a comma-separeted string of the available values. It will be assumed that each details will be defined in the snapshot.

Fetches the details available in the snapshot.

This is done at runtime to get the latest details list from the snapshot
but can be cached for future use.


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/origen_sim/simulator/user_details.rb', line 65

def fetch
  # Read the available details.
  # names = str_peek("#{debug_module}.PARAMETER_NAMES").split(',')
  names = @simulator.peek_str(detail_names_net)
  if names.nil?
    Origen.log.error(@fetch_error_message)

    # Returning false indicates that the fetch failed.
    false
  elsif names.empty?
    # Empty string was returned. No available details/no details given.
    {}
  else
    # Fetch each detail value and return as a Hash
    names.split(',').map do |n|
      [n, @simulator.str_peek(detail_to_net(n))]
    end.to_h
  end
end

#to_aryObject

This gets called for some reason when ‘puts’ is used for the object. Provide something here to avoid seeing the error message.



18
19
20
# File 'lib/origen_sim/simulator/user_details.rb', line 18

def to_ary
  nil
end