Class: Idl::ConcatenationExpressionAst

Inherits:
AstNode
  • Object
show all
Includes:
Rvalue
Defined in:
lib/idl/ast.rb

Overview

represents a concatenation expression

for example:

{1'b0, 5'd3}

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Idl::AstNode

Instance Method Details

#expressionsObject



3092
# File 'lib/idl/ast.rb', line 3092

def expressions = @children

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



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

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



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

This method returns an undefined value.

type check this node and all children

Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError

Parameters:

Raises:



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

Parameters:

  • symtab (SymbolTable)

    The context for the evaulation

Returns:

  • (Array<Integer>)

    The complete list of compile-time-known values, when they are integral

  • (Array<Boolean>)

    The complete list of compile-time-known values, when they are booleans

  • (AstNode::ValueError)

    if the list of values is not knowable at compile time