Class: Rhdl::AssignStatement

Inherits:
Statement show all
Defined in:
lib/rhdl/assign_statement.rb

Instance Method Summary collapse

Constructor Details

#initialize(var_name, expr) ⇒ AssignStatement

Returns a new instance of AssignStatement.



3
4
5
6
# File 'lib/rhdl/assign_statement.rb', line 3

def initialize(var_name, expr)
  @var_name = var_name
  @expr = expr
end

Instance Method Details

#check!(check_context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rhdl/assign_statement.rb', line 15

def check!(check_context)
  out_type = @expr.get_output_type(check_context)
  var_type = check_context.get_var_type(@var_name)

  # assignment type check
  if out_type.is_equal_or_child_of(var_type)
    raise "cannot assign type #{out_type} to var #{var_type}"
  end

  if out_type.bits != var_type.bits
    raise "cannot assign type #{out_type} to var #{var_type}, they are not the same size"
  end

  @expr.fanout(check_context, self)
  check_context.notify_driver(@var_name, self)

end

#generateObject



8
9
10
11
12
13
# File 'lib/rhdl/assign_statement.rb', line 8

def generate
  [
    #"//#{@expr.varnames};",
    "#{@var_name} = #{@expr.generate};"
  ]
end