Module: LLVM

Defined in:
lib/llvm/config.rb,
lib/llvm.rb,
lib/llvm/core.rb,
lib/llvm/linker.rb,
lib/llvm/target.rb,
lib/llvm/support.rb,
lib/llvm/version.rb,
lib/llvm/analysis.rb,
lib/llvm/core/type.rb,
lib/llvm/core/value.rb,
lib/llvm/core/module.rb,
lib/llvm/core/bitcode.rb,
lib/llvm/core/builder.rb,
lib/llvm/core/context.rb,
lib/llvm/transforms/ipo.rb,
lib/llvm/execution_engine.rb,
lib/llvm/core/pass_manager.rb,
lib/llvm/transforms/scalar.rb,
lib/llvm/transforms/builder.rb,
lib/llvm/transforms/vectorize.rb

Overview

Generated by ruby-llvm. Please do not change this file by hand.

Defined Under Namespace

Modules: C, CONFIG, PointerIdentity, Support Classes: Argument, BasicBlock, Builder, CallInst, Constant, ConstantArray, ConstantExpr, ConstantInt, ConstantReal, ConstantStruct, ConstantVector, Context, Double, Float, Function, FunctionPassManager, FunctionType, GenericValue, GlobalAlias, GlobalValue, GlobalVariable, IndirectBr, Instruction, IntType, JITCompiler, MemoryBuffer, Module, PassManager, PassManagerBuilder, Phi, StructType, SwitchInst, Target, TargetDataLayout, TargetMachine, Type, User, Value

Constant Summary collapse

LLVM_VERSION =
"3.3"
RUBY_LLVM_VERSION =
"3.3.0"
Int =
const_get("Int#{bits}")
TRUE =

Boolean values

::LLVM::Int1.from_i(-1)
FALSE =
::LLVM::Int1.from_i(0)

Class Method Summary collapse

Class Method Details

.Array(ty, sz = 0) ⇒ Object

Shortcut to Type.array.



176
177
178
# File 'lib/llvm/core/type.rb', line 176

def Array(ty, sz = 0)
  LLVM::Type.array(ty, sz)
end

.const_missing(const) ⇒ Object



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/llvm/core/value.rb', line 449

def LLVM.const_missing(const)
  case const.to_s
  when /Int(\d+)/
    width = $1.to_i
    name  = "Int#{width}"
    eval <<-KLASS
      class #{name} < ConstantInt
        def self.type
          Type.from_ptr(C.int_type(#{width}), :integer)
        end
      end
    KLASS
    const_get(name)
  else
    super
  end
end

.Double(val) ⇒ Object



563
564
565
# File 'lib/llvm/core/value.rb', line 563

def LLVM.Double(val)
  Double.from_f(val)
end

.Float(val) ⇒ Object

Create a LLVM::Float from a Ruby Float (val).



553
554
555
# File 'lib/llvm/core/value.rb', line 553

def LLVM.Float(val)
  Float.from_f(val)
end

.Function(argtypes, rettype, options = {}) ⇒ Object

Shortcut to Type.function.



191
192
193
# File 'lib/llvm/core/type.rb', line 191

def Function(argtypes, rettype, options = {})
  LLVM::Type.function(argtypes, rettype, options)
end

.init_jitObject

A shorthand for LLVM::Target.init_native



7
8
9
# File 'lib/llvm/target.rb', line 7

def self.init_jit
  LLVM::Target.init_native
end

.init_x86Object

Deprecated.

Use LLVM.init_jit or LLVM::Target.init(‘X86’).



12
13
14
15
# File 'lib/llvm/target.rb', line 12

def self.init_x86
  warn "LLVM.init_x86 is deprecated. Use LLVM.init_jit or LLVM::Target.init('X86')."
  LLVM::Target.init('X86')
end

.Int(val) ⇒ Object

Creates a LLVM Int (subclass of ConstantInt) at the NATIVE_INT_SIZE from a integer (val).



472
473
474
475
476
477
478
479
480
481
# File 'lib/llvm/core/value.rb', line 472

def LLVM.Int(val)
  case val
  when LLVM::ConstantInt then val
  when Integer then Int.from_i(val)
  when Value
    return val if val.type.kind == :integer
    raise "value not of integer type: #{val.type.kind}"
  else raise "can't make an LLVM::ConstantInt from #{val.class.name}"
  end
end

.load_library(libname) ⇒ Object



41
42
43
44
45
# File 'lib/llvm/support.rb', line 41

def load_library(libname)
  Support::C.load_library_permanently(libname)

  nil
end

.make_generic_value(ty, val) ⇒ Object



144
145
146
147
148
149
150
151
152
153
# File 'lib/llvm/execution_engine.rb', line 144

def make_generic_value(ty, val)
  case ty.kind
  when :double  then GenericValue.from_d(val)
  when :float   then GenericValue.from_f(val)
  when :pointer then GenericValue.from_value_ptr(val)
  when :integer then GenericValue.from_i(val, :type => ty)
  else
    raise "Unsupported type #{ty.kind}."
  end
end

.Pointer(ty) ⇒ Object

Shortcut to Type.pointer.



181
182
183
# File 'lib/llvm/core/type.rb', line 181

def Pointer(ty)
  LLVM::Type.pointer(ty)
end

.Struct(*elt_types) ⇒ Object

Shortcut to Type.struct.



196
197
198
199
200
201
202
203
# File 'lib/llvm/core/type.rb', line 196

def Struct(*elt_types)
  name = if elt_types.last.is_a? String
    elt_types.pop
  else
    nil
  end
  LLVM::Type.struct(elt_types, false, name)
end

.Type(ty) ⇒ Object

Creates a Type from the given object.



168
169
170
171
172
173
# File 'lib/llvm/core/type.rb', line 168

def Type(ty)
  case ty
  when LLVM::Type then ty
  else ty.type
  end
end

.Vector(ty, sz) ⇒ Object

Shortcut to Type.vector.



186
187
188
# File 'lib/llvm/core/type.rb', line 186

def Vector(ty, sz)
  LLVM::Type.vector(ty, sz)
end

.VoidObject

Shortcut to Type.void.



206
207
208
# File 'lib/llvm/core/type.rb', line 206

def Void
  LLVM::Type.void
end

.with_error_output {|FFI::MemoryPointer| ... } ⇒ nil

Same as #with_message_output, but raises a RuntimeError with the resulting message.

Yields:

  • (FFI::MemoryPointer)

Returns:

  • (nil)

Raises:

  • (RuntimeError)


41
42
43
44
45
# File 'lib/llvm/core.rb', line 41

def self.with_error_output(&block)
  error = with_message_output(&block)

  raise RuntimeError, error unless error.nil?
end

.with_message_output {|FFI::MemoryPointer| ... } ⇒ String?

Yields a pointer suitable for storing an LLVM output message. If the message pointer is non-NULL (an error has happened), converts the result to a string and returns it. Otherwise, returns nil.

Yields:

  • (FFI::MemoryPointer)

Returns:

  • (String, nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/llvm/core.rb', line 17

def self.with_message_output
  message = nil

  FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |str|
    result = yield str

    msg_ptr = str.read_pointer

    if result != 0
      raise RuntimeError, "Error is signalled, but msg_ptr is null" if msg_ptr.null?

      message = msg_ptr.read_string
      C.dispose_message msg_ptr
    end
  end

  message
end