Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 630634
Collapse All | Expand All

(-)a/.gitignore (+1 lines)
Lines 12-16 all_spec Link Here
12
/tmp
12
/tmp
13
/doc/
13
/doc/
14
/src/llvm/ext/llvm_ext.o
14
/src/llvm/ext/llvm_ext.o
15
/src/llvm/ext/llvm_ext.dwo
15
/src/ext/*.o
16
/src/ext/*.o
16
/src/ext/libcrystal.a
17
/src/ext/libcrystal.a
(-)a/Makefile (-2 lines)
Lines 37-44 LLVM_CONFIG_FINDER := \ Link Here
37
    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
37
    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
38
  command -v llvm-config-3.8 || command -v llvm-config38 || \
38
  command -v llvm-config-3.8 || command -v llvm-config38 || \
39
    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
39
    (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
40
  command -v llvm-config-3.6 || command -v llvm-config36 || \
41
  command -v llvm-config-3.5 || command -v llvm-config35 || \
42
  command -v llvm-config
40
  command -v llvm-config
43
LLVM_CONFIG := $(shell $(LLVM_CONFIG_FINDER))
41
LLVM_CONFIG := $(shell $(LLVM_CONFIG_FINDER))
44
LLVM_EXT_DIR = src/llvm/ext
42
LLVM_EXT_DIR = src/llvm/ext
(-)a/src/compiler/crystal/compiler.cr (-50 / +19 lines)
Lines 447-455 module Crystal Link Here
447
    protected def optimize(llvm_mod)
447
    protected def optimize(llvm_mod)
448
      fun_pass_manager = llvm_mod.new_function_pass_manager
448
      fun_pass_manager = llvm_mod.new_function_pass_manager
449
      {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
450
        fun_pass_manager.add_target_data target_machine.data_layout
451
      {% end %}
452
      pass_manager_builder.populate fun_pass_manager
449
      pass_manager_builder.populate fun_pass_manager
453
      fun_pass_manager.run llvm_mod
450
      fun_pass_manager.run llvm_mod
454
      module_pass_manager.run llvm_mod
451
      module_pass_manager.run llvm_mod
Lines 460-468 module Crystal Link Here
460
    private def module_pass_manager
457
    private def module_pass_manager
461
      @module_pass_manager ||= begin
458
      @module_pass_manager ||= begin
462
        mod_pass_manager = LLVM::ModulePassManager.new
459
        mod_pass_manager = LLVM::ModulePassManager.new
463
        {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
464
          mod_pass_manager.add_target_data target_machine.data_layout
465
        {% end %}
466
        pass_manager_builder.populate mod_pass_manager
460
        pass_manager_builder.populate mod_pass_manager
467
        mod_pass_manager
461
        mod_pass_manager
468
      end
462
      end
Lines 554-607 module Crystal Link Here
554
        can_reuse_previous_compilation =
548
        can_reuse_previous_compilation =
555
          !compiler.emit && !@bc_flags_changed && File.exists?(bc_name) && File.exists?(object_name)
549
          !compiler.emit && !@bc_flags_changed && File.exists?(bc_name) && File.exists?(object_name)
556
        {% if LibLLVM::IS_35 %}
550
        memory_buffer = llvm_mod.write_bitcode_to_memory_buffer
557
          # In LLVM 3.5 we can't write a bitcode to memory,
558
          # so instead we write it to another file
559
          bc_name_new = self.bc_name_new
560
          llvm_mod.write_bitcode_to_file(bc_name_new)
561
562
          if can_reuse_previous_compilation
563
            if FileUtils.cmp(bc_name, bc_name_new)
564
              # If the user cancelled a previous compilation it might be that
565
              # the .o file is empty
566
              if File.size(object_name) > 0
567
                File.delete bc_name_new
568
                must_compile = false
569
              end
570
            end
571
          end
572
          if must_compile
551
        if can_reuse_previous_compilation
573
            # Create/overwrite the .bc file (for next compilations)
552
          memory_io = IO::Memory.new(memory_buffer.to_slice)
574
            File.rename(bc_name_new, bc_name)
553
          changed = File.open(bc_name) { |bc_file| !FileUtils.cmp(bc_file, memory_io) }
575
            compiler.optimize llvm_mod if compiler.release?
576
            compiler.target_machine.emit_obj_to_file llvm_mod, object_name
577
          end
578
        {% else %}
579
          memory_buffer = llvm_mod.write_bitcode_to_memory_buffer
580
581
          if can_reuse_previous_compilation
582
            memory_io = IO::Memory.new(memory_buffer.to_slice)
583
            changed = File.open(bc_name) { |bc_file| !FileUtils.cmp(bc_file, memory_io) }
584
585
            # If the user cancelled a previous compilation
586
            # it might be that the .o file is empty
587
            if !changed && File.size(object_name) > 0
588
              must_compile = false
589
              memory_buffer.dispose
590
              memory_buffer = nil
591
            else
592
              # We need to compile, so we'll write the memory buffer to file
593
            end
594
          end
595
          # If there's a memory buffer, it means we must create a .o from it
554
          # If the user cancelled a previous compilation
596
          if memory_buffer
555
          # it might be that the .o file is empty
597
            # Create the .bc file (for next compilations)
556
          if !changed && File.size(object_name) > 0
598
            File.write(bc_name, memory_buffer.to_slice)
557
            must_compile = false
599
            memory_buffer.dispose
558
            memory_buffer.dispose
559
            memory_buffer = nil
560
          else
561
            # We need to compile, so we'll write the memory buffer to file
600
          end
562
          end
601
        {% end %}
563
        end
564
565
        # If there's a memory buffer, it means we must create a .o from it
566
        if memory_buffer
567
          # Create the .bc file (for next compilations)
568
          File.write(bc_name, memory_buffer.to_slice)
569
          memory_buffer.dispose
570
        end
602
        if must_compile
571
        if must_compile
603
          compiler.optimize llvm_mod if compiler.release?
572
          compiler.optimize llvm_mod if compiler.release?
(-)a/src/llvm.cr (-7 / +1 lines)
Lines 94-104 module LLVM Link Here
94
    string
94
    string
95
  end
95
  end
96
  {% if LibLLVM::IS_35 %}
96
  DEBUG_METADATA_VERSION = 3
97
    DEBUG_METADATA_VERSION = 1
98
  {% elsif LibLLVM::IS_36 %}
99
    DEBUG_METADATA_VERSION = 2
100
  {% else %}
101
    DEBUG_METADATA_VERSION = 3
102
  {% end %}
103
end
97
end
(-)a/src/llvm/context.cr (-4 / +4 lines)
Lines 9-17 class LLVM::Context Link Here
9
  end
9
  end
10
  def new_module(name : String) : Module
10
  def new_module(name : String) : Module
11
    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
11
    {% if LibLLVM::IS_38 %}
12
      Module.new(LibLLVM.module_create_with_name_in_context(name, self), name, self)
12
      Module.new(LibLLVM.module_create_with_name_in_context(name, self), name, self)
13
    {% else %}
13
    {% else %} # LLVM >= 3.9
14
      Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
14
      Module.new(LibLLVM.module_create_with_name_in_context(name, self), self)
15
    {% end %}
15
    {% end %}
16
  end
16
  end
Lines 104-112 class LLVM::Context Link Here
104
    if ret != 0 && msg
104
    if ret != 0 && msg
105
      raise LLVM.string_and_dispose(msg)
105
      raise LLVM.string_and_dispose(msg)
106
    end
106
    end
107
    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
107
    {% if LibLLVM::IS_38 %}
108
      Module.new(mod, "unknown", self)
108
      Module.new(mod, "unknown", self)
109
    {% else %}
109
    {% else %} # LLVM >= 3.9
110
      Module.new(mod, self)
110
      Module.new(mod, self)
111
    {% end %}
111
    {% end %}
112
  end
112
  end
(-)a/src/llvm/di_builder.cr (-20 / +4 lines)
Lines 31-46 struct LLVM::DIBuilder Link Here
31
  def create_function(scope, name, linkage_name, file, line, composite_type, is_local_to_unit, is_definition,
31
  def create_function(scope, name, linkage_name, file, line, composite_type, is_local_to_unit, is_definition,
32
                      scope_line, flags, is_optimized, func)
32
                      scope_line, flags, is_optimized, func)
33
    {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
33
    LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
34
      LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
34
      is_local_to_unit, is_definition, scope_line, flags, is_optimized, func)
35
                                            is_local_to_unit ? 1 : 0,
36
                                            is_definition ? 1 : 0,
37
                                            scope_line, flags,
38
                                            is_optimized ? 1 : 0, func)
39
    {% else %}
40
      LibLLVMExt.di_builder_create_function(self, scope, name, linkage_name, file, line, composite_type,
41
                                            is_local_to_unit, is_definition, scope_line, flags, is_optimized, func)
42
    {% end %}
43
  end
35
  end
44
  def create_auto_variable(scope, name, file, line, type, align_in_bits)
36
  def create_auto_variable(scope, name, file, line, type, align_in_bits)
Lines 87-105 struct LLVM::DIBuilder Link Here
87
  end
79
  end
88
  def create_replaceable_composite_type(scope, name, file, line, context : Context)
80
  def create_replaceable_composite_type(scope, name, file, line, context : Context)
89
    {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
81
    LibLLVMExt.di_builder_create_replaceable_composite_type(self, scope, name, file, line)
90
      LibLLVMExt.temporary_md_node(context, nil, 0).as(LibLLVMExt::Metadata)
91
    {% else %}
92
      LibLLVMExt.di_builder_create_replaceable_composite_type(self, scope, name, file, line)
93
    {% end %}
94
  end
82
  end
95
  def replace_temporary(from, to)
83
  def replace_temporary(from, to)
96
    {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
84
    LibLLVMExt.di_builder_replace_temporary(self, from, to)
97
      LibLLVMExt.metadata_replace_all_uses_with(from, to)
98
    {% else %}
99
      LibLLVMExt.di_builder_replace_temporary(self, from, to)
100
    {% end %}
101
  end
85
  end
102
  def end
86
  def end
(-)a/src/llvm/ext/llvm_ext.cc (-183 / +12 lines)
Lines 18-52 using namespace llvm; Link Here
18
#define LLVM_VERSION_LE(major, minor) \
18
#define LLVM_VERSION_LE(major, minor) \
19
  (LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
19
  (LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
20
#if LLVM_VERSION_LE(4, 0)
20
typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
21
typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef;
21
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
22
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DIBuilder, LLVMDIBuilderRef)
22
#if LLVM_VERSION_EQ(3, 5)
23
typedef LLVMValueRef LLVMMetadataRef;
24
typedef Value Metadata;
25
#define DIBuilderRef LLVMDIBuilderRef
26
27
#else /* LLVM != 3.5 */
28
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
23
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
29
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
24
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
30
inline Metadata **unwrap(LLVMMetadataRef *Vals) {
25
inline Metadata **unwrap(LLVMMetadataRef *Vals) {
31
  return reinterpret_cast<Metadata **>(Vals);
26
  return reinterpret_cast<Metadata **>(Vals);
32
}
27
}
33
#endif /* LLVM == 3.5 */
28
#endif
34
35
#if LLVM_VERSION_LE(3, 6)
36
template <typename T> T unwrapDIptr(LLVMMetadataRef v) {
37
  return v ? T(unwrap<MDNode>(v)) : T();
38
}
39
#define DIBuilderRef LLVMDIBuilderRef
40
#else /* LLVM > 3.6 */
41
typedef DIBuilder *DIBuilderRef;
29
typedef DIBuilder *DIBuilderRef;
42
#define DIArray DINodeArray
30
#define DIArray DINodeArray
43
template <typename T> T *unwrapDIptr(LLVMMetadataRef v) {
31
template <typename T> T *unwrapDIptr(LLVMMetadataRef v) {
44
  return (T *)(v ? unwrap<MDNode>(v) : NULL);
32
  return (T *)(v ? unwrap<MDNode>(v) : NULL);
45
}
33
}
46
#endif /* LLVM <= 3.6 */
47
#if LLVM_VERSION_LE(3, 6)
34
#if LLVM_VERSION_LE(3, 6)
48
#define OperandBundleDef void
35
#define OperandBundleDef void
Lines 66-78 void LLVMDIBuilderFinalize(LLVMDIBuilderRef dref) { unwrap(dref)->finalize(); } Link Here
66
LLVMMetadataRef LLVMDIBuilderCreateFile(DIBuilderRef Dref, const char *File,
53
LLVMMetadataRef LLVMDIBuilderCreateFile(DIBuilderRef Dref, const char *File,
67
                                        const char *Dir) {
54
                                        const char *Dir) {
68
#if LLVM_VERSION_LE(3, 6)
69
  DIBuilder *D = unwrap(Dref);
70
  DIFile F = D->createFile(File, Dir);
71
  return wrap(F);
72
#else
73
  return wrap(Dref->createFile(File, Dir));
55
  return wrap(Dref->createFile(File, Dir));
74
#endif
75
}
56
}
76
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(DIBuilderRef Dref, unsigned Lang,
57
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(DIBuilderRef Dref, unsigned Lang,
Lines 82-101 LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(DIBuilderRef Dref, unsigned Lang, Link Here
82
                                               int Optimized,
63
                                               int Optimized,
83
                                               const char *Flags,
64
                                               const char *Flags,
84
                                               unsigned RuntimeVersion) {
65
                                               unsigned RuntimeVersion) {
85
#if LLVM_VERSION_LE(3, 6)
66
#if LLVM_VERSION_LE(3, 9)
86
  DIBuilder *D = unwrap(Dref);
87
  DICompileUnit CU = D->createCompileUnit(Lang, File, Dir, Producer, Optimized,
88
                                          Flags, RuntimeVersion);
89
  return wrap(CU);
90
#else
91
# if LLVM_VERSION_LE(3, 9)
92
  return wrap(Dref->createCompileUnit(Lang, File, Dir, Producer, Optimized,
67
  return wrap(Dref->createCompileUnit(Lang, File, Dir, Producer, Optimized,
93
                                      Flags, RuntimeVersion));
68
                                      Flags, RuntimeVersion));
94
# else
69
#else
95
  DIFile *F = Dref->createFile(File, Dir);
70
  DIFile *F = Dref->createFile(File, Dir);
96
  return wrap(Dref->createCompileUnit(Lang, F, Producer, Optimized,
71
  return wrap(Dref->createCompileUnit(Lang, F, Producer, Optimized,
97
                                      Flags, RuntimeVersion));
72
                                      Flags, RuntimeVersion));
98
# endif
99
#endif
73
#endif
100
}
74
}
Lines 111-129 LLVMMetadataRef LLVMDIBuilderCreateFunction( Link Here
111
#endif
85
#endif
112
    bool IsOptimized,
86
    bool IsOptimized,
113
    LLVMValueRef Func) {
87
    LLVMValueRef Func) {
114
#if LLVM_VERSION_LE(3, 6)
115
  DIBuilder *D = unwrap(Dref);
116
  DISubprogram Sub = D->createFunction(
117
      unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
118
      Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit,
119
      IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func));
120
#else
121
  DISubprogram *Sub = Dref->createFunction(
88
  DISubprogram *Sub = Dref->createFunction(
122
      unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File), Line,
89
      unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File), Line,
123
      unwrapDI<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
90
      unwrapDI<DISubroutineType>(CompositeType), IsLocalToUnit, IsDefinition,
124
      ScopeLine, Flags, IsOptimized);
