Class: LLVM::Attribute
- Inherits:
-
Object
- Object
- LLVM::Attribute
- Includes:
- PointerIdentity
- Defined in:
- lib/llvm/core/attribute.rb
Overview
wrapper for LLVMAttributeRef
Class Method Summary collapse
-
.enum(kind, value = 0, context = Context.global) ⇒ Object
create enum attribute with optional value and context.
- .last_enum ⇒ Object
-
.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.
- .new(from) ⇒ Object
-
.string(key, value, context = Context.global) ⇒ Object
create string attribute with key and value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #enum? ⇒ Boolean
- #inspect ⇒ Object
- #kind ⇒ Object
- #kind_id ⇒ Object
- #readnone? ⇒ Boolean
- #readonly? ⇒ Boolean
- #string? ⇒ Boolean
- #to_s ⇒ Object
- #type? ⇒ Boolean
- #value ⇒ Object
- #writeonly? ⇒ Boolean
Methods included from PointerIdentity
Class Method Details
.enum(kind, value = 0, context = Context.global) ⇒ Object
create enum attribute with optional value and context
29 30 31 32 33 |
# File 'lib/llvm/core/attribute.rb', line 29 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_enum ⇒ Object
43 44 45 |
# File 'lib/llvm/core/attribute.rb', line 43 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
22 23 24 25 26 |
# File 'lib/llvm/core/attribute.rb', line 22 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
9 10 11 12 13 14 15 16 |
# File 'lib/llvm/core/attribute.rb', line 9 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
36 37 38 39 40 41 |
# File 'lib/llvm/core/attribute.rb', line 36 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
128 129 130 131 132 133 134 135 |
# File 'lib/llvm/core/attribute.rb', line 128 def ==(other) super if self.class == other.class # strings and symbols return true if to_s == other.to_s false end |
#enum? ⇒ Boolean
104 105 106 |
# File 'lib/llvm/core/attribute.rb', line 104 def enum? C.is_enum_attribute(self) end |
#inspect ⇒ Object
116 117 118 |
# File 'lib/llvm/core/attribute.rb', line 116 def inspect to_s end |
#kind ⇒ Object
92 93 94 95 96 |
# File 'lib/llvm/core/attribute.rb', line 92 def kind return enum_kind if enum? return string_kind if string? raise end |
#kind_id ⇒ Object
124 125 126 |
# File 'lib/llvm/core/attribute.rb', line 124 def kind_id enum_kind_id end |
#readnone? ⇒ Boolean
137 138 139 |
# File 'lib/llvm/core/attribute.rb', line 137 def readnone? enum_kind == 'readnone' || (enum_kind == 'memory' && enum_value_mem_none?) end |
#readonly? ⇒ Boolean
141 142 143 |
# File 'lib/llvm/core/attribute.rb', line 141 def readonly? enum_kind == 'readonly' || (enum_kind == 'memory' && enum_value_mem_read?) end |
#string? ⇒ Boolean
108 109 110 |
# File 'lib/llvm/core/attribute.rb', line 108 def string? C.is_string_attribute(self) end |
#to_s ⇒ Object
120 121 122 |
# File 'lib/llvm/core/attribute.rb', line 120 def to_s Support::C.get_attribute_as_string(self) end |
#type? ⇒ Boolean
112 113 114 |
# File 'lib/llvm/core/attribute.rb', line 112 def type? C.is_type_attribute(self) end |
#value ⇒ Object
98 99 100 101 102 |
# File 'lib/llvm/core/attribute.rb', line 98 def value return enum_value if enum? return string_value if string? raise end |
#writeonly? ⇒ Boolean
145 146 147 |
# File 'lib/llvm/core/attribute.rb', line 145 def writeonly? enum_kind == 'writeonly' || (enum_kind == 'memory' && enum_value_mem_write?) end |