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.



9769
9770
9771
# File 'lib/idlc/ast.rb', line 9769

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

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
# File 'lib/idlc/ast.rb', line 9820

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)


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

def const_eval?(symtab) = false

#csr_def(symtab) ⇒ Object



9785
9786
9787
9788
9789
9790
9791
9792
# File 'lib/idlc/ast.rb', line 9785

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



9804
9805
9806
# File 'lib/idlc/ast.rb', line 9804

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



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

def idx = @children[0]

#name(symtab) ⇒ Object



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

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

#to_hObject



9813
9814
9815
9816
9817
# File 'lib/idlc/ast.rb', line 9813

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

#to_idlObject



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

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:



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

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:



9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
# File 'lib/idlc/ast.rb', line 9774

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