91
      ScopeLine, Flags, IsOptimized);
125
  unwrap<Function>(Func)->setSubprogram(Sub);
92
  unwrap<Function>(Func)->setSubprogram(Sub);
126
#endif
127
  return wrap(Sub);
93
  return wrap(Sub);
128
}
94
}
Lines 132-149 LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(DIBuilderRef Dref, Link Here
132
                                                LLVMMetadataRef File,
98
                                                LLVMMetadataRef File,
133
                                                unsigned Line,
99
                                                unsigned Line,
134
                                                unsigned Column) {
100
                                                unsigned Column) {
135
#if LLVM_VERSION_LE(3, 6)
136
  DIBuilder *D = unwrap(Dref);
137
# if LLVM_VERSION_EQ(3, 5)
138
  DILexicalBlock LB = D->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column, 0);
139
# else /* LLVM <= 3.6 && LLVM != 3.5 */
140
  DILexicalBlock LB = D->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Column);
141
# endif
142
  return wrap(LB);
143
#else /* LLVM > 3.6 */
144
  return wrap(Dref->createLexicalBlock(unwrapDI<DIDescriptor>(Scope),
101
  return wrap(Dref->createLexicalBlock(unwrapDI<DIDescriptor>(Scope),
145
                                       unwrapDI<DIFile>(File), Line, Column));
102
                                       unwrapDI<DIFile>(File), Line, Column));
