Class: VPI::Handle::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-vpi/core/handle.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aMethName) ⇒ Property

Returns a new instance of Property.



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ruby-vpi/core/handle.rb', line 337

def initialize aMethName
  @methName = aMethName.to_s

  # parse property information from the given method name
    tokens = @methName.split('_')

    tokens.last.sub!(/[\?!=]$/, '')
    addendum  = $&
    @isAssign = $& == '='
    isQuery   = $& == '?'

    tokens.last =~ /^[a-z]$/ && tokens.pop
    @accessor = $&

    @name = tokens.pop

    @operation = unless tokens.empty?
      tokens.join('_') << (addendum || '')
    end

  # determine the VPI integer type for the property
    @name = @name.to_ruby_const_name
    @name.insert 0, 'Vpi' unless @name =~ /^[Vv]pi/

    begin
      @type = VPI.const_get(@name)
    rescue NameError
      raise ArgumentError, "#{@name.inspect} is not a valid VPI property"
    end

  @accessor = if @accessor
    @accessor.to_sym
  else
    # infer accessor from VPI property @name
    if isQuery
      :b
    else
      case @name
      when /Time$/
        :d

      when /Val$/
        :l

      when /Type$/, /Direction$/, /Index$/, /Size$/, /Strength\d?$/, /Polarity$/, /Edge$/, /Offset$/, /Mode$/, /LineNo$/
        :i

      when /Is[A-Z]/, /ed$/
        :b

      when /Name$/, /File$/, /Decompile$/
        :s

      when /Parent$/, /Inst$/, /Range$/, /Driver$/, /Net$/, /Load$/, /Conn$/, /Bit$/, /Word$/, /[LR]hs$/, /(In|Out)$/, /Term$/, /Argument$/, /Condition$/, /Use$/, /Operand$/, /Stmt$/, /Expr$/, /Scope$/, /Memory$/, /Delay$/
        :h
      end
    end
  end
end

Instance Attribute Details

#accessorObject (readonly)

Returns the value of attribute accessor.



335
336
337
# File 'lib/ruby-vpi/core/handle.rb', line 335

def accessor
  @accessor
end

#nameObject (readonly)

Returns the value of attribute name.



335
336
337
# File 'lib/ruby-vpi/core/handle.rb', line 335

def name
  @name
end

#operationObject (readonly)

Returns the value of attribute operation.



335
336
337
# File 'lib/ruby-vpi/core/handle.rb', line 335

def operation
  @operation
end

#typeObject (readonly)

Returns the value of attribute type.



335
336
337
# File 'lib/ruby-vpi/core/handle.rb', line 335

def type
  @type
end

Instance Method Details

#execute(aHandle, *aArgs, &aBlockArg) ⇒ Object



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/ruby-vpi/core/handle.rb', line 397

def execute aHandle, *aArgs, &aBlockArg
  if @operation
    aHandle.__send__(@operation, @type, *aArgs, &aBlockArg)
  else
    case @accessor
    when :d # delay values
      raise NotImplementedError, 'processing of delay values is not yet implemented.'
      # TODO: vpi_put_delays
      # TODO: vpi_get_delays

    when :l # logic values
      if @isAssign
        value = aArgs.shift
        aHandle.put_value(value, @type, *aArgs)
      else
        aHandle.get_value(@type)
      end

    when :i # integer values
      if @isAssign
        raise NotImplementedError
      else
        vpi_get(@type, aHandle)
      end

    when :b # boolean values
      if @isAssign
        raise NotImplementedError
      else
        value = vpi_get(@type, aHandle)
        value && (value != 0) # zero is false in C
      end

    when :s # string values
      if @isAssign
        raise NotImplementedError
      else
        vpi_get_str(@type, aHandle)
      end

    when :h # handle values
      if @isAssign
        raise NotImplementedError
      else
        vpi_handle(@type, aHandle)
      end

    when :a # array of child handles
      if @isAssign
        raise NotImplementedError
      else
        aHandle.to_a(@type)
      end

    else
      raise NoMethodError, "cannot access VPI property #{@name.inspect} for handle #{aHandle.inspect} through method #{@methName.inspect} with arguments #{aArgs.inspect}"
    end
  end
end