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=, #linkage, #linkage=, #section, #section=, #unnamed_addr=, #unnamed_addr?, #visibility, #visibility=

Methods inherited from Constant

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

Methods inherited from User

#operands

Methods inherited from Value

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

Methods included from PointerIdentity

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

Instance Method Details

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

Adds attr to this value’s attributes.



914
915
916
# File 'lib/llvm/core/value.rb', line 914

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

#attribute_countObject



923
924
925
# File 'lib/llvm/core/value.rb', line 923

def attribute_count
  function_attributes.count
end

#attributesObject



927
928
929
# File 'lib/llvm/core/value.rb', line 927

def attributes
  function_attributes.to_a
end

#basic_blocksObject

Returns an Enumerable of the BasicBlocks in this function.



896
897
898
# File 'lib/llvm/core/value.rb', line 896

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

#call_convObject

gets the calling convention of the function



876
877
878
# File 'lib/llvm/core/value.rb', line 876

def call_conv
  C.get_function_call_conv(self)
end

#call_conv=(conv) ⇒ Object

Sets the function’s calling convention and returns it.



871
872
873
# File 'lib/llvm/core/value.rb', line 871

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

#function_attributesObject



943
944
945
# File 'lib/llvm/core/value.rb', line 943

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

#function_typeObject



900
901
902
# File 'lib/llvm/core/value.rb', line 900

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

#gcObject



1125
1126
1127
# File 'lib/llvm/core/value.rb', line 1125

def gc
  C.get_gc(self)
end

#gc=(name) ⇒ Object



1121
1122
1123
# File 'lib/llvm/core/value.rb', line 1121

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

#inspectObject



1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/llvm/core/value.rb', line 1129

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



951
952
953
# File 'lib/llvm/core/value.rb', line 951

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

#paramsObject

Returns an Enumerable of the parameters in the function.



1088
1089
1090
# File 'lib/llvm/core/value.rb', line 1088

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

#personality_functionObject

Note:

Experimental and unsupported

Get personality function of function

Returns:

  • LLVM::Function



883
884
885
886
# File 'lib/llvm/core/value.rb', line 883

def personality_function
  ptr = C.get_personality_fn(self)
  LLVM::Function.from_ptr(ptr)
end

#personality_function=(personality_function) ⇒ Object

Note:

Experimental and unsupported

Set personality function of function

Returns:

  • self



891
892
893
# File 'lib/llvm/core/value.rb', line 891

def personality_function=(personality_function)
  C.set_personality_fn(self, personality_function)
end

#readnone?Boolean

Returns:

  • (Boolean)


931
932
933
# File 'lib/llvm/core/value.rb', line 931

def readnone?
  attributes.detect(&:readnone?)
end

#readonly?Boolean

Returns:

  • (Boolean)


935
936
937
# File 'lib/llvm/core/value.rb', line 935

def readonly?
  attributes.detect(&:readonly?)
end

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

Removes the given attribute from the function.



919
920
921
# File 'lib/llvm/core/value.rb', line 919

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

#return_attributesObject



947
948
949
# File 'lib/llvm/core/value.rb', line 947

def return_attributes
  AttributeCollection.new(self, 0)
end

#return_typeObject



909
910
911
# File 'lib/llvm/core/value.rb', line 909

def return_type
  type.return_type
end

#typeObject

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



905
906
907
# File 'lib/llvm/core/value.rb', line 905

def type
  function_type
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/llvm/analysis.rb', line 53

def valid?
  verify
end

#verifytrue, false

Verify that a function is valid.

Returns:

  • (true, false)


41
42
43
# File 'lib/llvm/analysis.rb', line 41

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)


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

def verify!
  # :nocov:
  do_verification(:abort_process)
  # :nocov:
end

#writeonly?Boolean

Returns:

  • (Boolean)


939
940
941
# File 'lib/llvm/core/value.rb', line 939

def writeonly?
  attributes.detect(&:writeonly?)
end