146
#endif /* LLVM <= 3.6 */
147
}
103
}
148
LLVMMetadataRef LLVMDIBuilderCreateBasicType(DIBuilderRef Dref,
104
LLVMMetadataRef LLVMDIBuilderCreateBasicType(DIBuilderRef Dref,
Lines 151-221 LLVMMetadataRef LLVMDIBuilderCreateBasicType(DIBuilderRef Dref, Link Here
151
                                             uint64_t SizeInBits,
107
                                             uint64_t SizeInBits,
152
                                             uint64_t AlignInBits,
108
                                             uint64_t AlignInBits,
153
                                             unsigned Encoding) {
109
                                             unsigned Encoding) {
154
#if LLVM_VERSION_LE(3, 6)
110
#if LLVM_VERSION_LE(3, 9)
155
  DIBuilder *D = unwrap(Dref);
156
  DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
157
  return wrap(T);
158
#else
159
# if LLVM_VERSION_LE(3, 9)
160
  return wrap(Dref->createBasicType(Name, SizeInBits, AlignInBits, Encoding));
111
  return wrap(Dref->createBasicType(Name, SizeInBits, AlignInBits, Encoding));
161
# else
112
#else
162
  return wrap(Dref->createBasicType(Name, SizeInBits, Encoding));
113
  return wrap(Dref->createBasicType(Name, SizeInBits, Encoding));
163
# endif
164
#endif
114
#endif
165
}
115
}
166
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(DIBuilderRef Dref,
116
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(DIBuilderRef Dref,
167
                                                  LLVMMetadataRef *Data,
117
                                                  LLVMMetadataRef *Data,
168
                                                  unsigned Length) {
118
                                                  unsigned Length) {
169
#if LLVM_VERSION_LE(3, 6)
170
  DIBuilder *D = unwrap(Dref);
171
# if LLVM_VERSION_EQ(3, 5)
172
  Value **DataValue = unwrap(Data);
173
  ArrayRef<Value *> Elements(DataValue, Length);
174
  DIArray A = D->getOrCreateArray(Elements);
175
# else /* LLVM <= 3.6 && LLVM != 3.5 */
176
  Metadata **DataValue = unwrap(Data);
177
  ArrayRef<Metadata *> Elements(DataValue, Length);
178
  DITypeArray A = D->getOrCreateTypeArray(Elements);
179
# endif
180
  return wrap(A);
181
#else /* LLVM > 3.6 */
182
  Metadata **DataValue = unwrap(Data);
119
  Metadata **DataValue = unwrap(Data);
183
  return wrap(
120
  return wrap(
184
      Dref->getOrCreateTypeArray(ArrayRef<Metadata *>(DataValue, Length))
121
      Dref->getOrCreateTypeArray(ArrayRef<Metadata *>(DataValue, Length))
185
          .get());
122
          .get());
186
#endif /* LLVM <= 3.6 */
187
}
123
}
188
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(DIBuilderRef Dref,
124
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(DIBuilderRef Dref,
189
                                              LLVMMetadataRef *Data,
125
                                              LLVMMetadataRef *Data,
190
                                              unsigned Length) {
126
                                              unsigned Length) {
191
#if LLVM_VERSION_LE(3, 6)
192
  DIBuilder *D = unwrap(Dref);
193
  ArrayRef<Metadata *> elements(unwrap(Data), Length);
194
  DIArray a = D->getOrCreateArray(elements);
195
196
  return wrap(a);
197
#else
198
  Metadata **DataValue = unwrap(Data);
127
  Metadata **DataValue = unwrap(Data);
199
  return wrap(
128
  return wrap(
200
      Dref->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Length)).get());
129
      Dref->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Length)).get());
