master
  1/*
  2 * Copyright (c) 2015 Andrew Kelley
  3 *
  4 * This file is part of zig, which is MIT licensed.
  5 * See http://opensource.org/licenses/MIT
  6 */
  7
  8#ifndef ZIG_ZIG_LLVM_HPP
  9#define ZIG_ZIG_LLVM_HPP
 10
 11#include <stdbool.h>
 12#include <stddef.h>
 13#include <llvm-c/Core.h>
 14#include <llvm-c/Analysis.h>
 15#include <llvm-c/Target.h>
 16#include <llvm-c/TargetMachine.h>
 17
 18#ifdef __cplusplus
 19#define ZIG_EXTERN_C extern "C"
 20#else
 21#define ZIG_EXTERN_C
 22#endif
 23
 24// ATTENTION: If you modify this file, be sure to update the corresponding
 25// extern function declarations in the self-hosted compiler.
 26
 27// synchronize with llvm/include/Transforms/Instrumentation.h::SanitizerCoverageOptions::Type
 28// synchronize with codegen/llvm/bindings.zig::TargetMachine::EmitOptions::Coverage::Type
 29enum ZigLLVMCoverageType {
 30    ZigLLVMCoverageType_None = 0,
 31    ZigLLVMCoverageType_Function,
 32    ZigLLVMCoverageType_BB,
 33    ZigLLVMCoverageType_Edge
 34};
 35
 36struct ZigLLVMCoverageOptions {
 37    ZigLLVMCoverageType CoverageType;
 38    bool IndirectCalls;
 39    bool TraceBB;
 40    bool TraceCmp;
 41    bool TraceDiv;
 42    bool TraceGep;
 43    bool Use8bitCounters;
 44    bool TracePC;
 45    bool TracePCGuard;
 46    bool Inline8bitCounters;
 47    bool InlineBoolFlag;
 48    bool PCTable;
 49    bool NoPrune;
 50    bool StackDepth;
 51    bool TraceLoads;
 52    bool TraceStores;
 53    bool CollectControlFlow;
 54};
 55
 56// synchronize with llvm/include/Pass.h::ThinOrFullLTOPhase
 57// synchronize with codegen/llvm/bindings.zig::EmitOptions::LtoPhase
 58enum ZigLLVMThinOrFullLTOPhase {
 59    ZigLLVMThinOrFullLTOPhase_None,
 60    ZigLLVMThinOrFullLTOPhase_ThinPreLink,
 61    ZigLLVMThinOrFullLTOPhase_ThinkPostLink,
 62    ZigLLVMThinOrFullLTOPhase_FullPreLink,
 63    ZigLLVMThinOrFullLTOPhase_FullPostLink,
 64};
 65
 66struct ZigLLVMEmitOptions {
 67    bool is_debug;
 68    bool is_small;
 69    // If not null, and `ZigLLVMTargetMachineEmitToFile` returns `false` indicating success, this
 70    // `char *` will be populated with a `malloc`-allocated string containing the serialized (as
 71    // JSON) time report data. The caller is responsible for freeing that memory.
 72    char **time_report_out;
 73    bool tsan;
 74    bool sancov;
 75    ZigLLVMThinOrFullLTOPhase lto;
 76    bool allow_fast_isel;
 77    bool allow_machine_outliner;
 78    const char *asm_filename;
 79    const char *bin_filename;
 80    const char *llvm_ir_filename;
 81    const char *bitcode_filename;
 82    ZigLLVMCoverageOptions coverage;
 83};
 84
 85// synchronize with llvm/include/Object/Archive.h::Object::Archive::Kind
 86// synchronize with codegen/llvm/bindings.zig::ArchiveKind
 87enum ZigLLVMArchiveKind {
 88    ZigLLVMArchiveKind_GNU,
 89    ZigLLVMArchiveKind_GNU64,
 90    ZigLLVMArchiveKind_BSD,
 91    ZigLLVMArchiveKind_DARWIN,
 92    ZigLLVMArchiveKind_DARWIN64,
 93    ZigLLVMArchiveKind_COFF,
 94    ZigLLVMArchiveKind_AIXBIG,
 95};
 96
 97// synchronize with llvm/include/Target/TargetOptions.h::FloatABI::ABIType
 98// synchronize with codegen/llvm/bindings.zig::TargetMachine::FloatABI
 99enum ZigLLVMFloatABI {
100    ZigLLVMFloatABI_Default, // Target-specific (either soft or hard depending on triple, etc).
101    ZigLLVMFloatABI_Soft,    // Soft float.
102    ZigLLVMFloatABI_Hard     // Hard float.
103};
104
105ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
106    char **error_message, const ZigLLVMEmitOptions *options);
107
108ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
109    const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
110    LLVMCodeModel CodeModel, bool function_sections, bool data_sections, ZigLLVMFloatABI float_abi,
111    const char *abi_name, bool emulated_tls);
112
113ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit);
114
115ZIG_EXTERN_C void ZigLLVMEnableBrokenDebugInfoCheck(LLVMContextRef context_ref);
116ZIG_EXTERN_C bool ZigLLVMGetBrokenDebugInfo(LLVMContextRef context_ref);
117
118ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv);
119
120ZIG_EXTERN_C bool ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early, bool disable_output);
121ZIG_EXTERN_C bool ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early, bool disable_output);
122ZIG_EXTERN_C bool ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early, bool disable_output);
123
124ZIG_EXTERN_C bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size_t file_name_count,
125    ZigLLVMArchiveKind archive_kind);
126
127#endif