Class: Idl::ConcatenationExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Overview
represents a concatenation expression
for example:
{1'b0, 5'd3}
Instance Method Summary collapse
- #expressions ⇒ 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.
Constructor Details
This class inherits a constructor from Idl::AstNode
Instance Method Details
#expressions ⇒ Object
3105 |
# File 'lib/idl/ast.rb', line 3105 def expressions = @children |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3144 |
# File 'lib/idl/ast.rb', line 3144 def to_idl = "{#{expressions.map { |exp| exp.to_idl }.join(',')}}" |
#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
3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 |
# File 'lib/idl/ast.rb', line 3121 def type(symtab) total_width = expressions.reduce(0) do |sum, exp| e_type = exp.type(symtab) return BitsUnknownType if e_type.width == :unknown sum + e_type.width end Type.new(:bits, width: total_width) end |
#type_check(symtab) ⇒ void
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 |
# File 'lib/idl/ast.rb', line 3108 def type_check(symtab) type_error "Must concatenate at least two objects" if expressions.size < 2 expressions.each do |exp| exp.type_check(symtab) e_type = exp.type(symtab) type_error "Concatenation only supports Bits<> types" unless e_type.kind == :bits internal_error "Negative width for element #{exp.text_value}" if (e_type.width != :unknown) && (e_type.width <= 0) end end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
3133 3134 3135 3136 3137 3138 3139 3140 3141 |
# File 'lib/idl/ast.rb', line 3133 def value(symtab) result = 0 total_width = 0 expressions.reverse_each do |exp| result |= (exp.value(symtab) << total_width) total_width += exp.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