201
#endif
202
}
130
}
203
LLVMMetadataRef
131
LLVMMetadataRef
204
LLVMDIBuilderCreateSubroutineType(DIBuilderRef Dref, LLVMMetadataRef File,
132
LLVMDIBuilderCreateSubroutineType(DIBuilderRef Dref, LLVMMetadataRef File,
205
                                  LLVMMetadataRef ParameterTypes) {
133
                                  LLVMMetadataRef ParameterTypes) {
206
#if LLVM_VERSION_LE(3, 6)
207
  DIBuilder *D = unwrap(Dref);
208
# if LLVM_VERSION_EQ(3, 5)
209
  DICompositeType CT = D->createSubroutineType(unwrapDI<DIFile>(File), unwrapDI<DIArray>(ParameterTypes));
210
# else /* LLVM <= 3.6 && LLVM != 3.5 */
211
  DICompositeType CT = D->createSubroutineType(unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes));
212
# endif
213
#else /* LLVM > 3.6 */
214
  DISubroutineType *CT = Dref->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes)));
134
  DISubroutineType *CT = Dref->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes)));
215
#endif /* LLVM <= 3.6 */
216
  return wrap(CT);
135
  return wrap(CT);
217
}
136
}
Lines 229-249 LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( Link Here
229
    DINode::DIFlags Flags,
148
    DINode::DIFlags Flags,
230
#endif
149
#endif
231
    uint32_t AlignInBits) {
150
    uint32_t AlignInBits) {
232
#if LLVM_VERSION_LE(3, 6)
151
#if LLVM_VERSION_LE(3, 9)
233
  DIBuilder *D = unwrap(Dref);
234
  DIVariable V = D->createLocalVariable(
235
      llvm::dwarf::DW_TAG_auto_variable, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
236
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, 0);
237
#else
238
# if LLVM_VERSION_LE(3, 9)
239
  DILocalVariable *V = Dref->createAutoVariable(
152
  DILocalVariable *V = Dref->createAutoVariable(
240
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
153
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
241
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
154
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
242
# else
155
#else
243
  DILocalVariable *V = Dref->createAutoVariable(
156
  DILocalVariable *V = Dref->createAutoVariable(
244
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
157
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
245
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, AlignInBits);
158
      unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, AlignInBits);
246
# endif
247
#endif
159
#endif
248
  return wrap(V);
160
  return wrap(V);
249
}
161
}
Lines 258-275 LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( Link Here
258
    DINode::DIFlags Flags
170
    DINode::DIFlags Flags
259
#endif
171
#endif
260
    ) {
172
    ) {
261
#if LLVM_VERSION_LE(3, 6)
262
  DIBuilder *D = unwrap(Dref);
263
  DIVariable V = D->createLocalVariable(
264
       llvm::dwarf::DW_TAG_arg_variable, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
265
       unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo);
266
  return wrap(V);
267
#else
268
  DILocalVariable *V = Dref->createParameterVariable
173
  DILocalVariable *V = Dref->createParameterVariable
269
    (unwrapDI<DIDescriptor>(Scope), Name, ArgNo, unwrapDI<DIFile>(File), Line,
174
    (unwrapDI<DIDescriptor>(Scope), Name, ArgNo, unwrapDI<DIFile>(File), Line,
270
     unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
175
     unwrapDI<DIType>(Ty), AlwaysPreserve, Flags);
271
  return wrap(V);
176
  return wrap(V);
272
#endif
273
}
177
}
274
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(DIBuilderRef Dref,
178
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(DIBuilderRef Dref,
Lines 278-323 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(DIBuilderRef Dref, Link Here
278
                                             LLVMMetadataRef Expr,
182
                                             LLVMMetadataRef Expr,
279
                                             LLVMValueRef DL,
183
                                             LLVMValueRef DL,
280
                                             LLVMBasicBlockRef Block) {
184
                                             LLVMBasicBlockRef Block) {
281
#if LLVM_VERSION_EQ(3, 5)
282
  DIBuilder *D = unwrap(Dref);
283
  Instruction *Instr =
284
    D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
285
                     unwrap(Block));
286
  Instr->setDebugLoc(DebugLoc::getFromDILocation(cast<MDNode>(DL)));
287
#endif
288
289
#if LLVM_VERSION_EQ(3, 6)
290
  DIBuilder *D = unwrap(Dref);
291
  Instruction *Instr =
292
    D->insertDeclare(unwrap(Storage), unwrapDI<DIVariable>(VarInfo),
293
                     unwrapDI<DIExpression>(Expr), unwrap(Block));
294
  Instr->setDebugLoc(DebugLoc::getFromDILocation(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())));
295
#endif
296
297
#if LLVM_VERSION_GE(3, 7)
298
  Instruction *Instr =
185
  Instruction *Instr =
299
    Dref->insertDeclare(unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
186
    Dref->insertDeclare(unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
300
                        unwrapDI<DIExpression>(Expr),
187
                        unwrapDI<DIExpression>(Expr),
301
                        DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
188
                        DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
302
                        unwrap(Block));
189
                        unwrap(Block));
303
#endif
304
305
  return wrap(Instr);
190
  return wrap(Instr);
306
}
191
}
307
LLVMMetadataRef LLVMDIBuilderCreateExpression(DIBuilderRef Dref, int64_t *Addr,
192
LLVMMetadataRef LLVMDIBuilderCreateExpression(DIBuilderRef Dref, int64_t *Addr,
308
                                              size_t Length) {
193
                                              size_t Length) {
309
#if LLVM_VERSION_LE(3, 6)
310
# if LLVM_VERSION_EQ(3, 5)
311
  return nullptr;
312
# else /* LLVM <= 3.6 && LLVM != 3.5 */
313
  DIBuilder *D = unwrap(Dref);
314
  DIExpression Expr = D->createExpression(ArrayRef<int64_t>(Addr, Length));
315
  return wrap(Expr);
316
# endif
317
#else /* LLVM > 3.6 */
318
  return wrap(Dref->createExpression(ArrayRef<int64_t>(Addr, Length)));
194
  return wrap(Dref->createExpression(ArrayRef<int64_t>(Addr, Length)));
319
#endif
320
}
195
}
321
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
196
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
Lines 325-354 LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( Link Here
325
    LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
200
    LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
326
    uint64_t AlignInBits, LLVMMetadataRef Elements,
201
    uint64_t AlignInBits, LLVMMetadataRef Elements,
327
    LLVMMetadataRef UnderlyingType) {
202
    LLVMMetadataRef UnderlyingType) {
328
#if LLVM_VERSION_LE(3, 6)
329
  DIBuilder *D = unwrap(Dref);
330
  DICompositeType enumType = D->createEnumerationType(
331
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
332
      SizeInBits, AlignInBits, unwrapDI<DIArray>(Elements),
333
      unwrapDI<DIType>(UnderlyingType));
334
#else
335
  DICompositeType *enumType = Dref->createEnumerationType(
203
  DICompositeType *enumType = Dref->createEnumerationType(
336
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
204
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber,
337
      SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
205
      SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)),
338
      unwrapDI<DIType>(UnderlyingType));
