class BOAST::Int

@!parse module VarFunctors; var_functorize Int; end

Attributes

signed[R]
size[R]
total_size[R]
vector_length[R]

Public Class Methods

new(hash={}) click to toggle source

Creates a new instance of Int. @param [Hash] hash contains named properties for the type @option hash [Integer] :size size of the Int type in byte. By default {BOAST.get_default_int_size}. @option hash [Integer] :vector_length length of the vector of Int. By default 1. @option hash [Integer] :signed specifies if the Int is signed or not. By default {BOAST.get_default_int_signed}.

# File lib/BOAST/Language/DataTypes.rb, line 167
def initialize(hash={})
  if hash[:size] then
    @size = hash[:size]
  else
    @size = get_default_int_size
  end
  if hash[:signed] != nil then
    @signed = hash[:signed]
  else
    @signed = get_default_int_signed
  end
  if hash[:vector_length] and hash[:vector_length] > 1 then
    @vector_length = hash[:vector_length]
    raise "Vectors need to have their element size specified!" unless @size
  else
    @vector_length = 1
  end
  @total_size = @size*@vector_length
end

Public Instance Methods

==(t) click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 157
def ==(t)
  return true if t.class == self.class and t.signed == signed and t.size == size and t.vector_length == vector_length
  return false
end
copy(options={}) click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 191
def copy(options={})
  hash = to_hash
  options.each { |k,v|
    hash[k] = v
  }
  return Int::new(hash)
end
decl() click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 203
def decl
  if lang == FORTRAN then
    return "integer(kind=#{@size})" if @size
    return "integer"
  end
  if lang == C then
    if @vector_length == 1 then
      s = ""
      s << "u" unless @signed
      return s+"int#{8*@size}_t" if @size
      return s+"int"
    elsif @vector_length > 1 then
      return get_vector_decl(self)
    end
  else
    s =""
    unless @signed then
      s << "u"
      s << "nsigned " if lang == CUDA and @vector_length == 1
    end
    case @size
    when 1
      s << "char"
    when 2
      s << "short"
    when 4
      s << "int"
    when 8
      if lang == CUDA
        case @vector_length
        when 1
          s << "long long"
        else
          s << "longlong"
        end
      else
        s << "long"
      end
    when nil
      s << "int"
    else
      raise "Unsupported integer size!"
    end
    if @vector_length > 1 then
      s << "#{@vector_length}"
    end
    return s
  end
end
decl_ffi() click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 253
def decl_ffi
  t = ""
  t << "u" unless @signed
  t << "int"
  t << "#{@size*8}" if @size
  return t.to_sym
end
signed?() click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 199
def signed?
  return @signed
end
suffix() click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 261
def suffix
  s = ""
  return s
end
to_hash() click to toggle source
# File lib/BOAST/Language/DataTypes.rb, line 187
def to_hash
  return { :size => @size, :vector_length => @vector_length, :signed => @signed }
end