Class: Idl::CsrFunctionCallAst

Inherits:
AstNode
  • Object
show all
Includes:
Rvalue
Defined in:
lib/idl/ast.rb

Overview

represents a function call for a CSR register for example:

CSR[mstatus].address()
CSR[mtval].sw_read()

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, function_name, csr) ⇒ CsrFunctionCallAst

Returns a new instance of CsrFunctionCallAst.



6044
6045
6046
6047
# File 'lib/idl/ast.rb', line 6044

def initialize(input, interval, function_name, csr)
  super(input, interval, [csr])
  @function_name = function_name
end

Instance Attribute Details

#function_nameString (readonly)

Returns The function being called.

Returns:

  • (String)

    The function being called



6040
6041
6042
# File 'lib/idl/ast.rb', line 6040

def function_name
  @function_name
end

Instance Method Details

#csrObject



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

def csr = @children[0]

#csr_def(symtab) ⇒ Object



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

def csr_def(symtab)
  csr.csr_def(symtab)
end

#csr_known?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


6074
6075
6076
# File 'lib/idl/ast.rb', line 6074

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

#csr_name(symtab) ⇒ Object



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

def csr_name(symtab)
  csr.csr_name(symtab)
end

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

def to_idl = "#{csr.to_idl}.#{function_call}()"

#type(symtab) ⇒ Object



6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
# File 'lib/idl/ast.rb', line 6057

def type(symtab)
  cfg_arch = symtab.cfg_arch

  case function_name
  when "sw_read"
    if csr_known?(symtab)
      Type.new(:bits, width: cfg_arch.csr(csr.csr_name(symtab)).length(cfg_arch))
    else
      Type.new(:bits, width: symtab.mxlen.nil? ? :unknown : symtab.mxlen)
    end
  when "address"
    Type.new(:bits, width: 12)
  else
    internal_error "No function '#{function_name}' for CSR. call type check first!"
  end
end

#type_check(symtab) ⇒ Object



6049
6050
6051
6052
6053
6054
6055
# File 'lib/idl/ast.rb', line 6049

def type_check(symtab)
  unless ["sw_read", "address"].include?(function_name)
    type_error "'#{function_name}' is not a supported CSR function call"
  end

  csr.type_check(symtab)
end

#value(symtab) ⇒ Object

TODO:

check the sw_read function body



6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
# File 'lib/idl/ast.rb', line 6087

def value(symtab)
  case function_name
  when "sw_read"
    value_error "CSR not knowable" unless csr_known?(symtab)
    cd = csr_def(symtab)
    cd.fields.each { |f| value_error "#{csr_name(symtab)}.#{f.name} not RO" unless f.type(symtab) == "RO" }

    value_error "TODO: CSRs with sw_read function"
  when "address"
    value_error "CSR not knowable" unless csr_known?(symtab)
    cd = csr_def(symtab)
    cd.address
  else
    internal_error "TODO: #{function_name}"
  end
end

#values(symtab) ⇒ Array<Integer>, ... Originally defined in module Rvalue

Return a complete list of possible compile-time-known values of the node, or raise a ValueError if the full list cannot be determined

For most AstNodes, this will just be a single-entry array

Parameters:

  • symtab (SymbolTable)

    The context for the evaluation

Returns:

  • (Array<Integer>)

    The complete list of compile-time-known values, when they are integral

  • (Array<Boolean>)

    The complete list of compile-time-known values, when they are booleans

  • (AstNode::ValueError)

    if the list of values is not knowable at compile time