llvm_backend.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. #if defined(GB_SYSTEM_WINDOWS)
  2. #include "llvm-c/Core.h"
  3. #include "llvm-c/ExecutionEngine.h"
  4. #include "llvm-c/Target.h"
  5. #include "llvm-c/Analysis.h"
  6. #include "llvm-c/Object.h"
  7. #include "llvm-c/BitWriter.h"
  8. #include "llvm-c/DebugInfo.h"
  9. #include "llvm-c/Transforms/AggressiveInstCombine.h"
  10. #include "llvm-c/Transforms/InstCombine.h"
  11. #include "llvm-c/Transforms/IPO.h"
  12. #include "llvm-c/Transforms/PassManagerBuilder.h"
  13. #include "llvm-c/Transforms/Scalar.h"
  14. #include "llvm-c/Transforms/Utils.h"
  15. #include "llvm-c/Transforms/Vectorize.h"
  16. #else
  17. #include <llvm-c/Core.h>
  18. #include <llvm-c/ExecutionEngine.h>
  19. #include <llvm-c/Target.h>
  20. #include <llvm-c/Analysis.h>
  21. #include <llvm-c/Object.h>
  22. #include <llvm-c/BitWriter.h>
  23. #include <llvm-c/DebugInfo.h>
  24. #include <llvm-c/Transforms/AggressiveInstCombine.h>
  25. #include <llvm-c/Transforms/InstCombine.h>
  26. #include <llvm-c/Transforms/IPO.h>
  27. #include <llvm-c/Transforms/PassManagerBuilder.h>
  28. #include <llvm-c/Transforms/Scalar.h>
  29. #include <llvm-c/Transforms/Utils.h>
  30. #include <llvm-c/Transforms/Vectorize.h>
  31. #endif
  32. struct lbProcedure;
  33. struct lbValue {
  34. LLVMValueRef value;
  35. Type *type;
  36. };
  37. enum lbAddrKind {
  38. lbAddr_Default,
  39. lbAddr_Map,
  40. lbAddr_Context,
  41. lbAddr_SoaVariable,
  42. lbAddr_RelativePointer,
  43. lbAddr_RelativeSlice,
  44. lbAddr_Swizzle,
  45. lbAddr_SwizzleLarge,
  46. };
  47. struct lbAddr {
  48. lbAddrKind kind;
  49. lbValue addr;
  50. union {
  51. struct {
  52. lbValue key;
  53. Type *type;
  54. Type *result;
  55. } map;
  56. struct {
  57. Selection sel;
  58. } ctx;
  59. struct {
  60. lbValue index;
  61. Ast *index_expr;
  62. } soa;
  63. struct {
  64. lbValue index;
  65. Ast *node;
  66. } index_set;
  67. struct {
  68. bool deref;
  69. } relative;
  70. struct {
  71. Type *type;
  72. u8 count; // 2, 3, or 4 components
  73. u8 indices[4];
  74. } swizzle;
  75. struct {
  76. Type *type;
  77. Slice<i32> indices;
  78. } swizzle_large;
  79. };
  80. };
  81. struct lbIncompleteDebugType {
  82. Type *type;
  83. LLVMMetadataRef metadata;
  84. };
  85. struct lbModule {
  86. LLVMModuleRef mod;
  87. LLVMContextRef ctx;
  88. struct lbGenerator *gen;
  89. CheckerInfo *info;
  90. AstPackage *pkg; // associated
  91. Map<LLVMTypeRef> types; // Key: Type *
  92. Map<Type *> llvm_types; // Key: LLVMTypeRef
  93. i32 internal_type_level;
  94. Map<lbValue> values; // Key: Entity *
  95. Map<lbAddr> soa_values; // Key: Entity *
  96. StringMap<lbValue> members;
  97. StringMap<lbProcedure *> procedures;
  98. Map<Entity *> procedure_values; // Key: LLVMValueRef
  99. Array<lbProcedure *> missing_procedures_to_check;
  100. StringMap<LLVMValueRef> const_strings;
  101. Map<lbProcedure *> anonymous_proc_lits; // Key: Ast *
  102. Map<struct lbFunctionType *> function_type_map; // Key: Type *
  103. Map<lbProcedure *> equal_procs; // Key: Type *
  104. Map<lbProcedure *> hasher_procs; // Key: Type *
  105. u32 nested_type_name_guid;
  106. Array<lbProcedure *> procedures_to_generate;
  107. Array<String> foreign_library_paths;
  108. lbProcedure *curr_procedure;
  109. LLVMDIBuilderRef debug_builder;
  110. LLVMMetadataRef debug_compile_unit;
  111. Map<LLVMMetadataRef> debug_values; // Key: Pointer
  112. Array<lbIncompleteDebugType> debug_incomplete_types;
  113. };
  114. struct lbGenerator {
  115. CheckerInfo *info;
  116. Array<String> output_object_paths;
  117. Array<String> output_temp_paths;
  118. String output_base;
  119. String output_name;
  120. Map<lbModule *> modules; // Key: AstPackage *
  121. Map<lbModule *> modules_through_ctx; // Key: LLVMContextRef *
  122. lbModule default_module;
  123. Map<lbProcedure *> anonymous_proc_lits; // Key: Ast *
  124. std::atomic<u32> global_array_index;
  125. std::atomic<u32> global_generated_index;
  126. };
  127. struct lbBlock {
  128. LLVMBasicBlockRef block;
  129. Scope *scope;
  130. isize scope_index;
  131. bool appended;
  132. Array<lbBlock *> preds;
  133. Array<lbBlock *> succs;
  134. };
  135. struct lbBranchBlocks {
  136. Ast *label;
  137. lbBlock *break_;
  138. lbBlock *continue_;
  139. };
  140. struct lbContextData {
  141. lbAddr ctx;
  142. isize scope_index;
  143. isize uses;
  144. };
  145. enum lbParamPasskind {
  146. lbParamPass_Value, // Pass by value
  147. lbParamPass_Pointer, // Pass as a pointer rather than by value
  148. lbParamPass_Integer, // Pass as an integer of the same size
  149. lbParamPass_ConstRef, // Pass as a pointer but the value is immutable
  150. lbParamPass_BitCast, // Pass by value and bit cast to the correct type
  151. lbParamPass_Tuple, // Pass across multiple parameters (System V AMD64, up to 2)
  152. };
  153. enum lbDeferExitKind {
  154. lbDeferExit_Default,
  155. lbDeferExit_Return,
  156. lbDeferExit_Branch,
  157. };
  158. enum lbDeferKind {
  159. lbDefer_Node,
  160. lbDefer_Instr,
  161. lbDefer_Proc,
  162. };
  163. struct lbDefer {
  164. lbDeferKind kind;
  165. isize scope_index;
  166. isize context_stack_count;
  167. lbBlock * block;
  168. union {
  169. Ast *stmt;
  170. // NOTE(bill): 'instr' will be copied every time to create a new one
  171. lbValue instr;
  172. struct {
  173. lbValue deferred;
  174. Array<lbValue> result_as_args;
  175. } proc;
  176. };
  177. };
  178. struct lbTargetList {
  179. lbTargetList *prev;
  180. bool is_block;
  181. lbBlock * break_;
  182. lbBlock * continue_;
  183. lbBlock * fallthrough_;
  184. };
  185. enum lbProcedureFlag : u32 {
  186. lbProcedureFlag_WithoutMemcpyPass = 1<<0,
  187. };
  188. struct lbCopyElisionHint {
  189. lbValue ptr;
  190. Ast * ast;
  191. bool used;
  192. };
  193. struct lbProcedure {
  194. u32 flags;
  195. u16 state_flags;
  196. lbProcedure *parent;
  197. Array<lbProcedure *> children;
  198. Entity * entity;
  199. lbModule * module;
  200. String name;
  201. Type * type;
  202. Ast * type_expr;
  203. Ast * body;
  204. u64 tags;
  205. ProcInlining inlining;
  206. bool is_foreign;
  207. bool is_export;
  208. bool is_entry_point;
  209. bool is_startup;
  210. lbFunctionType *abi_function_type;
  211. LLVMValueRef value;
  212. LLVMBuilderRef builder;
  213. bool is_done;
  214. lbAddr return_ptr;
  215. Array<lbValue> params;
  216. Array<lbDefer> defer_stmts;
  217. Array<lbBlock *> blocks;
  218. Array<lbBranchBlocks> branch_blocks;
  219. Scope * curr_scope;
  220. i32 scope_index;
  221. lbBlock * decl_block;
  222. lbBlock * entry_block;
  223. lbBlock * curr_block;
  224. lbTargetList * target_list;
  225. Ast *curr_stmt;
  226. Array<Scope *> scope_stack;
  227. Array<lbContextData> context_stack;
  228. LLVMMetadataRef debug_info;
  229. lbCopyElisionHint copy_elision_hint;
  230. };
  231. bool lb_init_generator(lbGenerator *gen, Checker *c);
  232. void lb_generate_module(lbGenerator *gen);
  233. String lb_mangle_name(lbModule *m, Entity *e);
  234. String lb_get_entity_name(lbModule *m, Entity *e, String name = {});
  235. LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value=0);
  236. LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type);
  237. void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value);
  238. void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name);
  239. lbProcedure *lb_create_procedure(lbModule *module, Entity *entity, bool ignore_body=false);
  240. void lb_end_procedure(lbProcedure *p);
  241. LLVMTypeRef lb_type(lbModule *m, Type *type);
  242. lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append=false);
  243. lbValue lb_const_nil(lbModule *m, Type *type);
  244. lbValue lb_const_undef(lbModule *m, Type *type);
  245. lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true);
  246. lbValue lb_const_bool(lbModule *m, Type *type, bool value);
  247. lbValue lb_const_int(lbModule *m, Type *type, u64 value);
  248. lbAddr lb_addr(lbValue addr);
  249. Type *lb_addr_type(lbAddr const &addr);
  250. LLVMTypeRef lb_addr_lb_type(lbAddr const &addr);
  251. void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value);
  252. lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr);
  253. lbValue lb_emit_load(lbProcedure *p, lbValue v);
  254. void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value);
  255. void lb_build_stmt(lbProcedure *p, Ast *stmt);
  256. lbValue lb_build_expr(lbProcedure *p, Ast *expr);
  257. lbAddr lb_build_addr(lbProcedure *p, Ast *expr);
  258. void lb_build_stmt_list(lbProcedure *p, Array<Ast *> const &stmts);
  259. lbValue lb_build_gep(lbProcedure *p, lbValue const &value, i32 index) ;
  260. lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index);
  261. lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index);
  262. lbValue lb_emit_array_epi(lbProcedure *p, lbValue value, isize index);
  263. lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index);
  264. lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel);
  265. lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel);
  266. lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type);
  267. lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type);
  268. void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block);
  269. lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t);
  270. lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right);
  271. lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, ProcInlining inlining = ProcInlining_none, bool use_return_ptr_hint = false);
  272. lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t);
  273. lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x);
  274. void lb_emit_jump(lbProcedure *p, lbBlock *target_block);
  275. void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block);
  276. void lb_start_block(lbProcedure *p, lbBlock *b);
  277. lbValue lb_build_call_expr(lbProcedure *p, Ast *expr);
  278. lbAddr lb_find_or_generate_context_ptr(lbProcedure *p);
  279. lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx);
  280. lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p);
  281. lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={});
  282. lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, i32 param_index=0, bool force_no_init=false);
  283. void lb_add_foreign_library_path(lbModule *m, Entity *e);
  284. lbValue lb_typeid(lbModule *m, Type *type);
  285. lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value);
  286. lbValue lb_address_from_load(lbProcedure *p, lbValue value);
  287. void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt);
  288. lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init);
  289. lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array<lbValue> const &args);
  290. lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index);
  291. lbValue lb_string_elem(lbProcedure *p, lbValue string);
  292. lbValue lb_string_len(lbProcedure *p, lbValue string);
  293. lbValue lb_cstring_len(lbProcedure *p, lbValue value);
  294. lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr);
  295. lbValue lb_slice_elem(lbProcedure *p, lbValue slice);
  296. lbValue lb_slice_len(lbProcedure *p, lbValue slice);
  297. lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da);
  298. lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da);
  299. lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da);
  300. lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da);
  301. lbValue lb_map_entries(lbProcedure *p, lbValue value);
  302. lbValue lb_map_entries_ptr(lbProcedure *p, lbValue value);
  303. lbValue lb_map_len(lbProcedure *p, lbValue value);
  304. lbValue lb_map_cap(lbProcedure *p, lbValue value);
  305. lbValue lb_soa_struct_len(lbProcedure *p, lbValue value);
  306. void lb_emit_increment(lbProcedure *p, lbValue addr);
  307. lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y);
  308. void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len);
  309. lbValue lb_type_info(lbModule *m, Type *type);
  310. lbValue lb_find_or_add_entity_string(lbModule *m, String const &str);
  311. lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr);
  312. bool lb_is_const(lbValue value);
  313. bool lb_is_const_or_global(lbValue value);
  314. bool lb_is_const_nil(lbValue value);
  315. String lb_get_const_string(lbModule *m, lbValue value);
  316. lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init=true);
  317. lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id);
  318. lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type);
  319. lbValue lb_gen_map_hash(lbProcedure *p, lbValue key, Type *key_type);
  320. void lb_insert_dynamic_map_key_and_value(lbProcedure *p, lbAddr addr, Type *map_type, lbValue map_key, lbValue map_value, Ast *node);
  321. lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e);
  322. lbValue lb_find_value_from_entity(lbModule *m, Entity *e);
  323. void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value);
  324. lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value);
  325. lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, TokenPos const &pos);
  326. lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos);
  327. lbValue lb_get_equal_proc_for_type(lbModule *m, Type *type);
  328. lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type);
  329. lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t);
  330. LLVMMetadataRef lb_debug_type(lbModule *m, Type *type);
  331. lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type);
  332. lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type);
  333. lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type);
  334. lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type);
  335. lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type);
  336. lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x);
  337. void lb_mem_zero_addr(lbProcedure *p, LLVMValueRef ptr, Type *type);
  338. void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e);
  339. lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type);
  340. lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block);
  341. LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_);
  342. LLVMValueRef llvm_const_named_struct(LLVMTypeRef t, LLVMValueRef *values, isize value_count_);
  343. void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name);
  344. lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t);
  345. bool lb_is_expr_untyped_const(Ast *expr);
  346. void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment);
  347. void lb_emit_init_context(lbProcedure *p, lbAddr addr);
  348. lbCopyElisionHint lb_set_copy_elision_hint(lbProcedure *p, lbAddr const &addr, Ast *ast);
  349. void lb_reset_copy_elision_hint(lbProcedure *p, lbCopyElisionHint prev_hint);
  350. lbValue lb_consume_copy_elision_hint(lbProcedure *p);
  351. bool lb_struct_has_padding_prefix(Type *t);
  352. #define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime"
  353. #define LB_STARTUP_TYPE_INFO_PROC_NAME "__$startup_type_info"
  354. #define LB_TYPE_INFO_DATA_NAME "__$type_info_data"
  355. #define LB_TYPE_INFO_TYPES_NAME "__$type_info_types_data"
  356. #define LB_TYPE_INFO_NAMES_NAME "__$type_info_names_data"
  357. #define LB_TYPE_INFO_OFFSETS_NAME "__$type_info_offsets_data"
  358. #define LB_TYPE_INFO_USINGS_NAME "__$type_info_usings_data"
  359. #define LB_TYPE_INFO_TAGS_NAME "__$type_info_tags_data"
  360. enum lbCallingConventionKind {
  361. lbCallingConvention_C = 0,
  362. lbCallingConvention_Fast = 8,
  363. lbCallingConvention_Cold = 9,
  364. lbCallingConvention_GHC = 10,
  365. lbCallingConvention_HiPE = 11,
  366. lbCallingConvention_WebKit_JS = 12,
  367. lbCallingConvention_AnyReg = 13,
  368. lbCallingConvention_PreserveMost = 14,
  369. lbCallingConvention_PreserveAll = 15,
  370. lbCallingConvention_Swift = 16,
  371. lbCallingConvention_CXX_FAST_TLS = 17,
  372. lbCallingConvention_FirstTargetCC = 64,
  373. lbCallingConvention_X86_StdCall = 64,
  374. lbCallingConvention_X86_FastCall = 65,
  375. lbCallingConvention_ARM_APCS = 66,
  376. lbCallingConvention_ARM_AAPCS = 67,
  377. lbCallingConvention_ARM_AAPCS_VFP = 68,
  378. lbCallingConvention_MSP430_INTR = 69,
  379. lbCallingConvention_X86_ThisCall = 70,
  380. lbCallingConvention_PTX_Kernel = 71,
  381. lbCallingConvention_PTX_Device = 72,
  382. lbCallingConvention_SPIR_FUNC = 75,
  383. lbCallingConvention_SPIR_KERNEL = 76,
  384. lbCallingConvention_Intel_OCL_BI = 77,
  385. lbCallingConvention_X86_64_SysV = 78,
  386. lbCallingConvention_Win64 = 79,
  387. lbCallingConvention_X86_VectorCall = 80,
  388. lbCallingConvention_HHVM = 81,
  389. lbCallingConvention_HHVM_C = 82,
  390. lbCallingConvention_X86_INTR = 83,
  391. lbCallingConvention_AVR_INTR = 84,
  392. lbCallingConvention_AVR_SIGNAL = 85,
  393. lbCallingConvention_AVR_BUILTIN = 86,
  394. lbCallingConvention_AMDGPU_VS = 87,
  395. lbCallingConvention_AMDGPU_GS = 88,
  396. lbCallingConvention_AMDGPU_PS = 89,
  397. lbCallingConvention_AMDGPU_CS = 90,
  398. lbCallingConvention_AMDGPU_KERNEL = 91,
  399. lbCallingConvention_X86_RegCall = 92,
  400. lbCallingConvention_AMDGPU_HS = 93,
  401. lbCallingConvention_MSP430_BUILTIN = 94,
  402. lbCallingConvention_AMDGPU_LS = 95,
  403. lbCallingConvention_AMDGPU_ES = 96,
  404. lbCallingConvention_AArch64_VectorCall = 97,
  405. lbCallingConvention_MaxID = 1023,
  406. };
  407. lbCallingConventionKind const lb_calling_convention_map[ProcCC_MAX] = {
  408. lbCallingConvention_C, // ProcCC_Invalid,
  409. lbCallingConvention_C, // ProcCC_Odin,
  410. lbCallingConvention_C, // ProcCC_Contextless,
  411. lbCallingConvention_C, // ProcCC_CDecl,
  412. lbCallingConvention_X86_StdCall, // ProcCC_StdCall,
  413. lbCallingConvention_X86_FastCall, // ProcCC_FastCall,
  414. lbCallingConvention_C, // ProcCC_None,
  415. lbCallingConvention_C, // ProcCC_Naked,
  416. lbCallingConvention_C, // ProcCC_InlineAsm,
  417. };
  418. enum : LLVMDWARFTypeEncoding {
  419. LLVMDWARFTypeEncoding_Address = 1,
  420. LLVMDWARFTypeEncoding_Boolean = 2,
  421. LLVMDWARFTypeEncoding_ComplexFloat = 3,
  422. LLVMDWARFTypeEncoding_Float = 4,
  423. LLVMDWARFTypeEncoding_Signed = 5,
  424. LLVMDWARFTypeEncoding_SignedChar = 6,
  425. LLVMDWARFTypeEncoding_Unsigned = 7,
  426. LLVMDWARFTypeEncoding_UnsignedChar = 8,
  427. LLVMDWARFTypeEncoding_ImaginaryFloat = 9,
  428. LLVMDWARFTypeEncoding_PackedDecimal = 10,
  429. LLVMDWARFTypeEncoding_NumericString = 11,
  430. LLVMDWARFTypeEncoding_Edited = 12,
  431. LLVMDWARFTypeEncoding_SignedFixed = 13,
  432. LLVMDWARFTypeEncoding_UnsignedFixed = 14,
  433. LLVMDWARFTypeEncoding_DecimalFloat = 15,
  434. LLVMDWARFTypeEncoding_Utf = 16,
  435. LLVMDWARFTypeEncoding_LoUser = 128,
  436. LLVMDWARFTypeEncoding_HiUser = 255
  437. };
  438. enum {
  439. DW_TAG_array_type = 1,
  440. DW_TAG_enumeration_type = 4,
  441. DW_TAG_structure_type = 19,
  442. DW_TAG_union_type = 23,
  443. DW_TAG_vector_type = 259,
  444. DW_TAG_subroutine_type = 21,
  445. DW_TAG_inheritance = 28,
  446. };
  447. enum : LLVMAttributeIndex {
  448. LLVMAttributeIndex_ReturnIndex = 0u,
  449. LLVMAttributeIndex_FunctionIndex = ~0u,
  450. LLVMAttributeIndex_FirstArgIndex = 1,
  451. };