Class: Idl::CsrWriteAst

Inherits:
AstNode show all
Includes:
Executable
Defined in:
lib/idlc/ast.rb,
lib/idlc/passes/find_referenced_csrs.rb

Constant Summary

Constants inherited from AstNode

AstNode::Bits1Type, AstNode::Bits32Type, AstNode::Bits64Type, AstNode::BoolType, AstNode::ConstBoolType, AstNode::PossiblyUnknownBits1Type, AstNode::PossiblyUnknownBits32Type, AstNode::PossiblyUnknownBits64Type, AstNode::ReachableFunctionCacheType, AstNode::StringType, AstNode::VoidType

Instance Attribute Summary

Attributes inherited from AstNode

#children, #input, #interval, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executable

#executable?

Methods inherited from AstNode

#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_src_registers, #freeze_tree, #gen_adoc, #gen_option_adoc, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #nullify_assignments, #pass_find_return_values, #path, #print_ast, #prune, #reachable_exceptions, #reachable_functions, #set_input_file, #set_input_file_unless_already_set, #source_line_file_offsets, #source_starting_offset, #source_yaml, #starting_line, #text_value, #truncation_warn, #type_error, #unindent, value_else, #value_else, value_error, #value_error, value_try, #value_try, write_back_nested

Constructor Details

#initialize(input, interval, idx) ⇒ CsrWriteAst

Returns a new instance of CsrWriteAst.



9754
9755
9756
# File 'lib/idlc/ast.rb', line 9754

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

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
# File 'lib/idlc/ast.rb', line 9805

def self.from_h(yaml, source_mapper)
  raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "csr_access_expr"

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  CsrWriteAst.new(
    input, interval,
    AstNode.from_h(yaml.fetch("csr_name_or_address_expr"), source_mapper)
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


9750
# File 'lib/idlc/ast.rb', line 9750

def const_eval?(symtab) = false

#csr_def(symtab) ⇒ Object



9770
9771
9772
9773
9774
9775
9776
9777
# File 'lib/idlc/ast.rb', line 9770

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



9789
9790
9791
# File 'lib/idlc/ast.rb', line 9789

def execute(symtab)
  value_error "CSR write"
end

#find_referenced_csrsObject



31
32
33
34
35
36
37
# File 'lib/idlc/passes/find_referenced_csrs.rb', line 31

def find_referenced_csrs
  if idx.is_a?(IntLiteralAst)
    []
  else
    [idx.text_value]
  end
end

#idxObject



9752
# File 'lib/idlc/ast.rb', line 9752

def idx = @children[0]

#name(symtab) ⇒ Object



9784
9785
9786
# File 'lib/idlc/ast.rb', line 9784

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

#to_hObject



9798
9799
9800
9801
9802
# File 'lib/idlc/ast.rb', line 9798

def to_h = {
  "kind" => "csr_access_expr",
  "csr_name_or_address_expr" => idx.to_h,
  "source" => source_yaml
}

#to_idlObject



9795
# File 'lib/idlc/ast.rb', line 9795

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:



9780
9781
9782
# File 'lib/idlc/ast.rb', line 9780

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

#type_check(symtab, strict:) ⇒ 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:



9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
# File 'lib/idlc/ast.rb', line 9759

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