Class: Idl::CsrReadExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
- #csr_def(symtab) ⇒ Object
- #csr_known?(symtab) ⇒ Boolean
- #csr_name(symtab) ⇒ Object
- #freeze_tree(symtab) ⇒ Object
-
#initialize(input, interval, idx) ⇒ CsrReadExpressionAst
constructor
A new instance of CsrReadExpressionAst.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab) ⇒ void
type check this node and all children.
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
-
#values(symtab) ⇒ Array<Integer>, ...
included
from 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.
Constructor Details
#initialize(input, interval, idx) ⇒ CsrReadExpressionAst
Returns a new instance of CsrReadExpressionAst.
5867 5868 5869 5870 5871 5872 5873 5874 5875 |
# File 'lib/idl/ast.rb', line 5867 def initialize(input, interval, idx) if idx.is_a?(AstNode) super(input, interval, [idx]) else super(input, interval, EMPTY_ARRAY) end @idx = idx end |
Instance Method Details
#csr_def(symtab) ⇒ Object
5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 |
# File 'lib/idl/ast.rb', line 5927 def csr_def(symtab) cfg_arch = symtab.cfg_arch idx_text = @idx.is_a?(String) ? @idx : @idx.text_value csr = cfg_arch.csr(idx_text) if !csr.nil? # this is a known csr name csr else # this is an expression value_result = value_try do idx_value = @idx.value(symtab) return cfg_arch.csrs.find { |csr| csr.address == idx_value } end # || we don't know at compile time which CSR this is... nil end end |
#csr_known?(symtab) ⇒ Boolean
5945 5946 5947 |
# File 'lib/idl/ast.rb', line 5945 def csr_known?(symtab) !csr_def(symtab).nil? end |
#csr_name(symtab) ⇒ Object
5949 5950 5951 5952 5953 |
# File 'lib/idl/ast.rb', line 5949 def csr_name(symtab) internal_error "No CSR" unless csr_known?(symtab) csr_def(symtab).name end |
#freeze_tree(symtab) ⇒ Object
5877 5878 5879 5880 5881 5882 5883 |
# File 'lib/idl/ast.rb', line 5877 def freeze_tree(symtab) return if frozen? @cfg_arch = symtab.cfg_arch # remember cfg_arch, used by gen_adoc pass @idx.freeze_tree(symtab) freeze end |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
5970 |
# File 'lib/idl/ast.rb', line 5970 def to_idl = "CSR[#{@idx.to_idl}]" |
#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
5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 |
# File 'lib/idl/ast.rb', line 5886 def type(symtab) cfg_arch = symtab.cfg_arch cd = csr_def(symtab) if cd.nil? # we don't know anything about this index, so we can only # treat this as a generic if symtab.mxlen == 32 Bits32Type else Bits64Type end else CsrType.new(cd, cfg_arch) end end |
#type_check(symtab) ⇒ void
5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 |
# File 'lib/idl/ast.rb', line 5904 def type_check(symtab) cfg_arch = symtab.cfg_arch idx_text = @idx.is_a?(String) ? @idx : @idx.text_value if !cfg_arch.csr(idx_text).nil? # this is a known csr name # nothing else to check else # this is an expression @idx.type_check(symtab) type_error "Csr index must be integral" unless @idx.type(symtab).integral? value_result = value_try do idx_value = @idx.value(symtab) csr_index = cfg_arch.csrs.index { |csr| csr.address == idx_value } type_error "No csr number '#{idx_value}' was found" if csr_index.nil? :ok end # OK, index doesn't have to be known end end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 |
# File 'lib/idl/ast.rb', line 5956 def value(symtab) cd = csr_def(symtab) value_error "CSR number not knowable" if cd.nil? if symtab.cfg_arch.fully_configured? value_error "CSR is not implemented" unless symtab.cfg_arch.transitive_implemented_csrs.any? { |icsr| icsr.name == cd.name } else value_error "CSR is not defined" unless symtab.cfg_arch.csrs.any? { |icsr| icsr.name == cd.name } end cd.fields.each { |f| value_error "#{csr_name(symtab)}.#{f.name} not RO" unless f.type(symtab) == "RO" } csr_def(symtab).fields.reduce(0) { |val, f| val | (f.value << f.location.begin) } 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