Class: Idl::CsrFieldAssignmentAst

Inherits:
AstNode
  • Object
show all
Includes:
Executable
Defined in:
lib/idl/ast.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, csr_field, write_value) ⇒ CsrFieldAssignmentAst

Returns a new instance of CsrFieldAssignmentAst.



2020
2021
2022
# File 'lib/idl/ast.rb', line 2020

def initialize(input, interval, csr_field, write_value)
  super(input, interval, [csr_field, write_value])
end

Instance Method Details

#csr_fieldObject



2017
# File 'lib/idl/ast.rb', line 2017

def csr_field = @children[0]

#execute(symtab) ⇒ void

This method returns an undefined value.

“execute” the statement by updating the variables in the symbol table

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Raises:

  • ValueError if some part of the statement cannot be executed at compile time



2058
2059
2060
# File 'lib/idl/ast.rb', line 2058

def execute(symtab)
  value_error "CSR field writes are never compile-time-executable"
end

#execute_unknown(symtab) ⇒ void

This method returns an undefined value.

“execute” the statement, forcing any variable assignments to an unknown state This is used down unknown conditional paths.

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Raises:

  • ValueError if some part of the statement cannot be executed at compile time



2063
# File 'lib/idl/ast.rb', line 2063

def execute_unknown(symtab); end

#field(symtab) ⇒ Object



2040
2041
2042
# File 'lib/idl/ast.rb', line 2040

def field(symtab)
  csr_field.field_def(symtab)
end

#to_idlObject



2065
# File 'lib/idl/ast.rb', line 2065

def to_idl = "#{csr_field.to_idl} = #{write_value.to_idl}"

#type(symtab) ⇒ Object



2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
# File 'lib/idl/ast.rb', line 2024

def type(symtab)
  if field(symtab).defined_in_all_bases?
    if symtab.cfg_arch.mxlen == 64 && symtab.cfg_arch.multi_xlen?
      Type.new(:bits, width: [field(symtab).location(symtab.cfg_arch, 32).size, field(symtab).location(symtab.cfg_arch, 64).size].max)
    else
      Type.new(:bits, width: field(symtab).location(symtab.cfg_arch, symtab.cfg_arch.mxlen).size)
    end
  elsif field(symtab).base64_only?
    Type.new(:bits, width: field(symtab).location(symtab.cfg_arch, 64).size)
  elsif field(symtab).base32_only?
    Type.new(:bits, width: field(symtab).location(symtab.cfg_arch, 32).size)
  else
    internal_error "Unexpected base for field"
  end
end

#type_check(symtab) ⇒ Object



2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
# File 'lib/idl/ast.rb', line 2044

def type_check(symtab)
  csr_field.type_check(symtab)
  value_try do
    if ["RO", "RO-H"].any?(csr_field.field_def(symtab).type(symtab))
      type_error "Cannot write to read-only CSR field"
    end
  end
  # ok, we don't know the type because the cfg_arch isn't configured

  write_value.type_check(symtab)
  type_error "Incompatible type in assignment" unless write_value.type(symtab).convertable_to?(type(symtab))
end

#write_valueObject



2018
# File 'lib/idl/ast.rb', line 2018

def write_value = @children[1]