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.
3163 3164 3165 |
# File 'lib/idl/ast.rb', line 3163 def initialize(input, interval, n, v) super(input, interval, [n, v]) end |
Instance Method Details
#n ⇒ Object
3160 |
# File 'lib/idl/ast.rb', line 3160 def n = @children[0] |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3200 |
# File 'lib/idl/ast.rb', line 3200 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
3189 3190 3191 3192 3193 3194 3195 3196 3197 |
# File 'lib/idl/ast.rb', line 3189 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
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 |
# File 'lib/idl/ast.rb', line 3168 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
3161 |
# File 'lib/idl/ast.rb', line 3161 def v = @children[1] |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
3180 3181 3182 3183 3184 3185 3186 |
# File 'lib/idl/ast.rb', line 3180 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