Class: LLVM::Function::AttributeCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/llvm/core/value.rb

Instance Method Summary collapse

Constructor Details

#initialize(fun, index) ⇒ AttributeCollection

Returns a new instance of AttributeCollection.



1017
1018
1019
1020
# File 'lib/llvm/core/value.rb', line 1017

def initialize(fun, index)
  @fun = fun
  @index = index
end

Instance Method Details

#add(attr) ⇒ Object



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'lib/llvm/core/value.rb', line 1022

def add(attr)
  attr_ref = case attr
  when Attribute
    attr
  when Symbol, String
    attr_kind_id = attribute_id(attr)
    if attr_kind_id.is_a?(Integer)
      ctx = Context.global
      C.create_enum_attribute(ctx, attr_kind_id, 0)
    else
      attr_kind_id
    end
  when Integer
    C.create_enum_attribute(ctx, attr, 0)
  else
    raise "Adding unknown attribute type: #{attr.inspect}"
  end
  C.add_attribute_at_index(@fun, @index, attr_ref)
end

#countObject



1047
1048
1049
# File 'lib/llvm/core/value.rb', line 1047

def count
  C.get_attribute_count_at_index(@fun, @index)
end

#remove(attr) ⇒ Object



1042
1043
1044
1045
# File 'lib/llvm/core/value.rb', line 1042

def remove(attr)
  attr_kind_id = attribute_id(attr)
  C.remove_enum_attribute_at_index(@fun, @index, attr_kind_id)
end

#to_aObject

-> Array



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/llvm/core/value.rb', line 1052

def to_a
  attr_refs = [] #: Array[Attribute]
  n = count
  FFI::MemoryPointer.new(:pointer, n) do |p|
    C.get_attributes_at_index(@fun, @index, p)
    attr_refs = p.read_array_of_type(:pointer, :read_pointer, n)
  end

  attr_refs.map { |e| Attribute.send(:from_ptr, e) }
end