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.



6081
6082
6083
# File 'lib/idl/ast.rb', line 6081

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

Instance Method Details

#csr_def(symtab) ⇒ Object



6097
6098
6099
6100
6101
6102
6103
6104
# File 'lib/idl/ast.rb', line 6097

def csr_def(symtab)
  if idx.is_a?(IntLiteralAst)
    # make sure this value is a defined CSR
    symtab.archdef.csrs.find { |csr| csr.address == idx.text_value.to_i }
  else
    symtab.archdef.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



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

def execute(symtab)
  value_error "CSR write"
end

#execute_unknown(symtab) ⇒ Object

nothing to do for a function call



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

def execute_unknown(symtab); end

#idxObject



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

def idx = @children[0]

#name(symtab) ⇒ Object



6111
6112
6113
# File 'lib/idl/ast.rb', line 6111

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



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

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:



6107
6108
6109
# File 'lib/idl/ast.rb', line 6107

def type(symtab)
  CsrType.new(csr_def(symtab), symtab.archdef)
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:



6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
# File 'lib/idl/ast.rb', line 6086

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