Class: LLVM::Attribute

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

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



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

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



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

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


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

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



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

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



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

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

#enum?Boolean

Returns:

  • (Boolean)


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

def enum?
  C.is_enum_attribute(self)
end

#inspectObject



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

def inspect
  return "\"#{kind}\" = \"#{value}\"" if string?
  return "#{kind}(#{value})" if enum?
  super
end

#kindObject



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

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

#kind_idObject



129
130
131
# File 'lib/llvm/core/attribute.rb', line 129

def kind_id
  enum_kind_id
end

#string?Boolean

Returns:

  • (Boolean)


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

def string?
  C.is_string_attribute(self)
end

#to_sObject



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

def to_s
  return kind if enum?
  super
end

#type?Boolean

Returns:

  • (Boolean)


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

def type?
  C.is_type_attribute(self)
end

#valueObject



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

def value
  return C.get_enum_attribute_value(self) if enum?
  return string_value if string?
  raise
end