Class: Idl::ReplicationExpressionAst

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

Overview

represents a replication expression

for example:

{5{5'd3}}

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, n, v) ⇒ ReplicationExpressionAst

Returns a new instance of ReplicationExpressionAst.



3144
3145
3146
# File 'lib/idl/ast.rb', line 3144

def initialize(input, interval, n, v)
  super(input, interval, [n, v])
end

Instance Method Details

#nObject



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

def n = @children[0]

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

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

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



3170
3171
3172
3173
3174
3175
3176
3177
3178
# File 'lib/idl/ast.rb', line 3170

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

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:



3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
# File 'lib/idl/ast.rb', line 3149

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

#vObject



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

def v = @children[1]

#value(symtab) ⇒ Object

Return the compile-time-known value of the node



3161
3162
3163
3164
3165
3166
3167
# File 'lib/idl/ast.rb', line 3161

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

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