Class: Rhdl::CheckContext
- Inherits:
-
Object
- Object
- Rhdl::CheckContext
- Defined in:
- lib/rhdl/check_context.rb
Instance Method Summary collapse
- #add_input_variable(name, paramstatement) ⇒ Object
- #add_output_variable(name, paramstatement) ⇒ Object
- #add_register_variable(name, paramstatement) ⇒ Object
- #add_wire_variable(name, paramstatement) ⇒ Object
- #fanout_check! ⇒ Object
- #get_var_type(name) ⇒ Object
-
#initialize ⇒ CheckContext
constructor
A new instance of CheckContext.
- #notify_driver(name, statement) ⇒ Object
- #notify_fanout(name, statement) ⇒ Object
Constructor Details
#initialize ⇒ CheckContext
3 4 5 6 7 8 |
# File 'lib/rhdl/check_context.rb', line 3 def initialize @variables = {} @types = { "uint" => DataType.new("uint", 1, nil) } end |
Instance Method Details
#add_input_variable(name, paramstatement) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rhdl/check_context.rb', line 10 def add_input_variable(name, paramstatement) raise "#{name} is already defined" if @variables[name] @variables[name] = { name: name, role: :input, kind: :wire, fanout: [], driver: true, # always driven type: @types[paramstatement.type].with_bits(paramstatement.bits) } end |
#add_output_variable(name, paramstatement) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rhdl/check_context.rb', line 23 def add_output_variable(name, paramstatement) raise "#{name} is already defined" if @variables[name] @variables[name] = { name: name, role: :output, kind: :wire, fanout: true, driver: nil, type: @types[paramstatement.type].with_bits(paramstatement.bits) } end |
#add_register_variable(name, paramstatement) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rhdl/check_context.rb', line 49 def add_register_variable(name, paramstatement) raise "#{name} is already defined" if @variables[name] @variables[name] = { name: name, role: :internal, kind: :register, fanout: [], driver: nil, type: @types[paramstatement.type].with_bits(paramstatement.bits) } end |
#add_wire_variable(name, paramstatement) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rhdl/check_context.rb', line 36 def add_wire_variable(name, paramstatement) raise "#{name} is already defined" if @variables[name] @variables[name] = { name: name, role: :output, kind: :wire, fanout: [], driver: nil, type: @types[paramstatement.type].with_bits(paramstatement.bits) } end |
#fanout_check! ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rhdl/check_context.rb', line 90 def fanout_check! @variables.each do |name, var| used = var[:fanout] == true || var[:fanout].length > 0 driven = !var[:driver].nil? if used && !driven raise "variable #{name} not driven but used" end if !used && driven raise "variable #{name} driven but not used" end if !used && !driven raise "variable #{name} completely unused" end end end |
#get_var_type(name) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/rhdl/check_context.rb', line 62 def get_var_type(name) if @variables[name].nil? raise "undefined variable '#{name}'" end @variables[name][:type] end |
#notify_driver(name, statement) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rhdl/check_context.rb', line 79 def notify_driver(name, statement) if @variables[name].nil? raise "variable #{name} does not exist, and cannot be driven" end unless @variables[name][:driver].nil? raise "variable #{name} is already being driven" end @variables[name][:driver] = statement end |
#notify_fanout(name, statement) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/rhdl/check_context.rb', line 71 def notify_fanout(name, statement) if @variables[name].nil? raise "variable #{name} does not exist" end @variables[name][:fanout] << statement end |