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
3092 |
# File 'lib/idl/ast.rb', line 3092 def expressions = @children |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3125 |
# File 'lib/idl/ast.rb', line 3125 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
3107 3108 3109 3110 3111 |
# File 'lib/idl/ast.rb', line 3107 def type(symtab) total_width = expressions.reduce(0) { |sum, exp| sum + exp.type(symtab).width } Type.new(:bits, width: total_width) end |
#type_check(symtab) ⇒ void
3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 |
# File 'lib/idl/ast.rb', line 3095 def type_check(symtab) type_error "Must concatenate at least two objects" if expressions.size < 2 expressions.each do |exp| exp.type_check(symtab) type_error "Concatenation only supports Bits<> types" unless exp.type(symtab).kind == :bits internal_error "Negative width for element #{exp.text_value}" if exp.type(symtab).width <= 0 end end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
3114 3115 3116 3117 3118 3119 3120 3121 3122 |
# File 'lib/idl/ast.rb', line 3114 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