-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LLVM: bind Context functions, and apply a general refactor
- Loading branch information
Ary Borenszweig
committed
Feb 11, 2017
1 parent
102be34
commit 4c6708c
Showing
14 changed files
with
282 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,112 @@ | ||
class LLVM::Context | ||
def initialize(@unwrap : LibLLVM::ContextRef) | ||
def self.new | ||
new(LibLLVM.create_context) | ||
end | ||
|
||
def initialize(@unwrap : LibLLVM::ContextRef, @dispose_on_finalize = true) | ||
end | ||
|
||
def new_module(name : String) : Module | ||
Module.new(LibLLVM.module_create_with_name_in_context(name, self)) | ||
end | ||
|
||
def new_builder : Builder | ||
Builder.new LibLLVM.create_builder_in_context(self) | ||
end | ||
|
||
def void : Type | ||
Type.new LibLLVM.void_type_in_context(self) | ||
end | ||
|
||
def int1 : Type | ||
Type.new LibLLVM.int1_type_in_context(self) | ||
end | ||
|
||
def int8 : Type | ||
Type.new LibLLVM.int8_type_in_context(self) | ||
end | ||
|
||
def int16 : Type | ||
Type.new LibLLVM.int16_type_in_context(self) | ||
end | ||
|
||
def int32 : Type | ||
Type.new LibLLVM.int32_type_in_context(self) | ||
end | ||
|
||
def int64 : Type | ||
Type.new LibLLVM.int64_type_in_context(self) | ||
end | ||
|
||
def int128 : Type | ||
Type.new LibLLVM.int128_type_in_context(self) | ||
end | ||
|
||
def int(bits : Int) : Type | ||
Type.new LibLLVM.int_type_in_context(self, bits) | ||
end | ||
|
||
def float : Type | ||
Type.new LibLLVM.float_type_in_context(self) | ||
end | ||
|
||
def double : Type | ||
Type.new LibLLVM.double_type_in_context(self) | ||
end | ||
|
||
def struct(name : String, packed = false) : Type | ||
llvm_struct = LibLLVM.struct_create_named(self, name) | ||
the_struct = Type.new llvm_struct | ||
element_types = (yield the_struct).as(Array(LLVM::Type)) | ||
LibLLVM.struct_set_body(llvm_struct, (element_types.to_unsafe.as(LibLLVM::TypeRef*)), element_types.size, packed ? 1 : 0) | ||
the_struct | ||
end | ||
|
||
def struct(element_types : Array(LLVM::Type), name = nil, packed = false) : Type | ||
if name | ||
self.struct(name, packed) { element_types } | ||
else | ||
Type.new LibLLVM.struct_type_in_context(self, (element_types.to_unsafe.as(LibLLVM::TypeRef*)), element_types.size, packed ? 1 : 0) | ||
end | ||
end | ||
|
||
def const_string(string : String) : Value | ||
Value.new LibLLVM.const_string_in_context(self, string, string.bytesize, 0) | ||
end | ||
|
||
def const_struct(values : Array(LLVM::Value), packed = false) : Value | ||
Value.new LibLLVM.const_struct_in_context(self, (values.to_unsafe.as(LibLLVM::ValueRef*)), values.size, packed ? 1 : 0) | ||
end | ||
|
||
def md_string(value : String) : Value | ||
LLVM::Value.new LibLLVM.md_string_in_context(self, value, value.bytesize) | ||
end | ||
|
||
def md_node(values : Array(Value)) : Value | ||
Value.new LibLLVM.md_node_in_context(self, (values.to_unsafe.as(LibLLVM::ValueRef*)), values.size) | ||
end | ||
|
||
def parse_ir(buf : MemoryBuffer) | ||
ret = LibLLVM.parse_ir_in_context(self, buf, out mod, out msg) | ||
if ret != 0 && msg | ||
raise LLVM.string_and_dispose(msg) | ||
end | ||
Module.new(mod) | ||
end | ||
|
||
def self.global : self | ||
new LibLLVM.get_global_context | ||
new LibLLVM.get_global_context, dispose_on_finalize: false | ||
end | ||
|
||
def ==(other : self) | ||
@unwrap == other.@unwrap | ||
end | ||
|
||
def to_unsafe | ||
@unwrap | ||
end | ||
|
||
def finalize | ||
LibLLVM.dispose_context(self) if @dispose_on_finalize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,4 +372,8 @@ module LLVM | |
NoReturn = 1 << 20 | ||
MainSubprogram = 1 << 21 | ||
end | ||
|
||
enum ModuleFlag : Int32 | ||
Warning = 2 | ||
end | ||
end |
Oops, something went wrong.