206
      unwrapDI<DIType>(UnderlyingType));
339
#endif
340
  return wrap(enumType);
207
  return wrap(enumType);
341
}
208
}
342
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(DIBuilderRef Dref,
209
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(DIBuilderRef Dref,
343
                                              const char *Name, int64_t Value) {
210
                                              const char *Name, int64_t Value) {
344
#if LLVM_VERSION_LE(3, 6)
345
  DIBuilder *D = unwrap(Dref);
346
  DIEnumerator e = D->createEnumerator(Name, Value);
347
  return wrap(e);
348
#else
349
  DIEnumerator *e = Dref->createEnumerator(Name, Value);
211
  DIEnumerator *e = Dref->createEnumerator(Name, Value);
350
#endif
351
  return wrap(e);
212
  return wrap(e);
352
}
213
}
Lines 367-388 LLVMDIBuilderCreateStructType(DIBuilderRef Dref, Link Here
367
#endif
228
#endif
368
                              LLVMMetadataRef DerivedFrom,
229
                              LLVMMetadataRef DerivedFrom,
369
                              LLVMMetadataRef Elements) {
230
                              LLVMMetadataRef Elements) {
370
#if LLVM_VERSION_LE(3, 6)
371
  DIBuilder *D = unwrap(Dref);
372
  DICompositeType CT = D->createStructType(
373
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
374
      SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
375
      unwrapDI<DIArray>(Elements));
376
#else
377
  DICompositeType *CT = Dref->createStructType(
231
  DICompositeType *CT = Dref->createStructType(
378
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
232
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
379
      SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
233
      SizeInBits, AlignInBits, Flags, unwrapDI<DIType>(DerivedFrom),
380
      DINodeArray(unwrapDI<MDTuple>(Elements)));
234
      DINodeArray(unwrapDI<MDTuple>(Elements)));
381
#endif
382
  return wrap(CT);
235
  return wrap(CT);
383
}
236
}
384
#if LLVM_VERSION_GE(3, 8)
385
LLVMMetadataRef
237
LLVMMetadataRef
386
LLVMDIBuilderCreateReplaceableCompositeType(DIBuilderRef Dref,
238
LLVMDIBuilderCreateReplaceableCompositeType(DIBuilderRef Dref,
387
                                            LLVMMetadataRef Scope,
239
                                            LLVMMetadataRef Scope,
Lines 409-415 LLVMDIBuilderReplaceTemporary(DIBuilderRef Dref, Link Here
409
  llvm::TempMDNode fwd_decl(Node);
261
  llvm::TempMDNode fwd_decl(Node);
410
  Dref->replaceTemporary(std::move(fwd_decl), Type);
262
  Dref->replaceTemporary(std::move(fwd_decl), Type);
411
}
263
}
412
#endif
413
LLVMMetadataRef
264
LLVMMetadataRef
414
LLVMDIBuilderCreateMemberType(DIBuilderRef Dref, LLVMMetadataRef Scope,
265
LLVMDIBuilderCreateMemberType(DIBuilderRef Dref, LLVMMetadataRef Scope,
Lines 422-437 LLVMDIBuilderCreateMemberType(DIBuilderRef Dref, LLVMMetadataRef Scope, Link Here
422
                              DINode::DIFlags Flags,
273
                              DINode::DIFlags Flags,
423
#endif
274
#endif
424
                              LLVMMetadataRef Ty) {
275
                              LLVMMetadataRef Ty) {
425
#if LLVM_VERSION_LE(3, 6)
426
  DIBuilder *D = unwrap(Dref);
427
  DIDerivedType DT = D->createMemberType(
428
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
429
      SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
430
#else
431
  DIDerivedType *DT = Dref->createMemberType(
276
  DIDerivedType *DT = Dref->createMemberType(
432
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
277
      unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line,
433
      SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
278
      SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty));
434
#endif
435
  return wrap(DT);
279
  return wrap(DT);
436
}
280
}
Lines 440-478 LLVMMetadataRef LLVMDIBuilderCreatePointerType(DIBuilderRef Dref, Link Here
440
                                               uint64_t SizeInBits,
284
                                               uint64_t SizeInBits,
441
                                               uint64_t AlignInBits,
285
                                               uint64_t AlignInBits,
442
                                               const char *Name) {
286
                                               const char *Name) {
443
#if LLVM_VERSION_LE(3, 6)
444
  DIBuilder *D = unwrap(Dref);
445
  DIDerivedType T = D->createPointerType(unwrapDI<DIType>(PointeeType),
446
                                         SizeInBits, AlignInBits, Name);
447
#else
448
  DIDerivedType *T = Dref->createPointerType(unwrapDI<DIType>(PointeeType),
287
  DIDerivedType *T = Dref->createPointerType(unwrapDI<DIType>(PointeeType),
449
                                             SizeInBits, AlignInBits, Name);
288
                                             SizeInBits, AlignInBits,
289
#if LLVM_VERSION_GE(5, 0)
290
                                             None,
450
#endif
291
#endif
292
                                             Name);
451
  return wrap(T);
293
  return wrap(T);
452
}
294
}
453
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
295
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
454
                                    unsigned Count) {
296
                                    unsigned Count) {
455
#if LLVM_VERSION_LE(3, 6)
456
  return wrap(MDNode::getTemporary(*unwrap(C),
457
                                   ArrayRef<Metadata *>(unwrap(MDs), Count)));
458
#else
459
  return wrap(MDTuple::getTemporary(*unwrap(C),
297
  return wrap(MDTuple::getTemporary(*unwrap(C),
460
                                    ArrayRef<Metadata *>(unwrap(MDs), Count))
298
                                    ArrayRef<Metadata *>(unwrap(MDs), Count))
461
                  .release());
299
                  .release());
462
#endif
463
}
300
}
464
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
301
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
465
#if LLVM_VERSION_LE(3, 6)
466
# if LLVM_VERSION_EQ(3, 5)
467
  auto *Node = unwrap<MDNode>(MD);
