2 * Copyright (c) 2015 Andrew Kelley
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
8 #ifndef ZIG_ZIG_LLVM_HPP
9 #define ZIG_ZIG_LLVM_HPP
13 #include <llvm-c/Core.h>
14 #include <llvm-c/Analysis.h>
15 #include <llvm-c/Target.h>
16 #include <llvm-c/TargetMachine.h>
19 #define ZIG_EXTERN_C extern "C"
24 // ATTENTION: If you modify this file, be sure to update the corresponding
25 // extern function declarations in the self-hosted compiler.
27 // synchronize with llvm/include/Transforms/Instrumentation.h::SanitizerCoverageOptions::Type
28 // synchronize with codegen/llvm/bindings.zig::TargetMachine::EmitOptions::Coverage::Type
29 enum ZigLLVMCoverageType
{
30 ZigLLVMCoverageType_None
= 0,
31 ZigLLVMCoverageType_Function
,
32 ZigLLVMCoverageType_BB
,
33 ZigLLVMCoverageType_Edge
36 struct ZigLLVMCoverageOptions
{
37 ZigLLVMCoverageType CoverageType
;
46 bool Inline8bitCounters
;
53 bool CollectControlFlow
;
56 struct ZigLLVMEmitOptions
{
64 const char *asm_filename
;
65 const char *bin_filename
;
66 const char *llvm_ir_filename
;
67 const char *bitcode_filename
;
68 ZigLLVMCoverageOptions coverage
;
71 // synchronize with llvm/include/Object/Archive.h::Object::Archive::Kind
72 // synchronize with codegen/llvm/bindings.zig::ArchiveKind
73 enum ZigLLVMArchiveKind
{
74 ZigLLVMArchiveKind_GNU
,
75 ZigLLVMArchiveKind_GNU64
,
76 ZigLLVMArchiveKind_BSD
,
77 ZigLLVMArchiveKind_DARWIN
,
78 ZigLLVMArchiveKind_DARWIN64
,
79 ZigLLVMArchiveKind_COFF
,
80 ZigLLVMArchiveKind_AIXBIG
,
83 // synchronize with llvm/include/Target/TargetOptions.h::FloatABI::ABIType
84 // synchronize with codegen/llvm/bindings.zig::TargetMachine::FloatABI
85 enum ZigLLVMFloatABI
{
86 ZigLLVMFloatABI_Default
, // Target-specific (either soft or hard depending on triple, etc).
87 ZigLLVMFloatABI_Soft
, // Soft float.
88 ZigLLVMFloatABI_Hard
// Hard float.
91 ZIG_EXTERN_C
bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref
, LLVMModuleRef module_ref
,
92 char **error_message
, const ZigLLVMEmitOptions
*options
);
94 ZIG_EXTERN_C LLVMTargetMachineRef
ZigLLVMCreateTargetMachine(LLVMTargetRef T
, const char *Triple
,
95 const char *CPU
, const char *Features
, LLVMCodeGenOptLevel Level
, LLVMRelocMode Reloc
,
96 LLVMCodeModel CodeModel
, bool function_sections
, bool data_sections
, ZigLLVMFloatABI float_abi
,
97 const char *abi_name
);
99 ZIG_EXTERN_C
void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref
, int limit
);
101 ZIG_EXTERN_C
void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref
);
102 ZIG_EXTERN_C
bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref
);
104 ZIG_EXTERN_C
void ZigLLVMParseCommandLineOptions(size_t argc
, const char *const *argv
);
106 ZIG_EXTERN_C
bool ZigLLDLinkCOFF(int argc
, const char **argv
, bool can_exit_early
, bool disable_output
);
107 ZIG_EXTERN_C
bool ZigLLDLinkELF(int argc
, const char **argv
, bool can_exit_early
, bool disable_output
);
108 ZIG_EXTERN_C
bool ZigLLDLinkWasm(int argc
, const char **argv
, bool can_exit_early
, bool disable_output
);
110 ZIG_EXTERN_C
bool ZigLLVMWriteArchive(const char *archive_name
, const char **file_names
, size_t file_name_count
,
111 ZigLLVMArchiveKind archive_kind
);
113 ZIG_EXTERN_C
bool ZigLLVMWriteImportLibrary(const char *def_path
, unsigned int coff_machine
,
114 const char *output_lib_path
, bool kill_at
);