Class: Idl::CsrWriteAst

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

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, idx) ⇒ CsrWriteAst

Returns a new instance of CsrWriteAst.



6117
6118
6119
# File 'lib/idl/ast.rb', line 6117

def initialize(input, interval, idx)
  super(input, interval, [idx])
end

Instance Method Details

#csr_def(symtab) ⇒ Object



6133
6134
6135
6136
6137
6138
6139
6140
# File 'lib/idl/ast.rb', line 6133

def csr_def(symtab)
  if idx.is_a?(IntLiteralAst)
    # make sure this value is a defined CSR
    symtab.cfg_arch.csrs.find { |csr| csr.address == idx.text_value.to_i }
  else
    symtab.cfg_arch.csr(idx.text_value)
  end
end

#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



6152
6153
6154
# File 'lib/idl/ast.rb', line 6152

def execute(symtab)
  value_error "CSR write"
end

#execute_unknown(symtab) ⇒ Object

nothing to do for a function call



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

def execute_unknown(symtab); end

#idxObject



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

def idx = @children[0]

#name(symtab) ⇒ Object



6147
6148
6149
# File 'lib/idl/ast.rb', line 6147

def name(symtab)
  csr_def(symtab).name
end

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



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

def to_idl = "CSR[#{idx.text_value}]"

#type(symtab) ⇒ Type

Given a specific symbol table, return the type of this node.

Should not be called until #type_check is called with the same arguments

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



6143
6144
6145
# File 'lib/idl/ast.rb', line 6143

def type(symtab)
  CsrType.new(csr_def(symtab), symtab.cfg_arch)
end

#type_check(symtab) ⇒ void

This method returns an undefined value.

type check this node and all children

Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError

Parameters:

Raises:



6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
# File 'lib/idl/ast.rb', line 6122

def type_check(symtab)
  if idx.is_a?(IntLiteralAst)
    # make sure this value is a defined CSR
    index = symtab.cfg_arch.csrs.index { |csr| csr.address == idx.value(symtab) }
    type_error "No csr number '#{idx.value(symtab)}' was found" if index.nil?
  else
    csr = symtab.cfg_arch.csr(idx.text_value)
    type_error "No csr named '#{idx.text_value}' was found" if csr.nil?
  end
end