302
  auto *Node = unwrap<MDNode>(MD);
468
# else /* LLVM <= 3.6 && LLVM != 3.5 */
469
  auto *Node = unwrap<MDNodeFwdDecl>(MD);
470
# endif
471
#else /* LLVM > 3.6 */
472
  auto *Node = unwrap<MDNode>(MD);
473
#endif
474
  Node->replaceAllUsesWith(unwrap<MDNode>(New));
303
  Node->replaceAllUsesWith(unwrap<MDNode>(New));
475
  MDNode::deleteTemporary(Node);
304
  MDNode::deleteTemporary(Node);
476
}
305
}
(-)a/src/llvm/function_pass_manager.cr (-6 lines)
Lines 2-13 class LLVM::FunctionPassManager Link Here
2
  def initialize(@unwrap : LibLLVM::PassManagerRef)
2
  def initialize(@unwrap : LibLLVM::PassManagerRef)
3
  end
3
  end
4
  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
5
    def add_target_data(target_data)
6
      LibLLVM.add_target_data target_data, self
7
    end
8
  {% end %}
9
10
  def run(mod : Module)
4
  def run(mod : Module)
11
    changed = false
5
    changed = false
12
    run do |runner|
6
    run do |runner|
(-)a/src/llvm/lib_llvm.cr (-15 / +5 lines)
Lines 6-13 lib LibLLVM Link Here
6
                   (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
6
                   (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
7
                   command -v llvm-config-3.8 || command -v llvm-config38 || \
7
                   command -v llvm-config-3.8 || command -v llvm-config38 || \
8
                   (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
8
                   (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
9
                   command -v llvm-config-3.6 || command -v llvm-config36 || \
10
                   command -v llvm-config-3.5 || command -v llvm-config35 || \
11
                   command -v llvm-config
9
                   command -v llvm-config
12
                  `.chomp.stringify
10
                  `.chomp.stringify
13
                }}
11
                }}
Lines 32-39 end Link Here
32
    IS_40 = {{LibLLVM::VERSION.starts_with?("4.0")}}
30
    IS_40 = {{LibLLVM::VERSION.starts_with?("4.0")}}
33
    IS_39 = {{LibLLVM::VERSION.starts_with?("3.9")}}
31
    IS_39 = {{LibLLVM::VERSION.starts_with?("3.9")}}
34
    IS_38 = {{LibLLVM::VERSION.starts_with?("3.8")}}
32
    IS_38 = {{LibLLVM::VERSION.starts_with?("3.8")}}
35
    IS_36 = {{LibLLVM::VERSION.starts_with?("3.6")}}
36
    IS_35 = {{LibLLVM::VERSION.starts_with?("3.5")}}
37
  end
33
  end
38
{% end %}
34
{% end %}
Lines 283-291 lib LibLLVM Link Here
283
  fun set_alignment = LLVMSetAlignment(value : ValueRef, bytes : UInt32)
279
  fun set_alignment = LLVMSetAlignment(value : ValueRef, bytes : UInt32)
284
  fun get_return_type = LLVMGetReturnType(TypeRef) : TypeRef
280
  fun get_return_type = LLVMGetReturnType(TypeRef) : TypeRef
285
  {% unless LibLLVM::IS_35 %}
281
  fun write_bitcode_to_memory_buffer = LLVMWriteBitcodeToMemoryBuffer(mod : ModuleRef) : MemoryBufferRef
286
    fun write_bitcode_to_memory_buffer = LLVMWriteBitcodeToMemoryBuffer(mod : ModuleRef) : MemoryBufferRef
287
  {% end %}
288
  fun dispose_memory_buffer = LLVMDisposeMemoryBuffer(buf : MemoryBufferRef) : Void
