Class: LLVM::Attribute

Inherits:
Object
  • Object
show all
Includes:
PointerIdentity
Defined in:
lib/llvm/core/attribute.rb

Overview

wrapper for LLVMAttributeRef

Instance Attribute Summary

Attributes included from PointerIdentity

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PointerIdentity

#eql?, #hash, #to_ptr

Class Method Details

.captures_noneObject

: -> Attribute?



32
33
34
# File 'lib/llvm/core/attribute.rb', line 32

def captures_none
  enum(:captures)
end

.enum(kind, value = 0, context = Context.global) ⇒ Object

create enum attribute with optional value and context : (untyped, ?Integer, ?Context) -> Attribute?



38
39
40
41
42
# File 'lib/llvm/core/attribute.rb', line 38

def enum(kind, value = 0, context = Context.global)
  attr_id = attribute_id(kind)
  ptr = C.create_enum_attribute(context, attr_id, value)
  from_ptr(ptr)
end

.last_enumObject

: -> Integer



54
55
56
# File 'lib/llvm/core/attribute.rb', line 54

def last_enum
  C.get_last_enum_attribute_kind
end

.memory(opts = {}) ⇒ Object

create a memory attribute from a hash where the keys are:

argmem, inaccessiblemem, memory

and the valid values are:

read, write, readwrite

: (?Hash[untyped, untyped]) -> Attribute?



25
26
27
28
29
# File 'lib/llvm/core/attribute.rb', line 25

def memory(opts = {})
  opts = opts.transform_keys(&:to_sym)
  val = bit_value(opts[:argmem]) | (bit_value(opts[:inaccessiblemem]) << 2) | (bit_value(opts[:memory]) << 4)
  enum(:memory, val)
end

.new(from) ⇒ Object

: (String | Symbol) -> Attribute?



11
12
13
14
15
16
17
18
# File 'lib/llvm/core/attribute.rb', line 11

def new(from)
  case from
  when String, Symbol
    enum(from)
  else
    raise "Not implemented to create Attribute from #{from.class}"
  end
end

.string(key, value, context = Context.global) ⇒ Object

create string attribute with key and value : (untyped, untyped, ?Context) -> Attribute?



46
47
48
49
50
51
# File 'lib/llvm/core/attribute.rb', line 46

def string(key, value, context = Context.global)
  key = key.to_s
  value = value.to_s
  ptr = C.create_string_attribute(context, key, key.size, value, value.size)
  from_ptr(ptr)
end

Instance Method Details

#==(other) ⇒ Object

: (untyped) -> bool



152
153
154
155
156
157
158
159
# File 'lib/llvm/core/attribute.rb', line 152

def ==(other)
  super if self.class == other.class

  # strings and symbols
  return true if to_s == other.to_s

  false
end

#enum?Boolean

: -> bool

Returns:

  • (Boolean)


122
123
124
# File 'lib/llvm/core/attribute.rb', line 122

def enum?
  C.is_enum_attribute(self)
end

#inspectObject

: -> String



137
138
139
# File 'lib/llvm/core/attribute.rb', line 137

def inspect
  to_s
end

#kindObject

: -> (Integer | String)



108
109
110
111
112
# File 'lib/llvm/core/attribute.rb', line 108

def kind
  return enum_kind if enum?
  return string_kind if string?
  raise
end

#kind_idObject

: -> Integer



147
148
149
# File 'lib/llvm/core/attribute.rb', line 147

def kind_id
  enum_kind_id
end

#readnone?Boolean

: -> bool

Returns:

  • (Boolean)


162
163
164
# File 'lib/llvm/core/attribute.rb', line 162

def readnone?
  enum_kind == 'readnone' || (enum_kind == 'memory' && enum_value_mem_none?)
end

#readonly?Boolean

: -> bool

Returns:

  • (Boolean)


167
168
169
# File 'lib/llvm/core/attribute.rb', line 167

def readonly?
  enum_kind == 'readonly' || (enum_kind == 'memory' && enum_value_mem_read?)
end

#string?Boolean

: -> bool

Returns:

  • (Boolean)


127
128
129
# File 'lib/llvm/core/attribute.rb', line 127

def string?
  C.is_string_attribute(self)
end

#to_sObject

: -> String



142
143
144
# File 'lib/llvm/core/attribute.rb', line 142

def to_s
  Support::C.get_attribute_as_string(self)
end

#type?Boolean

: -> bool

Returns:

  • (Boolean)


132
133
134
# File 'lib/llvm/core/attribute.rb', line 132

def type?
  C.is_type_attribute(self)
end

#valueObject

: -> (Integer | String)



115
116
117
118
119
# File 'lib/llvm/core/attribute.rb', line 115

def value
  return enum_value if enum?
  return string_value if string?
  raise
end

#writeonly?Boolean

: -> bool

Returns:

  • (Boolean)


172
173
174
# File 'lib/llvm/core/attribute.rb', line 172

def writeonly?
  enum_kind == 'writeonly' || (enum_kind == 'memory' && enum_value_mem_write?)
end