tilde_proc.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. gb_internal TB_FunctionPrototype *cg_procedure_type_as_prototype(cgModule *m, Type *type) {
  2. // TODO(bill): cache the procedure type generation
  3. GB_ASSERT(build_context.metrics.os == TargetOs_windows);
  4. GB_ASSERT(type != nullptr);
  5. type = base_type(type);
  6. GB_ASSERT(type->kind == Type_Proc);
  7. TypeProc *pt = &type->Proc;
  8. auto params = array_make<TB_PrototypeParam>(heap_allocator(), 0, pt->param_count);
  9. if (pt->params) for (Entity *e : pt->params->Tuple.variables) {
  10. TB_PrototypeParam param = {};
  11. Type *t = core_type(e->type);
  12. i64 sz = type_size_of(t);
  13. switch (t->kind) {
  14. case Type_Basic:
  15. switch (t->Basic.kind) {
  16. case Basic_bool:
  17. case Basic_b8:
  18. case Basic_b16:
  19. case Basic_b32:
  20. case Basic_b64:
  21. case Basic_i8:
  22. case Basic_u8:
  23. case Basic_i16:
  24. case Basic_u16:
  25. case Basic_i32:
  26. case Basic_u32:
  27. case Basic_i64:
  28. case Basic_u64:
  29. case Basic_i128:
  30. case Basic_u128:
  31. case Basic_rune:
  32. case Basic_int:
  33. case Basic_uint:
  34. case Basic_uintptr:
  35. param.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  36. break;
  37. case Basic_f16: param.dt = TB_TYPE_F16; break;
  38. case Basic_f32: param.dt = TB_TYPE_F32; break;
  39. case Basic_f64: param.dt = TB_TYPE_F64; break;
  40. case Basic_complex32:
  41. case Basic_complex64:
  42. case Basic_complex128:
  43. case Basic_quaternion64:
  44. case Basic_quaternion128:
  45. case Basic_quaternion256:
  46. param.dt = TB_TYPE_PTR;
  47. break;
  48. case Basic_rawptr:
  49. param.dt = TB_TYPE_PTR;
  50. break;
  51. case Basic_string: // ^u8 + int
  52. param.dt = TB_TYPE_PTR;
  53. break;
  54. case Basic_cstring: // ^u8
  55. param.dt = TB_TYPE_PTR;
  56. break;
  57. case Basic_any: // rawptr + ^Type_Info
  58. param.dt = TB_TYPE_PTR;
  59. break;
  60. case Basic_typeid:
  61. param.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  62. break;
  63. // Endian Specific Types
  64. case Basic_i16le:
  65. case Basic_u16le:
  66. case Basic_i32le:
  67. case Basic_u32le:
  68. case Basic_i64le:
  69. case Basic_u64le:
  70. case Basic_i128le:
  71. case Basic_u128le:
  72. case Basic_i16be:
  73. case Basic_u16be:
  74. case Basic_i32be:
  75. case Basic_u32be:
  76. case Basic_i64be:
  77. case Basic_u64be:
  78. case Basic_i128be:
  79. case Basic_u128be:
  80. param.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  81. break;
  82. case Basic_f16le: param.dt = TB_TYPE_F16; break;
  83. case Basic_f32le: param.dt = TB_TYPE_F32; break;
  84. case Basic_f64le: param.dt = TB_TYPE_F64; break;
  85. case Basic_f16be: param.dt = TB_TYPE_F16; break;
  86. case Basic_f32be: param.dt = TB_TYPE_F32; break;
  87. case Basic_f64be: param.dt = TB_TYPE_F64; break;
  88. }
  89. case Type_Pointer:
  90. case Type_MultiPointer:
  91. case Type_Proc:
  92. param.dt = TB_TYPE_PTR;
  93. break;
  94. default:
  95. switch (sz) {
  96. case 1: param.dt = TB_TYPE_I8; break;
  97. case 2: param.dt = TB_TYPE_I16; break;
  98. case 4: param.dt = TB_TYPE_I32; break;
  99. case 8: param.dt = TB_TYPE_I64; break;
  100. default:
  101. param.dt = TB_TYPE_PTR;
  102. break;
  103. }
  104. }
  105. if (param.dt.raw != 0) {
  106. if (is_blank_ident(e->token)) {
  107. param.name = alloc_cstring(temporary_allocator(), e->token.string);
  108. }
  109. param.debug_type = cg_debug_type(m, e->type);
  110. array_add(&params, param);
  111. }
  112. }
  113. auto results = array_make<TB_PrototypeParam>(heap_allocator(), 0, 1);
  114. Type *result_type = reduce_tuple_to_single_type(pt->results);
  115. if (result_type) {
  116. bool return_is_tuple = result_type->kind == Type_Tuple && is_calling_convention_odin(pt->calling_convention);
  117. if (return_is_tuple) {
  118. for (isize i = 0; i < result_type->Tuple.variables.count-1; i++) {
  119. Entity *e = result_type->Tuple.variables[i];
  120. TB_PrototypeParam param = {};
  121. param.dt = TB_TYPE_PTR;
  122. param.debug_type = cg_debug_type(m, alloc_type_pointer(e->type));
  123. array_add(&params, param);
  124. }
  125. result_type = result_type->Tuple.variables[result_type->Tuple.variables.count-1]->type;
  126. }
  127. Type *rt = core_type(result_type);
  128. i64 sz = type_size_of(rt);
  129. TB_PrototypeParam result = {};
  130. switch (rt->kind) {
  131. case Type_Basic:
  132. switch (rt->Basic.kind) {
  133. case Basic_bool:
  134. case Basic_b8:
  135. case Basic_b16:
  136. case Basic_b32:
  137. case Basic_b64:
  138. case Basic_i8:
  139. case Basic_u8:
  140. case Basic_i16:
  141. case Basic_u16:
  142. case Basic_i32:
  143. case Basic_u32:
  144. case Basic_i64:
  145. case Basic_u64:
  146. case Basic_i128:
  147. case Basic_u128:
  148. case Basic_rune:
  149. case Basic_int:
  150. case Basic_uint:
  151. case Basic_uintptr:
  152. result.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  153. break;
  154. case Basic_f16: result.dt = TB_TYPE_I16; break;
  155. case Basic_f32: result.dt = TB_TYPE_F32; break;
  156. case Basic_f64: result.dt = TB_TYPE_F64; break;
  157. case Basic_rawptr:
  158. result.dt = TB_TYPE_PTR;
  159. break;
  160. case Basic_cstring: // ^u8
  161. result.dt = TB_TYPE_PTR;
  162. break;
  163. case Basic_typeid:
  164. result.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  165. break;
  166. // Endian Specific Types
  167. case Basic_i16le:
  168. case Basic_u16le:
  169. case Basic_i32le:
  170. case Basic_u32le:
  171. case Basic_i64le:
  172. case Basic_u64le:
  173. case Basic_i128le:
  174. case Basic_u128le:
  175. case Basic_i16be:
  176. case Basic_u16be:
  177. case Basic_i32be:
  178. case Basic_u32be:
  179. case Basic_i64be:
  180. case Basic_u64be:
  181. case Basic_i128be:
  182. case Basic_u128be:
  183. result.dt = TB_TYPE_INTN(cast(u16)(8*sz));
  184. break;
  185. case Basic_f16le: result.dt = TB_TYPE_I16; break;
  186. case Basic_f32le: result.dt = TB_TYPE_F32; break;
  187. case Basic_f64le: result.dt = TB_TYPE_F64; break;
  188. case Basic_f16be: result.dt = TB_TYPE_I16; break;
  189. case Basic_f32be: result.dt = TB_TYPE_F32; break;
  190. case Basic_f64be: result.dt = TB_TYPE_F64; break;
  191. }
  192. case Type_Pointer:
  193. case Type_MultiPointer:
  194. case Type_Proc:
  195. result.dt = TB_TYPE_PTR;
  196. break;
  197. default:
  198. switch (sz) {
  199. case 1: result.dt = TB_TYPE_I8; break;
  200. case 2: result.dt = TB_TYPE_I16; break;
  201. case 4: result.dt = TB_TYPE_I32; break;
  202. case 8: result.dt = TB_TYPE_I64; break;
  203. }
  204. }
  205. if (result.dt.raw != 0) {
  206. result.debug_type = cg_debug_type(m, result_type);
  207. array_add(&results, result);
  208. } else {
  209. result.debug_type = cg_debug_type(m, alloc_type_pointer(result_type));
  210. result.dt = TB_TYPE_PTR;
  211. array_resize(&params, params.count+1);
  212. array_copy(&params, params, 1);
  213. params[0] = result;
  214. }
  215. }
  216. if (pt->calling_convention == ProcCC_Odin) {
  217. TB_PrototypeParam param = {};
  218. param.dt = TB_TYPE_PTR;
  219. param.debug_type = cg_debug_type(m, t_context_ptr);
  220. param.name = "__.context_ptr";
  221. array_add(&params, param);
  222. }
  223. return tb_prototype_create(m->mod, TB_CDECL, params.count, params.data, results.count, results.data, pt->c_vararg);
  224. }
  225. gb_internal cgProcedure *cg_procedure_create(cgModule *m, Entity *entity, bool ignore_body=false) {
  226. GB_ASSERT(entity != nullptr);
  227. GB_ASSERT(entity->kind == Entity_Procedure);
  228. if (!entity->Procedure.is_foreign) {
  229. if ((entity->flags & EntityFlag_ProcBodyChecked) == 0) {
  230. GB_PANIC("%.*s :: %s (was parapoly: %d %d)", LIT(entity->token.string), type_to_string(entity->type), is_type_polymorphic(entity->type, true), is_type_polymorphic(entity->type, false));
  231. }
  232. }
  233. String link_name = cg_get_entity_name(m, entity);
  234. cgProcedure *p = nullptr;
  235. {
  236. StringHashKey key = string_hash_string(link_name);
  237. cgValue *found = string_map_get(&m->members, key);
  238. if (found) {
  239. cg_add_entity(m, entity, *found);
  240. p = string_map_must_get(&m->procedures, key);
  241. if (!ignore_body && p->func != nullptr) {
  242. return nullptr;
  243. }
  244. }
  245. }
  246. if (p == nullptr) {
  247. p = gb_alloc_item(permanent_allocator(), cgProcedure);
  248. }
  249. p->module = m;
  250. p->entity = entity;
  251. p->name = link_name;
  252. DeclInfo *decl = entity->decl_info;
  253. ast_node(pl, ProcLit, decl->proc_lit);
  254. Type *pt = base_type(entity->type);
  255. GB_ASSERT(pt->kind == Type_Proc);
  256. p->type = entity->type;
  257. p->type_expr = decl->type_expr;
  258. p->body = pl->body;
  259. p->inlining = pl->inlining;
  260. p->is_foreign = entity->Procedure.is_foreign;
  261. p->is_export = entity->Procedure.is_export;
  262. p->is_entry_point = false;
  263. gbAllocator a = heap_allocator();
  264. p->children.allocator = a;
  265. // p->defer_stmts.allocator = a;
  266. // p->blocks.allocator = a;
  267. // p->branch_blocks.allocator = a;
  268. p->context_stack.allocator = a;
  269. p->scope_stack.allocator = a;
  270. map_init(&p->variable_map);
  271. // map_init(&p->tuple_fix_map, 0);
  272. TB_Linkage linkage = TB_LINKAGE_PRIVATE;
  273. if (p->is_export) {
  274. linkage = TB_LINKAGE_PUBLIC;
  275. } else if (p->is_foreign || ignore_body) {
  276. if (ignore_body) {
  277. linkage = TB_LINKAGE_PUBLIC;
  278. }
  279. p->symbol = cast(TB_Symbol *)tb_extern_create(m->mod, link_name.len, cast(char const *)link_name.text, TB_EXTERNAL_SO_LOCAL);
  280. }
  281. if (p->symbol == nullptr) {
  282. TB_Arena *arena = tb_default_arena();
  283. p->func = tb_function_create(m->mod, link_name.len, cast(char const *)link_name.text, linkage, TB_COMDAT_NONE);
  284. p->proto = cg_procedure_type_as_prototype(m, p->type);
  285. tb_function_set_prototype(p->func, p->proto, arena);
  286. p->symbol = cast(TB_Symbol *)p->func;
  287. }
  288. cgValue proc_value = cg_value(p->symbol, p->type);
  289. cg_add_entity(m, entity, proc_value);
  290. cg_add_member(m, p->name, proc_value);
  291. cg_add_procedure_value(m, p);
  292. return p;
  293. }
  294. gb_internal cgProcedure *cg_procedure_create_dummy(cgModule *m, String const &link_name, Type *type) {
  295. auto *prev_found = string_map_get(&m->members, link_name);
  296. GB_ASSERT_MSG(prev_found == nullptr, "failed to create dummy procedure for: %.*s", LIT(link_name));
  297. cgProcedure *p = gb_alloc_item(permanent_allocator(), cgProcedure);
  298. p->module = m;
  299. p->name = link_name;
  300. p->type = type;
  301. p->type_expr = nullptr;
  302. p->body = nullptr;
  303. p->tags = 0;
  304. p->inlining = ProcInlining_none;
  305. p->is_foreign = false;
  306. p->is_export = false;
  307. p->is_entry_point = false;
  308. gbAllocator a = heap_allocator();
  309. p->children.allocator = a;
  310. // p->defer_stmts.allocator = a;
  311. // p->blocks.allocator = a;
  312. // p->branch_blocks.allocator = a;
  313. p->scope_stack.allocator = a;
  314. p->context_stack.allocator = a;
  315. map_init(&p->variable_map);
  316. // map_init(&p->tuple_fix_map, 0);
  317. TB_Linkage linkage = TB_LINKAGE_PRIVATE;
  318. TB_Arena *arena = tb_default_arena();
  319. p->func = tb_function_create(m->mod, link_name.len, cast(char const *)link_name.text, linkage, TB_COMDAT_NONE);
  320. p->proto = cg_procedure_type_as_prototype(m, p->type);
  321. tb_function_set_prototype(p->func, p->proto, arena);
  322. p->symbol = cast(TB_Symbol *)p->func;
  323. cgValue proc_value = cg_value(p->symbol, p->type);
  324. cg_add_member(m, p->name, proc_value);
  325. cg_add_procedure_value(m, p);
  326. return p;
  327. }
  328. gb_internal void cg_procedure_begin(cgProcedure *p) {
  329. if (p == nullptr || p->func == nullptr) {
  330. return;
  331. }
  332. if (p->body == nullptr) {
  333. return;
  334. }
  335. GB_ASSERT(p->type->kind == Type_Proc);
  336. TypeProc *pt = &p->type->Proc;
  337. if (pt->params) {
  338. int param_index = 0;
  339. for (Entity *e : pt->params->Tuple.variables) {
  340. if (e->kind != Entity_Variable) {
  341. continue;
  342. }
  343. if (param_index >= p->proto->param_count) {
  344. break;
  345. }
  346. TB_Node *ptr = tb_inst_param_addr(p->func, param_index);
  347. cgValue local = cg_value(ptr, alloc_type_pointer(e->type));
  348. if (e != nullptr && e->token.string.len > 0 && e->token.string != "_") {
  349. // NOTE(bill): for debugging purposes only
  350. String name = e->token.string;
  351. TB_DebugType *debug_type = cg_debug_type(p->module, e->type);
  352. tb_node_append_attrib(ptr, tb_function_attrib_variable(p->func, name.len, cast(char const *)name.text, debug_type));
  353. }
  354. cgAddr addr = cg_addr(local);
  355. if (e) {
  356. map_set(&p->variable_map, e, addr);
  357. }
  358. // if (arg_type->kind == lbArg_Ignore) {
  359. // continue;
  360. // } else if (arg_type->kind == lbArg_Direct) {
  361. // if (e->token.string.len != 0 && !is_blank_ident(e->token.string)) {
  362. // LLVMTypeRef param_type = lb_type(p->module, e->type);
  363. // LLVMValueRef original_value = LLVMGetParam(p->value, param_offset+param_index);
  364. // LLVMValueRef value = OdinLLVMBuildTransmute(p, original_value, param_type);
  365. // lbValue param = {};
  366. // param.value = value;
  367. // param.type = e->type;
  368. // map_set(&p->direct_parameters, e, param);
  369. // lbValue ptr = lb_address_from_load_or_generate_local(p, param);
  370. // GB_ASSERT(LLVMIsAAllocaInst(ptr.value));
  371. // lb_add_entity(p->module, e, ptr);
  372. // lbBlock *block = p->decl_block;
  373. // if (original_value != value) {
  374. // block = p->curr_block;
  375. // }
  376. // LLVMValueRef debug_storage_value = value;
  377. // if (original_value != value && LLVMIsALoadInst(value)) {
  378. // debug_storage_value = LLVMGetOperand(value, 0);
  379. // }
  380. // lb_add_debug_param_variable(p, debug_storage_value, e->type, e->token, param_index+1, block, arg_type->kind);
  381. // }
  382. // } else if (arg_type->kind == lbArg_Indirect) {
  383. // if (e->token.string.len != 0 && !is_blank_ident(e->token.string)) {
  384. // lbValue ptr = {};
  385. // ptr.value = LLVMGetParam(p->value, param_offset+param_index);
  386. // ptr.type = alloc_type_pointer(e->type);
  387. // lb_add_entity(p->module, e, ptr);
  388. // lb_add_debug_param_variable(p, ptr.value, e->type, e->token, param_index+1, p->decl_block, arg_type->kind);
  389. // }
  390. // }
  391. }
  392. }
  393. }
  394. gb_internal void cg_procedure_end(cgProcedure *p) {
  395. if (p == nullptr || p->func == nullptr) {
  396. return;
  397. }
  398. tb_inst_ret(p->func, 0, nullptr);
  399. if (p->name == "main") {
  400. TB_Arena *arena = tb_default_arena();
  401. defer (arena->free(arena));
  402. TB_FuncOpt *opt = tb_funcopt_enter(p->func, arena);
  403. defer (tb_funcopt_exit(opt));
  404. tb_funcopt_print(opt);
  405. }
  406. tb_module_compile_function(p->module->mod, p->func, TB_ISEL_FAST);
  407. }
  408. gb_internal void cg_procedure_generate(cgProcedure *p) {
  409. if (p->body == nullptr) {
  410. return;
  411. }
  412. cg_procedure_begin(p);
  413. defer (cg_procedure_end(p));
  414. if (p->name != "bug.main" &&
  415. p->name != "main") {
  416. return;
  417. }
  418. cg_build_stmt(p, p->body);
  419. }
  420. gb_internal cgValue cg_find_procedure_value_from_entity(cgModule *m, Entity *e) {
  421. GB_ASSERT(is_type_proc(e->type));
  422. e = strip_entity_wrapping(e);
  423. GB_ASSERT(e != nullptr);
  424. GB_ASSERT(e->kind == Entity_Procedure);
  425. cgValue *found = nullptr;
  426. rw_mutex_shared_lock(&m->values_mutex);
  427. found = map_get(&m->values, e);
  428. rw_mutex_shared_unlock(&m->values_mutex);
  429. if (found) {
  430. return *found;
  431. }
  432. GB_PANIC("Error in: %s, missing procedure %.*s\n", token_pos_to_string(e->token.pos), LIT(e->token.string));
  433. return {};
  434. }
  435. gb_internal cgValue cg_build_call_expr_internal(cgProcedure *p, Ast *expr);
  436. gb_internal cgValue cg_build_call_expr(cgProcedure *p, Ast *expr) {
  437. expr = unparen_expr(expr);
  438. ast_node(ce, CallExpr, expr);
  439. cgValue res = cg_build_call_expr_internal(p, expr);
  440. if (ce->optional_ok_one) { // TODO(bill): Minor hack for #optional_ok procedures
  441. GB_PANIC("Handle optional_ok_one");
  442. // GB_ASSERT(is_type_tuple(res.type));
  443. // GB_ASSERT(res.type->Tuple.variables.count == 2);
  444. // return cg_emit_struct_ev(p, res, 0);
  445. }
  446. return res;
  447. }
  448. gb_internal cgValue cg_emit_call(cgProcedure * p, cgValue value, Slice<cgValue> args) {
  449. if (value.kind == cgValue_Symbol) {
  450. value = cg_value(tb_inst_get_symbol_address(p->func, value.symbol), value.type);
  451. }
  452. GB_ASSERT(value.kind == cgValue_Value);
  453. // TODO(bill): abstract out the function prototype stuff so that you handle the ABI correctly (at least for win64 at the moment)
  454. TB_FunctionPrototype *proto = cg_procedure_type_as_prototype(p->module, value.type);
  455. TB_Node *target = value.node;
  456. auto params = slice_make<TB_Node *>(temporary_allocator(), 0 /*proto->param_count*/);
  457. for_array(i, params) {
  458. // params[i] = proto
  459. }
  460. GB_ASSERT(target != nullptr);
  461. TB_MultiOutput multi_output = tb_inst_call(p->func, proto, target, params.count, params.data);
  462. gb_unused(multi_output);
  463. return {};
  464. }
  465. gb_internal cgValue cg_build_call_expr_internal(cgProcedure *p, Ast *expr) {
  466. ast_node(ce, CallExpr, expr);
  467. TypeAndValue tv = type_and_value_of_expr(expr);
  468. TypeAndValue proc_tv = type_and_value_of_expr(ce->proc);
  469. AddressingMode proc_mode = proc_tv.mode;
  470. if (proc_mode == Addressing_Type) {
  471. GB_ASSERT(ce->args.count == 1);
  472. cgValue x = cg_build_expr(p, ce->args[0]);
  473. return cg_emit_conv(p, x, tv.type);
  474. }
  475. Ast *proc_expr = unparen_expr(ce->proc);
  476. if (proc_mode == Addressing_Builtin) {
  477. Entity *e = entity_of_node(proc_expr);
  478. BuiltinProcId id = BuiltinProc_Invalid;
  479. if (e != nullptr) {
  480. id = cast(BuiltinProcId)e->Builtin.id;
  481. } else {
  482. id = BuiltinProc_DIRECTIVE;
  483. }
  484. if (id == BuiltinProc___entry_point) {
  485. if (p->module->info->entry_point) {
  486. cgValue entry_point = cg_find_procedure_value_from_entity(p->module, p->module->info->entry_point);
  487. GB_ASSERT(entry_point.node != nullptr);
  488. cg_emit_call(p, entry_point, {});
  489. }
  490. return {};
  491. }
  492. GB_PANIC("TODO(bill): builtin procs %d %.*s", id, LIT(builtin_procs[id].name));
  493. }
  494. // NOTE(bill): Regular call
  495. cgValue value = {};
  496. Entity *proc_entity = entity_of_node(proc_expr);
  497. if (proc_entity != nullptr) {
  498. if (proc_entity->flags & EntityFlag_Disabled) {
  499. GB_ASSERT(tv.type == nullptr);
  500. return {};
  501. }
  502. }
  503. if (proc_expr->tav.mode == Addressing_Constant) {
  504. ExactValue v = proc_expr->tav.value;
  505. switch (v.kind) {
  506. case ExactValue_Integer:
  507. {
  508. u64 u = big_int_to_u64(&v.value_integer);
  509. cgValue x = cg_value(tb_inst_uint(p->func, TB_TYPE_PTR, u), t_rawptr);
  510. value = cg_emit_conv(p, x, proc_expr->tav.type);
  511. break;
  512. }
  513. case ExactValue_Pointer:
  514. {
  515. u64 u = cast(u64)v.value_pointer;
  516. cgValue x = cg_value(tb_inst_uint(p->func, TB_TYPE_PTR, u), t_rawptr);
  517. value = cg_emit_conv(p, x, proc_expr->tav.type);
  518. break;
  519. }
  520. }
  521. }
  522. if (value.node == nullptr) {
  523. value = cg_build_expr(p, proc_expr);
  524. }
  525. if (value.kind == cgValue_Addr) {
  526. value = cg_emit_load(p, value);
  527. }
  528. GB_ASSERT(value.kind == cgValue_Value);
  529. GB_ASSERT(is_type_proc(value.type));
  530. return cg_emit_call(p, value, {});
  531. }