Class: LLVM::Function

Inherits:
GlobalValue show all
Defined in:
lib/llvm/analysis.rb,
lib/llvm/core/value.rb

Defined Under Namespace

Classes: AttributeCollection, BasicBlockCollection, ParameterCollection

Instance Method Summary collapse

Methods inherited from GlobalValue

#alignment, #alignment=, #declaration?, #dll_storage_class, #dll_storage_class=, #global_constant=, #global_constant?, #initializer, #initializer=, #linkage, #linkage=, #section, #section=, #unnamed_addr=, #unnamed_addr?, #visibility, #visibility=

Methods inherited from Constant

#bitcast_to, #gep, null, null_ptr, #ptr_to_int, undef

Methods inherited from User

#operands

Methods inherited from Value

#allocated_type, #constant?, #dump, from_ptr, from_ptr_kind, #global_parent, #kind, #name, #name=, #null?, to_ptr, #to_s, type, #undefined?

Methods included from PointerIdentity

#==, #eql?, #hash, #to_ptr

Instance Method Details

#add_attribute(attr, index = -1)) ⇒ Object

Adds attr to this value’s attributes.



832
833
834
# File 'lib/llvm/core/value.rb', line 832

def add_attribute(attr, index = -1)
  AttributeCollection.new(self, index).add(attr)
end

#attribute_countObject



841
842
843
# File 'lib/llvm/core/value.rb', line 841

def attribute_count
  function_attributes.count
end

#attributesObject



845
846
847
# File 'lib/llvm/core/value.rb', line 845

def attributes
  function_attributes.to_a
end

#basic_blocksObject

Returns an Enumerable of the BasicBlocks in this function.



814
815
816
# File 'lib/llvm/core/value.rb', line 814

def basic_blocks
  @basic_block_collection ||= BasicBlockCollection.new(self)
end

#call_convObject

gets the calling convention of the function



809
810
811
# File 'lib/llvm/core/value.rb', line 809

def call_conv
  C.get_function_call_conv(self)
end

#call_conv=(conv) ⇒ Object

Sets the function’s calling convention and returns it.



803
804
805
806
# File 'lib/llvm/core/value.rb', line 803

def call_conv=(conv)
  C.set_function_call_conv(self, conv)
  conv
end

#function_attributesObject



849
850
851
# File 'lib/llvm/core/value.rb', line 849

def function_attributes
  AttributeCollection.new(self, -1)
end

#function_typeObject



818
819
820
# File 'lib/llvm/core/value.rb', line 818

def function_type
  Type.from_ptr(C.get_element_type(self), :function)
end

#gcObject



1033
1034
1035
# File 'lib/llvm/core/value.rb', line 1033

def gc
  C.get_gc(self)
end

#gc=(name) ⇒ Object



1029
1030
1031
# File 'lib/llvm/core/value.rb', line 1029

def gc=(name)
  C.set_gc(self, name)
end

#inspectObject



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/llvm/core/value.rb', line 1037

def inspect
  {
    signature: to_s.lines[attribute_count == 0 ? 0 : 1],
    type: type.to_s,
    attributes: attribute_count,
    valid: valid?,
    blocks: basic_blocks.size,
    lines: to_s.lines.size,
  }.to_s
end

#param_attributes(index) ⇒ Object



857
858
859
# File 'lib/llvm/core/value.rb', line 857

def param_attributes(index)
  AttributeCollection.new(self, index)
end

#paramsObject

Returns an Enumerable of the parameters in the function.



996
997
998
# File 'lib/llvm/core/value.rb', line 996

def params
  @parameter_collection ||= ParameterCollection.new(self)
end

#remove_attribute(attr, index = -1)) ⇒ Object

Removes the given attribute from the function.



837
838
839
# File 'lib/llvm/core/value.rb', line 837

def remove_attribute(attr, index = -1)
  AttributeCollection.new(self, index).remove(attr)
end

#return_attributesObject



853
854
855
# File 'lib/llvm/core/value.rb', line 853

def return_attributes
  AttributeCollection.new(self, 0)
end

#return_typeObject



827
828
829
# File 'lib/llvm/core/value.rb', line 827

def return_type
  type.return_type
end

#typeObject

In LLVM 15, not overriding this yields a pointer type instead of a function type



823
824
825
# File 'lib/llvm/core/value.rb', line 823

def type
  function_type
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/llvm/analysis.rb', line 49

def valid?
  verify
end

#verifytrue, false

Verify that a function is valid.

Returns:

  • (true, false)


39
40
41
# File 'lib/llvm/analysis.rb', line 39

def verify
  do_verification(:return_status)
end

#verify!true, false

Verify that a function is valid, and abort the process if not.

Returns:

  • (true, false)


45
46
47
# File 'lib/llvm/analysis.rb', line 45

def verify!
  do_verification(:abort_process)
end