282
  fun dispose_memory_buffer = LLVMDisposeMemoryBuffer(buf : MemoryBufferRef) : Void
289
  fun get_buffer_start = LLVMGetBufferStart(buf : MemoryBufferRef) : UInt8*
283
  fun get_buffer_start = LLVMGetBufferStart(buf : MemoryBufferRef) : UInt8*
Lines 293-318 lib LibLLVM Link Here
293
  fun write_bitcode_to_fd = LLVMWriteBitcodeToFD(mod : ModuleRef, fd : LibC::Int, should_close : LibC::Int, unbuffered : LibC::Int) : LibC::Int
287
  fun write_bitcode_to_fd = LLVMWriteBitcodeToFD(mod : ModuleRef, fd : LibC::Int, should_close : LibC::Int, unbuffered : LibC::Int) : LibC::Int
294
  {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
288
  {% if LibLLVM::IS_38 %}
295
    fun add_target_data = LLVMAddTargetData(td : TargetDataRef, pm : PassManagerRef)
296
  {% end %}
297
298
  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
299
    fun copy_string_rep_of_target_data = LLVMCopyStringRepOfTargetData(data : TargetDataRef) : UInt8*
289
    fun copy_string_rep_of_target_data = LLVMCopyStringRepOfTargetData(data : TargetDataRef) : UInt8*
300
    fun get_target_machine_data = LLVMGetTargetMachineData(t : TargetMachineRef) : TargetDataRef
290
    fun get_target_machine_data = LLVMGetTargetMachineData(t : TargetMachineRef) : TargetDataRef
301
    fun set_data_layout = LLVMSetDataLayout(mod : ModuleRef, data : UInt8*)
291
    fun set_data_layout = LLVMSetDataLayout(mod : ModuleRef, data : UInt8*)
302
  {% else %}
292
  {% else %} # LLVM >= 3.9
303
    fun create_target_data_layout = LLVMCreateTargetDataLayout(t : TargetMachineRef) : TargetDataRef
293
    fun create_target_data_layout = LLVMCreateTargetDataLayout(t : TargetMachineRef) : TargetDataRef
304
    fun set_module_data_layout = LLVMSetModuleDataLayout(mod : ModuleRef, data : TargetDataRef)
294
    fun set_module_data_layout = LLVMSetModuleDataLayout(mod : ModuleRef, data : TargetDataRef)
305
  {% end %}
295
  {% end %}
306
  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
296
  {% if LibLLVM::IS_38 %}
307
    fun add_attribute = LLVMAddAttribute(arg : ValueRef, attr : LLVM::Attribute)
297
    fun add_attribute = LLVMAddAttribute(arg : ValueRef, attr : LLVM::Attribute)
308
    fun add_instr_attribute = LLVMAddInstrAttribute(instr : ValueRef, index : UInt32, attr : LLVM::Attribute)
298
    fun add_instr_attribute = LLVMAddInstrAttribute(instr : ValueRef, index : UInt32, attr : LLVM::Attribute)
309
    fun add_function_attr = LLVMAddFunctionAttr(fn : ValueRef, pa : LLVM::Attribute)
299
    fun add_function_attr = LLVMAddFunctionAttr(fn : ValueRef, pa : LLVM::Attribute)
310
    fun get_function_attr = LLVMGetFunctionAttr(fn : ValueRef) : LLVM::Attribute
300
    fun get_function_attr = LLVMGetFunctionAttr(fn : ValueRef) : LLVM::Attribute
311
    fun get_attribute = LLVMGetAttribute(arg : ValueRef) : LLVM::Attribute
301
    fun get_attribute = LLVMGetAttribute(arg : ValueRef) : LLVM::Attribute
312
  {% else %}
302
  {% else %} # LLVM >= 3.9
313
    type AttributeRef = Void*
303
    type AttributeRef = Void*
314
    alias AttributeIndex = UInt
304
    alias AttributeIndex = UInt
(-)a/src/llvm/lib_llvm_ext.cr (-24 / +11 lines)
Lines 13-31 lib LibLLVMExt Link Here
13
  fun create_di_builder = LLVMNewDIBuilder(LibLLVM::ModuleRef) : DIBuilder
13
  fun create_di_builder = LLVMNewDIBuilder(LibLLVM::ModuleRef) : DIBuilder
14
  fun di_builder_finalize = LLVMDIBuilderFinalize(DIBuilder)
14
  fun di_builder_finalize = LLVMDIBuilderFinalize(DIBuilder)
15
  {% if LibLLVM::IS_36 || LibLLVM::IS_35 %}
15
  fun di_builder_create_function = LLVMDIBuilderCreateFunction(
16
    fun di_builder_create_function = LLVMDIBuilderCreateFunction(
16
                                                               builder : DIBuilder, scope : Metadata, name : Char*,
17
                                                                 builder : DIBuilder, scope : Metadata, name : Char*,
17
                                                               linkage_name : Char*, file : Metadata, line : UInt,
18
                                                                 linkage_name : Char*, file : Metadata, line : UInt,
18
                                                               composite_type : Metadata, is_local_to_unit : Bool, is_definition : Bool,
19
                                                                 composite_type : Metadata, is_local_to_unit : Int, is_definition : Int,
19
                                                               scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Bool, func : LibLLVM::ValueRef) : Metadata
20
                                                                 scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Int, func : LibLLVM::ValueRef) : Metadata
21
  {% else %}
22
    fun di_builder_create_function = LLVMDIBuilderCreateFunction(
23
                                                                 builder : DIBuilder, scope : Metadata, name : Char*,
24
                                                                 linkage_name : Char*, file : Metadata, line : UInt,
25
                                                                 composite_type : Metadata, is_local_to_unit : Bool, is_definition : Bool,
26
                                                                 scope_line : UInt, flags : LLVM::DIFlags, is_optimized : Bool, func : LibLLVM::ValueRef) : Metadata
27
  {% end %}
28
  fun di_builder_create_file = LLVMDIBuilderCreateFile(builder : DIBuilder, file : Char*, dir : Char*) : Metadata
20
  fun di_builder_create_file = LLVMDIBuilderCreateFile(builder : DIBuilder, file : Char*, dir : Char*) : Metadata
29
  fun di_builder_create_compile_unit = LLVMDIBuilderCreateCompileUnit(builder : DIBuilder,
21
  fun di_builder_create_compile_unit = LLVMDIBuilderCreateCompileUnit(builder : DIBuilder,
Lines 94-110 lib LibLLVMExt Link Here
94
                                                                      align_in_bits : UInt64,
86
                                                                      align_in_bits : UInt64,
95
                                                                      name : Char*) : Metadata
87
                                                                      name : Char*) : Metadata
96
  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
88
  fun di_builder_create_replaceable_composite_type = LLVMDIBuilderCreateReplaceableCompositeType(builder : DIBuilder,
97
    fun temporary_md_node = LLVMTemporaryMDNode(context : LibLLVM::ContextRef, mds : Metadata*, count : UInt) : Metadata
89
                                                                                                 scope : Metadata,
98
    fun metadata_replace_all_uses_with = LLVMMetadataReplaceAllUsesWith(Metadata, Metadata)
90
                                                                                                 name : Char*,
99
  {% else %}
91
                                                                                                 file : Metadata,
100
    fun di_builder_create_replaceable_composite_type = LLVMDIBuilderCreateReplaceableCompositeType(builder : DIBuilder,
92
                                                                                                 line : UInt) : Metadata
101
                                                                                                   scope : Metadata,
93
  fun di_builder_replace_temporary = LLVMDIBuilderReplaceTemporary(builder : DIBuilder, from : Metadata, to : Metadata)
102
                                                                                                   name : Char*,
103
                                                                                                                    file : Metadata,
104
                                                                                                   line : UInt) : Metadata
105
    fun di_builder_replace_temporary = LLVMDIBuilderReplaceTemporary(builder : DIBuilder, from : Metadata, to : Metadata)
106
  {% end %}
107
  fun set_current_debug_location = LLVMSetCurrentDebugLocation2(LibLLVM::BuilderRef, Int, Int, Metadata, Metadata)
94
  fun set_current_debug_location = LLVMSetCurrentDebugLocation2(LibLLVM::BuilderRef, Int, Int, Metadata, Metadata)
(-)a/src/llvm/module.cr (-9 / +7 lines)
Lines 6-12 class LLVM::Module Link Here
6
  getter context : Context
6
  getter context : Context
7
  {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
7
  {% if LibLLVM::IS_38 %}
8
    def initialize(@unwrap : LibLLVM::ModuleRef, @name : String, @context : Context)
8
    def initialize(@unwrap : LibLLVM::ModuleRef, @name : String, @context : Context)
9
      @owned = false
9
      @owned = false
10
    end
10
    end
Lines 14-20 class LLVM::Module Link Here
14
    def name : String
14
    def name : String
15
      @name
15
      @name
16
    end
16
    end
17
  {% else %}
17
  {% else %} # LLVM >= 3.9
18
    def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
18
    def initialize(@unwrap : LibLLVM::ModuleRef, @context : Context)
19
      @owned = false
19
      @owned = false
20
    end
20
    end
Lines 34-42 class LLVM::Module Link Here
34
  end
34
  end
35
  def data_layout=(data : TargetData)
35
  def data_layout=(data : TargetData)
36
    {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
36
    {% if LibLLVM::IS_38 %}
37
      LibLLVM.set_data_layout(self, data.to_data_layout_string)
37
      LibLLVM.set_data_layout(self, data.to_data_layout_string)
38
    {% else %}
38
    {% else %} # LLVM >= 3.9
39
      LibLLVM.set_module_data_layout(self, data)
39
      LibLLVM.set_module_data_layout(self, data)
40
    {% end %}
40
    {% end %}
41
  end
41
  end
Lines 57-67 class LLVM::Module Link Here
57
    LibLLVM.write_bitcode_to_file self, filename
57
    LibLLVM.write_bitcode_to_file self, filename
58
  end
58
  end
59
  {% unless LibLLVM::IS_35 %}
59
  def write_bitcode_to_memory_buffer
60
    def write_bitcode_to_memory_buffer
60
    MemoryBuffer.new(LibLLVM.write_bitcode_to_memory_buffer self)
61
      MemoryBuffer.new(LibLLVM.write_bitcode_to_memory_buffer self)
61
  end
62
    end
63
  {% end %}
64
  def write_bitcode_to_fd(fd : Int, should_close = false, buffered = false)
62
  def write_bitcode_to_fd(fd : Int, should_close = false, buffered = false)
65
    LibLLVM.write_bitcode_to_fd(self, fd, should_close ? 1 : 0, buffered ? 1 : 0)
63
    LibLLVM.write_bitcode_to_fd(self, fd, should_close ? 1 : 0, buffered ? 1 : 0)
(-)a/src/llvm/module_pass_manager.cr (-6 lines)
Lines 3-14 class LLVM::ModulePassManager Link Here
3
    @unwrap = LibLLVM.pass_manager_create
3
    @unwrap = LibLLVM.pass_manager_create
4
  end
4
  end
5
  {% if LibLLVM::IS_35 || LibLLVM::IS_36 %}
6
    def add_target_data(target_data)
7
      LibLLVM.add_target_data target_data, self
8
    end
9
  {% end %}
10
11
  def run(mod)
5
  def run(mod)
12
    LibLLVM.run_pass_manager(self, mod) != 0
6
    LibLLVM.run_pass_manager(self, mod) != 0
13
  end
7
  end
(-)a/src/llvm/target_machine.cr (-3 / +2 lines)
Lines 9-17 class LLVM::TargetMachine Link Here
9
  def data_layout
9
  def data_layout
10
    @layout ||= begin
10
    @layout ||= begin
11
      layout = {% if LibLLVM::IS_38 || LibLLVM::IS_36 || LibLLVM::IS_35 %}
11
      layout = {% if LibLLVM::IS_38 %}
12
                 LibLLVM.get_target_machine_data(self)
12
                 LibLLVM.get_target_machine_data(self)
13
               {% else %}
13
               {% else %} # LLVM >= 3.9
14
                 LibLLVM.create_target_data_layout(self)
14
                 LibLLVM.create_target_data_layout(self)
15
               {% end %}
15
               {% end %}
16
      layout ? TargetData.new(layout) : raise "Missing layout for #{self}"
16
      layout ? TargetData.new(layout) : raise "Missing layout for #{self}"
17
-

Return to bug 630634