Class: LLVM::Attribute

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

Overview

wrapper for LLVMAttributeRef

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PointerIdentity

#eql?, #hash, #to_ptr

Class Method Details

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

create enum attribute with optional value and context



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

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



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

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


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

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



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



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

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



131
132
133
134
135
136
137
138
# File 'lib/llvm/core/attribute.rb', line 131

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

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

  false
end

#enum?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/llvm/core/attribute.rb', line 107

def enum?
  C.is_enum_attribute(self)
end

#inspectObject



119
120
121
# File 'lib/llvm/core/attribute.rb', line 119

def inspect
  to_s
end

#kindObject



95
96
97
98
99
# File 'lib/llvm/core/attribute.rb', line 95

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

#kind_idObject



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

def kind_id
  enum_kind_id
end

#readnone?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/llvm/core/attribute.rb', line 140

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

#readonly?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/llvm/core/attribute.rb', line 144

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

#string?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/llvm/core/attribute.rb', line 111

def string?
  C.is_string_attribute(self)
end

#to_sObject



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

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

#type?Boolean

Returns:

  • (Boolean)


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

def type?
  C.is_type_attribute(self)
end

#valueObject



101
102
103
104
105
# File 'lib/llvm/core/attribute.rb', line 101

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

#writeonly?Boolean

Returns:

  • (Boolean)


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

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