Class: Idl::AryRangeAccessAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
-
#initialize(input, interval, var, msb, lsb) ⇒ AryRangeAccessAst
constructor
A new instance of AryRangeAccessAst.
- #lsb ⇒ Object
- #msb ⇒ Object
-
#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.
- #var ⇒ Object
Constructor Details
#initialize(input, interval, var, msb, lsb) ⇒ AryRangeAccessAst
Returns a new instance of AryRangeAccessAst.
1566 1567 1568 |
# File 'lib/idl/ast.rb', line 1566 def initialize(input, interval, var, msb, lsb) super(input, interval, [var, msb, lsb]) end |
Instance Method Details
#lsb ⇒ Object
1564 |
# File 'lib/idl/ast.rb', line 1564 def lsb = @children[2] |
#msb ⇒ Object
1563 |
# File 'lib/idl/ast.rb', line 1563 def msb = @children[1] |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
1613 |
# File 'lib/idl/ast.rb', line 1613 def to_idl = "#{var.to_idl}[#{msb.to_idl}:#{lsb.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
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 |
# File 'lib/idl/ast.rb', line 1595 def type(symtab) value_result = value_try do msb_value = msb.value(symtab) lsb_value = lsb.value(symtab) range_size = msb_value - lsb_value + 1 return Type.new(:bits, width: range_size) end # don't know the width at compile time....assume the worst value_else(value_result) { var.type(symtab) } end |
#type_check(symtab) ⇒ void
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 |
# File 'lib/idl/ast.rb', line 1571 def type_check(symtab) var.type_check(symtab) msb.type_check(symtab) lsb.type_check(symtab) type_error "Range operator only defined for integral types (found #{var.type(symtab)})" unless var.type(symtab).integral? type_error "Range MSB must be an integral type" unless msb.type(symtab).integral? type_error "Range LSB must be an integral type" unless lsb.type(symtab).integral? value_result = value_try do msb_value = msb.value(symtab) lsb_value = lsb.value(symtab) if var.type(symtab).kind == :bits && msb_value >= var.type(symtab).width type_error "Range too large for bits (msb = #{msb_value}, range size = #{var.type(symtab).width})" end range_size = msb_value - lsb_value + 1 type_error "zero/negative range (#{msb_value}:#{lsb_value})" if range_size <= 0 end # OK, don't have to know end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
1607 1608 1609 1610 |
# File 'lib/idl/ast.rb', line 1607 def value(symtab) mask = (1 << (msb.value(symtab) - lsb.value(symtab) + 1)) - 1 (var.value(symtab) >> lsb.value(symtab)) & mask 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
#var ⇒ Object
1562 |
# File 'lib/idl/ast.rb', line 1562 def var = @children[0] |