| author | |
| committer | |
| log | 4ccb98bdcef86b2dac3bd1c8f01b9b823de6e9a4 |
| tree | a2c8d3c1ca26c82d1da0963acc978dfb7a1ead4f |
| parent | 014711c57ef6544745444e7867d4d03ffd8d389a |
5 files changed, 198 insertions(+), 38 deletions(-)
src/analyze.cpp+8-7| ... | @@ -83,7 +83,7 @@ static void resolve_type_and_recurse(CodeGen *g, AstNode *node) { | ... | @@ -83,7 +83,7 @@ static void resolve_type_and_recurse(CodeGen *g, AstNode *node) { |
| 83 | entry->type_ref = LLVMPointerType(child_type_node->entry->type_ref, 0); | 83 | entry->type_ref = LLVMPointerType(child_type_node->entry->type_ref, 0); |
| 84 | buf_resize(&entry->name, 0); | 84 | buf_resize(&entry->name, 0); |
| 85 | buf_appendf(&entry->name, "*%s %s", const_or_mut_str, buf_ptr(&child_type_node->entry->name)); | 85 | buf_appendf(&entry->name, "*%s %s", const_or_mut_str, buf_ptr(&child_type_node->entry->name)); |
| 86 | entry->di_type = g->dbuilder->createPointerType(child_type_node->entry->di_type, | 86 | entry->di_type = LLVMZigCreateDebugPointerType(g->dbuilder, child_type_node->entry->di_type, |
| 87 | g->pointer_size_bytes * 8, g->pointer_size_bytes * 8, buf_ptr(&entry->name)); | 87 | g->pointer_size_bytes * 8, g->pointer_size_bytes * 8, buf_ptr(&entry->name)); |
| 88 | g->type_table.put(&entry->name, entry); | 88 | g->type_table.put(&entry->name, entry); |
| 89 | type_node->entry = entry; | 89 | type_node->entry = entry; |
| ... | @@ -418,7 +418,8 @@ static void add_types(CodeGen *g) { | ... | @@ -418,7 +418,8 @@ static void add_types(CodeGen *g) { |
| 418 | entry->id = TypeIdU8; | 418 | entry->id = TypeIdU8; |
| 419 | entry->type_ref = LLVMInt8Type(); | 419 | entry->type_ref = LLVMInt8Type(); |
| 420 | buf_init_from_str(&entry->name, "u8"); | 420 | buf_init_from_str(&entry->name, "u8"); |
| 421 | entry->di_type = g->dbuilder->createBasicType(buf_ptr(&entry->name), 8, 8, llvm::dwarf::DW_ATE_unsigned); | 421 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 8, 8, |
| 422 | LLVMZigEncoding_DW_ATE_unsigned()); | ||
| 422 | g->type_table.put(&entry->name, entry); | 423 | g->type_table.put(&entry->name, entry); |
| 423 | } | 424 | } |
| 424 | { | 425 | { |
| ... | @@ -426,8 +427,8 @@ static void add_types(CodeGen *g) { | ... | @@ -426,8 +427,8 @@ static void add_types(CodeGen *g) { |
| 426 | entry->id = TypeIdI32; | 427 | entry->id = TypeIdI32; |
| 427 | entry->type_ref = LLVMInt32Type(); | 428 | entry->type_ref = LLVMInt32Type(); |
| 428 | buf_init_from_str(&entry->name, "i32"); | 429 | buf_init_from_str(&entry->name, "i32"); |
| 429 | entry->di_type = g->dbuilder->createBasicType(buf_ptr(&entry->name), 32, 32, | 430 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 32, 32, |
| 430 | llvm::dwarf::DW_ATE_signed); | 431 | LLVMZigEncoding_DW_ATE_signed()); |
| 431 | g->type_table.put(&entry->name, entry); | 432 | g->type_table.put(&entry->name, entry); |
| 432 | } | 433 | } |
| 433 | { | 434 | { |
| ... | @@ -435,8 +436,8 @@ static void add_types(CodeGen *g) { | ... | @@ -435,8 +436,8 @@ static void add_types(CodeGen *g) { |
| 435 | entry->id = TypeIdVoid; | 436 | entry->id = TypeIdVoid; |
| 436 | entry->type_ref = LLVMVoidType(); | 437 | entry->type_ref = LLVMVoidType(); |
| 437 | buf_init_from_str(&entry->name, "void"); | 438 | buf_init_from_str(&entry->name, "void"); |
| 438 | entry->di_type = g->dbuilder->createBasicType(buf_ptr(&entry->name), 0, 0, | 439 | entry->di_type = LLVMZigCreateDebugBasicType(g->dbuilder, buf_ptr(&entry->name), 0, 0, |
| 439 | llvm::dwarf::DW_ATE_unsigned); | 440 | LLVMZigEncoding_DW_ATE_unsigned()); |
| 440 | g->type_table.put(&entry->name, entry); | 441 | g->type_table.put(&entry->name, entry); |
| 441 | 442 | ||
| 442 | // invalid types are void | 443 | // invalid types are void |
| ... | @@ -488,7 +489,7 @@ void semantic_analyze(CodeGen *g) { | ... | @@ -488,7 +489,7 @@ void semantic_analyze(CodeGen *g) { |
| 488 | g->pointer_size_bytes = LLVMPointerSize(g->target_data_ref); | 489 | g->pointer_size_bytes = LLVMPointerSize(g->target_data_ref); |
| 489 | 490 | ||
| 490 | g->builder = LLVMCreateBuilder(); | 491 | g->builder = LLVMCreateBuilder(); |
| 491 | g->dbuilder = new llvm::DIBuilder(*llvm::unwrap(g->module), true); | 492 | g->dbuilder = LLVMZigCreateDIBuilder(g->module, true); |
| 492 | 493 | ||
| 493 | 494 | ||
| 494 | add_types(g); | 495 | add_types(g); |
src/codegen.cpp+23-23| ... | @@ -70,7 +70,7 @@ static LLVMTypeRef to_llvm_type(AstNode *type_node) { | ... | @@ -70,7 +70,7 @@ static LLVMTypeRef to_llvm_type(AstNode *type_node) { |
| 70 | return type_node->codegen_node->data.type_node.entry->type_ref; | 70 | return type_node->codegen_node->data.type_node.entry->type_ref; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | static llvm::DIType *to_llvm_debug_type(AstNode *type_node) { | 73 | static LLVMZigDIType *to_llvm_debug_type(AstNode *type_node) { |
| 74 | assert(type_node->type == NodeTypeType); | 74 | assert(type_node->type == NodeTypeType); |
| 75 | assert(type_node->codegen_node); | 75 | assert(type_node->codegen_node); |
| 76 | assert(type_node->codegen_node->data.type_node.entry); | 76 | assert(type_node->codegen_node->data.type_node.entry); |
| ... | @@ -86,9 +86,7 @@ static bool type_is_unreachable(AstNode *type_node) { | ... | @@ -86,9 +86,7 @@ static bool type_is_unreachable(AstNode *type_node) { |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | static void add_debug_source_node(CodeGen *g, AstNode *node) { | 88 | static void add_debug_source_node(CodeGen *g, AstNode *node) { |
| 89 | llvm::unwrap(g->builder)->SetCurrentDebugLocation(llvm::DebugLoc::get( | 89 | LLVMZigSetCurrentDebugLocation(g->builder, node->line + 1, node->column + 1, g->block_scopes.last()); |
| 90 | node->line + 1, node->column + 1, | ||
| 91 | g->block_scopes.last())); | ||
| 92 | } | 90 | } |
| 93 | 91 | ||
| 94 | static LLVMValueRef find_or_create_string(CodeGen *g, Buf *str) { | 92 | static LLVMValueRef find_or_create_string(CodeGen *g, Buf *str) { |
| ... | @@ -441,9 +439,9 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { | ... | @@ -441,9 +439,9 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 441 | static void gen_block(CodeGen *g, AstNode *block_node, bool add_implicit_return) { | 439 | static void gen_block(CodeGen *g, AstNode *block_node, bool add_implicit_return) { |
| 442 | assert(block_node->type == NodeTypeBlock); | 440 | assert(block_node->type == NodeTypeBlock); |
| 443 | 441 | ||
| 444 | llvm::DILexicalBlock *di_block = g->dbuilder->createLexicalBlock(g->block_scopes.last(), | 442 | LLVMZigDILexicalBlock *di_block = LLVMZigCreateLexicalBlock(g->dbuilder, g->block_scopes.last(), |
| 445 | g->di_file, block_node->line + 1, block_node->column + 1); | 443 | g->di_file, block_node->line + 1, block_node->column + 1); |
| 446 | g->block_scopes.append(di_block); | 444 | g->block_scopes.append(LLVMZigLexicalBlockToScope(di_block)); |
| 447 | 445 | ||
| 448 | add_debug_source_node(g, block_node); | 446 | add_debug_source_node(g, block_node); |
| 449 | 447 | ||
| ... | @@ -459,22 +457,27 @@ static void gen_block(CodeGen *g, AstNode *block_node, bool add_implicit_return) | ... | @@ -459,22 +457,27 @@ static void gen_block(CodeGen *g, AstNode *block_node, bool add_implicit_return) |
| 459 | g->block_scopes.pop(); | 457 | g->block_scopes.pop(); |
| 460 | } | 458 | } |
| 461 | 459 | ||
| 462 | static llvm::DISubroutineType *create_di_function_type(CodeGen *g, AstNodeFnProto *fn_proto, | 460 | static LLVMZigDISubroutineType *create_di_function_type(CodeGen *g, AstNodeFnProto *fn_proto, |
| 463 | llvm::DIFile *di_file) | 461 | LLVMZigDIFile *di_file) |
| 464 | { | 462 | { |
| 465 | llvm::SmallVector<llvm::Metadata *, 8> types; | 463 | llvm::SmallVector<llvm::Metadata *, 8> types; |
| 466 | 464 | ||
| 467 | llvm::DIType *return_type = to_llvm_debug_type(fn_proto->return_type); | 465 | llvm::DIType *return_type = reinterpret_cast<llvm::DIType*>(to_llvm_debug_type(fn_proto->return_type)); |
| 468 | types.push_back(return_type); | 466 | types.push_back(return_type); |
| 469 | 467 | ||
| 470 | for (int i = 0; i < fn_proto->params.length; i += 1) { | 468 | for (int i = 0; i < fn_proto->params.length; i += 1) { |
| 471 | AstNode *param_node = fn_proto->params.at(i); | 469 | AstNode *param_node = fn_proto->params.at(i); |
| 472 | assert(param_node->type == NodeTypeParamDecl); | 470 | assert(param_node->type == NodeTypeParamDecl); |
| 473 | llvm::DIType *param_type = to_llvm_debug_type(param_node->data.param_decl.type); | 471 | llvm::DIType *param_type = reinterpret_cast<llvm::DIType*>(to_llvm_debug_type(param_node->data.param_decl.type)); |
| 474 | types.push_back(param_type); | 472 | types.push_back(param_type); |
| 475 | } | 473 | } |
| 476 | 474 | ||
| 477 | return g->dbuilder->createSubroutineType(di_file, g->dbuilder->getOrCreateTypeArray(types)); | 475 | llvm::DIBuilder *dibuilder = reinterpret_cast<llvm::DIBuilder*>(g->dbuilder); |
| 476 | |||
| 477 | llvm::DISubroutineType *result = dibuilder->createSubroutineType( | ||
| 478 | reinterpret_cast<llvm::DIFile*>(di_file), | ||
| 479 | dibuilder->getOrCreateTypeArray(types)); | ||
| 480 | return reinterpret_cast<LLVMZigDISubroutineType*>(result); | ||
| 478 | } | 481 | } |
| 479 | 482 | ||
| 480 | void code_gen(CodeGen *g) { | 483 | void code_gen(CodeGen *g) { |
| ... | @@ -484,14 +487,14 @@ void code_gen(CodeGen *g) { | ... | @@ -484,14 +487,14 @@ void code_gen(CodeGen *g) { |
| 484 | bool is_optimized = g->build_type == CodeGenBuildTypeRelease; | 487 | bool is_optimized = g->build_type == CodeGenBuildTypeRelease; |
| 485 | const char *flags = ""; | 488 | const char *flags = ""; |
| 486 | unsigned runtime_version = 0; | 489 | unsigned runtime_version = 0; |
| 487 | g->compile_unit = g->dbuilder->createCompileUnit(llvm::dwarf::DW_LANG_C99, | 490 | g->compile_unit = LLVMZigCreateCompileUnit(g->dbuilder, LLVMZigLang_DW_LANG_C99(), |
| 488 | buf_ptr(&g->in_file), buf_ptr(&g->in_dir), | 491 | buf_ptr(&g->in_file), buf_ptr(&g->in_dir), |
| 489 | buf_ptr(producer), is_optimized, flags, runtime_version, | 492 | buf_ptr(producer), is_optimized, flags, runtime_version, |
| 490 | "", llvm::DIBuilder::FullDebug, 0, !g->strip_debug_symbols); | 493 | "", 0, !g->strip_debug_symbols); |
| 491 | 494 | ||
| 492 | g->block_scopes.append(g->compile_unit); | 495 | g->block_scopes.append(LLVMZigCompileUnitToScope(g->compile_unit)); |
| 493 | 496 | ||
| 494 | g->di_file = g->dbuilder->createFile(g->compile_unit->getFilename(), g->compile_unit->getDirectory()); | 497 | g->di_file = LLVMZigCreateFile(g->dbuilder, buf_ptr(&g->in_file), buf_ptr(&g->in_dir)); |
| 495 | 498 | ||
| 496 | 499 | ||
| 497 | // Generate function prototypes | 500 | // Generate function prototypes |
| ... | @@ -543,18 +546,17 @@ void code_gen(CodeGen *g) { | ... | @@ -543,18 +546,17 @@ void code_gen(CodeGen *g) { |
| 543 | AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; | 546 | AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; |
| 544 | 547 | ||
| 545 | // Add debug info. | 548 | // Add debug info. |
| 546 | llvm::DIScope *fn_scope = g->di_file; | 549 | LLVMZigDIScope *fn_scope = LLVMZigFileToScope(g->di_file); |
| 547 | unsigned line_number = fn_def_node->line + 1; | 550 | unsigned line_number = fn_def_node->line + 1; |
| 548 | unsigned scope_line = line_number; | 551 | unsigned scope_line = line_number; |
| 549 | bool is_definition = true; | 552 | bool is_definition = true; |
| 550 | unsigned flags = 0; | 553 | unsigned flags = 0; |
| 551 | llvm::Function *unwrapped_function = reinterpret_cast<llvm::Function*>(llvm::unwrap(fn)); | 554 | LLVMZigDISubprogram *subprogram = LLVMZigCreateFunction(g->dbuilder, |
| 552 | llvm::DISubprogram *subprogram = g->dbuilder->createFunction( | ||
| 553 | fn_scope, buf_ptr(&fn_proto->name), "", g->di_file, line_number, | 555 | fn_scope, buf_ptr(&fn_proto->name), "", g->di_file, line_number, |
| 554 | create_di_function_type(g, fn_proto, g->di_file), fn_table_entry->internal_linkage, | 556 | create_di_function_type(g, fn_proto, g->di_file), fn_table_entry->internal_linkage, |
| 555 | is_definition, scope_line, flags, is_optimized, unwrapped_function); | 557 | is_definition, scope_line, flags, is_optimized, fn); |
| 556 | 558 | ||
| 557 | g->block_scopes.append(subprogram); | 559 | g->block_scopes.append(LLVMZigSubprogramToScope(subprogram)); |
| 558 | 560 | ||
| 559 | LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn, "entry"); | 561 | LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn, "entry"); |
| 560 | LLVMPositionBuilderAtEnd(g->builder, entry_block); | 562 | LLVMPositionBuilderAtEnd(g->builder, entry_block); |
| ... | @@ -573,7 +575,7 @@ void code_gen(CodeGen *g) { | ... | @@ -573,7 +575,7 @@ void code_gen(CodeGen *g) { |
| 573 | } | 575 | } |
| 574 | assert(!g->errors.length); | 576 | assert(!g->errors.length); |
| 575 | 577 | ||
| 576 | g->dbuilder->finalize(); | 578 | LLVMZigDIBuilderFinalize(g->dbuilder); |
| 577 | 579 | ||
| 578 | LLVMDumpModule(g->module); | 580 | LLVMDumpModule(g->module); |
| 579 | 581 | ||
| ... | @@ -897,5 +899,3 @@ void code_gen_link(CodeGen *g, const char *out_file) { | ... | @@ -897,5 +899,3 @@ void code_gen_link(CodeGen *g, const char *out_file) { |
| 897 | generate_h_file(g); | 899 | generate_h_file(g); |
| 898 | } | 900 | } |
| 899 | } | 901 | } |
| 900 | |||
| 901 |
src/semantic_info.hpp+6-8| ... | @@ -10,9 +10,7 @@ | ... | @@ -10,9 +10,7 @@ |
| 10 | 10 | ||
| 11 | #include "codegen.hpp" | 11 | #include "codegen.hpp" |
| 12 | #include "hash_map.hpp" | 12 | #include "hash_map.hpp" |
| 13 | 13 | #include "zig_llvm.hpp" | |
| 14 | #include <llvm/IR/DIBuilder.h> | ||
| 15 | #include <llvm/IR/DiagnosticInfo.h> | ||
| 16 | 14 | ||
| 17 | struct FnTableEntry { | 15 | struct FnTableEntry { |
| 18 | LLVMValueRef fn_value; | 16 | LLVMValueRef fn_value; |
| ... | @@ -35,7 +33,7 @@ enum TypeId { | ... | @@ -35,7 +33,7 @@ enum TypeId { |
| 35 | struct TypeTableEntry { | 33 | struct TypeTableEntry { |
| 36 | TypeId id; | 34 | TypeId id; |
| 37 | LLVMTypeRef type_ref; | 35 | LLVMTypeRef type_ref; |
| 38 | llvm::DIType *di_type; | 36 | LLVMZigDIType *di_type; |
| 39 | 37 | ||
| 40 | TypeTableEntry *pointer_child; | 38 | TypeTableEntry *pointer_child; |
| 41 | bool pointer_is_const; | 39 | bool pointer_is_const; |
| ... | @@ -50,8 +48,8 @@ struct CodeGen { | ... | @@ -50,8 +48,8 @@ struct CodeGen { |
| 50 | AstNode *root; | 48 | AstNode *root; |
| 51 | ZigList<ErrorMsg> errors; | 49 | ZigList<ErrorMsg> errors; |
| 52 | LLVMBuilderRef builder; | 50 | LLVMBuilderRef builder; |
| 53 | llvm::DIBuilder *dbuilder; | 51 | LLVMZigDIBuilder *dbuilder; |
| 54 | llvm::DICompileUnit *compile_unit; | 52 | LLVMZigDICompileUnit *compile_unit; |
| 55 | HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table; | 53 | HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table; |
| 56 | HashMap<Buf *, LLVMValueRef, buf_hash, buf_eql_buf> str_table; | 54 | HashMap<Buf *, LLVMValueRef, buf_hash, buf_eql_buf> str_table; |
| 57 | HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> type_table; | 55 | HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> type_table; |
| ... | @@ -66,8 +64,8 @@ struct CodeGen { | ... | @@ -66,8 +64,8 @@ struct CodeGen { |
| 66 | bool is_native_target; | 64 | bool is_native_target; |
| 67 | Buf in_file; | 65 | Buf in_file; |
| 68 | Buf in_dir; | 66 | Buf in_dir; |
| 69 | ZigList<llvm::DIScope *> block_scopes; | 67 | ZigList<LLVMZigDIScope *> block_scopes; |
| 70 | llvm::DIFile *di_file; | 68 | LLVMZigDIFile *di_file; |
| 71 | ZigList<FnTableEntry *> fn_defs; | 69 | ZigList<FnTableEntry *> fn_defs; |
| 72 | Buf *out_name; | 70 | Buf *out_name; |
| 73 | OutType out_type; | 71 | OutType out_type; |
src/zig_llvm.cpp+115| ... | @@ -7,6 +7,13 @@ | ... | @@ -7,6 +7,13 @@ |
| 7 | 7 | ||
| 8 | #include "zig_llvm.hpp" | 8 | #include "zig_llvm.hpp" |
| 9 | 9 | ||
| 10 | /* | ||
| 11 | * The point of this file is to contain all the LLVM C++ API interaction so that: | ||
| 12 | * 1. The compile time of other files is kept under control. | ||
| 13 | * 2. Provide a C interface to the LLVM functions we need for self-hosting purposes. | ||
| 14 | * 3. Prevent C++ from infecting the rest of the project. | ||
| 15 | */ | ||
| 16 | |||
| 10 | #include <llvm/InitializePasses.h> | 17 | #include <llvm/InitializePasses.h> |
| 11 | #include <llvm/PassRegistry.h> | 18 | #include <llvm/PassRegistry.h> |
| 12 | #include <llvm/MC/SubtargetFeature.h> | 19 | #include <llvm/MC/SubtargetFeature.h> |
| ... | @@ -18,6 +25,8 @@ | ... | @@ -18,6 +25,8 @@ |
| 18 | #include <llvm/IR/Verifier.h> | 25 | #include <llvm/IR/Verifier.h> |
| 19 | #include <llvm/IR/Instructions.h> | 26 | #include <llvm/IR/Instructions.h> |
| 20 | #include <llvm/IR/IRBuilder.h> | 27 | #include <llvm/IR/IRBuilder.h> |
| 28 | #include <llvm/IR/DIBuilder.h> | ||
| 29 | #include <llvm/IR/DiagnosticInfo.h> | ||
| 21 | #include <llvm/Analysis/TargetLibraryInfo.h> | 30 | #include <llvm/Analysis/TargetLibraryInfo.h> |
| 22 | #include <llvm/Analysis/TargetTransformInfo.h> | 31 | #include <llvm/Analysis/TargetTransformInfo.h> |
| 23 | #include <llvm/Transforms/IPO.h> | 32 | #include <llvm/Transforms/IPO.h> |
| ... | @@ -122,3 +131,109 @@ LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A | ... | @@ -122,3 +131,109 @@ LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A |
| 122 | call_inst->setCallingConv(CC); | 131 | call_inst->setCallingConv(CC); |
| 123 | return wrap(unwrap(B)->Insert(call_inst)); | 132 | return wrap(unwrap(B)->Insert(call_inst)); |
| 124 | } | 133 | } |
| 134 | |||
| 135 | LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, | ||
| 136 | uint64_t size_in_bits, uint64_t align_in_bits, const char *name) | ||
| 137 | { | ||
| 138 | DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createPointerType( | ||
| 139 | reinterpret_cast<DIType*>(pointee_type), size_in_bits, align_in_bits, name); | ||
| 140 | return reinterpret_cast<LLVMZigDIType*>(di_type); | ||
| 141 | } | ||
| 142 | |||
| 143 | LLVMZigDIType *LLVMZigCreateDebugBasicType(LLVMZigDIBuilder *dibuilder, const char *name, | ||
| 144 | uint64_t size_in_bits, uint64_t align_in_bits, unsigned encoding) | ||
| 145 | { | ||
| 146 | DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createBasicType( | ||
| 147 | name, size_in_bits, align_in_bits, encoding); | ||
| 148 | return reinterpret_cast<LLVMZigDIType*>(di_type); | ||
| 149 | } | ||
| 150 | |||
| 151 | unsigned LLVMZigEncoding_DW_ATE_unsigned(void) { | ||
| 152 | return dwarf::DW_ATE_unsigned; | ||
| 153 | } | ||
| 154 | |||
| 155 | unsigned LLVMZigEncoding_DW_ATE_signed(void) { | ||
| 156 | return dwarf::DW_ATE_signed; | ||
| 157 | } | ||
| 158 | |||
| 159 | unsigned LLVMZigLang_DW_LANG_C99(void) { | ||
| 160 | return dwarf::DW_LANG_C99; | ||
| 161 | } | ||
| 162 | |||
| 163 | LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved) { | ||
| 164 | DIBuilder *di_builder = new DIBuilder(*llvm::unwrap(module), allow_unresolved); | ||
| 165 | return reinterpret_cast<LLVMZigDIBuilder *>(di_builder); | ||
| 166 | } | ||
| 167 | |||
| 168 | void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope) { | ||
| 169 | unwrap(builder)->SetCurrentDebugLocation(llvm::DebugLoc::get( | ||
| 170 | line, column, reinterpret_cast<DIScope*>(scope))); | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | LLVMZigDILexicalBlock *LLVMZigCreateLexicalBlock(LLVMZigDIBuilder *dbuilder, LLVMZigDIScope *scope, | ||
| 175 | LLVMZigDIFile *file, unsigned line, unsigned col) | ||
| 176 | { | ||
| 177 | DILexicalBlock *result = reinterpret_cast<DIBuilder*>(dbuilder)->createLexicalBlock( | ||
| 178 | reinterpret_cast<DIScope*>(scope), | ||
| 179 | reinterpret_cast<DIFile*>(file), | ||
| 180 | line, | ||
| 181 | col); | ||
| 182 | return reinterpret_cast<LLVMZigDILexicalBlock*>(result); | ||
| 183 | } | ||
| 184 | |||
| 185 | LLVMZigDIScope *LLVMZigLexicalBlockToScope(LLVMZigDILexicalBlock *lexical_block) { | ||
| 186 | DIScope *scope = reinterpret_cast<DILexicalBlock*>(lexical_block); | ||
| 187 | return reinterpret_cast<LLVMZigDIScope*>(scope); | ||
| 188 | } | ||
| 189 | |||
| 190 | LLVMZigDIScope *LLVMZigCompileUnitToScope(LLVMZigDICompileUnit *compile_unit) { | ||
| 191 | DIScope *scope = reinterpret_cast<DICompileUnit*>(compile_unit); | ||
| 192 | return reinterpret_cast<LLVMZigDIScope*>(scope); | ||
| 193 | } | ||
| 194 | |||
| 195 | LLVMZigDIScope *LLVMZigFileToScope(LLVMZigDIFile *difile) { | ||
| 196 | DIScope *scope = reinterpret_cast<DIFile*>(difile); | ||
| 197 | return reinterpret_cast<LLVMZigDIScope*>(scope); | ||
| 198 | } | ||
| 199 | |||
| 200 | LLVMZigDIScope *LLVMZigSubprogramToScope(LLVMZigDISubprogram *subprogram) { | ||
| 201 | DIScope *scope = reinterpret_cast<DISubprogram*>(subprogram); | ||
| 202 | return reinterpret_cast<LLVMZigDIScope*>(scope); | ||
| 203 | } | ||
| 204 | |||
| 205 | LLVMZigDICompileUnit *LLVMZigCreateCompileUnit(LLVMZigDIBuilder *dibuilder, | ||
| 206 | unsigned lang, const char *file, const char *dir, const char *producer, | ||
| 207 | bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name, | ||
| 208 | uint64_t dwo_id, bool emit_debug_info) | ||
| 209 | { | ||
| 210 | DICompileUnit *result = reinterpret_cast<DIBuilder*>(dibuilder)->createCompileUnit( | ||
| 211 | lang, file, dir, producer, is_optimized, flags, runtime_version, split_name, | ||
| 212 | DIBuilder::FullDebug, dwo_id, emit_debug_info); | ||
| 213 | return reinterpret_cast<LLVMZigDICompileUnit*>(result); | ||
| 214 | } | ||
| 215 | |||
| 216 | LLVMZigDIFile *LLVMZigCreateFile(LLVMZigDIBuilder *dibuilder, const char *filename, const char *directory) { | ||
| 217 | DIFile *result = reinterpret_cast<DIBuilder*>(dibuilder)->createFile(filename, directory); | ||
| 218 | return reinterpret_cast<LLVMZigDIFile*>(result); | ||
| 219 | } | ||
| 220 | |||
| 221 | LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigDIScope *scope, | ||
| 222 | const char *name, const char *linkage_name, LLVMZigDIFile *file, unsigned lineno, | ||
| 223 | LLVMZigDISubroutineType *ty, bool is_local_to_unit, bool is_definition, unsigned scope_line, | ||
| 224 | unsigned flags, bool is_optimized, LLVMValueRef function) | ||
| 225 | { | ||
| 226 | llvm::Function *unwrapped_function = reinterpret_cast<llvm::Function*>(unwrap(function)); | ||
| 227 | DISubprogram *result = reinterpret_cast<DIBuilder*>(dibuilder)->createFunction( | ||
| 228 | reinterpret_cast<DIScope*>(scope), | ||
| 229 | name, linkage_name, | ||
| 230 | reinterpret_cast<DIFile*>(file), | ||
| 231 | lineno, | ||
| 232 | reinterpret_cast<DISubroutineType*>(ty), | ||
| 233 | is_local_to_unit, is_definition, scope_line, flags, is_optimized, unwrapped_function); | ||
| 234 | return reinterpret_cast<LLVMZigDISubprogram*>(result); | ||
| 235 | } | ||
| 236 | |||
| 237 | void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder) { | ||
| 238 | reinterpret_cast<DIBuilder*>(dibuilder)->finalize(); | ||
| 239 | } |
src/zig_llvm.hpp+46| ... | @@ -14,6 +14,15 @@ | ... | @@ -14,6 +14,15 @@ |
| 14 | #include <llvm-c/Initialization.h> | 14 | #include <llvm-c/Initialization.h> |
| 15 | #include <llvm-c/TargetMachine.h> | 15 | #include <llvm-c/TargetMachine.h> |
| 16 | 16 | ||
| 17 | struct LLVMZigDIType; | ||
| 18 | struct LLVMZigDIBuilder; | ||
| 19 | struct LLVMZigDICompileUnit; | ||
| 20 | struct LLVMZigDIScope; | ||
| 21 | struct LLVMZigDIFile; | ||
| 22 | struct LLVMZigDILexicalBlock; | ||
| 23 | struct LLVMZigDISubprogram; | ||
| 24 | struct LLVMZigDISubroutineType; | ||
| 25 | |||
| 17 | void LLVMZigInitializeLoopStrengthReducePass(LLVMPassRegistryRef R); | 26 | void LLVMZigInitializeLoopStrengthReducePass(LLVMPassRegistryRef R); |
| 18 | void LLVMZigInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R); | 27 | void LLVMZigInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R); |
| 19 | void LLVMZigInitializeUnreachableBlockElimPass(LLVMPassRegistryRef R); | 28 | void LLVMZigInitializeUnreachableBlockElimPass(LLVMPassRegistryRef R); |
| ... | @@ -26,4 +35,41 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef | ... | @@ -26,4 +35,41 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef |
| 26 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, | 35 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, |
| 27 | unsigned NumArgs, unsigned CC, const char *Name); | 36 | unsigned NumArgs, unsigned CC, const char *Name); |
| 28 | 37 | ||
| 38 | |||
| 39 | LLVMZigDIType *LLVMZigCreateDebugPointerType(LLVMZigDIBuilder *dibuilder, LLVMZigDIType *pointee_type, | ||
| 40 | uint64_t size_in_bits, uint64_t align_in_bits, const char *name); | ||
| 41 | |||
| 42 | LLVMZigDIType *LLVMZigCreateDebugBasicType(LLVMZigDIBuilder *dibuilder, const char *name, | ||
| 43 | uint64_t size_in_bits, uint64_t align_in_bits, unsigned encoding); | ||
| 44 | |||
| 45 | unsigned LLVMZigEncoding_DW_ATE_unsigned(void); | ||
| 46 | unsigned LLVMZigEncoding_DW_ATE_signed(void); | ||
| 47 | unsigned LLVMZigLang_DW_LANG_C99(void); | ||
| 48 | |||
| 49 | LLVMZigDIBuilder *LLVMZigCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); | ||
| 50 | |||
| 51 | void LLVMZigSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, LLVMZigDIScope *scope); | ||
| 52 | |||
| 53 | LLVMZigDIScope *LLVMZigLexicalBlockToScope(LLVMZigDILexicalBlock *lexical_block); | ||
| 54 | LLVMZigDIScope *LLVMZigCompileUnitToScope(LLVMZigDICompileUnit *compile_unit); | ||
| 55 | LLVMZigDIScope *LLVMZigFileToScope(LLVMZigDIFile *difile); | ||
| 56 | LLVMZigDIScope *LLVMZigSubprogramToScope(LLVMZigDISubprogram *subprogram); | ||
| 57 | |||
| 58 | LLVMZigDILexicalBlock *LLVMZigCreateLexicalBlock(LLVMZigDIBuilder *dbuilder, LLVMZigDIScope *scope, | ||
| 59 | LLVMZigDIFile *file, unsigned line, unsigned col); | ||
| 60 | |||
| 61 | LLVMZigDICompileUnit *LLVMZigCreateCompileUnit(LLVMZigDIBuilder *dibuilder, | ||
| 62 | unsigned lang, const char *file, const char *dir, const char *producer, | ||
| 63 | bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name, | ||
| 64 | uint64_t dwo_id, bool emit_debug_info); | ||
| 65 | |||
| 66 | LLVMZigDIFile *LLVMZigCreateFile(LLVMZigDIBuilder *dibuilder, const char *filename, const char *directory); | ||
| 67 | |||
| 68 | LLVMZigDISubprogram *LLVMZigCreateFunction(LLVMZigDIBuilder *dibuilder, LLVMZigDIScope *scope, | ||
| 69 | const char *name, const char *linkage_name, LLVMZigDIFile *file, unsigned lineno, | ||
| 70 | LLVMZigDISubroutineType *ty, bool is_local_to_unit, bool is_definition, unsigned scope_line, | ||
| 71 | unsigned flags, bool is_optimized, LLVMValueRef function); | ||
| 72 | |||
| 73 | void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder); | ||
| 74 | |||
| 29 | #endif | 75 | #endif |