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



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

def expressions = @children

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



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

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:



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

Parameters:

  • symtab (SymbolTable)

    The context for the evaluation

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