Class: Idl::ReplicationExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Overview
represents a replication expression
for example:
{5{5'd3}}
Instance Method Summary collapse
-
#initialize(input, interval, n, v) ⇒ ReplicationExpressionAst
constructor
A new instance of ReplicationExpressionAst.
- #n ⇒ 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.
- #v ⇒ Object
-
#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, n, v) ⇒ ReplicationExpressionAst
Returns a new instance of ReplicationExpressionAst.
3144 3145 3146 |
# File 'lib/idl/ast.rb', line 3144 def initialize(input, interval, n, v) super(input, interval, [n, v]) end |
Instance Method Details
#n ⇒ Object
3141 |
# File 'lib/idl/ast.rb', line 3141 def n = @children[0] |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3181 |
# File 'lib/idl/ast.rb', line 3181 def to_idl = "{#{n.to_idl}{#{v.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
3170 3171 3172 3173 3174 3175 3176 3177 3178 |
# File 'lib/idl/ast.rb', line 3170 def type(symtab) value_result = value_try do width = (n.value(symtab) * v.type(symtab).width) return Type.new(:bits, width:) end value_else(value_result) do Type.new(:bits, width: :unknown) end end |
#type_check(symtab) ⇒ void
3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 |
# File 'lib/idl/ast.rb', line 3149 def type_check(symtab) n.type_check(symtab) v.type_check(symtab) type_error "value of replication must be a Bits type" unless v.type(symtab).kind == :bits value_try do type_error "replication amount must be positive (#{n.value(symtab)})" unless n.value(symtab).positive? end # type_error "replication amount must be known at compile time" end |
#v ⇒ Object
3142 |
# File 'lib/idl/ast.rb', line 3142 def v = @children[1] |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
3161 3162 3163 3164 3165 3166 3167 |
# File 'lib/idl/ast.rb', line 3161 def value(symtab) result = 0 n.value(symtab).times do |i| result |= v.value(symtab) << (i * v.type(symtab).width) end result 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