Class: Idl::CsrSoftwareWriteAst

Inherits:
AstNode
  • Object
show all
Includes:
Executable
Defined in:
lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.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_referenced_csrs, #find_src_registers, #freeze_tree, #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, #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, csr, expression) ⇒ CsrSoftwareWriteAst

Returns a new instance of CsrSoftwareWriteAst.



9579
9580
9581
# File 'lib/idlc/ast.rb', line 9579

def initialize(input, interval, csr, expression)
  super(input, interval, [csr, expression])
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
# File 'lib/idlc/ast.rb', line 9620

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

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  CsrSoftwareWriteAst.new(
    input, interval,
    AstNode.from_h(yaml.fetch("csr"), source_mapper),
    AstNode.from_h(yaml.fetch("value"), source_mapper)
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = false

#csrObject



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

def csr = @children[0]

#csr_known?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


9593
9594
9595
# File 'lib/idlc/ast.rb', line 9593

def csr_known?(symtab)
  csr.csr_known?(symtab)
end

#csr_nameObject



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

def csr_name = csr.csr_name

#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



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

def execute(_symtab) = value_error "CSR writes are global"

#expressionObject



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

def expression = @children[1]

#gen_adoc(indent, indent_spaces: 2) ⇒ Object



87
88
89
# File 'lib/idlc/passes/gen_adoc.rb', line 87

def gen_adoc(indent, indent_spaces: 2)
  "#{' ' * indent}#{csr.gen_adoc(indent, indent_spaces:)}.sw_write(#{expression.gen_adoc(0, indent_spaces:)})"
end

#prune(symtab, forced_type: nil) ⇒ Object



989
990
991
# File 'lib/idlc/passes/prune.rb', line 989

def prune(symtab, forced_type: nil)
  CsrSoftwareWriteAst.new(input, interval, csr.dup, expression.prune(symtab))
end

#to_hObject



9612
9613
9614
9615
9616
9617
# File 'lib/idlc/ast.rb', line 9612

def to_h = {
  "kind" => "csr_sw_write_expr",
  "csr" => csr.to_h,
  "value" => expression.to_h,
  "source" => source_yaml
}

#to_idlObject



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

def to_idl = "#{csr.to_idl}.sw_write(#{expression.to_idl})"

#type_check(symtab, strict:) ⇒ Object



9583
9584
9585
9586
9587
9588
9589
9590
9591
# File 'lib/idlc/ast.rb', line 9583

def type_check(symtab, strict:)
  csr.type_check(symtab, strict:)
  expression.type_check(symtab, strict:)

  e_type = expression.type(symtab)
  return if e_type.kind == :bits && ((e_type.width == :unknown || symtab.mxlen.nil?) || (e_type.width == symtab.mxlen))

  type_error "CSR value must be an XReg"
end

#value(_symtab) ⇒ Object

Return the compile-time-known value of the node



9600
9601
9602
# File 'lib/idlc/ast.rb', line 9600

def value(_symtab)
  value_error "CSR writes are global"
end