Class: Idl::CsrReadExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb,
lib/idlc/passes/find_referenced_csrs.rb
Defined Under Namespace
Classes: Memo
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 collapse
-
#csr_name ⇒ Object
readonly
Returns the value of attribute csr_name.
Attributes inherited from AstNode
#children, #input, #interval, #parent
Class Method Summary collapse
Instance Method Summary collapse
- #const_eval?(symtab) ⇒ Boolean
- #csr_def(symtab) ⇒ Object
- #csr_known?(symtab) ⇒ Boolean
- #find_referenced_csrs ⇒ Object
- #gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
-
#initialize(input, interval, csr_name) ⇒ CsrReadExpressionAst
constructor
A new instance of CsrReadExpressionAst.
- #prune(symtab, forced_type: nil) ⇒ Object
- #to_h ⇒ Object
- #to_idl ⇒ Object
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab, strict:) ⇒ void
type check this node and all children.
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
Methods included from Rvalue
#max_value, #min_value, #truncate, #values
Methods inherited from AstNode
#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #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_name) ⇒ CsrReadExpressionAst
Returns a new instance of CsrReadExpressionAst.
9509 9510 9511 9512 9513 9514 |
# File 'lib/idlc/ast.rb', line 9509 def initialize(input, interval, csr_name) super(input, interval, []) @csr_name = csr_name @memo = Memo.new end |
Instance Attribute Details
#csr_name ⇒ Object (readonly)
Returns the value of attribute csr_name.
9507 9508 9509 |
# File 'lib/idlc/ast.rb', line 9507 def csr_name @csr_name end |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
9553 9554 9555 9556 9557 9558 9559 9560 9561 |
# File 'lib/idlc/ast.rb', line 9553 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "csr_read_expr" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) CsrReadExpressionAst.new( input, interval, yaml.fetch("csr_name") ) end |
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
9505 |
# File 'lib/idlc/ast.rb', line 9505 def const_eval?(symtab) = !csr_def(symtab).value.nil? |
#csr_def(symtab) ⇒ Object
9524 9525 9526 |
# File 'lib/idlc/ast.rb', line 9524 def csr_def(symtab) @memo.csr_obj ||= symtab.csr(@csr_name) end |
#csr_known?(symtab) ⇒ Boolean
9528 9529 9530 |
# File 'lib/idlc/ast.rb', line 9528 def csr_known?(symtab) !csr_def(symtab).nil? end |
#find_referenced_csrs ⇒ Object
24 25 26 |
# File 'lib/idlc/passes/find_referenced_csrs.rb', line 24 def find_referenced_csrs [csr_name] end |
#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
327 328 329 |
# File 'lib/idlc/passes/gen_adoc.rb', line 327 def gen_adoc(indent = 0, indent_spaces: 2) "#{' ' * indent}" + "CSR[%%UDB_DOC_LINK%csr;#{csr_name};#{text_value}%%]" end |
#prune(symtab, forced_type: nil) ⇒ Object
747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/idlc/passes/prune.rb', line 747 def prune(symtab, forced_type: nil) value_result = value_try do v = value(symtab) if type(symtab).width == :unknown value_error "unknown width" end return PruneHelpers.create_int_literal(v, forced_type: forced_type || type(symtab)) end value_else(value_result) do CsrReadExpressionAst.new(input, interval, @csr_name) end end |
#to_h ⇒ Object
9546 9547 9548 9549 9550 |
# File 'lib/idlc/ast.rb', line 9546 def to_h = { "kind" => "csr_read_expr", "csr_name" => @csr_name, "source" => source_yaml } |
#to_idl ⇒ Object
9543 |
# File 'lib/idlc/ast.rb', line 9543 def to_idl = "CSR[#{@csr_name}]" |
#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
9517 |
# File 'lib/idlc/ast.rb', line 9517 def type(symtab) = @memo.type ||= CsrType.new(csr_def(symtab)) |
#type_check(symtab, strict:) ⇒ void
9520 9521 9522 |
# File 'lib/idlc/ast.rb', line 9520 def type_check(symtab, strict:) type_error "CSR '#{@csr_name}' is not defined" unless symtab.csr?(@csr_name) end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
9533 9534 9535 9536 9537 9538 9539 |
# File 'lib/idlc/ast.rb', line 9533 def value(symtab) v = csr_def(symtab).value if v.nil? value_error "CSR is not defined" end v end |