kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 3a7dee7c549e750febd91c290e48c8be74eb6bea
parent a4511b4fb8f7e0fe12062e90ab957e4e786894a4
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed, 10 Jun 2026 08:52:48 -0700

format

Diffstat:
Mdriver/cmd/build.c | 9++++-----
Mdriver/cmd/cc.c | 11++++++-----
Mdriver/cmd/dbg.c | 148++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mdriver/cmd/ld.c | 35++++++++++++++++++-----------------
Mdriver/cmd/objdump.c | 34+++++++++++++++-------------------
Mdriver/env/posix.c | 40+++++++++++++++++++++-------------------
Mdriver/env/uctx_rv64_freebsd.c | 86++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mdriver/env/uctx_x86_64_freebsd.c | 26+++++++++++++-------------
Mdriver/lib/hosted.c | 27++++++++++++++-------------
Mdriver/lib/inputs.c | 13+++++--------
Mdriver/lib/link_flags.c | 30+++++++++++++-----------------
Mdriver/lib/link_flags.h | 4++--
Mdriver/lib/runtime.c | 132++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mdriver/lib/wasm_run.c | 97+++++++++++++++++++++++++++++++++++--------------------------------------------
Mdriver/lib/wasm_run.h | 6+++---
Minclude/kit/cg.h | 3++-
Minclude/kit/compile.h | 11++++++-----
Minclude/kit/core.h | 3++-
Minclude/kit/object.h | 8+++++---
Minclude/kit/support/hashmap.h | 6++++--
Mlang/c/decl/decl.c | 4++--
Mlang/c/parse/cg_adapter.c | 11+++++++----
Mlang/c/parse/parse.c | 8++++----
Mlang/c/parse/parse_expr.c | 3+--
Mlang/c/parse/parse_init.c | 3+--
Mlang/c/parse/parse_priv.h | 5++---
Mlang/c/type/type.c | 3+--
Mlang/cpp/pp/pp.c | 12++++++++----
Mlang/toy/builtins.c | 3+--
Mlang/toy/compile.c | 3++-
Mlang/toy/expr.c | 3+--
Mlang/toy/internal.h | 4++--
Mlang/toy/parser.c | 18++++++------------
Mlang/toy/parser_core.c | 7++++---
Mlang/wasm/wasm.c | 3++-
Mrt/include/kit/backtrace.h | 6+++---
Mrt/include/setjmp.h | 14++++++++------
Mrt/include/stdint.h | 4++--
Msrc/abi/abi.c | 3++-
Msrc/abi/abi_rv64.c | 15+++++++--------
Msrc/abi/abi_sysv_x64.c | 5+++--
Msrc/api/compile.c | 9+++++----
Msrc/api/core.c | 6+++---
Msrc/api/link.c | 7+++----
Msrc/api/object_detect.c | 4++--
Msrc/api/package.c | 9+++++----
Msrc/api/wasm_host.c | 119+++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/arch/aa64/native.c | 4++--
Msrc/arch/aa64/reloc.c | 6+++---
Msrc/arch/arch.h | 6+++---
Msrc/arch/c_target/c_emit.c | 35+++++++++++++++++------------------
Msrc/arch/riscv/asm.c | 9+++++----
Msrc/arch/riscv/disasm.c | 10+++++-----
Msrc/arch/riscv/isa.c | 618+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Msrc/arch/riscv/native.c | 4++--
Msrc/arch/riscv/reloc.c | 5+++--
Msrc/arch/wasm/disasm.c | 3++-
Msrc/arch/wasm/ir_emit.c | 5++---
Msrc/arch/x64/native.c | 37+++++++++++++++++--------------------
Msrc/arch/x64/reloc.c | 2+-
Msrc/asm/asm.c | 3++-
Msrc/cg/arith.c | 121+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/cg/call.c | 6++++--
Msrc/cg/fold.c | 4++--
Msrc/cg/internal.h | 4++--
Msrc/cg/memory.c | 6++----
Msrc/cg/native_asm.c | 12+++++-------
Msrc/cg/native_asm.h | 22+++++++++++-----------
Msrc/cg/native_direct_target.c | 18+++++++++---------
Msrc/cg/native_direct_target.h | 17+++++++++--------
Msrc/debug/debug_emit.c | 2+-
Msrc/debug/debug_form.c | 7++++---
Msrc/dist/blob.c | 3++-
Msrc/dist/cas.c | 1-
Msrc/emu/emu.c | 9++++++---
Msrc/emu/emu.h | 4++--
Msrc/interp/engine.c | 45+++++++++++++++++++++++----------------------
Msrc/link/link.c | 6++++--
Msrc/link/link_arch.h | 8++++----
Msrc/link/link_internal.h | 9++++-----
Msrc/link/link_jit.c | 8++++----
Msrc/link/link_layout.c | 5++---
Msrc/link/link_reloc_desc.h | 6++++--
Msrc/link/link_reloc_layout.c | 7+++----
Msrc/link/link_relocatable.c | 9++++++---
Msrc/link/link_resolve.c | 3++-
Msrc/obj/bytebuf.h | 6++++--
Msrc/obj/coff/read.c | 42++++++++++++++++++------------------------
Msrc/obj/coff/read_dso.c | 9++++++---
Msrc/obj/coff/read_image.c | 40++++++++++++++++++++++------------------
Msrc/obj/elf/elf.h | 4++--
Msrc/obj/elf/emu_load.c | 7++++---
Msrc/obj/elf/link.c | 8++++----
Msrc/obj/elf/read.c | 16+++++++++-------
Msrc/obj/elf/reloc_riscv64.c | 9+++++----
Msrc/obj/format.h | 3++-
Msrc/obj/macho/emit.c | 4++--
Msrc/obj/macho/read.c | 9++++++---
Msrc/obj/registry.c | 5++---
Msrc/obj/reloc.c | 18++++++++++++------
Msrc/obj/reloc.h | 18+++++++++---------
Msrc/obj/symresolve.c | 5+++--
Msrc/obj/symresolve.h | 6+++---
Msrc/opt/cg_ir_lower.c | 25+++++++++++++------------
Msrc/opt/ir.c | 19+++++++++++++------
Msrc/opt/ir.h | 8++++----
Msrc/opt/opt.c | 7++++---
Msrc/opt/pass_cfg.c | 3+--
Msrc/opt/pass_lower.c | 5++---
Msrc/opt/pass_native_emit.c | 16++++++++--------
Msrc/wasm/decode.c | 4++--
Msrc/wasm/insn.c | 3++-
Msrc/wasm/validate.c | 9+++------
Msrc/wasm/wasm_insn_table.c | 21+++++++++------------
Msrc/wasm/wasm_insn_table.h | 4++--
Msrc/wasm/wat.c | 7++++---
Mtest/api/abi_classify_test.c | 25+++++++++++--------------
Mtest/api/cg_fp_cmp_test.c | 3+--
Mtest/api/cg_type_test.c | 3+--
Mtest/arch/rv32_decode_test.c | 10+++++-----
Mtest/arch/rv64_decode_test.c | 15+++++++--------
Mtest/arch/x64_inline_test.c | 11++++++-----
Mtest/cg/native_direct_target_test.c | 4++--
Mtest/coff/kit-roundtrip-coff.c | 4++--
Mtest/coff/pe-image-read.c | 19++++++++++---------
Mtest/elf/unit/rv32_class32.c | 12+++++-------
Mtest/link/coff_weak_alias_test.c | 9++++-----
Mtest/link/harness/jit_runner.c | 9++++-----
Mtest/link/jit_tls_relax_test.c | 18+++++++++---------
Mtest/link/reloc_apply_test.c | 7+++----
Mtest/link/rv32_jit_test.c | 5+++--
Mtest/parse/cases/builtin_29_return_address.c | 3++-
Mtest/parse/cases/builtin_31_return_address_anchor.c | 3++-
Mtest/parse/cases/gnu_inline_control_flow.c | 3++-
Mtest/rt/cases/print_backtrace.c | 12+++++++-----
Mtest/wasm/harness/start_wasm.c | 6++----
136 files changed, 1475 insertions(+), 1155 deletions(-)

diff --git a/driver/cmd/build.c b/driver/cmd/build.c @@ -1272,8 +1272,8 @@ static int build_run_link(BuildOptions* o, KitCompiler* compiler, /* Translate the recorded link order into KitLinkInputOrder. (build never * records SOURCE_MEMORY items, so nsource_files is immaterial here.) */ - norder = driver_link_inputs_build_order(&o->inputs, source_obj_index, - source_order_keep, o->nsources, order); + norder = driver_link_inputs_build_order( + &o->inputs, source_obj_index, source_order_keep, o->nsources, order); { KitLinkSessionOptions lopts; @@ -1920,9 +1920,8 @@ static int build_main(int argc, char** argv, int kind, const char* tool) { rc = 1; goto done; } - driver_link_inputs_insert_runtime_archives(&o.inputs, &rt, o.target, - o.hosted.nfinal, - o.hosted.nafter); + driver_link_inputs_insert_runtime_archives( + &o.inputs, &rt, o.target, o.hosted.nfinal, o.hosted.nafter); driver_runtime_archive_fini(&env, &rt); } } else if (o.inputs.npending_libs) { diff --git a/driver/cmd/cc.c b/driver/cmd/cc.c @@ -739,8 +739,9 @@ static int cc_parse(int argc, char** argv, CcOptions* o) { "use =zero"); return 1; } else { - driver_errf(CC_TOOL, "-ftrivial-auto-var-init=: unknown mode '%s' " - "(expected zero, pattern, or uninitialized)", + driver_errf(CC_TOOL, + "-ftrivial-auto-var-init=: unknown mode '%s' " + "(expected zero, pattern, or uninitialized)", mode); return 1; } @@ -2244,9 +2245,9 @@ static int cc_run_link_exe(DriverEnv* env, const CcOptions* o, * one input), so every add flows through the ordered path. */ { DriverLinkInputs li; - norder = driver_link_inputs_build_order( - &o->inputs, source_obj_index, source_order_keep, o->nsource_files, - order); + norder = driver_link_inputs_build_order(&o->inputs, source_obj_index, + source_order_keep, + o->nsource_files, order); memset(&li, 0, sizeof(li)); li.objs = objs; li.nobjs = nobjs; diff --git a/driver/cmd/dbg.c b/driver/cmd/dbg.c @@ -151,13 +151,16 @@ void driver_help_dbg(void) { " info variables [PATTERN] list JIT globals matching PATTERN\n" "\n" "BATCH / SCRIPTING\n" - " --script FILE execute debugger commands from FILE (repeatable)\n" - " --command CMD execute CMD as if typed at the REPL (repeatable)\n" + " --script FILE execute debugger commands from FILE " + "(repeatable)\n" + " --command CMD execute CMD as if typed at the REPL " + "(repeatable)\n" " -c CMD same as --command\n" " --batch non-interactive: suppress banner, exit after\n" " --script / --command sources drain; exit 1 on\n" " any command error\n" - " Note: multi-line jit{} / expr{} blocks in --script files must fit\n" + " Note: multi-line jit{} / expr{} blocks in --script files must " + "fit\n" " on a single line (continuation reads go to stdin, not the file).\n" "\n" "SIGNALS\n" @@ -218,16 +221,18 @@ static int dbg_set_default_language(DbgOpts* o, const char* name) { } static int dbg_script_entry_push(DbgOpts* o, DbgEntryKind kind, - const char* value) { + const char* value) { if (o->nscript_entries >= o->script_entries_cap) { uint32_t nc = o->script_entries_cap ? o->script_entries_cap * 2 : 4; size_t old_sz = (size_t)o->script_entries_cap * sizeof(DbgScriptEntry); size_t new_sz = (size_t)nc * sizeof(DbgScriptEntry); - DbgScriptEntry* nb = o->env->heap->realloc(o->env->heap, - o->script_entries, - old_sz, new_sz, - _Alignof(DbgScriptEntry)); - if (!nb) { driver_errf(DBG_TOOL, "out of memory"); return 1; } + DbgScriptEntry* nb = + o->env->heap->realloc(o->env->heap, o->script_entries, old_sz, new_sz, + _Alignof(DbgScriptEntry)); + if (!nb) { + driver_errf(DBG_TOOL, "out of memory"); + return 1; + } o->script_entries = nb; o->script_entries_cap = nc; } @@ -725,8 +730,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, uint64_t pc; if (file_n == 0) { - dbg_errf(s, "empty file in '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + dbg_errf(s, "empty file in '%.*s'", KIT_SLICE_ARG(kit_slice_cstr(spec))); return 1; } file = dbg_dup(s->env, spec, file_n, &file_size); @@ -737,13 +741,13 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, used = dbg_parse_uint(colon + 1, &line64); if (!used || colon[1 + used] != '\0') { dbg_errf(s, "expected file.c:LINE, got '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); driver_free(s->env, file, file_size); return 1; } if (!s->dwarf) { dbg_errf(s, "no DWARF: cannot resolve %.*s", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); driver_free(s->env, file, file_size); return 1; } @@ -752,7 +756,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, (uint32_t)line64, &pc); if (rc == KIT_NOT_FOUND) { dbg_errf(s, "no line %u in %.*s", (uint32_t)line64, - KIT_SLICE_ARG(kit_slice_cstr(file))); + KIT_SLICE_ARG(kit_slice_cstr(file))); driver_free(s->env, file, file_size); return 1; } @@ -763,21 +767,21 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, kit_dwarf_line_to_addr_all(s->dwarf, kit_slice_cstr(file), (uint32_t)line64, cands, 8u, &n); dbg_errf(s, "ambiguous: %.*s:%u matches %u files", - KIT_SLICE_ARG(kit_slice_cstr(file)), (uint32_t)line64, - (unsigned)n); + KIT_SLICE_ARG(kit_slice_cstr(file)), (uint32_t)line64, + (unsigned)n); for (k = 0; k < n && k < 8u; ++k) { dbg_errf(s, " %.*s (0x%llx)", KIT_SLICE_ARG(cands[k].file), - (unsigned long long)cands[k].pc); + (unsigned long long)cands[k].pc); } if (n > 8u) dbg_errf(s, " ... and %u more", n - 8u); dbg_errf(s, "use a longer path suffix (e.g. b dir/%.*s:%u)", - KIT_SLICE_ARG(kit_slice_cstr(file)), (uint32_t)line64); + KIT_SLICE_ARG(kit_slice_cstr(file)), (uint32_t)line64); driver_free(s->env, file, file_size); return 1; } if (rc != KIT_OK) { dbg_errf(s, "no line entry for %.*s", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); driver_free(s->env, file, file_size); return 1; } @@ -795,7 +799,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, size_t used = dbg_parse_uint(spec, &v); if (!used || spec[used] != '\0') { dbg_errf(s, "trailing junk in address '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); return 1; } *kind_out = BP_ADDR; @@ -814,7 +818,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, if (name_n == 0) { dbg_errf(s, "empty symbol in '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); return 1; } name = dbg_dup(s->env, spec, name_n, &name_size); @@ -825,7 +829,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, resolved = kit_jit_lookup(s->jit, kit_slice_cstr(name)); if (!resolved) { dbg_errf(s, "symbol not found: %.*s", - KIT_SLICE_ARG(kit_slice_cstr(name))); + KIT_SLICE_ARG(kit_slice_cstr(name))); driver_free(s->env, name, name_size); return 1; } @@ -835,7 +839,7 @@ static int dbg_resolve_loc(DbgState* s, const char* spec, BpKind* kind_out, size_t used = dbg_parse_uint(plus + 1, &off); if (!used || plus[1 + used] != '\0') { dbg_errf(s, "bad offset in '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); return 1; } } @@ -1013,7 +1017,7 @@ static int dbg_drive(DbgState* s, DbgRunMode mode) { s->entry_addr = kit_jit_lookup(s->jit, kit_slice_cstr(s->entry_name)); if (!s->entry_addr) { dbg_errf(s, "entry symbol not found: %.*s", - KIT_SLICE_ARG(kit_slice_cstr(s->entry_name))); + KIT_SLICE_ARG(kit_slice_cstr(s->entry_name))); return 1; } } @@ -1472,8 +1476,7 @@ static void dbg_cmd_print(DbgState* s, const char* name) { dbg_translate_loc(s, &loc); if (dbg_read_value(s, &loc, &s->last_stop.regs, stack_buf, sizeof(stack_buf), &buf, &alloc, &got) != 0) { - dbg_errf(s, "could not read %.*s", - KIT_SLICE_ARG(kit_slice_cstr(name))); + dbg_errf(s, "could not read %.*s", KIT_SLICE_ARG(kit_slice_cstr(name))); return; } driver_printf("%.*s = ", KIT_SLICE_ARG(kit_slice_cstr(name))); @@ -1499,7 +1502,7 @@ static void dbg_cmd_print(DbgState* s, const char* name) { } } dbg_errf(s, "no variable or symbol named '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(name))); + KIT_SLICE_ARG(kit_slice_cstr(name))); } } @@ -1529,7 +1532,7 @@ static void dbg_cmd_set(DbgState* s, const char* name, uint64_t value) { : KIT_NOT_FOUND; if (rc != KIT_OK) { dbg_errf(s, "no variable named '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(name))); + KIT_SLICE_ARG(kit_slice_cstr(name))); return; } } @@ -1556,8 +1559,7 @@ static void dbg_cmd_set(DbgState* s, const char* name, uint64_t value) { case KIT_DLOC_REG: { KitUnwindFrame fr = s->last_stop.regs; if (loc.v.reg >= 32) { - dbg_errf(s, "register %u outside the snapshot range", - loc.v.reg); + dbg_errf(s, "register %u outside the snapshot range", loc.v.reg); return; } fr.regs[loc.v.reg] = value; @@ -1570,7 +1572,7 @@ static void dbg_cmd_set(DbgState* s, const char* name, uint64_t value) { } case KIT_DLOC_EXPR: dbg_errf(s, "cannot set '%.*s': location is a DWARF expression", - KIT_SLICE_ARG(kit_slice_cstr(name))); + KIT_SLICE_ARG(kit_slice_cstr(name))); return; } } @@ -1591,7 +1593,7 @@ static void dbg_cmd_jump(DbgState* s, uint64_t pc) { fr.pc = pc; if (kit_jit_session_set_regs(s->session, &fr) != 0) { dbg_errf(s, "jump failed (pc 0x%llx outside image?)", - (unsigned long long)pc); + (unsigned long long)pc); return; } s->last_stop.regs = fr; @@ -1613,7 +1615,7 @@ static void dbg_cmd_info_vars(DbgState* s, uint32_t mask, const char* label) { } if (!s->dwarf) { dbg_errf(s, "no DWARF: %.*s unavailable", - KIT_SLICE_ARG(kit_slice_cstr(label))); + KIT_SLICE_ARG(kit_slice_cstr(label))); return; } @@ -1927,9 +1929,8 @@ static const char* dbg_jit_default_name(KitCompiler* c, KitLanguage lang, static int dbg_jit_uses_default_name(KitCompiler* c, KitLanguage lang, const char* input_name) { char def[DBG_JIT_NAME_CAP]; - return !input_name || - driver_streq(input_name, - dbg_jit_default_name(c, lang, def, sizeof def)); + return !input_name || driver_streq(input_name, dbg_jit_default_name( + c, lang, def, sizeof def)); } static int dbg_make_repl_source_name(KitCompiler* c, KitLanguage lang, @@ -2090,9 +2091,8 @@ static int dbg_jit_compile_append_ex(DbgState* s, KitLanguage lang, * earlier toplevel source on later compiles (toy today), per the * frontend's static capability rather than a hard-coded language. */ KitFrontendCaps caps = {0}; - int cache_source = - kit_frontend_caps(s->compiler, lang, &caps) == KIT_OK && - caps.cache_repl_toplevel_source; + int cache_source = kit_frontend_caps(s->compiler, lang, &caps) == KIT_OK && + caps.cache_repl_toplevel_source; if (cache_source && input_kind == KIT_FRONTEND_INPUT_REPL_TOPLEVEL && dbg_source_cache_put(s, sin.name, src, len) != 0) { dbg_errf(s, "out of memory caching source for list"); @@ -2223,10 +2223,10 @@ static void dbg_cmd_edit(DbgState* s, const char* rest) { dbg_errf(s, "usage: edit [c|toy|asm|name.ext]"); return; } - if (!driver_edit_temp(s->env, - dbg_jit_language_suffix(s->compiler, lang, suffix, - sizeof suffix), - NULL, 0, &src, &len)) { + if (!driver_edit_temp( + s->env, + dbg_jit_language_suffix(s->compiler, lang, suffix, sizeof suffix), + NULL, 0, &src, &len)) { dbg_errf(s, "editor failed"); return; } @@ -2272,17 +2272,19 @@ static void dbg_cmd_language(DbgState* s, const char* rest) { } driver_memcpy(tmp, p, n); tmp[n] = '\0'; - /* `:language` only needs the resolved language; the display name is recomputed - * below from dbg_jit_default_name, so no name buffer is requested. */ + /* `:language` only needs the resolved language; the display name is + * recomputed below from dbg_jit_default_name, so no name buffer is requested. + */ lang = dbg_jit_language_for_tag(s, tmp, NULL, 0, NULL); if (lang == KIT_LANG_COUNT) { dbg_errf(s, "unsupported language: %.*s", - KIT_SLICE_ARG(kit_slice_cstr(tmp))); + KIT_SLICE_ARG(kit_slice_cstr(tmp))); return; } s->default_jit_lang = lang; - s->default_jit_name = dbg_jit_default_name( - s->compiler, lang, s->default_jit_name_buf, sizeof s->default_jit_name_buf); + s->default_jit_name = + dbg_jit_default_name(s->compiler, lang, s->default_jit_name_buf, + sizeof s->default_jit_name_buf); driver_printf( "Language: %.*s\n", KIT_SLICE_ARG(kit_slice_cstr(dbg_jit_language_name(s->compiler, lang)))); @@ -2432,7 +2434,7 @@ static void dbg_cmd_expr(DbgState* s, const char* expr) { entry = kit_jit_lookup(s->jit, kit_slice_cstr(name)); if (!entry) { dbg_errf(s, "expression thunk not found: %.*s", - KIT_SLICE_ARG(kit_slice_cstr(name))); + KIT_SLICE_ARG(kit_slice_cstr(name))); goto out; } if (dbg_call_u64_entry(s, entry, NULL, 0, &ret) == 0) { @@ -2645,7 +2647,7 @@ static void dbg_cmd_list(DbgState* s, const char* spec) { if (!s->dwarf) { dbg_errf(s, "no DWARF: cannot resolve %.*s", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); return; } @@ -2656,8 +2658,7 @@ static void dbg_cmd_list(DbgState* s, const char* spec) { } flen = (size_t)(colon - spec); if (flen == 0 || flen >= sizeof(path)) { - dbg_errf(s, "bad file in '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + dbg_errf(s, "bad file in '%.*s'", KIT_SLICE_ARG(kit_slice_cstr(spec))); return; } driver_memcpy(path, spec, flen); @@ -2674,19 +2675,19 @@ static void dbg_cmd_list(DbgState* s, const char* spec) { (uint32_t)line_u, &pc); if (st == KIT_NOT_FOUND) { dbg_errf(s, "no line %u in %.*s", (uint32_t)line_u, - KIT_SLICE_ARG(kit_slice_cstr(path))); + KIT_SLICE_ARG(kit_slice_cstr(path))); return; } if (st == KIT_AMBIGUOUS) { dbg_errf(s, - "ambiguous: %.*s:%u matches multiple files; " - "use a longer path suffix", - KIT_SLICE_ARG(kit_slice_cstr(path)), (uint32_t)line_u); + "ambiguous: %.*s:%u matches multiple files; " + "use a longer path suffix", + KIT_SLICE_ARG(kit_slice_cstr(path)), (uint32_t)line_u); return; } if (st != KIT_OK) { dbg_errf(s, "no line entry for %.*s", - KIT_SLICE_ARG(kit_slice_cstr(spec))); + KIT_SLICE_ARG(kit_slice_cstr(spec))); return; } } @@ -2748,8 +2749,7 @@ static void dbg_cmd_break(DbgState* s, const char* spec) { } if (dbg_bp_arm(s, b) != 0) { - dbg_errf(s, "failed to arm breakpoint at 0x%llx", - (unsigned long long)addr); + dbg_errf(s, "failed to arm breakpoint at 0x%llx", (unsigned long long)addr); b->session_id = 0; b->enabled = 0; } @@ -3024,7 +3024,7 @@ static int dbg_dispatch(DbgState* s, char* line) { dbg_cmd_info_syms(s, KIT_SK_OBJ, *pat ? pat : NULL); } else { dbg_errf(s, "unknown 'info' subcommand: %.*s", - KIT_SLICE_ARG(kit_slice_cstr(what))); + KIT_SLICE_ARG(kit_slice_cstr(what))); } return 0; } @@ -3054,7 +3054,7 @@ static int dbg_dispatch(DbgState* s, char* line) { used = dbg_parse_uint(val_s, &v); if (!used || val_s[used] != '\0') { dbg_errf(s, "expected integer value, got '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(val_s))); + KIT_SLICE_ARG(kit_slice_cstr(val_s))); return 0; } dbg_cmd_set(s, name, v); @@ -3071,8 +3071,7 @@ static int dbg_dispatch(DbgState* s, char* line) { } used = dbg_parse_uint(addr_s, &addr); if (!used || addr_s[used] != '\0') { - dbg_errf(s, "bad address '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(addr_s))); + dbg_errf(s, "bad address '%.*s'", KIT_SLICE_ARG(kit_slice_cstr(addr_s))); return 0; } dbg_cmd_jump(s, addr); @@ -3164,7 +3163,7 @@ static int dbg_dispatch(DbgState* s, char* line) { used = dbg_parse_uint(addr_s, &addr); if (!used || addr_s[used] != '\0') { dbg_errf(s, "bad address '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(addr_s))); + KIT_SLICE_ARG(kit_slice_cstr(addr_s))); return 0; } dbg_take_word(rest, &count_s); @@ -3172,7 +3171,7 @@ static int dbg_dispatch(DbgState* s, char* line) { used = dbg_parse_uint(count_s, &count); if (!used || count_s[used] != '\0') { dbg_errf(s, "bad count '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(count_s))); + KIT_SLICE_ARG(kit_slice_cstr(count_s))); return 0; } } @@ -3193,16 +3192,14 @@ static int dbg_dispatch(DbgState* s, char* line) { } used = dbg_parse_uint(addr_s, &addr); if (!used || addr_s[used] != '\0') { - dbg_errf(s, "bad address '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(addr_s))); + dbg_errf(s, "bad address '%.*s'", KIT_SLICE_ARG(kit_slice_cstr(addr_s))); return 0; } dbg_take_word(rest, &count_s); if (*count_s) { used = dbg_parse_uint(count_s, &count); if (!used || count_s[used] != '\0') { - dbg_errf(s, "bad count '%.*s'", - KIT_SLICE_ARG(kit_slice_cstr(count_s))); + dbg_errf(s, "bad count '%.*s'", KIT_SLICE_ARG(kit_slice_cstr(count_s))); return 0; } } @@ -3219,7 +3216,7 @@ static int dbg_dispatch(DbgState* s, char* line) { dbg_cmd_expr(s, raw); } else { dbg_errf(s, "unknown command: %.*s (try 'h')", - KIT_SLICE_ARG(kit_slice_cstr(cmd))); + KIT_SLICE_ARG(kit_slice_cstr(cmd))); } return 0; } @@ -3538,9 +3535,8 @@ static void dbg_repl(DbgState* s) { /* Phase 1: drain --script / --command sources in order. */ for (i = 0; i < s->nscript_entries; i++) { DbgScriptEntry* e = &s->script_entries[i]; - int quit = (e->kind == DBG_ENTRY_FILE) - ? dbg_run_script_file(s, e->value) - : dbg_run_script_cmd(s, e->value); + int quit = (e->kind == DBG_ENTRY_FILE) ? dbg_run_script_file(s, e->value) + : dbg_run_script_cmd(s, e->value); if (quit) return; } @@ -3630,9 +3626,9 @@ int driver_dbg(int argc, char** argv) { dbg_fill_compile_options(&o, &st.copts, &st.pp); st.jit = jit; st.default_jit_lang = dbg_default_language_from_inputs(compiler, &o); - st.default_jit_name = dbg_jit_default_name( - st.compiler, st.default_jit_lang, st.default_jit_name_buf, - sizeof st.default_jit_name_buf); + st.default_jit_name = dbg_jit_default_name(st.compiler, st.default_jit_lang, + st.default_jit_name_buf, + sizeof st.default_jit_name_buf); st.prog_argc = (int)o.prog_argc; st.prog_argv = o.prog_argv; st.entry_name = o.entry; diff --git a/driver/cmd/ld.c b/driver/cmd/ld.c @@ -122,12 +122,12 @@ typedef struct LdOptions { uint32_t nrpaths; const char** rpath_links; /* -rpath-link DIR (advisory) */ uint32_t nrpath_links; - int new_dtags; /* 1=DT_RUNPATH (default), 0=DT_RPATH */ - int export_dynamic; /* -E / --export-dynamic */ - int gc_sections; /* --gc-sections / --no-gc-sections */ - int strip_debug; /* -S / --strip-debug */ - int allow_undefined; /* shared output undefined-symbol policy */ - int static_link; /* -static: hosted libc should pick static profile */ + int new_dtags; /* 1=DT_RUNPATH (default), 0=DT_RPATH */ + int export_dynamic; /* -E / --export-dynamic */ + int gc_sections; /* --gc-sections / --no-gc-sections */ + int strip_debug; /* -S / --strip-debug */ + int allow_undefined; /* shared output undefined-symbol policy */ + int static_link; /* -static: hosted libc should pick static profile */ int wants_hosted_libc; /* -lc: expand crt + libc through hosted resolver */ DriverHostedPlan hosted; @@ -828,8 +828,9 @@ static int ld_parse(int argc, char** argv, LdOptions* o) { } /* -Ttext ADDR / -Ttext=ADDR: set the static ET_EXEC image (text) base, for * freestanding images that must load at a fixed address (e.g. the qemu - * `virt` RAM base 0x80000000). Matched here; the bare "-T" above is an exact - * match, so it never swallows -Ttext. No effect on PIE/scripted layouts. */ + * `virt` RAM base 0x80000000). Matched here; the bare "-T" above is an + * exact match, so it never swallows -Ttext. No effect on PIE/scripted + * layouts. */ { const char* tval = NULL; if (driver_streq(a, "-Ttext")) { @@ -1470,14 +1471,14 @@ static int ld_run_link(LdOptions* o) { /* Auto-detect target from the object inputs, falling back to the host target. * The PIC default is a property of the *target*, not the host: hosted targets - * default to PIE, freestanding ones to no-PIE (driver_default_pic). The host's - * default PIC must never leak onto a detected cross target; only an EXPLICIT - * -static/-pie/-no-pie/-shared wins. + * default to PIE, freestanding ones to no-PIE (driver_default_pic). The + * host's default PIC must never leak onto a detected cross target; only an + * EXPLICIT -static/-pie/-no-pie/-shared wins. * * Detection takes the arch from the first object, but the OS from any object: - * a freestanding (`*-none-elf`, EI_OSABI=STANDALONE) object means a freestanding - * link even if a foreign object (e.g. a clang-assembled startup stub, which - * stamps EI_OSABI=SysV and so decodes as Linux) appears first. */ + * a freestanding (`*-none-elf`, EI_OSABI=STANDALONE) object means a + * freestanding link even if a foreign object (e.g. a clang-assembled startup + * stub, which stamps EI_OSABI=SysV and so decodes as Linux) appears first. */ if (initial_nobject_files > 0) { KitTargetSpec detected; if (kit_detect_target(obj_lf[0].data.data, obj_lf[0].data.size, @@ -1525,8 +1526,7 @@ static int ld_run_link(LdOptions* o) { "or -static for a static link"); goto out; } - if (!o->pic_explicit) - o->pie = 1; + if (!o->pic_explicit) o->pie = 1; } /* Auto-link kit's compiler runtime for any target that has a variant — @@ -1534,7 +1534,8 @@ static int ld_run_link(LdOptions* o) { * whose runtime (and, for rv32, the float-ABI it was detected with) is * resolved like every other target's. A target with no variant is implicitly * -nostdlib and supplies its own libkit_rt.a on the command line, so skip - * resolution rather than erroring. -nostdlib forces the skip for any target. */ + * resolution rather than erroring. -nostdlib forces the skip for any target. + */ if (!o->relocatable && !o->no_default_libs && driver_runtime_has_variant(o->target)) { if (driver_runtime_resolve(o->env, o->support_dir, o->driver_path, diff --git a/driver/cmd/objdump.c b/driver/cmd/objdump.c @@ -153,7 +153,6 @@ void driver_help_objdump(void) { static int j_match(const ObjdumpOpts* o, KitSlice name); - /* Names match the IMAGE_DIRECTORY_ENTRY_* index. Keep aligned with the * order in coff.h to avoid drift. */ static const char* pe_dir_name(uint32_t i) { @@ -226,7 +225,6 @@ static const char* pe_subsystem_name(uint16_t s) { } } - /* Render objdump's "file format" spelling: the obj layer's canonical bare * name (elf/coff/macho/wasm) plus the bitwidth suffix this tool presents. * wasm carries no suffix; an out-of-range fmt renders "unknown". The bare @@ -314,13 +312,13 @@ static void dump_pe_private(KitObjFile* f, const char* label) { KIT_SLICE_ARG(kit_slice_cstr(arch_str(target.arch)))); driver_printf(" ImageBase: 0x%llx\n", (unsigned long long)info.image_base); + driver_printf(" AddressOfEntryPoint: 0x%llx\n", + (unsigned long long)(info.entry > info.image_base + ? info.entry - info.image_base + : 0)); driver_printf( - " AddressOfEntryPoint: 0x%llx\n", - (unsigned long long)(info.entry > info.image_base - ? info.entry - info.image_base - : 0)); - driver_printf(" Subsystem: %u (%.*s)\n", (unsigned)raw.subsystem, - KIT_SLICE_ARG(kit_slice_cstr(pe_subsystem_name(raw.subsystem)))); + " Subsystem: %u (%.*s)\n", (unsigned)raw.subsystem, + KIT_SLICE_ARG(kit_slice_cstr(pe_subsystem_name(raw.subsystem)))); driver_printf(" DllCharacteristics: 0x%04x\n", (unsigned)raw.dllchars); driver_printf("\nData Directories:\n"); @@ -832,11 +830,10 @@ static void dump_file_header(KitObjFile* f, const char* label) { have_info ? (unsigned long long)info.entry : 0ull); { char fmt_buf[FMT_STR_CAP]; - driver_printf( - "format: %.*s, sections: %u, symbols: %u\n\n", - KIT_SLICE_ARG(kit_slice_cstr( - fmt_str(fmt, target.ptr_size, fmt_buf, sizeof fmt_buf))), - nsec, nsym); + driver_printf("format: %.*s, sections: %u, symbols: %u\n\n", + KIT_SLICE_ARG(kit_slice_cstr( + fmt_str(fmt, target.ptr_size, fmt_buf, sizeof fmt_buf))), + nsec, nsym); } if (fmt == KIT_OBJ_COFF && kind != KIT_OBJ_KIND_REL) { PeRaw raw; @@ -1328,12 +1325,11 @@ static void dump_obj(const KitContext* ctx, const KitDisasmContext* dctx, KitObjFmt fmt = kit_obj_fmt(f); char fmt_buf[FMT_STR_CAP]; - driver_printf( - "%.*s:\tfile format %.*s-%.*s\n\n", - KIT_SLICE_ARG(kit_slice_cstr(label)), - KIT_SLICE_ARG( - kit_slice_cstr(fmt_str(fmt, target.ptr_size, fmt_buf, sizeof fmt_buf))), - KIT_SLICE_ARG(kit_slice_cstr(arch_str(target.arch)))); + driver_printf("%.*s:\tfile format %.*s-%.*s\n\n", + KIT_SLICE_ARG(kit_slice_cstr(label)), + KIT_SLICE_ARG(kit_slice_cstr( + fmt_str(fmt, target.ptr_size, fmt_buf, sizeof fmt_buf))), + KIT_SLICE_ARG(kit_slice_cstr(arch_str(target.arch)))); if (opts->f) dump_file_header(f, label); if (opts->h) dump_sections(f, opts); diff --git a/driver/env/posix.c b/driver/env/posix.c @@ -278,9 +278,7 @@ KitWriter* driver_stderr_writer(DriverEnv* e) { return driver_stdio_writer(e, stderr); } -const char* const* driver_environ(void) { - return (const char* const*)environ; -} +const char* const* driver_environ(void) { return (const char* const*)environ; } /* ---------------- file_io (POSIX open/read/write/stat) ---------------- */ @@ -363,11 +361,11 @@ int driver_path_mtime_ns(const char* path, int64_t* out) { } static uint8_t posix_mode_to_wasm_filetype(mode_t m) { - if (S_ISREG(m)) return 4; - if (S_ISDIR(m)) return 3; - if (S_ISLNK(m)) return 7; - if (S_ISBLK(m)) return 1; - if (S_ISCHR(m)) return 2; + if (S_ISREG(m)) return 4; + if (S_ISDIR(m)) return 3; + if (S_ISLNK(m)) return 7; + if (S_ISBLK(m)) return 1; + if (S_ISCHR(m)) return 2; if (S_ISSOCK(m)) return 6; return 0; } @@ -385,20 +383,20 @@ int driver_path_stat(const char* path, uint64_t* out_size, } typedef struct DriverDirEntryRec { - char* name; - size_t name_alloc; + char* name; + size_t name_alloc; uint32_t name_len; uint64_t ino; uint64_t size; uint64_t mtime_ns; - uint8_t filetype; + uint8_t filetype; } DriverDirEntryRec; struct DriverDirHandle { - DriverEnv* env; + DriverEnv* env; DriverDirEntryRec* entries; - size_t entries_alloc; - uint64_t count; + size_t entries_alloc; + uint64_t count; }; DriverDirHandle* driver_open_dir(DriverEnv* env, const char* path) { @@ -418,7 +416,10 @@ DriverDirHandle* driver_open_dir(DriverEnv* env, const char* path) { h = (DriverDirHandle*)env->heap->alloc(env->heap, sizeof(*h), _Alignof(DriverDirHandle)); - if (!h) { closedir(d); return NULL; } + if (!h) { + closedir(d); + return NULL; + } memset(h, 0, sizeof(*h)); h->env = env; @@ -464,7 +465,8 @@ DriverDirHandle* driver_open_dir(DriverEnv* env, const char* path) { child = (char*)driver_alloc(env, child_alloc); if (child) { size_t off = 0; - memcpy(child, path, plen); off += plen; + memcpy(child, path, plen); + off += plen; if (slash) child[off++] = '/'; memcpy(child + off, name, name_len); child[off + name_len] = '\0'; @@ -496,10 +498,10 @@ int driver_read_dir_entry(DriverDirHandle* h, uint64_t index, DriverDirEntryRec* e; if (!h || index >= h->count) return 1; e = &h->entries[index]; - *out_name = e->name; + *out_name = e->name; *out_name_len = e->name_len; - *out_ino = e->ino; - *out_size = e->size; + *out_ino = e->ino; + *out_size = e->size; *out_mtime_ns = e->mtime_ns; *out_filetype = e->filetype; return 0; diff --git a/driver/env/uctx_rv64_freebsd.c b/driver/env/uctx_rv64_freebsd.c @@ -13,48 +13,48 @@ void dbg_ucontext_to_frame(const ucontext_t* uc, KitUnwindFrame* f) { const struct gpregs* gp = &uc->uc_mcontext.mc_gpregs; - f->regs[0] = 0; /* x0 is always zero */ - f->regs[1] = (uint64_t)gp->gp_ra; - f->regs[2] = (uint64_t)gp->gp_sp; - f->regs[3] = (uint64_t)gp->gp_gp; - f->regs[4] = (uint64_t)gp->gp_tp; - f->regs[5] = (uint64_t)gp->gp_t[0]; /* t0 */ - f->regs[6] = (uint64_t)gp->gp_t[1]; /* t1 */ - f->regs[7] = (uint64_t)gp->gp_t[2]; /* t2 */ - f->regs[8] = (uint64_t)gp->gp_s[0]; /* s0/fp */ - f->regs[9] = (uint64_t)gp->gp_s[1]; /* s1 */ - f->regs[10] = (uint64_t)gp->gp_a[0]; /* a0 */ - f->regs[11] = (uint64_t)gp->gp_a[1]; /* a1 */ - f->regs[12] = (uint64_t)gp->gp_a[2]; /* a2 */ - f->regs[13] = (uint64_t)gp->gp_a[3]; /* a3 */ - f->regs[14] = (uint64_t)gp->gp_a[4]; /* a4 */ - f->regs[15] = (uint64_t)gp->gp_a[5]; /* a5 */ - f->regs[16] = (uint64_t)gp->gp_a[6]; /* a6 */ - f->regs[17] = (uint64_t)gp->gp_a[7]; /* a7 */ - f->regs[18] = (uint64_t)gp->gp_s[2]; /* s2 */ - f->regs[19] = (uint64_t)gp->gp_s[3]; /* s3 */ - f->regs[20] = (uint64_t)gp->gp_s[4]; /* s4 */ - f->regs[21] = (uint64_t)gp->gp_s[5]; /* s5 */ - f->regs[22] = (uint64_t)gp->gp_s[6]; /* s6 */ - f->regs[23] = (uint64_t)gp->gp_s[7]; /* s7 */ - f->regs[24] = (uint64_t)gp->gp_s[8]; /* s8 */ - f->regs[25] = (uint64_t)gp->gp_s[9]; /* s9 */ + f->regs[0] = 0; /* x0 is always zero */ + f->regs[1] = (uint64_t)gp->gp_ra; + f->regs[2] = (uint64_t)gp->gp_sp; + f->regs[3] = (uint64_t)gp->gp_gp; + f->regs[4] = (uint64_t)gp->gp_tp; + f->regs[5] = (uint64_t)gp->gp_t[0]; /* t0 */ + f->regs[6] = (uint64_t)gp->gp_t[1]; /* t1 */ + f->regs[7] = (uint64_t)gp->gp_t[2]; /* t2 */ + f->regs[8] = (uint64_t)gp->gp_s[0]; /* s0/fp */ + f->regs[9] = (uint64_t)gp->gp_s[1]; /* s1 */ + f->regs[10] = (uint64_t)gp->gp_a[0]; /* a0 */ + f->regs[11] = (uint64_t)gp->gp_a[1]; /* a1 */ + f->regs[12] = (uint64_t)gp->gp_a[2]; /* a2 */ + f->regs[13] = (uint64_t)gp->gp_a[3]; /* a3 */ + f->regs[14] = (uint64_t)gp->gp_a[4]; /* a4 */ + f->regs[15] = (uint64_t)gp->gp_a[5]; /* a5 */ + f->regs[16] = (uint64_t)gp->gp_a[6]; /* a6 */ + f->regs[17] = (uint64_t)gp->gp_a[7]; /* a7 */ + f->regs[18] = (uint64_t)gp->gp_s[2]; /* s2 */ + f->regs[19] = (uint64_t)gp->gp_s[3]; /* s3 */ + f->regs[20] = (uint64_t)gp->gp_s[4]; /* s4 */ + f->regs[21] = (uint64_t)gp->gp_s[5]; /* s5 */ + f->regs[22] = (uint64_t)gp->gp_s[6]; /* s6 */ + f->regs[23] = (uint64_t)gp->gp_s[7]; /* s7 */ + f->regs[24] = (uint64_t)gp->gp_s[8]; /* s8 */ + f->regs[25] = (uint64_t)gp->gp_s[9]; /* s9 */ f->regs[26] = (uint64_t)gp->gp_s[10]; /* s10 */ f->regs[27] = (uint64_t)gp->gp_s[11]; /* s11 */ - f->regs[28] = (uint64_t)gp->gp_t[3]; /* t3 */ - f->regs[29] = (uint64_t)gp->gp_t[4]; /* t4 */ - f->regs[30] = (uint64_t)gp->gp_t[5]; /* t5 */ - f->regs[31] = (uint64_t)gp->gp_t[6]; /* t6 */ - f->pc = (uint64_t)gp->gp_sepc; + f->regs[28] = (uint64_t)gp->gp_t[3]; /* t3 */ + f->regs[29] = (uint64_t)gp->gp_t[4]; /* t4 */ + f->regs[30] = (uint64_t)gp->gp_t[5]; /* t5 */ + f->regs[31] = (uint64_t)gp->gp_t[6]; /* t6 */ + f->pc = (uint64_t)gp->gp_sepc; f->cfa = (uint64_t)gp->gp_s[0]; /* s0/fp; CFI refines */ } void dbg_frame_to_ucontext(const KitUnwindFrame* f, ucontext_t* uc) { struct gpregs* gp = &uc->uc_mcontext.mc_gpregs; - gp->gp_ra = (__register_t)f->regs[1]; - gp->gp_sp = (__register_t)f->regs[2]; - gp->gp_gp = (__register_t)f->regs[3]; - gp->gp_tp = (__register_t)f->regs[4]; + gp->gp_ra = (__register_t)f->regs[1]; + gp->gp_sp = (__register_t)f->regs[2]; + gp->gp_gp = (__register_t)f->regs[3]; + gp->gp_tp = (__register_t)f->regs[4]; gp->gp_t[0] = (__register_t)f->regs[5]; gp->gp_t[1] = (__register_t)f->regs[6]; gp->gp_t[2] = (__register_t)f->regs[7]; @@ -68,14 +68,14 @@ void dbg_frame_to_ucontext(const KitUnwindFrame* f, ucontext_t* uc) { gp->gp_a[5] = (__register_t)f->regs[15]; gp->gp_a[6] = (__register_t)f->regs[16]; gp->gp_a[7] = (__register_t)f->regs[17]; - gp->gp_s[2] = (__register_t)f->regs[18]; - gp->gp_s[3] = (__register_t)f->regs[19]; - gp->gp_s[4] = (__register_t)f->regs[20]; - gp->gp_s[5] = (__register_t)f->regs[21]; - gp->gp_s[6] = (__register_t)f->regs[22]; - gp->gp_s[7] = (__register_t)f->regs[23]; - gp->gp_s[8] = (__register_t)f->regs[24]; - gp->gp_s[9] = (__register_t)f->regs[25]; + gp->gp_s[2] = (__register_t)f->regs[18]; + gp->gp_s[3] = (__register_t)f->regs[19]; + gp->gp_s[4] = (__register_t)f->regs[20]; + gp->gp_s[5] = (__register_t)f->regs[21]; + gp->gp_s[6] = (__register_t)f->regs[22]; + gp->gp_s[7] = (__register_t)f->regs[23]; + gp->gp_s[8] = (__register_t)f->regs[24]; + gp->gp_s[9] = (__register_t)f->regs[25]; gp->gp_s[10] = (__register_t)f->regs[26]; gp->gp_s[11] = (__register_t)f->regs[27]; gp->gp_t[3] = (__register_t)f->regs[28]; diff --git a/driver/env/uctx_x86_64_freebsd.c b/driver/env/uctx_x86_64_freebsd.c @@ -12,16 +12,16 @@ void dbg_ucontext_to_frame(const ucontext_t* uc, KitUnwindFrame* f) { const mcontext_t* mc = &uc->uc_mcontext; memset(f, 0, sizeof(*f)); - f->regs[0] = (uint64_t)mc->mc_rax; - f->regs[1] = (uint64_t)mc->mc_rdx; - f->regs[2] = (uint64_t)mc->mc_rcx; - f->regs[3] = (uint64_t)mc->mc_rbx; - f->regs[4] = (uint64_t)mc->mc_rsi; - f->regs[5] = (uint64_t)mc->mc_rdi; - f->regs[6] = (uint64_t)mc->mc_rbp; - f->regs[7] = (uint64_t)mc->mc_rsp; - f->regs[8] = (uint64_t)mc->mc_r8; - f->regs[9] = (uint64_t)mc->mc_r9; + f->regs[0] = (uint64_t)mc->mc_rax; + f->regs[1] = (uint64_t)mc->mc_rdx; + f->regs[2] = (uint64_t)mc->mc_rcx; + f->regs[3] = (uint64_t)mc->mc_rbx; + f->regs[4] = (uint64_t)mc->mc_rsi; + f->regs[5] = (uint64_t)mc->mc_rdi; + f->regs[6] = (uint64_t)mc->mc_rbp; + f->regs[7] = (uint64_t)mc->mc_rsp; + f->regs[8] = (uint64_t)mc->mc_r8; + f->regs[9] = (uint64_t)mc->mc_r9; f->regs[10] = (uint64_t)mc->mc_r10; f->regs[11] = (uint64_t)mc->mc_r11; f->regs[12] = (uint64_t)mc->mc_r12; @@ -29,7 +29,7 @@ void dbg_ucontext_to_frame(const ucontext_t* uc, KitUnwindFrame* f) { f->regs[14] = (uint64_t)mc->mc_r14; f->regs[15] = (uint64_t)mc->mc_r15; f->regs[16] = (uint64_t)mc->mc_rip; - f->pc = (uint64_t)mc->mc_rip; + f->pc = (uint64_t)mc->mc_rip; f->cfa = (uint64_t)mc->mc_rsp; } @@ -43,8 +43,8 @@ void dbg_frame_to_ucontext(const KitUnwindFrame* f, ucontext_t* uc) { mc->mc_rdi = (__register_t)f->regs[5]; mc->mc_rbp = (__register_t)f->regs[6]; mc->mc_rsp = (__register_t)f->regs[7]; - mc->mc_r8 = (__register_t)f->regs[8]; - mc->mc_r9 = (__register_t)f->regs[9]; + mc->mc_r8 = (__register_t)f->regs[8]; + mc->mc_r9 = (__register_t)f->regs[9]; mc->mc_r10 = (__register_t)f->regs[10]; mc->mc_r11 = (__register_t)f->regs[11]; mc->mc_r12 = (__register_t)f->regs[12]; diff --git a/driver/lib/hosted.c b/driver/lib/hosted.c @@ -163,19 +163,19 @@ static int hosted_add_linux_defines(DriverHostedPlan* plan, int gnu) { static const char* freebsd_version_str(uint8_t major) { /* Static strings indexed by major version; 0 = unspecified → "15". */ - static const char* const tab[21] = { - "15", - "1","2","3","4","5","6","7","8","9","10", - "11","12","13","14","15","16","17","18","19","20" - }; + static const char* const tab[21] = {"15", "1", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "11", "12", "13", + "14", "15", "16", "17", "18", "19", "20"}; return (major < 21) ? tab[major] : "15"; } -static int hosted_add_freebsd_defines(DriverHostedPlan* plan, uint8_t version_major) { +static int hosted_add_freebsd_defines(DriverHostedPlan* plan, + uint8_t version_major) { /* __FreeBSD__ must be present and version-encoded or the base headers fail to * compile. The version is derived from the triple; 0 falls back to 15. */ if (hosted_add_clang_compat_defines(plan) != 0 || - hosted_add_define(plan, "__FreeBSD__", freebsd_version_str(version_major)) != 0 || + hosted_add_define(plan, "__FreeBSD__", + freebsd_version_str(version_major)) != 0 || hosted_add_define(plan, "__ELF__", "1") != 0 || hosted_add_define(plan, "__unix__", "1") != 0 || hosted_add_define(plan, "__unix", "1") != 0 || @@ -525,7 +525,8 @@ static int hosted_resolve_windows_mingw(const DriverHostedRequest* req, * archives are scanned in order with lazy member pulls, one pass leaves * late-discovered undefs unresolved; re-listing the core set lets the * linker pull the members the first pass missed. This is NOT a verbatim - * duplicate of the list above (the system import libs are not repeated). */ + * duplicate of the list above (the system import libs are not repeated). + */ hosted_add_required_search( plan->after, &plan->nafter, DRIVER_HOSTED_MAX_AFTER, req, dirs, "libmingw32.a", DRIVER_HOSTED_INPUT_ARCHIVE) != 0 || @@ -674,7 +675,8 @@ static int hosted_dirs_from_sysroot(DriverHostedDirs* dirs, const HostedProfile* profile = hosted_profile_for_os(target.os); dirs->root = sysroot; /* a single explicit sysroot; -print-sysroot reports it */ - if (!profile) return 0; /* unsupported target; the dispatcher emits the error */ + if (!profile) + return 0; /* unsupported target; the dispatcher emits the error */ return profile->sysroot_layout(dirs, target, sysroot); } @@ -735,8 +737,8 @@ int driver_hosted_resolve(const DriverHostedRequest* req, /* Transfer libdir ownership from dirs into the plan so callers can add * them to their lib search path for user-specified -l resolution. */ uint32_t j; - for (j = 0; j < dirs.nlibdirs && - j < DRIVER_HOSTED_MAX_LIB_SEARCH_DIRS; ++j) { + for (j = 0; j < dirs.nlibdirs && j < DRIVER_HOSTED_MAX_LIB_SEARCH_DIRS; + ++j) { out->lib_search_dirs[j] = dirs.libdirs[j]; out->lib_search_dir_sizes[j] = dirs.libdir_sizes[j]; dirs.libdirs[j] = NULL; @@ -771,8 +773,7 @@ void driver_hosted_plan_fini(DriverEnv* env, DriverHostedPlan* plan) { } for (i = 0; i < plan->nlib_search_dirs; ++i) { if (plan->lib_search_dirs[i]) - driver_free(env, plan->lib_search_dirs[i], - plan->lib_search_dir_sizes[i]); + driver_free(env, plan->lib_search_dirs[i], plan->lib_search_dir_sizes[i]); } memset(plan, 0, sizeof(*plan)); } diff --git a/driver/lib/inputs.c b/driver/lib/inputs.c @@ -109,14 +109,11 @@ const char* driver_inputs_first_name(const DriverInputs* in) { /* Load every input through env.file_io, compile sources via `compiler` with * `copts`, and JIT-link. The compiler must outlive the JIT — it backs * jit->c, which kit_jit_lookup dereferences. */ -int driver_inputs_compile_and_jit(DriverInputs* in, KitCompiler* compiler, - const KitJitHost* host, - const KitCCompileOptions* copts, - const KitPreprocessOptions* pp, - const char* entry, - void* (*extern_resolver)(void*, KitSlice), - void* extern_resolver_user, - KitJit** out_jit) { +int driver_inputs_compile_and_jit( + DriverInputs* in, KitCompiler* compiler, const KitJitHost* host, + const KitCCompileOptions* copts, const KitPreprocessOptions* pp, + const char* entry, void* (*extern_resolver)(void*, KitSlice), + void* extern_resolver_user, KitJit** out_jit) { DriverEnv* env = in->env; const char* tool = in->tool; KitContext ctx = driver_env_to_context(env); diff --git a/driver/lib/link_flags.c b/driver/lib/link_flags.c @@ -17,8 +17,8 @@ static int lf_grow_rpaths(DriverLinkFlags* lf) { uint32_t new_cap = old_cap ? old_cap * 2u : 8u; const char** nr; if (new_cap <= old_cap) return 1; - nr = (const char**)driver_alloc_zeroed(lf->env, - (size_t)new_cap * sizeof(*nr)); + nr = + (const char**)driver_alloc_zeroed(lf->env, (size_t)new_cap * sizeof(*nr)); if (!nr) return 1; if (lf->rpaths) { driver_memcpy(nr, lf->rpaths, (size_t)lf->nrpaths * sizeof(*lf->rpaths)); @@ -50,8 +50,7 @@ static int lf_grow_owned(DriverLinkFlags* lf) { } if (lf->owned_string_sizes) { driver_memcpy(nsz, lf->owned_string_sizes, - (size_t)lf->nowned_strings * - sizeof(*lf->owned_string_sizes)); + (size_t)lf->nowned_strings * sizeof(*lf->owned_string_sizes)); driver_free(lf->env, lf->owned_string_sizes, (size_t)old_cap * sizeof(*lf->owned_string_sizes)); } @@ -215,8 +214,8 @@ int driver_link_flags_init(DriverLinkFlags* lf, DriverEnv* env, lf->cap_owned_strings = cap; lf->rpaths = (const char**)driver_alloc_zeroed(env, (size_t)cap * sizeof(*lf->rpaths)); - lf->owned_strings = - (char**)driver_alloc_zeroed(env, (size_t)cap * sizeof(*lf->owned_strings)); + lf->owned_strings = (char**)driver_alloc_zeroed( + env, (size_t)cap * sizeof(*lf->owned_strings)); lf->owned_string_sizes = (size_t*)driver_alloc_zeroed( env, (size_t)cap * sizeof(*lf->owned_string_sizes)); if (!lf->rpaths || !lf->owned_strings || !lf->owned_string_sizes) { @@ -241,9 +240,9 @@ void driver_link_flags_fini(DriverLinkFlags* lf) { driver_free(lf->env, lf->owned_strings, (size_t)lf->cap_owned_strings * sizeof(*lf->owned_strings)); if (lf->owned_string_sizes) - driver_free(lf->env, lf->owned_string_sizes, - (size_t)lf->cap_owned_strings * - sizeof(*lf->owned_string_sizes)); + driver_free( + lf->env, lf->owned_string_sizes, + (size_t)lf->cap_owned_strings * sizeof(*lf->owned_string_sizes)); memset(lf, 0, sizeof(*lf)); } @@ -251,15 +250,13 @@ int driver_link_flags_record_build_id(DriverLinkFlags* lf, const char* val) { return lf_record_build_id_span(lf, val, driver_strlen(val)); } -int driver_link_flags_record_pe_subsystem(DriverLinkFlags* lf, - const char* val, size_t n) { - if (lf_subsystem_eq(val, n, "CONSOLE") || - lf_subsystem_eq(val, n, "CUI")) { +int driver_link_flags_record_pe_subsystem(DriverLinkFlags* lf, const char* val, + size_t n) { + if (lf_subsystem_eq(val, n, "CONSOLE") || lf_subsystem_eq(val, n, "CUI")) { lf->pe_subsystem = KIT_PE_SUBSYSTEM_WINDOWS_CUI; return 0; } - if (lf_subsystem_eq(val, n, "WINDOWS") || - lf_subsystem_eq(val, n, "GUI")) { + if (lf_subsystem_eq(val, n, "WINDOWS") || lf_subsystem_eq(val, n, "GUI")) { lf->pe_subsystem = KIT_PE_SUBSYSTEM_WINDOWS_GUI; return 0; } @@ -401,8 +398,7 @@ int driver_link_flags_fill_options(const DriverLinkFlags* lf, lopts->build_id_len = lf->build_id_len; lopts->gc_sections = lf->gc_sections != 0; lopts->strip_debug = lf->strip_debug != 0; - lopts->pie = - driver_link_pie(target, explicit_pie, shared, relocatable) != 0; + lopts->pie = driver_link_pie(target, explicit_pie, shared, relocatable) != 0; lopts->pe_subsystem = lf->pe_subsystem; lopts->interp_path = kit_slice_cstr(lf->interp_path); lopts->soname = kit_slice_cstr(lf->soname); diff --git a/driver/lib/link_flags.h b/driver/lib/link_flags.h @@ -40,8 +40,8 @@ void driver_link_flags_fini(DriverLinkFlags* lf); int driver_link_flags_record_wl(DriverLinkFlags* lf, const char* arg); int driver_link_flags_record_build_id(DriverLinkFlags* lf, const char* val); -int driver_link_flags_record_pe_subsystem(DriverLinkFlags* lf, - const char* val, size_t n); +int driver_link_flags_record_pe_subsystem(DriverLinkFlags* lf, const char* val, + size_t n); int driver_link_flags_fill_options(const DriverLinkFlags* lf, KitTargetSpec target, int explicit_pie, diff --git a/driver/lib/runtime.c b/driver/lib/runtime.c @@ -34,15 +34,23 @@ typedef struct RuntimeVariant { } RuntimeVariant; static const char* const kRtSrcX64[] = { - "assert/assert.c", "int/int.c", - "int/si_div.c", "fp/fp.c", - "mem/mem.c", "string/string.c", - "ctype/ctype.c", "stdlib/stdlib.c", - "stdlib/qsort.c", "stdio/printf.c", + "assert/assert.c", + "int/int.c", + "int/si_div.c", + "fp/fp.c", + "mem/mem.c", + "string/string.c", + "ctype/ctype.c", + "stdlib/stdlib.c", + "stdlib/qsort.c", + "stdio/printf.c", "atomic/atomic_freestanding.c", - "cache/clear_cache.c", "kit/ifunc_init.c", - "int64/int64.c", "coro/x86_64.c", - "coro/coro.c", "stack/backtrace.c", + "cache/clear_cache.c", + "kit/ifunc_init.c", + "int64/int64.c", + "coro/x86_64.c", + "coro/coro.c", + "stack/backtrace.c", "stack/print_backtrace.c", }; @@ -60,30 +68,49 @@ static const char* const kRtSrcX64Windows[] = { }; static const char* const kRtSrcAarch64Elf[] = { - "assert/assert.c", "int/int.c", - "int/si_div.c", "fp/fp.c", - "mem/mem.c", "string/string.c", - "ctype/ctype.c", "stdlib/stdlib.c", - "stdlib/qsort.c", "stdio/printf.c", + "assert/assert.c", + "int/int.c", + "int/si_div.c", + "fp/fp.c", + "mem/mem.c", + "string/string.c", + "ctype/ctype.c", + "stdlib/stdlib.c", + "stdlib/qsort.c", + "stdio/printf.c", "atomic/atomic_freestanding.c", - "cache/clear_cache.c", "kit/ifunc_init.c", - "int64/int64.c", "coro/aarch64.c", - "coro/coro.c", "fp_tf/fp_tf.c", - "fp_ti/fp_ti.c", "coro/aarch64_elf.s", - "stack/backtrace.c", "stack/print_backtrace.c", + "cache/clear_cache.c", + "kit/ifunc_init.c", + "int64/int64.c", + "coro/aarch64.c", + "coro/coro.c", + "fp_tf/fp_tf.c", + "fp_ti/fp_ti.c", + "coro/aarch64_elf.s", + "stack/backtrace.c", + "stack/print_backtrace.c", }; static const char* const kRtSrcAarch64Darwin[] = { - "assert/assert.c", "int/int.c", - "int/si_div.c", "fp/fp.c", - "mem/mem.c", "string/string.c", - "ctype/ctype.c", "stdlib/stdlib.c", - "stdlib/qsort.c", "stdio/printf.c", + "assert/assert.c", + "int/int.c", + "int/si_div.c", + "fp/fp.c", + "mem/mem.c", + "string/string.c", + "ctype/ctype.c", + "stdlib/stdlib.c", + "stdlib/qsort.c", + "stdio/printf.c", "atomic/atomic_freestanding.c", - "cache/clear_cache.c", "kit/ifunc_init.c", - "int64/int64.c", "coro/aarch64.c", - "coro/coro.c", "coro/aarch64_macho.s", - "stack/backtrace.c", "stack/print_backtrace.c", + "cache/clear_cache.c", + "kit/ifunc_init.c", + "int64/int64.c", + "coro/aarch64.c", + "coro/coro.c", + "coro/aarch64_macho.s", + "stack/backtrace.c", + "stack/print_backtrace.c", }; static const char* const kRtSrcAarch64Windows[] = { @@ -99,16 +126,25 @@ static const char* const kRtSrcAarch64Windows[] = { }; static const char* const kRtSrcRv64Elf[] = { - "assert/assert.c", "int/int.c", - "int/si_div.c", "fp/fp.c", - "mem/mem.c", "string/string.c", - "ctype/ctype.c", "stdlib/stdlib.c", - "stdlib/qsort.c", "stdio/printf.c", + "assert/assert.c", + "int/int.c", + "int/si_div.c", + "fp/fp.c", + "mem/mem.c", + "string/string.c", + "ctype/ctype.c", + "stdlib/stdlib.c", + "stdlib/qsort.c", + "stdio/printf.c", "atomic/atomic_freestanding.c", - "cache/clear_cache.c", "kit/ifunc_init.c", - "int64/int64.c", "coro/riscv64.c", - "coro/coro.c", "fp_tf/fp_tf.c", - "fp_ti/fp_ti.c", "stack/backtrace.c", + "cache/clear_cache.c", + "kit/ifunc_init.c", + "int64/int64.c", + "coro/riscv64.c", + "coro/coro.c", + "fp_tf/fp_tf.c", + "fp_ti/fp_ti.c", + "stack/backtrace.c", "stack/print_backtrace.c", }; @@ -118,15 +154,23 @@ static const char* const kRtSrcRv64Elf[] = { * (hardware single-float) variants; only the -march/-mabi the sources are * compiled with differ, captured per-variant in the table below. */ static const char* const kRtSrcRv32Elf[] = { - "assert/assert.c", "int/int.c", - "int/si_div.c", "fp/fp.c", - "mem/mem.c", "string/string.c", - "ctype/ctype.c", "stdlib/stdlib.c", - "stdlib/qsort.c", "stdio/printf.c", + "assert/assert.c", + "int/int.c", + "int/si_div.c", + "fp/fp.c", + "mem/mem.c", + "string/string.c", + "ctype/ctype.c", + "stdlib/stdlib.c", + "stdlib/qsort.c", + "stdio/printf.c", "atomic/atomic_freestanding.c", - "cache/clear_cache.c", "kit/ifunc_init.c", - "int32/int32.c", "coro/riscv32.c", - "coro/coro.c", "stack/backtrace.c", + "cache/clear_cache.c", + "kit/ifunc_init.c", + "int32/int32.c", + "coro/riscv32.c", + "coro/coro.c", + "stack/backtrace.c", "stack/print_backtrace.c", }; diff --git a/driver/lib/wasm_run.c b/driver/lib/wasm_run.c @@ -9,8 +9,7 @@ #include "driver.h" #define DRIVER_WASM_DEFAULT_MAX_INSTANCE_BYTES (64ull * 1024ull * 1024ull) -#define DRIVER_WASM_DEFAULT_MAX_TOTAL_MEMORY_BYTES \ - (1024ull * 1024ull * 1024ull) +#define DRIVER_WASM_DEFAULT_MAX_TOTAL_MEMORY_BYTES (1024ull * 1024ull * 1024ull) typedef void (*DriverWasmInitFn)(KitWasmInstance*); typedef int (*DriverWasmMainFn)(KitWasmInstance*); @@ -256,9 +255,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-memory-max") || driver_strneq(a, "--wasm-memory-max=", 18)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-memory-max", - driver_strneq(a, "--wasm-memory-max=", 18) ? a + 18 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-memory-max", + driver_strneq(a, "--wasm-memory-max=", 18) ? a + 18 : NULL); if (!v) return -1; if (wasm_parse_size(v, &u64) != 0) { driver_errf(tool, "--wasm-memory-max requires a byte size"); @@ -269,9 +268,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-instance-max") || driver_strneq(a, "--wasm-instance-max=", 20)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-instance-max", - driver_strneq(a, "--wasm-instance-max=", 20) ? a + 20 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-instance-max", + driver_strneq(a, "--wasm-instance-max=", 20) ? a + 20 : NULL); if (!v) return -1; if (wasm_parse_size(v, &u64) != 0) { driver_errf(tool, "--wasm-instance-max requires a byte size"); @@ -282,9 +281,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-memories-max") || driver_strneq(a, "--wasm-memories-max=", 20)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-memories-max", - driver_strneq(a, "--wasm-memories-max=", 20) ? a + 20 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-memories-max", + driver_strneq(a, "--wasm-memories-max=", 20) ? a + 20 : NULL); if (!v) return -1; if (wasm_parse_u64_dec(v, &u64) != 0 || u64 > UINT32_MAX) { driver_errf(tool, "--wasm-memories-max requires a non-negative integer"); @@ -295,9 +294,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-imports") || driver_strneq(a, "--wasm-imports=", 15)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-imports", - driver_strneq(a, "--wasm-imports=", 15) ? a + 15 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-imports", + driver_strneq(a, "--wasm-imports=", 15) ? a + 15 : NULL); if (!v) return -1; return wasm_set_import_mode(tool, o, v) == 0 ? 1 : -1; } @@ -309,20 +308,19 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-env-pass") || driver_strneq(a, "--wasm-env-pass=", 16)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-env-pass", - driver_strneq(a, "--wasm-env-pass=", 16) ? a + 16 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-env-pass", + driver_strneq(a, "--wasm-env-pass=", 16) ? a + 16 : NULL); if (!v) return -1; - if (wasm_list_push(tool, o->env_pass, o->argv_bound, &o->nenv_pass, v) != - 0) + if (wasm_list_push(tool, o->env_pass, o->argv_bound, &o->nenv_pass, v) != 0) return -1; return 1; } if (driver_streq(a, "--wasm-env-set") || driver_strneq(a, "--wasm-env-set=", 15)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-env-set", - driver_strneq(a, "--wasm-env-set=", 15) ? a + 15 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-env-set", + driver_strneq(a, "--wasm-env-set=", 15) ? a + 15 : NULL); if (!v) return -1; if (wasm_list_push(tool, o->env_set, o->argv_bound, &o->nenv_set, v) != 0) return -1; @@ -341,9 +339,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-map-dir") || driver_strneq(a, "--wasm-map-dir=", 15)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-map-dir", - driver_strneq(a, "--wasm-map-dir=", 15) ? a + 15 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-map-dir", + driver_strneq(a, "--wasm-map-dir=", 15) ? a + 15 : NULL); if (!v) return -1; if (wasm_list_push(tool, o->map_dirs, o->argv_bound, &o->nmap_dirs, v) != 0) return -1; @@ -351,9 +349,9 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, } if (driver_streq(a, "--wasm-map-file") || driver_strneq(a, "--wasm-map-file=", 16)) { - v = wasm_take_value(tool, argc, argv, index, "--wasm-map-file", - driver_strneq(a, "--wasm-map-file=", 16) ? a + 16 - : NULL); + v = wasm_take_value( + tool, argc, argv, index, "--wasm-map-file", + driver_strneq(a, "--wasm-map-file=", 16) ? a + 16 : NULL); if (!v) return -1; if (wasm_list_push(tool, o->map_files, o->argv_bound, &o->nmap_files, v) != 0) @@ -370,24 +368,21 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions* o, const char* tool, if (driver_streq(a, "--wasm-stdio") || driver_strneq(a, "--wasm-stdio=", 13)) { v = wasm_take_value(tool, argc, argv, index, "--wasm-stdio", - driver_strneq(a, "--wasm-stdio=", 13) ? a + 13 - : NULL); + driver_strneq(a, "--wasm-stdio=", 13) ? a + 13 : NULL); if (!v) return -1; return wasm_set_stdio_mode(tool, o, v) == 0 ? 1 : -1; } if (driver_streq(a, "--wasm-clock") || driver_strneq(a, "--wasm-clock=", 13)) { v = wasm_take_value(tool, argc, argv, index, "--wasm-clock", - driver_strneq(a, "--wasm-clock=", 13) ? a + 13 - : NULL); + driver_strneq(a, "--wasm-clock=", 13) ? a + 13 : NULL); if (!v) return -1; return wasm_set_clock_mode(tool, o, v) == 0 ? 1 : -1; } if (driver_streq(a, "--wasm-random") || driver_strneq(a, "--wasm-random=", 14)) { v = wasm_take_value(tool, argc, argv, index, "--wasm-random", - driver_strneq(a, "--wasm-random=", 14) ? a + 14 - : NULL); + driver_strneq(a, "--wasm-random=", 14) ? a + 14 : NULL); if (!v) return -1; return wasm_set_random_mode(tool, o, v) == 0 ? 1 : -1; } @@ -569,9 +564,8 @@ static uint32_t wasm_process_env_count(void) { static int wasm_build_env(DriverWasmHostBuild* b, KitWasmHostConfig* cfg) { const DriverWasmRunOptions* o = b->opts; - uint32_t inherited = o->env_mode == DRIVER_WASM_ENV_INHERIT - ? wasm_process_env_count() - : 0u; + uint32_t inherited = + o->env_mode == DRIVER_WASM_ENV_INHERIT ? wasm_process_env_count() : 0u; uint64_t cap64 = (uint64_t)inherited + o->nenv_pass + o->nenv_set; uint32_t n = 0; uint32_t i; @@ -641,8 +635,7 @@ static int wasm_suffix_mode_len(const char* s, size_t len, uint32_t* flags, } static int wasm_build_one_mount(DriverWasmHostBuild* b, const char* spec, - uint32_t extra_flags, - KitWasmFsMount* out) { + uint32_t extra_flags, KitWasmFsMount* out) { const char* eq = wasm_find_eq(spec); const char* host; const char* guest; @@ -706,12 +699,11 @@ static int wasm_build_mounts(DriverWasmHostBuild* b, KitWasmHostConfig* cfg) { return 0; } -static KitStatus wasm_driver_write(void* user, uint32_t fd, - const uint8_t* data, size_t n, - size_t* nwritten_out) { +static KitStatus wasm_driver_write(void* user, uint32_t fd, const uint8_t* data, + size_t n, size_t* nwritten_out) { DriverWasmHostBuild* b = (DriverWasmHostBuild*)user; - KitWriter* w = fd == 2u ? driver_stderr_writer(b->env) - : driver_stdout_writer(b->env); + KitWriter* w = + fd == 2u ? driver_stderr_writer(b->env) : driver_stdout_writer(b->env); KitStatus st; if (!w) return KIT_NOMEM; st = kit_writer_write(w, data, n); @@ -802,9 +794,8 @@ static KitStatus wasm_driver_read_dir_entry(void* user, void* handle, uint8_t filetype = 0; int r; (void)user; - r = driver_read_dir_entry((DriverDirHandle*)handle, index, - &name, &name_len, &ino, &size, &mtime_ns, - &filetype); + r = driver_read_dir_entry((DriverDirHandle*)handle, index, &name, &name_len, + &ino, &size, &mtime_ns, &filetype); if (r == 1) return KIT_NOT_FOUND; if (r != 0) return KIT_IO; out->ino = ino; @@ -831,8 +822,7 @@ static void wasm_build_release(DriverWasmHostBuild* b) { if (b->owned) driver_free(b->env, b->owned, (size_t)b->owned_cap * sizeof(*b->owned)); if (b->mounts) - driver_free(b->env, b->mounts, - (size_t)b->mounts_cap * sizeof(*b->mounts)); + driver_free(b->env, b->mounts, (size_t)b->mounts_cap * sizeof(*b->mounts)); if (b->env_entries) { driver_free(b->env, b->env_entries, (size_t)b->env_cap * sizeof(*b->env_entries)); @@ -889,8 +879,7 @@ static int wasm_build_host(const DriverWasmRunOptions* opts, const char* tool, cfg.open_dir = wasm_driver_open_dir; cfg.read_dir_entry = wasm_driver_read_dir_entry; cfg.close_dir = wasm_driver_close_dir; - if (wasm_build_env(b, &cfg) != 0 || wasm_build_mounts(b, &cfg) != 0) - return 1; + if (wasm_build_env(b, &cfg) != 0 || wasm_build_mounts(b, &cfg) != 0) return 1; st = kit_wasm_host_new(&cfg, &b->host); if (st != KIT_OK) { driver_errf(tool, "%s", wasm_status_name(st)); @@ -899,9 +888,9 @@ static int wasm_build_host(const DriverWasmRunOptions* opts, const char* tool, return 0; } -static int wasm_bind_imports(const DriverWasmRunOptions* opts, - const char* tool, KitCompiler* compiler, - KitJit* jit, DriverWasmHostBuild* build, +static int wasm_bind_imports(const DriverWasmRunOptions* opts, const char* tool, + KitCompiler* compiler, KitJit* jit, + DriverWasmHostBuild* build, KitWasmInstance* inst) { KitStatus st; if (opts->imports == DRIVER_WASM_IMPORT_TEST) { diff --git a/driver/lib/wasm_run.h b/driver/lib/wasm_run.h @@ -78,10 +78,10 @@ int driver_wasm_run_try_consume(DriverWasmRunOptions*, const char* tool, int driver_wasm_run_options_used(const DriverWasmRunOptions*); /* Returns 0 when the image is not a kit-lowered Wasm module. Otherwise runs - * the Wasm init + entry sequence, stores the result in *rc_out, and returns 1. */ + * the Wasm init + entry sequence, stores the result in *rc_out, and returns 1. + */ int driver_wasm_run_call_entry(const DriverWasmRunOptions*, const char* tool, - KitCompiler*, KitJit*, void* entry, - int* rc_out); + KitCompiler*, KitJit*, void* entry, int* rc_out); int driver_wasm_run_call_entry_interp(const DriverWasmRunOptions*, const char* tool, KitCompiler*, KitJit*, diff --git a/include/kit/cg.h b/include/kit/cg.h @@ -182,7 +182,8 @@ KIT_API uint32_t kit_cg_type_ptr_address_space(KitCompiler*, KitCgTypeId); KIT_API KitCgTypeId kit_cg_type_array_elem(KitCompiler*, KitCgTypeId); KIT_API uint64_t kit_cg_type_array_count(KitCompiler*, KitCgTypeId); -/* The function's result; result.type == KIT_CG_TYPE_NONE for a void function. */ +/* The function's result; result.type == KIT_CG_TYPE_NONE for a void function. + */ KIT_API KitCgFuncResult kit_cg_type_func_result(KitCompiler*, KitCgTypeId); KIT_API uint32_t kit_cg_type_func_nparams(KitCompiler*, KitCgTypeId); KIT_API KitCgFuncParam kit_cg_type_func_param(KitCompiler*, KitCgTypeId, diff --git a/include/kit/compile.h b/include/kit/compile.h @@ -162,11 +162,12 @@ typedef struct KitFrontendVTable { uint32_t nextensions; /* Counted list of canonical names and aliases (e.g. the `-x` spellings a - * driver accepts) that identify this frontend's language. kit_language_for_name - * walks every registered frontend's list (case-sensitively, matching the - * driver's exact `-x` spellings) to map a name back to a KitLanguage, and - * kit_language_name returns the first (canonical) entry for a language. May be - * NULL/0 for frontends with no name; such a language is then unnamed. */ + * driver accepts) that identify this frontend's language. + * kit_language_for_name walks every registered frontend's list + * (case-sensitively, matching the driver's exact `-x` spellings) to map a + * name back to a KitLanguage, and kit_language_name returns the first + * (canonical) entry for a language. May be NULL/0 for frontends with no name; + * such a language is then unnamed. */ const KitSlice* names; uint32_t nnames; diff --git a/include/kit/core.h b/include/kit/core.h @@ -259,7 +259,8 @@ typedef struct KitPathPrefixMap { /* Hardening policy for automatic variables with no explicit initializer * (clang/gcc -ftrivial-auto-var-init). UNINIT keeps the C default (no implicit - * store); ZERO emits a zero store; PATTERN emits a recognizable byte pattern. */ + * store); ZERO emits a zero store; PATTERN emits a recognizable byte pattern. + */ typedef enum KitAutoVarInit { KIT_AUTOVAR_UNINIT = 0, KIT_AUTOVAR_ZERO = 1, diff --git a/include/kit/object.h b/include/kit/object.h @@ -217,7 +217,7 @@ KIT_API KitStatus kit_obj_builder_symbol_set_vis(KitObjBuilder*, KitObjSymbol, KIT_API KitStatus kit_obj_builder_find_symbol(const KitObjBuilder*, KitSym, KitObjSymbol* out); KIT_API KitStatus kit_obj_builder_wasm_add_custom(KitObjBuilder*, KitSlice name, - KitSlice data); + KitSlice data); KIT_API KitStatus kit_obj_builder_section_replace_bytes(KitObjBuilder*, KitObjSection, const void* data, @@ -401,7 +401,8 @@ KIT_API void kit_obj_rpathiter_free(KitObjRpathIter*); /* Dynamic symbol table (.dynsym / dyld export trie / PE export table). * Reuses the KitObjSymInfo shape and the KitObjSymIter handle — drive * it with kit_obj_symiter_next / _free. Empty on relocatable objects. */ -KIT_API KitStatus kit_obj_dynsymiter_new(const KitObjFile*, KitObjSymIter** out); +KIT_API KitStatus kit_obj_dynsymiter_new(const KitObjFile*, + KitObjSymIter** out); /* Dynamic relocations (.rela.dyn / .rela.plt / dyld binds / PE base relocs). * Reuses KitObjReloc and the KitObjRelocIter handle — drive it with @@ -430,7 +431,8 @@ typedef struct KitObjImageRaw { #define KIT_OBJ_RAW_PE_DLLCHARS 0x80000001u typedef struct KitObjImageRawIter KitObjImageRawIter; -KIT_API KitStatus kit_obj_image_rawiter_new(KitObjFile*, KitObjImageRawIter** out); +KIT_API KitStatus kit_obj_image_rawiter_new(KitObjFile*, + KitObjImageRawIter** out); KIT_API KitIterResult kit_obj_image_rawiter_next(KitObjImageRawIter*, KitObjImageRaw* out); KIT_API void kit_obj_image_rawiter_free(KitObjImageRawIter*); diff --git a/include/kit/support/hashmap.h b/include/kit/support/hashmap.h @@ -105,7 +105,8 @@ static inline uint32_t kit_hash_u64(uint64_t x) { if (m->cap == 0 || \ m->used * KIT_HASHMAP_LOAD_DEN >= m->cap * KIT_HASHMAP_LOAD_NUM) \ NAME##_resize(m, m->cap ? m->cap * 2u : KIT_HASHMAP_INIT_CAP); \ - if (m->cap == 0) return -1; /* resize OOM'd from empty: avoid NULL deref */\ + if (m->cap == 0) \ + return -1; /* resize OOM'd from empty: avoid NULL deref */ \ mask = m->cap - 1u; \ j = HASH_FN(k) & mask; \ while (m->slots[j].k) { \ @@ -127,7 +128,8 @@ static inline uint32_t kit_hash_u64(uint64_t x) { if (m->cap == 0 || \ m->used * KIT_HASHMAP_LOAD_DEN >= m->cap * KIT_HASHMAP_LOAD_NUM) \ NAME##_resize(m, m->cap ? m->cap * 2u : KIT_HASHMAP_INIT_CAP); \ - if (m->cap == 0) return -1; /* resize OOM'd from empty: avoid NULL deref */\ + if (m->cap == 0) \ + return -1; /* resize OOM'd from empty: avoid NULL deref */ \ mask = m->cap - 1u; \ j = HASH_FN(k) & mask; \ while (m->slots[j].k) { \ diff --git a/lang/c/decl/decl.c b/lang/c/decl/decl.c @@ -93,8 +93,8 @@ static ObjSymId decl_emit_cg_sym(DeclTable* t, const Decl* slot) { decl.kind = (slot->type && slot->type->kind == TY_FUNC) ? KIT_CG_DECL_FUNC : KIT_CG_DECL_OBJECT; decl.display_name = slot->name; - decl.linkage_name = kit_cg_c_linkage_name( - t->c, slot->asm_name ? slot->asm_name : slot->name); + decl.linkage_name = + kit_cg_c_linkage_name(t->c, slot->asm_name ? slot->asm_name : slot->name); decl.type = type_cg_id_in_pool(t->c, t->pool, slot->type); decl.sym = decl_sym_attrs(slot); if (decl.kind == KIT_CG_DECL_FUNC) { diff --git a/lang/c/parse/cg_adapter.c b/lang/c/parse/cg_adapter.c @@ -132,8 +132,9 @@ PcgLvAux* pcg_top_lv_aux(Parser* p) { } PcgLvAux* pcg_lv_aux_at(Parser* p, u32 depth) { - return (p->cg_type_sp > depth) ? &p->cg_slot_stack[p->cg_type_sp - 1u - depth].aux - : NULL; + return (p->cg_type_sp > depth) + ? &p->cg_slot_stack[p->cg_type_sp - 1u - depth].aux + : NULL; } const Type* pcg_top_type(Parser* p) { @@ -705,7 +706,8 @@ void pcg_deref(Parser* p, const Type* pointee) { * pointer stays on the CG stack untouched. */ pcg_retag_top(p, pointee); if (p->cg_type_sp) { - p->cg_slot_stack[p->cg_type_sp - 1u].flags = pcg_lvalue_flags_for_type(pointee); + p->cg_slot_stack[p->cg_type_sp - 1u].flags = + pcg_lvalue_flags_for_type(pointee); p->cg_slot_stack[p->cg_type_sp - 1u].aux.base_kind = PCG_LV_BASE_POINTER_RV; } } @@ -1195,7 +1197,8 @@ void pcg_inline_asm(Parser* p, const char* tmpl, const AsmConstraint* outs, a.clobbers = cl; a.nclobbers = nclob; if (pcg_emit_enabled(p)) kit_cg_inline_asm(p->cg, a); - /* Mirror kit_cg_inline_asm's stack effect on the parser's typed shadow stack. */ + /* Mirror kit_cg_inline_asm's stack effect on the parser's typed shadow stack. + */ for (u32 i = 0; i < nin; ++i) pcg_drop_type(p); for (u32 i = 0; i < nout; ++i) pcg_push_type(p, outs[i].type); } diff --git a/lang/c/parse/parse.c b/lang/c/parse/parse.c @@ -913,8 +913,7 @@ static void parse_init_declarator(Parser* p, const DeclSpecs* specs) { to_rvalue(p); { const Type* rhs = pcg_top_type(p); - CSemCheck chk = - c_sem_check_assignment(p->pool, var_ty, rhs); + CSemCheck chk = c_sem_check_assignment(p->pool, var_ty, rhs); if (!chk.ok) perr(p, "%.*s", KIT_SLICE_ARG(kit_slice_cstr(chk.message))); } @@ -1297,8 +1296,9 @@ static void parse_external_decl(Parser* p) { ObjSecId fn_section_id; u32 fn_decl_flags; Sym fn_alias_target; - fent = declare_function(p, name, fn_ty, &specs, loc, dattrs, dinfo.asm_label, - &fn_section_id, &fn_decl_flags, &fn_alias_target); + fent = + declare_function(p, name, fn_ty, &specs, loc, dattrs, dinfo.asm_label, + &fn_section_id, &fn_decl_flags, &fn_alias_target); attr_list_append(&fent->attrs, dattrs); if (is_punct(&p->cur, '{')) { diff --git a/lang/c/parse/parse_expr.c b/lang/c/parse/parse_expr.c @@ -3454,8 +3454,7 @@ void parse_assign_expr(Parser* p) { to_rvalue(p); { const Type* rhs = pcg_top_type(p); - CSemCheck chk = - c_sem_check_assignment(p->pool, lhs, rhs); + CSemCheck chk = c_sem_check_assignment(p->pool, lhs, rhs); if (!chk.ok) perr(p, "%.*s", KIT_SLICE_ARG(kit_slice_cstr(chk.message))); } coerce_top_to_lvalue(p); diff --git a/lang/c/parse/parse_init.c b/lang/c/parse/parse_init.c @@ -341,8 +341,7 @@ static void init_field_at(Parser* p, FrameSlot slot, const Type* arr_ty, to_rvalue(p); { const Type* rhs = pcg_top_type(p); - CSemCheck chk = - c_sem_check_assignment(p->pool, f->type, rhs); + CSemCheck chk = c_sem_check_assignment(p->pool, f->type, rhs); if (!chk.ok) perr(p, "%.*s", KIT_SLICE_ARG(kit_slice_cstr(chk.message))); } coerce_top_to_lvalue(p); diff --git a/lang/c/parse/parse_priv.h b/lang/c/parse/parse_priv.h @@ -443,9 +443,8 @@ static inline int is_kw(const Parser* p, const Tok* t, CKw k) { if (k == KW_INLINE && (t->v.ident == p->sym_inline_alias || t->v.ident == p->sym_inline_alias2)) return 1; - if (k == KW_RESTRICT && - (t->v.ident == p->sym_restrict_alias || - t->v.ident == p->sym_restrict_alias2)) + if (k == KW_RESTRICT && (t->v.ident == p->sym_restrict_alias || + t->v.ident == p->sym_restrict_alias2)) return 1; if (k == KW_THREAD_LOCAL && t->v.ident == p->sym_thread_alias) return 1; return 0; diff --git a/lang/c/type/type.c b/lang/c/type/type.c @@ -636,8 +636,7 @@ static KitCgTypeId type_cg_record_layout(TypeCgLower* l, const Type* t) { if (t->rec.fields[i].flags & FIELD_BITFIELD) { fields[i].flags |= KIT_CG_FIELD_BITFIELD; fields[i].bit_width = t->rec.fields[i].bitfield_width; - fields[i].bit_signed = - type_is_signed_integer(t->rec.fields[i].type); + fields[i].bit_signed = type_is_signed_integer(t->rec.fields[i].type); if (t->rec.fields[i].flags & FIELD_ZERO_WIDTH) { fields[i].flags |= KIT_CG_FIELD_ZERO_WIDTH; } diff --git a/lang/cpp/pp/pp.c b/lang/cpp/pp/pp.c @@ -347,7 +347,8 @@ static void pp_register_static_predefined(Pp* pp) { * kernel UAPI headers use these directly in GCC mode (e.g. * <asm-generic/int-ll64.h>'s `typedef __signed__ char __s8;`). kit parses the * canonical keywords; map the GCC spellings onto them. (`__restrict` is - * additionally a parser keyword alias for the configs that #undef the macro.) */ + * additionally a parser keyword alias for the configs that #undef the macro.) + */ pp_define(pp, "__volatile__", "volatile"); pp_define(pp, "__const__", "const"); pp_define(pp, "__signed__", "signed"); @@ -434,14 +435,16 @@ static void pp_register_os_predefined(Pp* pp, KitTargetSpec target) { * still needs to handle the syntax if/when the macro is removed.) */ pp_define(pp, "__declspec(x)", ""); - /* __extension__ is erased unconditionally in pp_register_static_predefined. */ + /* __extension__ is erased unconditionally in + * pp_register_static_predefined. */ /* __restrict / __restrict__: GCC-flavored alternates to the C99 * `restrict` keyword. kit parses `restrict` already; map the * GCC spellings onto it. */ pp_define(pp, "__restrict", "restrict"); pp_define(pp, "__restrict__", "restrict"); /* __volatile__/__const__/__signed__ erased->canonical unconditionally in - * pp_register_static_predefined (GNU spellings glibc/UAPI headers use). */ + * pp_register_static_predefined (GNU spellings glibc/UAPI headers use). + */ /* MSVC calling-convention attributes. On x86_64 they're no-ops * (every function uses the Win64 ABI) and on ARM64 likewise; on * i386 they actually mean something but kit doesn't target it. @@ -526,7 +529,8 @@ static void pp_register_target_predefined(Pp* pp) { /* OS-specific predefines (Windows/mingw + MSVC machine macros) live in one * os-keyed table — pp_register_os_predefined — so adding an OS personality * touches a single place. Emitted here, between the data-model size macros - * and the stddef.h type aliases, to preserve the predefined-macro ordering. */ + * and the stddef.h type aliases, to preserve the predefined-macro ordering. + */ pp_register_os_predefined(pp, target); /* stddef.h base aliases */ diff --git a/lang/toy/builtins.c b/lang/toy/builtins.c @@ -1334,8 +1334,7 @@ KitCgTypeId toy_parse_atomic_generic_builtin(ToyParser* p, KitSym name, if (ptr_ty == KIT_CG_TYPE_NONE || !toy_expect_comma(p)) return KIT_CG_TYPE_NONE; expected_ty = toy_parse_expr(p); - if (expected_ty == KIT_CG_TYPE_NONE) - return KIT_CG_TYPE_NONE; + if (expected_ty == KIT_CG_TYPE_NONE) return KIT_CG_TYPE_NONE; if (!toy_type_can_implicitly_cast(p, expected_ty, ty)) { toy_error(p, p->cur.loc, "atomic_cmpxchg type mismatch"); return KIT_CG_TYPE_NONE; diff --git a/lang/toy/compile.c b/lang/toy/compile.c @@ -240,7 +240,8 @@ const KitFrontendVTable kit_toy_frontend_vtable = { (uint32_t)(sizeof toy_names / sizeof toy_names[0]), toy_frontend_commit, toy_frontend_abort, - /* cache_repl_toplevel_source: the toy REPL re-reads earlier toplevel text. */ + /* cache_repl_toplevel_source: the toy REPL re-reads earlier toplevel text. + */ {false, KIT_FRONTEND_LTO_CG, true}, NULL, /* parse_options: no toy-specific flags yet */ NULL, /* free_options */ diff --git a/lang/toy/expr.c b/lang/toy/expr.c @@ -1132,8 +1132,7 @@ static KitCgTypeId toy_parse_expr_postfix(ToyParser* p) { p->last_type = field_toy_type; toy_ty = field_toy_type; if (resolved != KIT_CG_TYPE_NONE && resolved != ty) { - if (!toy_emit_checked_cast(p, ty, resolved)) - return KIT_CG_TYPE_NONE; + if (!toy_emit_checked_cast(p, ty, resolved)) return KIT_CG_TYPE_NONE; ty = resolved; } } else { diff --git a/lang/toy/internal.h b/lang/toy/internal.h @@ -332,8 +332,8 @@ typedef struct { /* Map an already-interned token sym against a const table, interning each row * name once. On a hit, sets *out and returns 1; on a miss, raises * "unknown <what>" and returns 0. */ -int toy_lookup_const(ToyParser* p, KitSym tok, const ToyConstRow* rows, size_t n, - const char* what, uint64_t* out); +int toy_lookup_const(ToyParser* p, KitSym tok, const ToyConstRow* rows, + size_t n, const char* what, uint64_t* out); /* Parse a ".name" dot-const and resolve it via `rows`. When `strict_ident` is * set the name must be a bare identifier ("expected <expected>" on failure); diff --git a/lang/toy/parser.c b/lang/toy/parser.c @@ -295,8 +295,7 @@ static int toy_parse_record_initializer(ToyParser* p, KitCgLocal slot, return 0; } } - if (expr_ty != field.type && - !toy_emit_checked_cast(p, expr_ty, field.type)) + if (expr_ty != field.type && !toy_emit_checked_cast(p, expr_ty, field.type)) return 0; kit_cg_store(p->cg, toy_mem_access(p, field.type)); if (!toy_parser_match(p, TOK_COMMA)) break; @@ -649,8 +648,7 @@ static int toy_parse_while_initializer_named(ToyParser* p, KitCgLocal slot, p->nscopes--; return 0; } - if (else_ty != result_ty && - !toy_emit_checked_cast(p, else_ty, result_ty)) { + if (else_ty != result_ty && !toy_emit_checked_cast(p, else_ty, result_ty)) { p->nscopes--; return 0; } @@ -1279,8 +1277,7 @@ static int toy_parse_break_stmt(ToyParser* p) { expr_ty, p->last_type, "break value type mismatch")) return 0; - if (expr_ty != result_ty && - !toy_emit_checked_cast(p, expr_ty, result_ty)) + if (expr_ty != result_ty && !toy_emit_checked_cast(p, expr_ty, result_ty)) return 0; kit_cg_break(p->cg, target_scope->cg_scope); if (!toy_parser_expect(p, TOK_SEMI)) { @@ -1735,8 +1732,7 @@ static int toy_parse_stmt(ToyParser* p) { toy_error(p, p->cur.loc, "type mismatch in assignment"); return 0; } - if (expr_ty != lhs_ty && - !toy_emit_checked_cast(p, expr_ty, lhs_ty)) + if (expr_ty != lhs_ty && !toy_emit_checked_cast(p, expr_ty, lhs_ty)) return 0; } else if (!toy_type_can_implicitly_cast(p, expr_ty, lhs_ty)) { toy_error(p, p->cur.loc, "type mismatch in assignment"); @@ -1783,8 +1779,7 @@ static int toy_parse_stmt(ToyParser* p) { toy_push_var_lvalue(p, v); kit_cg_deref(p->cg, 0); /* pointer VALUE -> PLACE for store */ kit_cg_swap(p->cg); - if (expr_ty != v->type && - !toy_emit_checked_cast(p, expr_ty, v->type)) + if (expr_ty != v->type && !toy_emit_checked_cast(p, expr_ty, v->type)) return 0; kit_cg_store(p->cg, toy_mem_access(p, v->type)); } else { @@ -1813,8 +1808,7 @@ static int toy_parse_stmt(ToyParser* p) { kit_cg_push_symbol_addr(p->cg, toy_global_cur_sym(p, g), 0); kit_cg_deref(p->cg, 0); /* pointer VALUE -> PLACE for store */ kit_cg_swap(p->cg); - if (expr_ty != g->type && - !toy_emit_checked_cast(p, expr_ty, g->type)) + if (expr_ty != g->type && !toy_emit_checked_cast(p, expr_ty, g->type)) return 0; kit_cg_store(p->cg, toy_mem_access(p, g->type)); } diff --git a/lang/toy/parser_core.c b/lang/toy/parser_core.c @@ -419,8 +419,8 @@ int toy_sym_is(ToyParser* p, KitSym sym, const char* name) { return sym == kit_sym_intern(p->c, kit_slice_cstr(name)); } -int toy_lookup_const(ToyParser* p, KitSym tok, const ToyConstRow* rows, size_t n, - const char* what, uint64_t* out) { +int toy_lookup_const(ToyParser* p, KitSym tok, const ToyConstRow* rows, + size_t n, const char* what, uint64_t* out) { size_t i; for (i = 0; i < n; ++i) { if (tok == kit_sym_intern(p->c, kit_slice_cstr(rows[i].name))) { @@ -451,7 +451,8 @@ int toy_parse_dot_const(ToyParser* p, const ToyConstRow* rows, size_t n, } int toy_parse_flag_set(ToyParser* p, const ToyConstRow* rows, size_t n, - const char* unknown, int comma_prefixed, uint32_t* mask) { + const char* unknown, int comma_prefixed, + uint32_t* mask) { for (;;) { KitSym name; uint64_t value; diff --git a/lang/wasm/wasm.c b/lang/wasm/wasm.c @@ -151,7 +151,8 @@ static void wasm_frontend_free(KitFrontendState* frontend) { static const KitSlice wasm_extensions[] = {KIT_SLICE_LIT("wat"), KIT_SLICE_LIT("wasm")}; -/* Canonical `-x` name plus alias; mirrors the driver's "wasm"/"wat" spellings. */ +/* Canonical `-x` name plus alias; mirrors the driver's "wasm"/"wat" spellings. + */ static const KitSlice wasm_names[] = {KIT_SLICE_LIT("wasm"), KIT_SLICE_LIT("wat")}; diff --git a/rt/include/kit/backtrace.h b/rt/include/kit/backtrace.h @@ -46,9 +46,9 @@ int __kit_backtrace(void** buf, int max, int skip); * __kit_print_backtrace's own frame is skipped, so #0 is the return address * into its direct caller (the site that asked for a trace). The address is the * unsymbolized return address; pipe it to `kit addr2line -e <image>` to recover - * `func at file:line`. Like __kit_backtrace this is a freestanding frame-pointer - * walk — no libc, no DWARF, no printf — so it is safe to call from a crash or - * panic handler. See doc/plan/BACKTRACE.md (L3a). */ + * `func at file:line`. Like __kit_backtrace this is a freestanding + * frame-pointer walk — no libc, no DWARF, no printf — so it is safe to call + * from a crash or panic handler. See doc/plan/BACKTRACE.md (L3a). */ void __kit_print_backtrace(void); /* Output sink for __kit_print_backtrace (and the freestanding assert handler). diff --git a/rt/include/setjmp.h b/rt/include/setjmp.h @@ -33,23 +33,25 @@ typedef struct { * jmp_buf covers mingw's aarch64/x86_64 _JBLEN. Non-Windows targets resolve * bare setjmp from the host libc (POSIX) or libkit_rt's per-arch coro asm. */ #if defined(_WIN32) -# if defined(__aarch64__) || defined(__arm__) +#if defined(__aarch64__) || defined(__arm__) /* aarch64/arm mingw ship the self-contained non-SEH __mingw_setjmp / - * __mingw_longjmp pair (libmingwex, no .pdata dependency). Bind by asm-label. */ + * __mingw_longjmp pair (libmingwex, no .pdata dependency). Bind by asm-label. + */ int setjmp(jmp_buf env) __asm__("__mingw_setjmp"); _Noreturn void longjmp(jmp_buf env, int val) __asm__("__mingw_longjmp"); -# else +#else /* x86_64 mingw exposes no __mingw_setjmp; its non-SEH idiom (the header's * __USE_MINGW_SETJMP_NON_SEH path) is `_setjmp((buf), NULL)` — the ucrt * intrinsic with a null frame so longjmp performs no SEH unwinding. `_setjmp` * is a COFF weak-external alias to ucrt's `__intrinsic_setjmp`; the linker * resolves that alias (see src/link/link_resolve.c). longjmp is a real ucrt * export. The macro supplies the implicit frame argument; the declaration keeps - * the standard 1-argument setjmp prototype for callers that take its address. */ + * the standard 1-argument setjmp prototype for callers that take its address. + */ int _setjmp(jmp_buf env, void* frame); _Noreturn void longjmp(jmp_buf env, int val); -# define setjmp(env) _setjmp((env), (void*)0) -# endif +#define setjmp(env) _setjmp((env), (void*)0) +#endif #else int setjmp(jmp_buf env); _Noreturn void longjmp(jmp_buf env, int val); diff --git a/rt/include/stdint.h b/rt/include/stdint.h @@ -159,9 +159,9 @@ typedef __UINTMAX_TYPE__ uintmax_t; inconsistently predefined across compiler versions and targets). */ #define __KIT_PASTE(a, b) a##b #define __KIT_XPASTE(a, b) __KIT_PASTE(a, b) -#define INT64_C(c) __KIT_XPASTE(c, __INT64_C_SUFFIX__) +#define INT64_C(c) __KIT_XPASTE(c, __INT64_C_SUFFIX__) #define UINT64_C(c) __KIT_XPASTE(c, __UINT64_C_SUFFIX__) -#define INTMAX_C(c) __KIT_XPASTE(c, __INTMAX_C_SUFFIX__) +#define INTMAX_C(c) __KIT_XPASTE(c, __INTMAX_C_SUFFIX__) #define UINTMAX_C(c) __KIT_XPASTE(c, __UINTMAX_C_SUFFIX__) #endif diff --git a/src/abi/abi.c b/src/abi/abi.c @@ -184,7 +184,8 @@ void abi_classify_int128_pair(TargetABI* a, ABIArgInfo* out) { /* The single-register scalar tail shared by every per-ABI classify_scalar: a * DIRECT argument with exactly one register part carrying the whole scalar. - * `is_fp` selects the part class; the caller owns the FP-eligibility decision. */ + * `is_fp` selects the part class; the caller owns the FP-eligibility decision. + */ void abi_classify_scalar_reg_part(TargetABI* a, ABIArgInfo* out, ABITypeInfo ti, int is_fp) { out->kind = ABI_ARG_DIRECT; diff --git a/src/abi/abi_rv64.c b/src/abi/abi_rv64.c @@ -23,8 +23,8 @@ * -> FP parts (fa pair) when FP-eligible; * * one FP + one INT scalar (in either order, ≤ 2*XLEN) * -> (fa, a) or (a, fa) pair; - * * otherwise INT parts up to 2*XLEN (passed in up to 2 GPRs). - * large struct -> INDIRECT (sret for return; byval for args) + * * otherwise INT parts up to 2*XLEN (passed in up to 2 + * GPRs). large struct -> INDIRECT (sret for return; byval for args) * * Long double is IEEE-754 binary128 (quad) and __int128 are 16-byte scalars * passed/returned in an aligned pair of integer registers (low-order half in @@ -139,8 +139,8 @@ static void classify_scalar(TargetABI* a, KitCgTypeId t, ABIArgInfo* out) { * this is the 16-byte long double / __int128 pair; on rv32 it is the 8-byte * i64 / soft-double pair. A double is only excluded from the pair here when * it is FP-eligible (handled by the single-FP-part path below). */ - int fp_part = (ti.scalar_kind == ABI_SC_FLOAT) && - riscv_fp_eligible(d.flen, ti.size); + int fp_part = + (ti.scalar_kind == ABI_SC_FLOAT) && riscv_fp_eligible(d.flen, ti.size); if (ti.size == 2u * d.gpr_bytes && !fp_part && (ti.scalar_kind == ABI_SC_INT || ti.scalar_kind == ABI_SC_FLOAT)) { ABIArgPart* parts = arena_array(a->c->tu, ABIArgPart, 2); @@ -170,8 +170,8 @@ static u32 riscv32_scalar_split_lane_size(TargetABI* a, KitCgTypeId t) { ABITypeInfo ti = abi_cg_type_info(a, t); int fp_part; if (d.gpr_bytes != 4u) return 0; - fp_part = (ti.scalar_kind == ABI_SC_FLOAT) && - riscv_fp_eligible(d.flen, ti.size); + fp_part = + (ti.scalar_kind == ABI_SC_FLOAT) && riscv_fp_eligible(d.flen, ti.size); if (ti.size == 2u * d.gpr_bytes && !fp_part && (ti.scalar_kind == ABI_SC_INT || ti.scalar_kind == ABI_SC_FLOAT)) return d.gpr_bytes; @@ -236,8 +236,7 @@ static void classify_aggregate(TargetABI* a, KitCgTypeId t, ABIArgInfo* out, memset(parts, 0, sizeof(ABIArgPart) * nparts); u32 off = 0; for (u32 i = 0; i < nparts; ++i) { - u32 chunk = - (ti.size - off > d.gpr_bytes) ? d.gpr_bytes : (ti.size - off); + u32 chunk = (ti.size - off > d.gpr_bytes) ? d.gpr_bytes : (ti.size - off); parts[i].cls = ABI_CLASS_INT; parts[i].loc = ABI_LOC_REG; parts[i].size = chunk; diff --git a/src/abi/abi_sysv_x64.c b/src/abi/abi_sysv_x64.c @@ -205,8 +205,9 @@ static void classify_one(TargetABI* a, KitCgTypeId t, ABIArgInfo* out, static ABIFuncInfo* sysv_x64_compute_func_info(TargetABI* a, KitCgTypeId fn) { /* SysV-x64 passes the sret pointer in rdi (the first integer arg register), * consuming that slot, so sret_consumes_int_arg follows has_sret. */ - ABIFuncInfo* info = abi_compute_func_info_generic(a, fn, classify_one, - /*sret_consumes_int_arg=*/1); + ABIFuncInfo* info = + abi_compute_func_info_generic(a, fn, classify_one, + /*sret_consumes_int_arg=*/1); /* Variadic register-save-area offsets at function entry. Counts the * GP/FP register slots consumed by the fixed (named) parameters; va_start diff --git a/src/api/compile.c b/src/api/compile.c @@ -651,10 +651,11 @@ KitIterResult kit_dep_iter_next(KitDepIter* it, KitDepEdge* out) { out->included_name = included ? pool_slice(it->c->global, included->name) : KIT_SLICE_NULL; out->include_loc = edge->include_loc; - /* `bracketed` is the spelling form (<...> vs "..."); `from_system_path` is the - * resolved-dir system flag (whether an -isystem dir satisfied the header), - * threaded from find_and_open_include through SourceInclude.resolved_system. - * They differ when a <...> include is resolved via a plain -I dir. */ + /* `bracketed` is the spelling form (<...> vs "..."); `from_system_path` is + * the resolved-dir system flag (whether an -isystem dir satisfied the + * header), threaded from find_and_open_include through + * SourceInclude.resolved_system. They differ when a <...> include is resolved + * via a plain -I dir. */ out->bracketed = (uint8_t)(edge->system ? 1 : 0); out->from_system_path = (uint8_t)(edge->resolved_system ? 1 : 0); out->pad[0] = 0; diff --git a/src/api/core.c b/src/api/core.c @@ -41,7 +41,7 @@ KitStatus kit_target_new(const KitContext* ctx, const KitTargetOptions* opts, arch = arch_lookup(opts->spec.arch); if (!arch) { kit_ctx_diagf(ctx, "unsupported target architecture: %u", - (unsigned)opts->spec.arch); + (unsigned)opts->spec.arch); return KIT_UNSUPPORTED; } @@ -93,7 +93,7 @@ KitStatus kit_target_new(const KitContext* ctx, const KitTargetOptions* opts, arch, &t->spec, opts->isa, t->feature_words, t->nfeature_words); if (st != KIT_OK) { kit_ctx_diagf(ctx, "unsupported ISA/profile for %s: %.*s", arch->name, - KIT_SLICE_ARG(opts->isa)); + KIT_SLICE_ARG(opts->isa)); kit_target_free(t); return st == KIT_UNSUPPORTED ? KIT_INVALID : st; } @@ -104,7 +104,7 @@ KitStatus kit_target_new(const KitContext* ctx, const KitTargetOptions* opts, KitSlice name = opts->features[i].name; if (!arch_target_feature_index(arch, name, &idx)) { kit_ctx_diagf(ctx, "unknown target feature for %s: %.*s", arch->name, - KIT_SLICE_ARG(name)); + KIT_SLICE_ARG(name)); kit_target_free(t); return KIT_INVALID; } diff --git a/src/api/link.c b/src/api/link.c @@ -322,10 +322,9 @@ static void link_lto_refmarks_add(LinkLtoRefMarks* marks, ObjSymId sym, if (marks->nmarks == marks->cap) { h = marks->c->ctx->heap; ncap = marks->cap ? marks->cap * 2u : 32u; - nm = (LinkLtoRefMark*)h->realloc(h, marks->marks, - sizeof(*marks->marks) * marks->cap, - sizeof(*marks->marks) * ncap, - _Alignof(LinkLtoRefMark)); + nm = (LinkLtoRefMark*)h->realloc( + h, marks->marks, sizeof(*marks->marks) * marks->cap, + sizeof(*marks->marks) * ncap, _Alignof(LinkLtoRefMark)); if (!nm) compiler_panic(marks->c, SRCLOC_NONE, "link: oom on LTO semantic-ref marks"); diff --git a/src/api/object_detect.c b/src/api/object_detect.c @@ -230,8 +230,8 @@ static KitStatus detect_pe(const u8* d, size_t len, KitTargetSpec* out) { KitArchKind arch; if (len < 64) return KIT_MALFORMED; /* DOS header */ if (!(d[0] == 'M' && d[1] == 'Z')) return KIT_MALFORMED; - e_lfanew = (u32)d[60] | ((u32)d[61] << 8) | ((u32)d[62] << 16) | - ((u32)d[63] << 24); + e_lfanew = + (u32)d[60] | ((u32)d[61] << 8) | ((u32)d[62] << 16) | ((u32)d[63] << 24); /* Need the 4-byte PE signature + the 20-byte IMAGE_FILE_HEADER. */ if ((u64)e_lfanew + 4u + 20u > (u64)len) return KIT_MALFORMED; pe_sig = (u32)d[e_lfanew] | ((u32)d[e_lfanew + 1] << 8) | diff --git a/src/api/package.c b/src/api/package.c @@ -337,7 +337,8 @@ static int pkg_source_add_entry(PkgSource* src, const char* tree_path, return DIST_ERR; } if (pkg_source_store_blob(src, fd, &bi, take_fd) != DIST_OK) { - kit_ctx_diagf(src->ctx, "create: failed to store blob metadata: %s", tree_path); + kit_ctx_diagf(src->ctx, "create: failed to store blob metadata: %s", + tree_path); return DIST_ERR; } e = &src->tree.entries[src->tree.n_entries++]; @@ -415,7 +416,7 @@ static int pkg_source_load_blob_from_cas(PkgSource* src, DistCas* cas, if (existing->size != e->size || memcmp(existing->root, e->root, DIST_BLAKE2B_LEN) != 0) { kit_ctx_diagf(src->ctx, "create: duplicate blob metadata mismatch: %s", - e->path); + e->path); return DIST_ERR; } return DIST_OK; @@ -656,8 +657,8 @@ static int pkg_create_kpkg(const KitCasHost* host, const KitContext* ctx, tree_url[0] = '\0'; index_url[0] = '\0'; if (shape != PKG_NATIVE_FAT && !external_dir) { - kit_ctx_diagf(ctx, - "create: --external DIR is required for non-fat native packages"); + kit_ctx_diagf( + ctx, "create: --external DIR is required for non-fat native packages"); goto done; } if (pkg_external_id_path(tree_url, sizeof tree_url, "tree", src->tree_id) != diff --git a/src/api/wasm_host.c b/src/api/wasm_host.c @@ -18,8 +18,8 @@ typedef struct KitWasmOpenFd { KitFileData data; const KitFileIO* io; uint64_t pos; - void* dir_handle; - char* host_path; + void* dir_handle; + char* host_path; size_t host_path_size; /* 0=borrowed (KIT_WASM_FS_FILE), >0=heap-owned */ } KitWasmOpenFd; @@ -127,8 +127,7 @@ static const char* wasm_guest_basename(const char* path) { return path + last; } -static int wasm_bytes_eq_cstr(const uint8_t* a, uint32_t alen, - const char* b) { +static int wasm_bytes_eq_cstr(const uint8_t* a, uint32_t alen, const char* b) { uint32_t i; if (!a || !b) return 0; for (i = 0; i < alen; ++i) { @@ -164,8 +163,8 @@ static int wasm_mem_ptr(KitWasmInstance* inst, uint32_t addr, uint32_t n, static int wasm_read_u32(KitWasmInstance* inst, uint32_t addr, uint32_t* out) { uint8_t* p; if (!wasm_mem_ptr(inst, addr, 4u, &p)) return 0; - *out = ((uint32_t)p[0]) | ((uint32_t)p[1] << 8) | - ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24); + *out = ((uint32_t)p[0]) | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | + ((uint32_t)p[3] << 24); return 1; } @@ -194,15 +193,21 @@ static int wasm_write_u64(KitWasmInstance* inst, uint32_t addr, uint64_t v) { } static void wasm_put_u64_le(uint8_t* buf, uint32_t off, uint64_t v) { - buf[off+0] = (uint8_t)(v); buf[off+1] = (uint8_t)(v >> 8); - buf[off+2] = (uint8_t)(v >> 16); buf[off+3] = (uint8_t)(v >> 24); - buf[off+4] = (uint8_t)(v >> 32); buf[off+5] = (uint8_t)(v >> 40); - buf[off+6] = (uint8_t)(v >> 48); buf[off+7] = (uint8_t)(v >> 56); + buf[off + 0] = (uint8_t)(v); + buf[off + 1] = (uint8_t)(v >> 8); + buf[off + 2] = (uint8_t)(v >> 16); + buf[off + 3] = (uint8_t)(v >> 24); + buf[off + 4] = (uint8_t)(v >> 32); + buf[off + 5] = (uint8_t)(v >> 40); + buf[off + 6] = (uint8_t)(v >> 48); + buf[off + 7] = (uint8_t)(v >> 56); } static void wasm_put_u32_le(uint8_t* buf, uint32_t off, uint32_t v) { - buf[off+0] = (uint8_t)(v); buf[off+1] = (uint8_t)(v >> 8); - buf[off+2] = (uint8_t)(v >> 16); buf[off+3] = (uint8_t)(v >> 24); + buf[off + 0] = (uint8_t)(v); + buf[off + 1] = (uint8_t)(v >> 8); + buf[off + 2] = (uint8_t)(v >> 16); + buf[off + 3] = (uint8_t)(v >> 24); } /* wasi_filestat_t: dev(u64@0) ino(u64@8) filetype(u8@16)+7pad nlink(u64@24) @@ -356,8 +361,7 @@ static int32_t wasi_environ_get(KitWasmInstance* inst, int32_t env_i, int32_t buf_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); return wasm_write_strings(inst, w->host->config.env, w->host->config.nenv, - (uint32_t)env_i, - (uint32_t)buf_i) + (uint32_t)env_i, (uint32_t)buf_i) ? WASI_ESUCCESS : WASI_EINVAL; } @@ -378,8 +382,7 @@ static int32_t wasi_args_get(KitWasmInstance* inst, int32_t args_i, int32_t buf_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); return wasm_write_strings(inst, w->host->config.args, w->host->config.nargs, - (uint32_t)args_i, - (uint32_t)buf_i) + (uint32_t)args_i, (uint32_t)buf_i) ? WASI_ESUCCESS : WASI_EINVAL; } @@ -519,8 +522,8 @@ static int32_t wasi_path_open(KitWasmInstance* inst, int32_t dirfd_i, int32_t dirflags_i, int32_t path_i, int32_t path_len_i, int32_t oflags_i, int64_t rights_base_i, - int64_t rights_inheriting_i, - int32_t fdflags_i, int32_t opened_fd_i) { + int64_t rights_inheriting_i, int32_t fdflags_i, + int32_t opened_fd_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); const KitWasmFsMount* m = wasm_preopen_for_fd(w, (uint32_t)dirfd_i); uint8_t* guest_path; @@ -541,8 +544,7 @@ static int32_t wasi_path_open(KitWasmInstance* inst, int32_t dirfd_i, if (!open_as_dir && (!w->host->config.file_io || !w->host->config.file_io->read_all)) return WASI_ENOSYS; - if (!wasm_mem_ptr(inst, (uint32_t)path_i, (uint32_t)path_len_i, - &guest_path)) + if (!wasm_mem_ptr(inst, (uint32_t)path_i, (uint32_t)path_len_i, &guest_path)) return WASI_EINVAL; if (!wasm_guest_path_safe(guest_path, (uint32_t)path_len_i)) return WASI_ENOTCAPABLE; @@ -565,8 +567,7 @@ static int32_t wasi_path_open(KitWasmInstance* inst, int32_t dirfd_i, host_path_size); return WASI_ENOSYS; } - st = w->host->config.open_dir(w->host->config.user, host_path, - &dir_handle); + st = w->host->config.open_dir(w->host->config.user, host_path, &dir_handle); if (st != KIT_OK) { if (host_path_size > 0) w->host->config.heap->free(w->host->config.heap, host_path, @@ -618,9 +619,8 @@ static int32_t wasi_path_open(KitWasmInstance* inst, int32_t dirfd_i, } } -static int32_t wasi_fd_read(KitWasmInstance* inst, int32_t fd_i, - int32_t iovs_i, int32_t iovs_len_i, - int32_t nread_i) { +static int32_t wasi_fd_read(KitWasmInstance* inst, int32_t fd_i, int32_t iovs_i, + int32_t iovs_len_i, int32_t nread_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); uint32_t fd = (uint32_t)fd_i; uint32_t iovs = (uint32_t)iovs_i; @@ -668,9 +668,8 @@ static int32_t wasi_fd_close(KitWasmInstance* inst, int32_t fd_i) { return WASI_ESUCCESS; } -static int32_t wasi_fd_seek(KitWasmInstance* inst, int32_t fd_i, - int64_t offset, int32_t whence_i, - int32_t newoffset_i) { +static int32_t wasi_fd_seek(KitWasmInstance* inst, int32_t fd_i, int64_t offset, + int32_t whence_i, int32_t newoffset_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); uint32_t fd = (uint32_t)fd_i; int64_t base; @@ -678,10 +677,17 @@ static int32_t wasi_fd_seek(KitWasmInstance* inst, int32_t fd_i, if (fd >= KIT_WASM_HOST_MAX_FDS || !w->fds[fd].used) return WASI_EBADF; if (w->fds[fd].is_dir) return WASI_EISDIR; switch (whence_i) { - case 0: base = 0; break; - case 1: base = (int64_t)w->fds[fd].pos; break; - case 2: base = (int64_t)(uint64_t)w->fds[fd].data.size; break; - default: return WASI_EINVAL; + case 0: + base = 0; + break; + case 1: + base = (int64_t)w->fds[fd].pos; + break; + case 2: + base = (int64_t)(uint64_t)w->fds[fd].data.size; + break; + default: + return WASI_EINVAL; } if (offset < 0 && (uint64_t)(-offset) > (uint64_t)base) return WASI_EINVAL; newpos = base + offset; @@ -729,8 +735,8 @@ static int32_t wasi_fd_filestat_get(KitWasmInstance* inst, int32_t fd_i, ft = w->fds[fd].is_dir ? KIT_WASM_FILETYPE_DIRECTORY : KIT_WASM_FILETYPE_REGULAR_FILE; if (w->host->config.stat_path && w->fds[fd].host_path) { - w->host->config.stat_path(w->host->config.user, w->fds[fd].host_path, - &size, &mtime_ns, &ft); + w->host->config.stat_path(w->host->config.user, w->fds[fd].host_path, &size, + &mtime_ns, &ft); } else if (!w->fds[fd].is_dir) { size = (uint64_t)w->fds[fd].data.size; } @@ -741,8 +747,7 @@ static int32_t wasi_fd_filestat_get(KitWasmInstance* inst, int32_t fd_i, static int32_t wasi_path_filestat_get(KitWasmInstance* inst, int32_t dirfd_i, int32_t flags_i, int32_t path_i, - int32_t path_len_i, - int32_t filestat_i) { + int32_t path_len_i, int32_t filestat_i) { KitWasmRuntimeInstance* w = wasm_wrap_from_instance(inst); const KitWasmFsMount* m = wasm_preopen_for_fd(w, (uint32_t)dirfd_i); uint8_t* guest_path; @@ -769,8 +774,8 @@ static int32_t wasi_path_filestat_get(KitWasmInstance* inst, int32_t dirfd_i, (uint32_t)path_len_i, &host_path, &host_path_size); if (st != KIT_OK) return wasm_status_errno(st); } - st = w->host->config.stat_path(w->host->config.user, host_path, - &size, &mtime_ns, &ft); + st = w->host->config.stat_path(w->host->config.user, host_path, &size, + &mtime_ns, &ft); if (host_path_size > 0) w->host->config.heap->free(w->host->config.heap, host_path, host_path_size); if (st != KIT_OK) return wasm_status_errno(st); @@ -846,29 +851,24 @@ static void* wasm_wasi_resolve(void* user, const char* module, KitWasmValType p_fd_readdir[5] = {KIT_WASM_VAL_I32, KIT_WASM_VAL_I32, KIT_WASM_VAL_I32, KIT_WASM_VAL_I64, KIT_WASM_VAL_I32}; - if (!host || !(host->config.flags & KIT_WASM_HOST_WASI_PREVIEW1)) - return NULL; + if (!host || !(host->config.flags & KIT_WASM_HOST_WASI_PREVIEW1)) return NULL; if (!wasm_streq(module, "wasi_snapshot_preview1")) return NULL; if (wasm_streq(field, "proc_exit") && wasm_sig(type, p_proc_exit, 1u, NULL, 0u)) return (void*)(uintptr_t)wasi_proc_exit; - if (wasm_streq(field, "fd_write") && - wasm_sig(type, p4_i32, 4u, r_i32, 1u)) + if (wasm_streq(field, "fd_write") && wasm_sig(type, p4_i32, 4u, r_i32, 1u)) return (void*)(uintptr_t)wasi_fd_write; if (wasm_streq(field, "environ_sizes_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_environ_sizes_get; - if (wasm_streq(field, "environ_get") && - wasm_sig(type, p2_i32, 2u, r_i32, 1u)) + if (wasm_streq(field, "environ_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_environ_get; if (wasm_streq(field, "args_sizes_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_args_sizes_get; - if (wasm_streq(field, "args_get") && - wasm_sig(type, p2_i32, 2u, r_i32, 1u)) + if (wasm_streq(field, "args_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_args_get; - if (wasm_streq(field, "random_get") && - wasm_sig(type, p2_i32, 2u, r_i32, 1u)) + if (wasm_streq(field, "random_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_random_get; if (wasm_streq(field, "clock_time_get") && wasm_sig(type, p_clock, 3u, r_i32, 1u)) @@ -882,17 +882,14 @@ static void* wasm_wasi_resolve(void* user, const char* module, if (wasm_streq(field, "path_open") && wasm_sig(type, p_path_open, 9u, r_i32, 1u)) return (void*)(uintptr_t)wasi_path_open; - if (wasm_streq(field, "fd_read") && - wasm_sig(type, p4_i32, 4u, r_i32, 1u)) + if (wasm_streq(field, "fd_read") && wasm_sig(type, p4_i32, 4u, r_i32, 1u)) return (void*)(uintptr_t)wasi_fd_read; if (wasm_streq(field, "fd_close") && wasm_sig(type, p_proc_exit, 1u, r_i32, 1u)) return (void*)(uintptr_t)wasi_fd_close; - if (wasm_streq(field, "fd_seek") && - wasm_sig(type, p_fd_seek, 4u, r_i32, 1u)) + if (wasm_streq(field, "fd_seek") && wasm_sig(type, p_fd_seek, 4u, r_i32, 1u)) return (void*)(uintptr_t)wasi_fd_seek; - if (wasm_streq(field, "fd_tell") && - wasm_sig(type, p2_i32, 2u, r_i32, 1u)) + if (wasm_streq(field, "fd_tell") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) return (void*)(uintptr_t)wasi_fd_tell; if (wasm_streq(field, "fd_filestat_get") && wasm_sig(type, p2_i32, 2u, r_i32, 1u)) @@ -918,8 +915,7 @@ KIT_API KitStatus kit_wasm_host_new(const KitWasmHostConfig* config, const KitWasmFsMount* m = &config->mounts[i]; if (!m->host_path || !m->guest_path || m->guest_path[0] != '/') return KIT_INVALID; - if ((m->flags & KIT_WASM_FS_FILE) && - (!*wasm_guest_basename(m->guest_path))) + if ((m->flags & KIT_WASM_FS_FILE) && (!*wasm_guest_basename(m->guest_path))) return KIT_INVALID; } host = (KitWasmHost*)config->heap->alloc(config->heap, sizeof(*host), @@ -963,7 +959,7 @@ KIT_API KitStatus kit_wasm_instance_new(KitWasmHost* host, KitJit* jit, st = wasm_u64_to_size(allocation_bytes, &allocation_size); if (st != KIT_OK) return st; w = (KitWasmRuntimeInstance*)heap->alloc(heap, allocation_size, - _Alignof(KitWasmRuntimeInstance)); + _Alignof(KitWasmRuntimeInstance)); if (!w) return KIT_NOMEM; memset(w, 0, allocation_size); w->host = host; @@ -1048,8 +1044,7 @@ KIT_API void kit_wasm_instance_free(KitWasmInstance* inst) { if (!inst) return; w = wasm_wrap_from_instance(inst); heap = w->host->config.heap; - for (i = 0; i < KIT_WASM_HOST_MAX_FDS; ++i) - wasm_fd_close_slot(w, i); + for (i = 0; i < KIT_WASM_HOST_MAX_FDS; ++i) wasm_fd_close_slot(w, i); for (i = 0; i < w->nmemories; ++i) { size_t mem_size; if (w->memories && w->memories[i] && @@ -1059,15 +1054,13 @@ KIT_API void kit_wasm_instance_free(KitWasmInstance* inst) { if (w->memories) heap->free(heap, w->memories, (size_t)w->nmemories * sizeof(uint8_t*)); if (w->memory_bytes) - heap->free(heap, w->memory_bytes, - (size_t)w->nmemories * sizeof(uint64_t)); + heap->free(heap, w->memory_bytes, (size_t)w->nmemories * sizeof(uint64_t)); allocation_size = (size_t)w->allocation_bytes; heap->free(heap, w, allocation_size); } KIT_API KitStatus kit_wasm_host_bind_imports(KitWasmHost* host, - KitCompiler* compiler, - KitJit* jit, + KitCompiler* compiler, KitJit* jit, KitWasmInstance* inst) { if (!host || !compiler || !jit || !inst) return KIT_INVALID; return kit_wasm_bind_host_imports(compiler, jit, inst, NULL, 0, diff --git a/src/arch/aa64/native.c b/src/arch/aa64/native.c @@ -4681,8 +4681,8 @@ static void aa_asm_hook_run_template(NativeDirectTarget* d, const char* tmpl, const AsmConstraint* outs, u32 nout, Operand* bound_outs, const AsmConstraint* ins, u32 nin, - Operand* bound_ins, - const Sym* clobbers, u32 nclob) { + Operand* bound_ins, const Sym* clobbers, + u32 nclob) { AA64Asm* a = aa64_asm_open(d->base.c); aa64_inline_bind(a, outs, nout, bound_outs, ins, nin, bound_ins, clobbers, nclob); diff --git a/src/arch/aa64/reloc.c b/src/arch/aa64/reloc.c @@ -280,7 +280,8 @@ void aa64_jit_tls_le_relax(Compiler* c, RelocKind k, u8* site, u64 storage, aa64_reloc_apply_insn(c, R_AARCH64_ADR_PREL_PG_HI21, mrs, storage, 0, site_pc - 4u); wr_u32_le(site, 0x91000000u | (rd << 5) | rd); /* add rd, rd, #0 */ - aa64_reloc_apply_insn(c, R_AARCH64_ADD_ABS_LO12_NC, site, storage, 0, site_pc); + aa64_reloc_apply_insn(c, R_AARCH64_ADD_ABS_LO12_NC, site, storage, 0, + site_pc); wr_u32_le(add_lo, 0xd503201fu); /* nop */ } @@ -298,8 +299,7 @@ int aa64_jit_reloc_relax(Compiler* c, RelocKind k, const JitRelaxCtx* ctx) { * Rewrite the ADRP to MOVZ rd,#0 so rd becomes 0 directly; the paired ADD's * assembled imm12 of 0 already gives rd += 0, so leave it as add rd,rd,#0. */ if (ctx->weak_undef_zero) { - if (k == R_AARCH64_ADR_PREL_PG_HI21 || - k == R_AARCH64_ADR_PREL_PG_HI21_NC) { + if (k == R_AARCH64_ADR_PREL_PG_HI21 || k == R_AARCH64_ADR_PREL_PG_HI21_NC) { u32 rd = rd_u32_le(P_bytes) & 0x1fu; wr_u32_le(P_bytes, 0xd2800000u | rd); /* movz rd, #0 */ return 1; diff --git a/src/arch/arch.h b/src/arch/arch.h @@ -15,9 +15,9 @@ * yields a DWARF index + a C-string name) into the public KitArchReg out * struct. Each arch's register_at is a one-line wrapper delegating here with * its own iter_get, so the conversion lives in exactly one place. */ -static inline int arch_register_at_public( - uint32_t idx, KitArchReg* out, - int (*iter_get)(uint32_t, uint32_t*, const char**)) { +static inline int arch_register_at_public(uint32_t idx, KitArchReg* out, + int (*iter_get)(uint32_t, uint32_t*, + const char**)) { const char* nm = NULL; int rc; if (!out) return 1; diff --git a/src/arch/c_target/c_emit.c b/src/arch/c_target/c_emit.c @@ -63,22 +63,21 @@ ObjSymId obj_tlv_bootstrap_get(const ObjBuilder*); * so we capture the pre-grow cap and clear [old_cap, new_cap). * * Both are macros so VEC_GROW can derive element size/alignment from *ptr. */ -#define c_vec_grow_or_panic(t, ptr, cap, want) \ - do { \ - if (VEC_GROW((t)->c->ctx->heap, (ptr), (cap), (want))) { \ - compiler_panic((t)->c, (SrcLoc){0, 0, 0}, \ - "C target: out of memory"); \ - } \ +#define c_vec_grow_or_panic(t, ptr, cap, want) \ + do { \ + if (VEC_GROW((t)->c->ctx->heap, (ptr), (cap), (want))) { \ + compiler_panic((t)->c, (SrcLoc){0, 0, 0}, "C target: out of memory"); \ + } \ } while (0) -#define c_vec_grow_zeroed(t, ptr, cap, want) \ - do { \ - u32 c_vgz_old_ = (cap); \ - c_vec_grow_or_panic((t), (ptr), (cap), (want)); \ - if ((cap) > c_vgz_old_) { \ - memset((ptr) + c_vgz_old_, 0, \ - ((size_t)((cap) - c_vgz_old_)) * sizeof(*(ptr))); \ - } \ +#define c_vec_grow_zeroed(t, ptr, cap, want) \ + do { \ + u32 c_vgz_old_ = (cap); \ + c_vec_grow_or_panic((t), (ptr), (cap), (want)); \ + if ((cap) > c_vgz_old_) { \ + memset((ptr) + c_vgz_old_, 0, \ + ((size_t)((cap) - c_vgz_old_)) * sizeof(*(ptr))); \ + } \ } while (0) /* === Target state === */ @@ -3660,9 +3659,8 @@ static void c_emit_data_symbol(CTarget* t, ObjSymId id, const ObjSym* os) { * existing `weak` attribute works as expected. */ if (os->bind == SB_WEAK) { const ObjFormatImpl* fmt = obj_format_lookup(t->c->target.obj); - const char* weak_attr = (fmt && fmt->weak_undef_attr) - ? fmt->weak_undef_attr - : "weak"; + const char* weak_attr = + (fmt && fmt->weak_undef_attr) ? fmt->weak_undef_attr : "weak"; cbuf_puts(b, "__attribute__(("); cbuf_puts(b, weak_attr); cbuf_puts(b, ")) "); @@ -3802,7 +3800,8 @@ static void c_emit_data_symbol(CTarget* t, ObjSymId id, const ObjSym* os) { * value) into a data slot. A PC-relative or section-difference reloc is * not a C constant expression, and a sub-pointer-width address cannot be * truncated into its slot in portable C — reject those rather than - * silently mis-size the slot (the width logic below assumes ABS32/ABS64). */ + * silently mis-size the slot (the width logic below assumes ABS32/ABS64). + */ for (u32 i = 0; i < nrelocs; ++i) { if (rs[i]->kind != R_ABS32 && rs[i]->kind != R_ABS64) compiler_panic(t->c, (SrcLoc){0, 0, 0}, diff --git a/src/arch/riscv/asm.c b/src/arch/riscv/asm.c @@ -966,8 +966,8 @@ static void rv_emit_la_pseudo(AsmDriver* d) { * On rv32 there is no ADDIW and the GPR is 32 bits wide, so every constant * fits a LUI + ADDI pair (the add already wraps mod 2^32). The variant's * has_w_forms gates both the ADDIW use and the >32-bit recursion below. */ -static void rv_emit_li_value(MCEmitter* mc, const RiscvVariant* variant, - u32 rd, i64 val) { +static void rv_emit_li_value(MCEmitter* mc, const RiscvVariant* variant, u32 rd, + i64 val) { if (!variant->has_w_forms || (val >= -2147483648LL && val <= 2147483647LL)) { i64 hi20 = ((val + 0x800) >> 12) & 0xfffffLL; i64 lo12 = rv_sext12(val); @@ -1050,8 +1050,9 @@ static void rv64_arch_asm_insn(ArchAsm* base, AsmDriver* d, Sym mnemonic) { (void)asm_driver_cur_section(d); desc = rv64_asm_find(pool_slice(asm_driver_pool(d), mnemonic), av); if (!desc) - asm_driver_panic(d, av == (u8)RV_AV_RV32 ? "rv32 asm: unsupported instruction" - : "rv64 asm: unsupported instruction"); + asm_driver_panic(d, av == (u8)RV_AV_RV32 + ? "rv32 asm: unsupported instruction" + : "rv64 asm: unsupported instruction"); if (rv64_emit_pseudo(d, desc)) return; if (desc->flags & RV64_ASMFL_C16) rv64_emit16(mc, assemble_one(d, desc)); diff --git a/src/arch/riscv/disasm.c b/src/arch/riscv/disasm.c @@ -183,8 +183,8 @@ static u16 rv64_decode_flags(const Rv64InsnDesc* desc, u32 word) { * jr/jalr pair is a control transfer, and bit[12] selects c.jalr (which * links ra, so it is a call). */ u32 hw = word & 0xffffu; - u32 rs2 = (hw >> 2) & 0x1fu; /* bits[6:2] */ - u32 rd_rs1 = (hw >> 7) & 0x1fu; /* bits[11:7] */ + u32 rs2 = (hw >> 2) & 0x1fu; /* bits[6:2] */ + u32 rd_rs1 = (hw >> 7) & 0x1fu; /* bits[11:7] */ if (rs2 == 0u && rd_rs1 != 0u) { flags |= KIT_DECODE_TERMINATOR | KIT_DECODE_BRANCH; if (((hw >> 12) & 1u) != 0u) flags |= KIT_DECODE_CALL; /* c.jalr */ @@ -247,9 +247,9 @@ static void rv64_decode_operands(const Rv64InsnDesc* desc, u32 word, u64 pc, /* SLLIW/SRLIW/SRAIW (I_SHIFTW) are always a 5-bit shamt. The plain * SLLI/SRLI/SRAI shamt is 6-bit on rv64 but 5-bit on rv32 (bit 25 is * funct7 there), so the mask follows variant->shamt_bits. */ - u32 shamt_mask = - (fmt == RV64_FMT_I_SHIFTW || variant->shamt_bits == 5u) ? 0x1fu - : 0x3fu; + u32 shamt_mask = (fmt == RV64_FMT_I_SHIFTW || variant->shamt_bits == 5u) + ? 0x1fu + : 0x3fu; out->noperands = 3; rv_decop_reg(&out->operands[0], i.rd, 64); rv_decop_reg(&out->operands[1], i.rs1, 64); diff --git a/src/arch/riscv/isa.c b/src/arch/riscv/isa.c @@ -119,16 +119,41 @@ const Rv64InsnDesc rv64_insn_table[] = { {MN("and"), MATCH_R(0x00, 0x7, RV_OP), MASK_R, RV64_FMT_R, 0, 0, {0}}, /* 32-bit (W) variants — OP_32 = 0x3b (RV64-only major opcode) */ - {MN("addw"), MATCH_R(0x00, 0x0, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("subw"), MATCH_R(0x20, 0x0, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("sllw"), MATCH_R(0x00, 0x1, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("srlw"), MATCH_R(0x00, 0x5, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("sraw"), MATCH_R(0x20, 0x5, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, + {MN("addw"), + MATCH_R(0x00, 0x0, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("subw"), + MATCH_R(0x20, 0x0, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("sllw"), + MATCH_R(0x00, 0x1, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("srlw"), + MATCH_R(0x00, 0x5, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("sraw"), + MATCH_R(0x20, 0x5, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, /* ---- I-type immediate ALU (OP_IMM=0x13) ---- * Aliases: `li rd, imm` = ADDI rd, x0, imm (rs1=x0). @@ -139,7 +164,8 @@ const Rv64InsnDesc rv64_insn_table[] = { 0xffffffffu, RV64_FMT_SYSTEM, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, {MN("li"), 0x00000013u, 0x000f807fu, RV64_FMT_I, RV64_ASMFL_ALIAS, 0, {0}}, /* mv: ADDI with imm=0. mask requires imm12=0 + funct3=0 + op. */ {MN("mv"), 0x00000013u, 0xfff0707fu, RV64_FMT_I, RV64_ASMFL_ALIAS, 0, {0}}, @@ -149,14 +175,16 @@ const Rv64InsnDesc rv64_insn_table[] = { 0xfff0707fu, RV64_FMT_I, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, /* snez: SLTU rd, x0, rs2 — rs1=x0, funct3=3, op=OP. */ {MN("snez"), 0x00003033u, 0xfe0ff07fu, RV64_FMT_R, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, /* not: XORI rd, rs, -1 — imm12=0xfff, funct3=4, op=OP_IMM. */ {MN("not"), 0xfff04013u, 0xfff0707fu, RV64_FMT_I, RV64_ASMFL_ALIAS, 0, {0}}, /* neg: SUB rd, x0, rs2 — rs1=x0, funct7=0x20, funct3=0. */ @@ -167,7 +195,8 @@ const Rv64InsnDesc rv64_insn_table[] = { 0xfe0ff07fu, RV64_FMT_R, RV64_ASMFL_ALIAS, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("addi"), MATCH_I(0x0, RV_OP_IMM), MASK_I, RV64_FMT_I, 0, 0, {0}}, {MN("slti"), MATCH_I(0x2, RV_OP_IMM), MASK_I, RV64_FMT_I, 0, 0, {0}}, {MN("sltiu"), MATCH_I(0x3, RV_OP_IMM), MASK_I, RV64_FMT_I, 0, 0, {0}}, @@ -181,19 +210,22 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_ISHIFT, RV64_FMT_I_SHIFT, 0, - 0, {0}}, + 0, + {0}}, {MN("srli"), MATCH_ISHIFT(0x00, 0x5, RV_OP_IMM), MASK_ISHIFT, RV64_FMT_I_SHIFT, 0, - 0, {0}}, + 0, + {0}}, {MN("srai"), MATCH_ISHIFT(0x10, 0x5, RV_OP_IMM), MASK_ISHIFT, RV64_FMT_I_SHIFT, 0, - 0, {0}}, + 0, + {0}}, /* OP_IMM_32: ADDIW + word shifts. sext.w alias = ADDIW rd, rs, 0. * OP_IMM_32 major opcode (0x1b) is absent on rv32 — all RV64-only. */ @@ -202,27 +234,36 @@ const Rv64InsnDesc rv64_insn_table[] = { 0xfff0707fu, RV64_FMT_I, RV64_ASMFL_ALIAS, - RV_AV_RV64, {0}}, - {MN("addiw"), MATCH_I(0x0, RV_OP_IMM_32), MASK_I, RV64_FMT_I, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, + {MN("addiw"), + MATCH_I(0x0, RV_OP_IMM_32), + MASK_I, + RV64_FMT_I, + 0, + RV_AV_RV64, + {0}}, {MN("slliw"), MATCH_ISHIFTW(0x00, 0x1, RV_OP_IMM_32), MASK_ISHIFTW, RV64_FMT_I_SHIFTW, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("srliw"), MATCH_ISHIFTW(0x00, 0x5, RV_OP_IMM_32), MASK_ISHIFTW, RV64_FMT_I_SHIFTW, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("sraiw"), MATCH_ISHIFTW(0x20, 0x5, RV_OP_IMM_32), MASK_ISHIFTW, RV64_FMT_I_SHIFTW, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, /* ---- LUI / AUIPC ---- */ {MN("lui"), MATCH_U(RV_LUI), MASK_U, RV64_FMT_U, 0, 0, {0}}, @@ -232,19 +273,34 @@ const Rv64InsnDesc rv64_insn_table[] = { {MN("lb"), MATCH_I(0x0, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, 0, {0}}, {MN("lh"), MATCH_I(0x1, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, 0, {0}}, {MN("lw"), MATCH_I(0x2, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, 0, {0}}, - {MN("ld"), MATCH_I(0x3, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, - RV_AV_RV64, {0}}, /* LD funct3=3 RV64-only */ + {MN("ld"), + MATCH_I(0x3, RV_LOAD), + MASK_I, + RV64_FMT_LOAD, + 0, + RV_AV_RV64, + {0}}, /* LD funct3=3 RV64-only */ {MN("lbu"), MATCH_I(0x4, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, 0, {0}}, {MN("lhu"), MATCH_I(0x5, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, 0, {0}}, - {MN("lwu"), MATCH_I(0x6, RV_LOAD), MASK_I, RV64_FMT_LOAD, 0, - RV_AV_RV64, {0}}, /* LWU funct3=6 RV64-only */ + {MN("lwu"), + MATCH_I(0x6, RV_LOAD), + MASK_I, + RV64_FMT_LOAD, + 0, + RV_AV_RV64, + {0}}, /* LWU funct3=6 RV64-only */ /* ---- Stores (S-type, op=STORE=0x23) ---- */ {MN("sb"), MATCH_S(0x0, RV_STORE), MASK_S, RV64_FMT_STORE, 0, 0, {0}}, {MN("sh"), MATCH_S(0x1, RV_STORE), MASK_S, RV64_FMT_STORE, 0, 0, {0}}, {MN("sw"), MATCH_S(0x2, RV_STORE), MASK_S, RV64_FMT_STORE, 0, 0, {0}}, - {MN("sd"), MATCH_S(0x3, RV_STORE), MASK_S, RV64_FMT_STORE, 0, - RV_AV_RV64, {0}}, /* SD funct3=3 RV64-only */ + {MN("sd"), + MATCH_S(0x3, RV_STORE), + MASK_S, + RV64_FMT_STORE, + 0, + RV_AV_RV64, + {0}}, /* SD funct3=3 RV64-only */ /* ---- Branches (B-type, op=BRANCH=0x63) ---- * Aliases: `beqz rs, off` = BEQ rs, x0, off; `bnez rs, off` = BNE. */ @@ -253,13 +309,15 @@ const Rv64InsnDesc rv64_insn_table[] = { 0x01f0707fu, RV64_FMT_B, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, {MN("bnez"), 0x00001063u, 0x01f0707fu, RV64_FMT_B, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, {MN("beq"), MATCH_B(0x0, RV_BRANCH), MASK_B, RV64_FMT_B, 0, 0, {0}}, {MN("bne"), MATCH_B(0x1, RV_BRANCH), MASK_B, RV64_FMT_B, 0, 0, {0}}, {MN("blt"), MATCH_B(0x4, RV_BRANCH), MASK_B, RV64_FMT_B, 0, 0, {0}}, @@ -278,13 +336,15 @@ const Rv64InsnDesc rv64_insn_table[] = { 0xffffffffu, RV64_FMT_SYSTEM, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, {MN("jr"), 0x00000067u, 0xfff07fffu, RV64_FMT_JALR, RV64_ASMFL_ALIAS, - 0, {0}}, + 0, + {0}}, {MN("j"), 0x0000006fu, 0x00000fffu, RV64_FMT_J, RV64_ASMFL_ALIAS, 0, {0}}, {MN("jal"), MATCH_J(RV_JAL), MASK_J, RV64_FMT_J, 0, 0, {0}}, {MN("jalr"), MATCH_I(0x0, RV_JALR), MASK_I, RV64_FMT_JALR, 0, 0, {0}}, @@ -310,7 +370,8 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FULL, RV64_FMT_SYSTEM, 0, - 0, {0}}, + 0, + {0}}, /* ---- System (ECALL/EBREAK) ---- */ {MN("ecall"), @@ -318,13 +379,15 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FULL, RV64_FMT_SYSTEM, 0, - 0, {0}}, + 0, + {0}}, {MN("ebreak"), MATCH_FULL(0x00100073u), MASK_FULL, RV64_FMT_SYSTEM, 0, - 0, {0}}, + 0, + {0}}, /* ================================================================= * Zicsr (CSR access) — RV_SYSTEM with funct3 ∈ {1..3, 5..7}. @@ -367,16 +430,41 @@ const Rv64InsnDesc rv64_insn_table[] = { {MN("rem"), MATCH_R(0x01, 0x6, RV_OP), MASK_R, RV64_FMT_R, 0, 0, {0}}, {MN("remu"), MATCH_R(0x01, 0x7, RV_OP), MASK_R, RV64_FMT_R, 0, 0, {0}}, /* W-form multiply/divide — OP_32 major opcode, RV64-only. */ - {MN("mulw"), MATCH_R(0x01, 0x0, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("divw"), MATCH_R(0x01, 0x4, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("divuw"), MATCH_R(0x01, 0x5, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("remw"), MATCH_R(0x01, 0x6, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, - {MN("remuw"), MATCH_R(0x01, 0x7, RV_OP_32), MASK_R, RV64_FMT_R, 0, - RV_AV_RV64, {0}}, + {MN("mulw"), + MATCH_R(0x01, 0x0, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("divw"), + MATCH_R(0x01, 0x4, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("divuw"), + MATCH_R(0x01, 0x5, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("remw"), + MATCH_R(0x01, 0x6, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, + {MN("remuw"), + MATCH_R(0x01, 0x7, RV_OP_32), + MASK_R, + RV64_FMT_R, + 0, + RV_AV_RV64, + {0}}, /* ================================================================= * RV32F / RV32D — single and double precision FP @@ -387,49 +475,57 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmsub.s"), MATCH_R4(RV_FMT_S, RV_MSUB), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fnmsub.s"), MATCH_R4(RV_FMT_S, RV_NMSUB), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fnmadd.s"), MATCH_R4(RV_FMT_S, RV_NMADD), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmadd.d"), MATCH_R4(RV_FMT_D, RV_MADD), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmsub.d"), MATCH_R4(RV_FMT_D, RV_MSUB), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fnmsub.d"), MATCH_R4(RV_FMT_D, RV_NMSUB), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fnmadd.d"), MATCH_R4(RV_FMT_D, RV_NMADD), MASK_R4, RV64_FMT_R4, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, /* FP arithmetic — rm field (funct3) is the rounding mode and prints * as the DYN(=7) default suppressed. funct7 low bits select fmt. */ @@ -438,49 +534,57 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fsub.s"), MATCH_FP_RM(0x04, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmul.s"), MATCH_FP_RM(0x08, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fdiv.s"), MATCH_FP_RM(0x0c, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fadd.d"), MATCH_FP_RM(0x01, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fsub.d"), MATCH_FP_RM(0x05, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmul.d"), MATCH_FP_RM(0x09, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fdiv.d"), MATCH_FP_RM(0x0d, RV_OP_FP), MASK_FP_RM, RV64_FMT_FP_RM, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, /* FP sqrt — funct7 = 0x2c (S) / 0x2d (D), rs2 must be 0. */ {MN("fsqrt.s"), @@ -488,13 +592,15 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fsqrt.d"), MATCH_FP_CVT(0x2d, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, /* FP min/max — funct7 = 0x14/0x15, funct3 = 0 (min) / 1 (max). */ {MN("fmin.s"), @@ -502,25 +608,29 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fmax.s"), MATCH_FP_R(0x14, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fmin.d"), MATCH_FP_R(0x15, 0x0, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fmax.d"), MATCH_FP_R(0x15, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, /* FP sign-injection — funct7 = 0x10/0x11, funct3 = 0/1/2 = J/JN/JX. */ {MN("fsgnj.s"), @@ -528,37 +638,43 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fsgnjn.s"), MATCH_FP_R(0x10, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fsgnjx.s"), MATCH_FP_R(0x10, 0x2, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fsgnj.d"), MATCH_FP_R(0x11, 0x0, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fsgnjn.d"), MATCH_FP_R(0x11, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fsgnjx.d"), MATCH_FP_R(0x11, 0x2, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_FP | RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, /* FP compare — funct7 = 0x50 (S) / 0x51 (D), funct3 = 0/1/2 = LE/LT/EQ. * rd is integer GPR (not FP). */ @@ -567,37 +683,43 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("flt.s"), MATCH_FP_R(0x50, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("feq.s"), MATCH_FP_R(0x50, 0x2, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("fle.d"), MATCH_FP_R(0x51, 0x0, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("flt.d"), MATCH_FP_R(0x51, 0x1, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, {MN("feq.d"), MATCH_FP_R(0x51, 0x2, RV_OP_FP), MASK_FP_R, RV64_FMT_FP_R, RV64_ASMFL_NORM, - 0, {0}}, + 0, + {0}}, /* FP classification — rd is GPR, rs1 is FPR, rs2=0, rm/funct3=1. */ {MN("fclass.s"), @@ -605,13 +727,15 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_CVT | (7u << 12), RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fclass.d"), MATCH_FP_R(0x71, 0x1, RV_OP_FP) | (0u << 20), MASK_FP_CVT | (7u << 12), RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, /* FP conversions — funct7 selects {direction, fmt}, rs2 selects * integer width/signedness. */ @@ -620,109 +744,127 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fcvt.wu.s"), MATCH_FP_CVT(0x60, 0x1, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fcvt.l.s"), MATCH_FP_CVT(0x60, 0x2, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - RV_AV_RV64, {0}}, /* 64-bit int dest needs 64-bit GPR */ + RV_AV_RV64, + {0}}, /* 64-bit int dest needs 64-bit GPR */ {MN("fcvt.lu.s"), MATCH_FP_CVT(0x60, 0x3, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.w.d"), MATCH_FP_CVT(0x61, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fcvt.wu.d"), MATCH_FP_CVT(0x61, 0x1, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fcvt.l.d"), MATCH_FP_CVT(0x61, 0x2, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.lu.d"), MATCH_FP_CVT(0x61, 0x3, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.s.w"), MATCH_FP_CVT(0x68, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fcvt.s.wu"), MATCH_FP_CVT(0x68, 0x1, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fcvt.s.l"), MATCH_FP_CVT(0x68, 0x2, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.s.lu"), MATCH_FP_CVT(0x68, 0x3, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.d.w"), MATCH_FP_CVT(0x69, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fcvt.d.wu"), MATCH_FP_CVT(0x69, 0x1, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fcvt.d.l"), MATCH_FP_CVT(0x69, 0x2, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.d.lu"), MATCH_FP_CVT(0x69, 0x3, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("fcvt.s.d"), MATCH_FP_CVT(0x20, 0x1, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fcvt.d.s"), MATCH_FP_CVT(0x21, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, /* FP bitcast moves — funct7 + rs2=0 + funct3=0 fixed. */ {MN("fmv.x.w"), @@ -730,25 +872,29 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - 0, {0}}, + 0, + {0}}, {MN("fmv.w.x"), MATCH_FP_CVT(0x78, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fmv.x.d"), MATCH_FP_CVT(0x71, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, 0, - RV_AV_RV64, {0}}, /* moves a 64-bit double through a GPR */ + RV_AV_RV64, + {0}}, /* moves a 64-bit double through a GPR */ {MN("fmv.d.x"), MATCH_FP_CVT(0x79, 0x0, RV_OP_FP), MASK_FP_CVT, RV64_FMT_FP_CVT, RV64_ASMFL_FP, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, /* FP load/store */ {MN("flw"), @@ -756,25 +902,29 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_I, RV64_FMT_FP_LOAD, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fld"), MATCH_I(0x3, RV_LOAD_FP), MASK_I, RV64_FMT_FP_LOAD, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fsw"), MATCH_S(0x2, RV_STORE_FP), MASK_S, RV64_FMT_FP_STORE, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("fsd"), MATCH_S(0x3, RV_STORE_FP), MASK_S, RV64_FMT_FP_STORE, RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, /* ================================================================= * RV64A (atomic) — AMO funct5 + funct3 (W=2, D=3). aq/rl vary, so @@ -787,73 +937,85 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - 0, {0}}, + 0, + {0}}, {MN("lr.w.rl"), MATCH_AMO_ORDER(0x02, 0, 1, 0x2, RV_AMO), MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - 0, {0}}, + 0, + {0}}, {MN("lr.w.aqrl"), MATCH_AMO_ORDER(0x02, 1, 1, 0x2, RV_AMO), MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - 0, {0}}, + 0, + {0}}, {MN("lr.d.aq"), MATCH_AMO_ORDER(0x02, 1, 0, 0x3, RV_AMO), MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("lr.d.rl"), MATCH_AMO_ORDER(0x02, 0, 1, 0x3, RV_AMO), MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("lr.d.aqrl"), MATCH_AMO_ORDER(0x02, 1, 1, 0x3, RV_AMO), MASK_AMO_ORDER | (0x1fu << 20), RV64_FMT_LR, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("sc.w.aq"), MATCH_AMO_ORDER(0x03, 1, 0, 0x2, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("sc.w.rl"), MATCH_AMO_ORDER(0x03, 0, 1, 0x2, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("sc.w.aqrl"), MATCH_AMO_ORDER(0x03, 1, 1, 0x2, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("sc.d.aq"), MATCH_AMO_ORDER(0x03, 1, 0, 0x3, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("sc.d.rl"), MATCH_AMO_ORDER(0x03, 0, 1, 0x3, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("sc.d.aqrl"), MATCH_AMO_ORDER(0x03, 1, 1, 0x3, RV_AMO), MASK_AMO_ORDER, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, /* `av` tags the doubleword (.d) atomics RV_AV_RV64 (RV64-only); word (.w) * forms pass 0 (BOTH). The av byte sits between flags and pad[1]. */ #define RV64_AMO_ORDER_ROWS(mn, f5, f3, av) \ @@ -862,13 +1024,15 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_AMO_ORDER, \ RV64_FMT_AMO, \ 0, \ - (av), {0}}, \ + (av), \ + {0}}, \ {MN(mn ".rl"), \ MATCH_AMO_ORDER(f5, 0, 1, f3, RV_AMO), \ MASK_AMO_ORDER, \ RV64_FMT_AMO, \ 0, \ - (av), {0}}, \ + (av), \ + {0}}, \ { \ MN(mn ".aqrl"), MATCH_AMO_ORDER(f5, 1, 1, f3, RV_AMO), MASK_AMO_ORDER, \ RV64_FMT_AMO, 0, (av), {0} \ @@ -896,133 +1060,155 @@ const Rv64InsnDesc rv64_insn_table[] = { MASK_AMO | (0x1fu << 20), RV64_FMT_LR, 0, - 0, {0}}, + 0, + {0}}, {MN("lr.d"), MATCH_AMO(0x02, 0x3, RV_AMO), MASK_AMO | (0x1fu << 20), RV64_FMT_LR, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("sc.w"), MATCH_AMO(0x03, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("sc.d"), MATCH_AMO(0x03, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amoswap.w"), MATCH_AMO(RV_AMO_SWAP, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amoadd.w"), MATCH_AMO(RV_AMO_ADD, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amoxor.w"), MATCH_AMO(RV_AMO_XOR, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amoand.w"), MATCH_AMO(RV_AMO_AND, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amoor.w"), MATCH_AMO(RV_AMO_OR, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amomin.w"), MATCH_AMO(RV_AMO_MIN, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amomax.w"), MATCH_AMO(RV_AMO_MAX, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amominu.w"), MATCH_AMO(RV_AMO_MINU, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amomaxu.w"), MATCH_AMO(RV_AMO_MAXU, 0x2, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - 0, {0}}, + 0, + {0}}, {MN("amoswap.d"), MATCH_AMO(RV_AMO_SWAP, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amoadd.d"), MATCH_AMO(RV_AMO_ADD, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amoxor.d"), MATCH_AMO(RV_AMO_XOR, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amoand.d"), MATCH_AMO(RV_AMO_AND, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amoor.d"), MATCH_AMO(RV_AMO_OR, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amomin.d"), MATCH_AMO(RV_AMO_MIN, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amomax.d"), MATCH_AMO(RV_AMO_MAX, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amominu.d"), MATCH_AMO(RV_AMO_MINU, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, {MN("amomaxu.d"), MATCH_AMO(RV_AMO_MAXU, 0x3, RV_AMO), MASK_AMO, RV64_FMT_AMO, 0, - RV_AV_RV64, {0}}, + RV_AV_RV64, + {0}}, /* ================================================================= * RV64C compressed — assembler rows. The disassembler uses the @@ -1037,62 +1223,116 @@ const Rv64InsnDesc rv64_insn_table[] = { {MN("c.li"), 0x4001u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, {MN("c.addi"), 0x0001u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, /* q1/f3=001: c.addiw on rv64, but the SAME encoding is c.jal on rv32. */ - {MN("c.addiw"), 0x2001u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.jal"), 0x2001u, 0xe003u, RV64_FMT_CJ, RV64_ASMFL_C16, - RV_AV_RV32, {0}}, + {MN("c.addiw"), + 0x2001u, + 0xe003u, + RV64_FMT_CI, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.jal"), + 0x2001u, + 0xe003u, + RV64_FMT_CJ, + RV64_ASMFL_C16, + RV_AV_RV32, + {0}}, {MN("c.slli"), 0x0002u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, {MN("c.lui"), 0x6001u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, {MN("c.addi16sp"), 0x6101u, 0xef83u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, {MN("c.lwsp"), 0x4002u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, 0, {0}}, /* q2/f3=011: c.ldsp on rv64, c.flwsp on rv32 (same encoding). */ - {MN("c.ldsp"), 0x6002u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.flwsp"), 0x6002u, 0xe003u, RV64_FMT_CI, - RV64_ASMFL_C16 | RV64_ASMFL_FP, RV_AV_RV32, {0}}, + {MN("c.ldsp"), + 0x6002u, + 0xe003u, + RV64_FMT_CI, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.flwsp"), + 0x6002u, + 0xe003u, + RV64_FMT_CI, + RV64_ASMFL_C16 | RV64_ASMFL_FP, + RV_AV_RV32, + {0}}, {MN("c.fldsp"), 0x2002u, 0xe003u, RV64_FMT_CI, RV64_ASMFL_C16 | RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("c.swsp"), 0xc002u, 0xe003u, RV64_FMT_CSS, RV64_ASMFL_C16, 0, {0}}, /* q2/f3=111: c.sdsp on rv64, c.fswsp on rv32 (same encoding). */ - {MN("c.sdsp"), 0xe002u, 0xe003u, RV64_FMT_CSS, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.fswsp"), 0xe002u, 0xe003u, RV64_FMT_CSS, - RV64_ASMFL_C16 | RV64_ASMFL_FP, RV_AV_RV32, {0}}, + {MN("c.sdsp"), + 0xe002u, + 0xe003u, + RV64_FMT_CSS, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.fswsp"), + 0xe002u, + 0xe003u, + RV64_FMT_CSS, + RV64_ASMFL_C16 | RV64_ASMFL_FP, + RV_AV_RV32, + {0}}, {MN("c.fsdsp"), 0xa002u, 0xe003u, RV64_FMT_CSS, RV64_ASMFL_C16 | RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("c.addi4spn"), 0x0000u, 0xe003u, RV64_FMT_CIW, RV64_ASMFL_C16, 0, {0}}, {MN("c.lw"), 0x4000u, 0xe003u, RV64_FMT_CL, RV64_ASMFL_C16, 0, {0}}, /* q0/f3=011: c.ld on rv64, c.flw on rv32 (same encoding). */ - {MN("c.ld"), 0x6000u, 0xe003u, RV64_FMT_CL, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.flw"), 0x6000u, 0xe003u, RV64_FMT_CL, - RV64_ASMFL_C16 | RV64_ASMFL_FP, RV_AV_RV32, {0}}, + {MN("c.ld"), + 0x6000u, + 0xe003u, + RV64_FMT_CL, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.flw"), + 0x6000u, + 0xe003u, + RV64_FMT_CL, + RV64_ASMFL_C16 | RV64_ASMFL_FP, + RV_AV_RV32, + {0}}, {MN("c.fld"), 0x2000u, 0xe003u, RV64_FMT_CL, RV64_ASMFL_C16 | RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("c.sw"), 0xc000u, 0xe003u, RV64_FMT_CS, RV64_ASMFL_C16, 0, {0}}, /* q0/f3=111: c.sd on rv64, c.fsw on rv32 (same encoding). */ - {MN("c.sd"), 0xe000u, 0xe003u, RV64_FMT_CS, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.fsw"), 0xe000u, 0xe003u, RV64_FMT_CS, - RV64_ASMFL_C16 | RV64_ASMFL_FP, RV_AV_RV32, {0}}, + {MN("c.sd"), + 0xe000u, + 0xe003u, + RV64_FMT_CS, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.fsw"), + 0xe000u, + 0xe003u, + RV64_FMT_CS, + RV64_ASMFL_C16 | RV64_ASMFL_FP, + RV_AV_RV32, + {0}}, {MN("c.fsd"), 0xa000u, 0xe003u, RV64_FMT_CS, RV64_ASMFL_C16 | RV64_ASMFL_FP, - 0, {0}}, + 0, + {0}}, {MN("c.srli"), 0x8001u, 0xec03u, RV64_FMT_CB, RV64_ASMFL_C16, 0, {0}}, {MN("c.srai"), 0x8401u, 0xec03u, RV64_FMT_CB, RV64_ASMFL_C16, 0, {0}}, {MN("c.andi"), 0x8801u, 0xec03u, RV64_FMT_CB, RV64_ASMFL_C16, 0, {0}}, @@ -1101,10 +1341,20 @@ const Rv64InsnDesc rv64_insn_table[] = { {MN("c.or"), 0x8c41u, 0xfc63u, RV64_FMT_CA, RV64_ASMFL_C16, 0, {0}}, {MN("c.and"), 0x8c61u, 0xfc63u, RV64_FMT_CA, RV64_ASMFL_C16, 0, {0}}, /* c.subw/c.addw are RV64-only (their CA slot is reserved on rv32). */ - {MN("c.subw"), 0x9c01u, 0xfc63u, RV64_FMT_CA, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, - {MN("c.addw"), 0x9c21u, 0xfc63u, RV64_FMT_CA, RV64_ASMFL_C16, - RV_AV_RV64, {0}}, + {MN("c.subw"), + 0x9c01u, + 0xfc63u, + RV64_FMT_CA, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, + {MN("c.addw"), + 0x9c21u, + 0xfc63u, + RV64_FMT_CA, + RV64_ASMFL_C16, + RV_AV_RV64, + {0}}, {MN("c.j"), 0xa001u, 0xe003u, RV64_FMT_CJ, RV64_ASMFL_C16, 0, {0}}, {MN("c.beqz"), 0xc001u, 0xe003u, RV64_FMT_CB, RV64_ASMFL_C16, 0, {0}}, {MN("c.bnez"), 0xe001u, 0xe003u, RV64_FMT_CB, RV64_ASMFL_C16, 0, {0}}, @@ -1119,12 +1369,12 @@ const u32 rv64_insn_table_n = * still accepted) and by the disassembler to print CSRs symbolically. The * table round-trips: each number maps to exactly one canonical name. */ const Rv64CsrName rv64_csr_names[] = { - {"fflags", 0x001}, {"frm", 0x002}, {"fcsr", 0x003}, - {"cycle", 0xC00}, {"time", 0xC01}, {"instret", 0xC02}, - {"mstatus", 0x300}, {"misa", 0x301}, {"mie", 0x304}, - {"mtvec", 0x305}, {"mscratch", 0x340}, {"mepc", 0x341}, - {"mcause", 0x342}, {"mtval", 0x343}, {"mip", 0x344}, - {"mvendorid", 0xF11}, {"marchid", 0xF12}, {"mimpid", 0xF13}, + {"fflags", 0x001}, {"frm", 0x002}, {"fcsr", 0x003}, + {"cycle", 0xC00}, {"time", 0xC01}, {"instret", 0xC02}, + {"mstatus", 0x300}, {"misa", 0x301}, {"mie", 0x304}, + {"mtvec", 0x305}, {"mscratch", 0x340}, {"mepc", 0x341}, + {"mcause", 0x342}, {"mtval", 0x343}, {"mip", 0x344}, + {"mvendorid", 0xF11}, {"marchid", 0xF12}, {"mimpid", 0xF13}, {"mhartid", 0xF14}, }; const u32 rv64_csr_names_n = @@ -1238,7 +1488,8 @@ const Rv64InsnDesc* rv64_disasm_find_c(u32 word, u8 av_wanted, bool rv32 = (av_wanted & RV_AV_RV32) != 0u; if (idx) return &rv64_c_table[idx]; /* Pattern-match remaining common C-instructions. We synthesize into the - * caller-owned scratch descriptor that the printer interprets by funct3+op. */ + * caller-owned scratch descriptor that the printer interprets by funct3+op. + */ u32 op = hw & 0x3u; u32 f3 = (hw >> 13) & 0x7u; if (op == 3u) return NULL; /* uncompressed */ @@ -1249,9 +1500,8 @@ const Rv64InsnDesc* rv64_disasm_find_c(u32 word, u8 av_wanted, u32 rd_rs1 = (hw >> 7) & 0x1fu; u32 rs2 = (hw >> 2) & 0x1fu; if (funct4 == 0x8u) { - const Rv64InsnDesc* d = - rv64c_mk(scratch, hw, rs2 == 0 ? "c.jr" : "c.mv", RV64_FMT_CR, - RV64_ASMFL_C16); + const Rv64InsnDesc* d = rv64c_mk(scratch, hw, rs2 == 0 ? "c.jr" : "c.mv", + RV64_FMT_CR, RV64_ASMFL_C16); return rd_rs1 == 0 ? NULL : d; } if (funct4 == 0x9u) { @@ -1275,8 +1525,8 @@ const Rv64InsnDesc* rv64_disasm_find_c(u32 word, u8 av_wanted, return rv64c_mk(scratch, hw, "c.addi", RV64_FMT_CI, RV64_ASMFL_C16); if (op == 1u && f3 == 3u) { u32 rd = (hw >> 7) & 0x1fu; - return rv64c_mk(scratch, hw, rd == 2u ? "c.addi16sp" : "c.lui", - RV64_FMT_CI, RV64_ASMFL_C16); + return rv64c_mk(scratch, hw, rd == 2u ? "c.addi16sp" : "c.lui", RV64_FMT_CI, + RV64_ASMFL_C16); } if (op == 1u && f3 == 4u) { u32 top = (hw >> 10) & 0x3u; diff --git a/src/arch/riscv/native.c b/src/arch/riscv/native.c @@ -4071,8 +4071,8 @@ static void rv_asm_hook_run_template(NativeDirectTarget* d, const char* tmpl, const AsmConstraint* outs, u32 nout, Operand* bound_outs, const AsmConstraint* ins, u32 nin, - Operand* bound_ins, - const Sym* clobbers, u32 nclob) { + Operand* bound_ins, const Sym* clobbers, + u32 nclob) { Rv64Asm* asmh = rv64_asm_open(d->base.c); rv64_inline_bind(asmh, outs, nout, bound_outs, ins, nin, bound_ins, clobbers, nclob); diff --git a/src/arch/riscv/reloc.c b/src/arch/riscv/reloc.c @@ -293,7 +293,8 @@ void rv_jit_tls_le_relax(Compiler* c, RelocKind k, u8* site, u64 storage, if ((rd_u32_le(site) & 0x7fu) != 0x37u) /* lui */ compiler_panic(c, SRCLOC_NONE, "riscv jit tls: unexpected access sequence"); add_w = rd_u32_le(add); - if ((add_w & 0x7fu) != 0x33u || ((add_w >> 15) & 0x1fu) != 4u) /* add ?,tp,? */ + if ((add_w & 0x7fu) != 0x33u || + ((add_w >> 15) & 0x1fu) != 4u) /* add ?,tp,? */ compiler_panic(c, SRCLOC_NONE, "riscv jit tls: unexpected access sequence"); rd_tmp = (rd_u32_le(site) >> 7) & 0x1fu; disp = (i64)storage - (i64)site_pc; @@ -301,7 +302,7 @@ void rv_jit_tls_le_relax(Compiler* c, RelocKind k, u8* site, u64 storage, if (lo12 & 0x800) lo12 -= 0x1000; /* sign-extend 12-bit */ hi20 = (u32)(((disp - (i64)lo12) >> 12) & 0xfffffu); wr_u32_le(site, 0x00000017u | (rd_tmp << 7) | (hi20 << 12)); /* auipc */ - wr_u32_le(add, 0x00000013u); /* nop */ + wr_u32_le(add, 0x00000013u); /* nop */ addi_w = rd_u32_le(addi); wr_u32_le(addi, (addi_w & 0x000fffffu) | (((u32)lo12 & 0xfffu) << 20)); } diff --git a/src/arch/wasm/disasm.c b/src/arch/wasm/disasm.c @@ -75,7 +75,8 @@ static const char* valtype_name(i64 b) { * shared operand class from WASM_INSN_TABLE rather than re-listing kinds. */ static void render_operands(WasmDisasm* d, const WasmInsn* in) { const WasmInsnInfo* info = wasm_insn_info((WasmInsnKind)in->kind); - WasmOperandClass oc = info ? (WasmOperandClass)info->operand_class : WASM_OC_NONE; + WasmOperandClass oc = + info ? (WasmOperandClass)info->operand_class : WASM_OC_NONE; switch (oc) { case WASM_OC_SLEB: strbuf_put_i64(&d->ops, in->imm); diff --git a/src/arch/wasm/ir_emit.c b/src/arch/wasm/ir_emit.c @@ -358,9 +358,8 @@ static void wasm_ir_emit_call(WasmIrEmitter* e, const CgIrInst* in) { } d.args = args; if (src->result != CG_LOCAL_NONE) { - d.ret = - wasm_ir_abi_value(e, src->result, ret_type, abi ? &abi->ret : NULL, - abi && abi->has_sret, 0, in->loc); + d.ret = wasm_ir_abi_value(e, src->result, ret_type, abi ? &abi->ret : NULL, + abi && abi->has_sret, 0, in->loc); } wasm_call((CGTarget*)&e->target->base, &d); if (args) h->free(h, args, sizeof(*args) * src->nargs); diff --git a/src/arch/x64/native.c b/src/arch/x64/native.c @@ -1836,22 +1836,18 @@ static void x64_reserve_callee_saves(NativeTarget* t, const u32* used, static int x64_reg_is_callee_int(const X64ABIRegs* abi, Reg r); static int x64_reg_is_callee_fp(const X64ABIRegs* abi, Reg r); -static u32 x64_live_callee_saved_mask(NativeTarget* t, - NativeAllocClass cls) { +static u32 x64_live_callee_saved_mask(NativeTarget* t, NativeAllocClass cls) { X64NativeTarget* a = x64_of(t); const X64ABIRegs* abi = a->abi ? a->abi : x64_abi_for_os(t->c->target.os); u32 mask = 0; for (Reg r = 0; r < 16u; ++r) { - if (cls == NATIVE_REG_INT && x64_reg_is_callee_int(abi, r)) - mask |= 1u << r; - if (cls == NATIVE_REG_FP && x64_reg_is_callee_fp(abi, r)) - mask |= 1u << r; + if (cls == NATIVE_REG_INT && x64_reg_is_callee_int(abi, r)) mask |= 1u << r; + if (cls == NATIVE_REG_FP && x64_reg_is_callee_fp(abi, r)) mask |= 1u << r; } return mask; } -static u32 x64_live_caller_saved_mask(NativeTarget* t, - NativeAllocClass cls) { +static u32 x64_live_caller_saved_mask(NativeTarget* t, NativeAllocClass cls) { const NativeAllocClassInfo* ci = native_target_class_info(t, cls); if (!ci) return 0; return ci->caller_saved_mask & ~x64_live_callee_saved_mask(t, cls); @@ -2728,8 +2724,8 @@ static void x64_emit_call(NativeTarget* t, const NativeCallPlan* plan) { } static void x64_plan_ret(NativeTarget* t, const CGFuncDesc* fd, - const NativeLoc* value, - NativeCallPlanRet** out_rets, u32* out_nrets) { + const NativeLoc* value, NativeCallPlanRet** out_rets, + u32* out_nrets) { X64NativeTarget* a = x64_of(t); const ABIFuncInfo* abi = abi_cg_func_info(t->c->abi, fd->fn_type); NativeCallPlanRet* rets = NULL; @@ -3436,14 +3432,14 @@ static void x64_intrinsic(NativeTarget* t, IntrinKind kind, return; case INTRIN_SYSCALL: if (ndst == 1u && narg >= 1u && narg <= 7u) { - static const u32 syscall_regs[7] = { - X64_RAX, X64_RDI, X64_RSI, X64_RDX, X64_R10, X64_R8, X64_R9}; + static const u32 syscall_regs[7] = {X64_RAX, X64_RDI, X64_RSI, X64_RDX, + X64_R10, X64_R8, X64_R9}; X64ArgMove moves[7]; for (u32 i = 0; i < narg; ++i) { X64ArgMove* m = &moves[i]; memset(m, 0, sizeof *m); - m->dst = native_loc_reg(dsts[0].type, NATIVE_REG_INT, - syscall_regs[i]); + m->dst = + native_loc_reg(dsts[0].type, NATIVE_REG_INT, syscall_regs[i]); m->src = args[i]; m->size = t->c->target.ptr_size; } @@ -4021,8 +4017,8 @@ static void x64_asm_block_native(NativeTarget* t, const char* tmpl, for (i = 0; i < nout; ++i) { KitCgTypeId type = outs[i].type ? outs[i].type : out_locs[i].type; NativeLoc outloc = out_locs[i]; - NativeAsmPinnedLoc pinned = - native_asm_prepare_pinned_loc(t, outs[i].reg, outs[i].str, type, outloc); + NativeAsmPinnedLoc pinned = native_asm_prepare_pinned_loc( + t, outs[i].reg, outs[i].str, type, outloc); if (pinned.has_pin) { if (pinned.pin_status != NATIVE_ASM_REG_PIN_OK) x64_asm_panic_at(c, loc, @@ -4067,7 +4063,8 @@ static void x64_asm_block_native(NativeTarget* t, const char* tmpl, x64_asm_load_loc_to_reg(a, loc, in_locs[i], inloc); } else if ((body[0] == 'r') && inloc.kind != NATIVE_LOC_REG) { Reg r; - if (ntmp >= 2u) x64_asm_panic_at(c, loc, "too many memory asm operands"); + if (ntmp >= 2u) + x64_asm_panic_at(c, loc, "too many memory asm operands"); r = (ntmp == 0u) ? (Reg)X64_TMP_INT : (Reg)X64_TMP_INT2; ntmp++; inloc = native_loc_reg(type, NATIVE_REG_INT, r); @@ -4093,7 +4090,7 @@ static void x64_asm_block_native(NativeTarget* t, const char* tmpl, if (!staged_outs || !staged_outs[i]) continue; if (bound_outs[i].kind != X64_INLINE_OPK_REG) continue; cls = bound_outs[i].pad[0] == X64_INLINE_OPCLS_FP ? NATIVE_REG_FP - : NATIVE_REG_INT; + : NATIVE_REG_INT; src = native_loc_reg(bound_outs[i].type, cls, (Reg)bound_outs[i].v.local); x64_asm_store_reg_to_loc(a, loc, out_locs[i], src); } @@ -4372,8 +4369,8 @@ static void x64_asm_hook_run_template(NativeDirectTarget* d, const char* tmpl, const AsmConstraint* outs, u32 nout, Operand* bound_outs, const AsmConstraint* ins, u32 nin, - Operand* bound_ins, - const Sym* clobbers, u32 nclob) { + Operand* bound_ins, const Sym* clobbers, + u32 nclob) { X64Asm* asmh = x64_asm_open(d->base.c); x64_inline_bind(asmh, outs, nout, bound_outs, ins, nin, bound_ins, clobbers, nclob); diff --git a/src/arch/x64/reloc.c b/src/arch/x64/reloc.c @@ -114,7 +114,7 @@ void x64_jit_tls_le_relax(Compiler* c, RelocKind k, u8* site, u64 storage, rd = ((u32)(mov[3] >> 3) & 7u) | ((mov[1] & 0x04u) ? 8u : 0u); for (p = mov; p < block_end; ++p) *p = 0x90u; /* nop the block */ lea = block_end - 7; - disp = (i64)storage - (i64)(site_pc + 4u); /* rip = end of lea */ + disp = (i64)storage - (i64)(site_pc + 4u); /* rip = end of lea */ lea[0] = (u8)(0x48u | ((rd >= 8u) ? 0x04u : 0x00u)); /* REX.W (+REX.R) */ lea[1] = 0x8Du; /* lea */ lea[2] = (u8)(((rd & 7u) << 3) | 5u); /* mod=00 reg=rd rm=101 (rip) */ diff --git a/src/asm/asm.c b/src/asm/asm.c @@ -900,7 +900,8 @@ static void do_directive(AsmDriver* d, Sym name) { * __TEXT,__eh_frame) fall back to SEC_OTHER. Flags are derived from the * resolved kind: every Mach-O section is allocated (so SEC_OTHER keeps * SF_ALLOC), and __TEXT,__cstring additionally carries SF_STRINGS. The - * comma name is preserved so the writer round-trips seg/sect verbatim. */ + * comma name is preserved so the writer round-trips seg/sect verbatim. + */ if (!obj_macho_seckind_for_secname(p, nn, &kind)) kind = SEC_OTHER; switch (kind) { case SEC_TEXT: diff --git a/src/cg/arith.c b/src/cg/arith.c @@ -502,7 +502,8 @@ static void api_wide64_binop_inline(KitCg* g, BinOp iop) { break; } default: - compiler_panic(g->c, g->cur_loc, "KitCg: unsupported wide i64 inline binop"); + compiler_panic(g->c, g->cur_loc, + "KitCg: unsupported wide i64 inline binop"); return; } api_wide8_store_lane(g, ar, lo, rlo); @@ -601,11 +602,13 @@ static void api_wide64_cmp_inline(KitCg* g, CmpOp cop) { break; case CMP_LE_S: case CMP_LE_U: /* a<=b == !(b<a) */ - res = wide8_i32_binop(g, BO_XOR, wide8_lt(g, sg, blo, bhi, alo, ahi), one); + res = + wide8_i32_binop(g, BO_XOR, wide8_lt(g, sg, blo, bhi, alo, ahi), one); break; case CMP_GE_S: case CMP_GE_U: /* a>=b == !(a<b) */ - res = wide8_i32_binop(g, BO_XOR, wide8_lt(g, sg, alo, ahi, blo, bhi), one); + res = + wide8_i32_binop(g, BO_XOR, wide8_lt(g, sg, alo, ahi, blo, bhi), one); break; default: compiler_panic(g->c, g->cur_loc, "KitCg: unsupported wide i64 compare"); @@ -645,7 +648,8 @@ static void wide8_umul32(KitCg* g, Operand a, Operand b, Operand* plo, Operand ah = wide8_i32_binop(g, BO_SHR_U, a, sh16); Operand bl = wide8_i32_binop(g, BO_AND, b, mask); Operand bh = wide8_i32_binop(g, BO_SHR_U, b, sh16); - Operand ll = wide8_i32_binop(g, BO_IMUL, al, bl); /* bits 0..31 (<=32 bits) */ + Operand ll = + wide8_i32_binop(g, BO_IMUL, al, bl); /* bits 0..31 (<=32 bits) */ Operand lh = wide8_i32_binop(g, BO_IMUL, al, bh); /* bits 16..47 */ Operand hl = wide8_i32_binop(g, BO_IMUL, ah, bl); /* bits 16..47 */ Operand hh = wide8_i32_binop(g, BO_IMUL, ah, bh); /* bits 32..63 */ @@ -710,8 +714,9 @@ static void api_wide64_overflow_inline(KitCg* g, KitCgIntrinsic intrin) { rlo = wide8_i32_binop(g, BO_IADD, alo, blo); carry = wide8_i32_cmp(g, CMP_LT_U, rlo, alo); rhi = wide8_i32_binop(g, BO_IADD, ahi, bhi); - /* carry-out of the high lane = (rhi<ahi) before +carry, OR wrap on +carry. - * Compute rhi step by step so we can detect the final carry-out. */ + /* carry-out of the high lane = (rhi<ahi) before +carry, OR wrap on + * +carry. Compute rhi step by step so we can detect the final carry-out. + */ Operand c_hi0 = wide8_i32_cmp(g, CMP_LT_U, rhi, ahi); rhi = wide8_i32_binop(g, BO_IADD, rhi, carry); Operand c_hi1 = wide8_i32_cmp(g, CMP_LT_U, rhi, carry); @@ -927,7 +932,8 @@ int api_try_wide8_convert(KitCg* g, ConvKind ck, KitCgTypeId sty, Operand lolane = api_wide8_load_lane(g, addr, lo); api_release(g, v); api_push(g, api_make_sv(lolane, i32)); - if (api_unalias_type(g->c, dty) != i32) api_cg_convert_kind(g, dty, CV_TRUNC); + if (api_unalias_type(g->c, dty) != i32) + api_cg_convert_kind(g, dty, CV_TRUNC); return 1; } } @@ -1063,8 +1069,9 @@ void kit_cg_int_binop(KitCg* g, KitCgIntBinOp op, uint32_t flags) { } /* 64-bit int split into 32-bit lanes: mul/div/rem/shift become __*di3 * runtime calls; add/sub/and/or/xor are emitted inline as 2-word lane ops - * (no compiler-rt helper exists for them). Both keep the value memory-resident - * so the allocator never tries to put 8 bytes in one 4-byte value slot. */ + * (no compiler-rt helper exists for them). Both keep the value + * memory-resident so the allocator never tries to put 8 bytes in one 4-byte + * value slot. */ if (g && (api_wide64_stack_top(g, 0) || api_wide64_stack_top(g, 1))) { if (api_wideint64_binop_helper(iop)) api_wideint64_binop(g, iop); @@ -1205,7 +1212,8 @@ static int api_target_double_is_soft(KitCg* g) { } /* True when ty is a 64-bit float (double) AND the target lacks hardware double. - * f128 is handled by the separate api_f128_* path, so width must be exactly 64. */ + * f128 is handled by the separate api_f128_* path, so width must be exactly 64. + */ static int api_type_is_soft_double(KitCg* g, KitCgTypeId ty) { if (!api_target_double_is_soft(g)) return 0; return kit_cg_type_float_width((KitCompiler*)g->c, ty) == 64; @@ -1233,10 +1241,14 @@ static int api_soft_single_stack_top(KitCg* g, u32 depth) { * api_softdf_binop_helper with the __*sf3 names). */ static const char* api_softsf_binop_helper(KitCgFpBinOp op) { switch (op) { - case KIT_CG_FP_ADD: return "__addsf3"; - case KIT_CG_FP_SUB: return "__subsf3"; - case KIT_CG_FP_MUL: return "__mulsf3"; - case KIT_CG_FP_DIV: return "__divsf3"; + case KIT_CG_FP_ADD: + return "__addsf3"; + case KIT_CG_FP_SUB: + return "__subsf3"; + case KIT_CG_FP_MUL: + return "__mulsf3"; + case KIT_CG_FP_DIV: + return "__divsf3"; } return NULL; } @@ -1318,8 +1330,8 @@ void kit_cg_fp_unop(KitCg* g, KitCgFpUnOp op, uint32_t flags) { /* Soft-float single-libcall comparison: call `name(a,b)` (both operands of type * `opty`) and test its i32 three-way result against 0 with `icmp`. Consumes the * two operands on the stack and pushes the i32 boolean. Shared by the f128 (tf) - * and soft-double (df) paths — only the helper name and operand type differ; the - * compiler-rt NaN-sign convention is identical for both. */ + * and soft-double (df) paths — only the helper name and operand type differ; + * the compiler-rt NaN-sign convention is identical for both. */ static void api_softfp_cmp_call(KitCg* g, const char* name, KitCgTypeId opty, CmpOp icmp) { KitCgTypeId i32 = builtin_id(KIT_CG_BUILTIN_I32); @@ -1755,50 +1767,51 @@ static const IntrinDesc kIntrinTable[] = { [KIT_CG_INTRIN_BSWAP] = {INTRIN_BSWAP, "bswap", false, false}, [KIT_CG_INTRIN_SETJMP] = {INTRIN_SETJMP, "setjmp", false, false}, [KIT_CG_INTRIN_LONGJMP] = {INTRIN_LONGJMP, "longjmp", true, false}, - [KIT_CG_INTRIN_SADD_OVERFLOW] = - {INTRIN_SADD_OVERFLOW, "sadd_overflow", false, true}, - [KIT_CG_INTRIN_UADD_OVERFLOW] = - {INTRIN_UADD_OVERFLOW, "uadd_overflow", false, true}, - [KIT_CG_INTRIN_SSUB_OVERFLOW] = - {INTRIN_SSUB_OVERFLOW, "ssub_overflow", false, true}, - [KIT_CG_INTRIN_USUB_OVERFLOW] = - {INTRIN_USUB_OVERFLOW, "usub_overflow", false, true}, - [KIT_CG_INTRIN_SMUL_OVERFLOW] = - {INTRIN_SMUL_OVERFLOW, "smul_overflow", false, true}, - [KIT_CG_INTRIN_UMUL_OVERFLOW] = - {INTRIN_UMUL_OVERFLOW, "umul_overflow", false, true}, + [KIT_CG_INTRIN_SADD_OVERFLOW] = {INTRIN_SADD_OVERFLOW, "sadd_overflow", + false, true}, + [KIT_CG_INTRIN_UADD_OVERFLOW] = {INTRIN_UADD_OVERFLOW, "uadd_overflow", + false, true}, + [KIT_CG_INTRIN_SSUB_OVERFLOW] = {INTRIN_SSUB_OVERFLOW, "ssub_overflow", + false, true}, + [KIT_CG_INTRIN_USUB_OVERFLOW] = {INTRIN_USUB_OVERFLOW, "usub_overflow", + false, true}, + [KIT_CG_INTRIN_SMUL_OVERFLOW] = {INTRIN_SMUL_OVERFLOW, "smul_overflow", + false, true}, + [KIT_CG_INTRIN_UMUL_OVERFLOW] = {INTRIN_UMUL_OVERFLOW, "umul_overflow", + false, true}, [KIT_CG_INTRIN_FMA] = {INTRIN_NONE, "fma", false, false}, [KIT_CG_INTRIN_PREFETCH] = {INTRIN_PREFETCH, "prefetch", true, false}, [KIT_CG_INTRIN_EXPECT] = {INTRIN_EXPECT, "expect", false, false}, - [KIT_CG_INTRIN_ASSUME_ALIGNED] = - {INTRIN_ASSUME_ALIGNED, "assume_aligned", false, false}, + [KIT_CG_INTRIN_ASSUME_ALIGNED] = {INTRIN_ASSUME_ALIGNED, "assume_aligned", + false, false}, [KIT_CG_INTRIN_SYSCALL] = {INTRIN_SYSCALL, "syscall", false, false}, [KIT_CG_INTRIN_IRQ_SAVE] = {INTRIN_IRQ_SAVE, "irq_save", false, false}, - [KIT_CG_INTRIN_IRQ_RESTORE] = - {INTRIN_IRQ_RESTORE, "irq_restore", true, false}, - [KIT_CG_INTRIN_IRQ_DISABLE] = - {INTRIN_IRQ_DISABLE, "irq_disable", true, false}, + [KIT_CG_INTRIN_IRQ_RESTORE] = {INTRIN_IRQ_RESTORE, "irq_restore", true, + false}, + [KIT_CG_INTRIN_IRQ_DISABLE] = {INTRIN_IRQ_DISABLE, "irq_disable", true, + false}, [KIT_CG_INTRIN_IRQ_ENABLE] = {INTRIN_IRQ_ENABLE, "irq_enable", true, false}, [KIT_CG_INTRIN_DMB] = {INTRIN_DMB, "dmb", true, false}, [KIT_CG_INTRIN_DSB] = {INTRIN_DSB, "dsb", true, false}, [KIT_CG_INTRIN_ISB] = {INTRIN_ISB, "isb", true, false}, [KIT_CG_INTRIN_DCACHE_CLEAN] = {INTRIN_NONE, "dcache_clean", false, false}, - [KIT_CG_INTRIN_DCACHE_INVALIDATE] = - {INTRIN_NONE, "dcache_invalidate", false, false}, - [KIT_CG_INTRIN_DCACHE_CLEAN_INVALIDATE] = - {INTRIN_NONE, "dcache_clean_invalidate", false, false}, - [KIT_CG_INTRIN_ICACHE_INVALIDATE] = - {INTRIN_NONE, "icache_invalidate", false, false}, + [KIT_CG_INTRIN_DCACHE_INVALIDATE] = {INTRIN_NONE, "dcache_invalidate", + false, false}, + [KIT_CG_INTRIN_DCACHE_CLEAN_INVALIDATE] = {INTRIN_NONE, + "dcache_clean_invalidate", false, + false}, + [KIT_CG_INTRIN_ICACHE_INVALIDATE] = {INTRIN_NONE, "icache_invalidate", + false, false}, [KIT_CG_INTRIN_CPU_NOP] = {INTRIN_CPU_NOP, "cpu_nop", true, false}, [KIT_CG_INTRIN_CPU_YIELD] = {INTRIN_CPU_YIELD, "cpu_yield", true, false}, [KIT_CG_INTRIN_WFI] = {INTRIN_WFI, "wfi", true, false}, [KIT_CG_INTRIN_WFE] = {INTRIN_WFE, "wfe", true, false}, [KIT_CG_INTRIN_SEV] = {INTRIN_SEV, "sev", true, false}, [KIT_CG_INTRIN_CORO_SWITCH] = {INTRIN_NONE, "coro_switch", false, false}, - [KIT_CG_INTRIN_FRAME_ADDRESS] = - {INTRIN_FRAME_ADDRESS, "frame_address", false, false}, - [KIT_CG_INTRIN_RETURN_ADDRESS] = - {INTRIN_RETURN_ADDRESS, "return_address", false, false}, + [KIT_CG_INTRIN_FRAME_ADDRESS] = {INTRIN_FRAME_ADDRESS, "frame_address", + false, false}, + [KIT_CG_INTRIN_RETURN_ADDRESS] = {INTRIN_RETURN_ADDRESS, "return_address", + false, false}, }; _Static_assert(sizeof(kIntrinTable) / sizeof(kIntrinTable[0]) == @@ -1859,11 +1872,21 @@ void kit_cg_intrinsic(KitCg* g, KitCgIntrinsic intrin, uint32_t nargs, KitCgTypeId i64 = builtin_id(KIT_CG_BUILTIN_I64); KitCgTypeId ret = i32; switch (intrin) { - case KIT_CG_INTRIN_CLZ: name = "__clzdi2"; break; - case KIT_CG_INTRIN_CTZ: name = "__ctzdi2"; break; - case KIT_CG_INTRIN_POPCOUNT: name = "__popcountdi2"; break; - case KIT_CG_INTRIN_BSWAP: name = "__bswapdi2"; ret = i64; break; - default: break; + case KIT_CG_INTRIN_CLZ: + name = "__clzdi2"; + break; + case KIT_CG_INTRIN_CTZ: + name = "__ctzdi2"; + break; + case KIT_CG_INTRIN_POPCOUNT: + name = "__popcountdi2"; + break; + case KIT_CG_INTRIN_BSWAP: + name = "__bswapdi2"; + ret = i64; + break; + default: + break; } if (name) { ApiSValue arg = api_pop(g); diff --git a/src/cg/call.c b/src/cg/call.c @@ -198,7 +198,8 @@ void kit_cg_call(KitCg* g, uint32_t nargs, KitCgTypeId fn_type, emit_tail = want_tail ? api_tail_decide(g, &desc, attrs.tail) : 0; desc.flags = emit_tail ? CG_CALL_TAIL : CG_CALL_NONE; - result_type = emit_tail ? KIT_CG_TYPE_NONE : cg_type_func_result_id(g->c, fty); + result_type = + emit_tail ? KIT_CG_TYPE_NONE : cg_type_func_result_id(g->c, fty); if (result_type != KIT_CG_TYPE_NONE) desc.result = api_alloc_call_result(g, result_type); @@ -248,7 +249,8 @@ void api_call_symbol_common(KitCg* g, KitCgSym sym, uint32_t nargs, emit_tail = want_tail ? api_tail_decide(g, &desc, attrs.tail) : 0; desc.flags = emit_tail ? CG_CALL_TAIL : CG_CALL_NONE; - result_type = emit_tail ? KIT_CG_TYPE_NONE : cg_type_func_result_id(g->c, fty); + result_type = + emit_tail ? KIT_CG_TYPE_NONE : cg_type_func_result_id(g->c, fty); if (result_type != KIT_CG_TYPE_NONE) desc.result = api_alloc_call_result(g, result_type); api_finish_call(g, &desc, want_tail, emit_tail); diff --git a/src/cg/fold.c b/src/cg/fold.c @@ -32,8 +32,8 @@ int api_type_is_bool(Compiler* c, KitCgTypeId id) { return ty->kind == KIT_CG_TYPE_BOOL; } -/* The width-arithmetic core now lives in cg/ir_eval.{c,h} (shared with opt). The - * fold.h surface (still consumed by arith.c / control.c) stays as thin +/* The width-arithmetic core now lives in cg/ir_eval.{c,h} (shared with opt). + * The fold.h surface (still consumed by arith.c / control.c) stays as thin * delegators. */ u64 api_width_mask(u32 width) { return kit_ir_width_mask(width); } diff --git a/src/cg/internal.h b/src/cg/internal.h @@ -137,8 +137,8 @@ struct KitCg { KitCgUnitOptions cur_unit; u32 nsource_units; /* Monotonic, nonzero per source unit (set at kit_cg_begin_unit). Used to tell - * a same-TU re-definition (legal tentative-definition coalescing) apart from a - * genuine cross-TU contribution that must go through symresolve_merge. */ + * a same-TU re-definition (legal tentative-definition coalescing) apart from + * a genuine cross-TU contribution that must go through symresolve_merge. */ u32 cur_unit_seq; u8 unit_active; u8 finished; diff --git a/src/cg/memory.c b/src/cg/memory.c @@ -77,13 +77,11 @@ static int api_const_data_can_defer(const KitCg* g) { if (!g || g->opt_level < 1) return 0; if (g->fn_ret_type == KIT_CG_TYPE_NONE) return 0; if (g->data_sym != OBJ_SYM_NONE || g->data_sec != OBJ_SEC_NONE) return 0; - if (g->data_local_static_target || g->data_discard || - g->data_tls_collect) { + if (g->data_local_static_target || g->data_discard || g->data_tls_collect) { return 0; } return g->target && g->target->local_static_data_begin && - g->target->local_static_data_write && - g->target->local_static_data_end; + g->target->local_static_data_write && g->target->local_static_data_end; } static int api_const_data_emit_deferred(KitCg* g, ObjSymId sym, diff --git a/src/cg/native_asm.c b/src/cg/native_asm.c @@ -6,7 +6,7 @@ #include "cg/native_direct_target.h" /* NativeDirectTarget, for the direct binder */ #include "cg/type.h" /* builtin_id */ #include "core/arena.h" /* arena_zarray */ -#include "core/pool.h" /* pool_slice for native_asm_resolve_pin */ +#include "core/pool.h" /* pool_slice for native_asm_resolve_pin */ void native_file_scope_asm(NativeTarget* t, const char* src, size_t len) { AsmLexer* lex = asm_lex_open_mem(t->c, "<file-scope-asm>", src, len); @@ -286,8 +286,7 @@ void native_asm_bind_direct_operands(NativeDirectTarget* d, const char* tmpl, int matched = native_asm_match_index(body); KitCgTypeId type = ins[i].type ? ins[i].type : in_ops[i].type; if (matched >= 0) { - if ((u32)matched >= nout) - h->panic(d, "matching constraint out of range"); + if ((u32)matched >= nout) h->panic(d, "matching constraint out of range"); if (native_asm_constraint_early(outs[matched].str)) h->panic(d, "matching input names early-clobber output"); if (bound_outs[matched].kind != h->opk_reg) @@ -340,10 +339,9 @@ void native_asm_bind_direct_operands(NativeDirectTarget* d, const char* tmpl, NativeAllocClass cls = bound_outs[i].pad[0] == h->opcls_fp ? NATIVE_REG_FP : NATIVE_REG_INT; if (outs[i].dir == KIT_CG_ASM_INOUT) { - h->load_operand_to_reg( - d, out_ops[i], - native_loc_reg(bound_outs[i].type, cls, - (Reg)bound_outs[i].v.local)); + h->load_operand_to_reg(d, out_ops[i], + native_loc_reg(bound_outs[i].type, cls, + (Reg)bound_outs[i].v.local)); } } else if (bound_outs[i].kind == OPK_INDIRECT) { NativeLoc loc = diff --git a/src/cg/native_asm.h b/src/cg/native_asm.h @@ -101,8 +101,8 @@ int native_asm_constraint_reg_class(const char* constraint, * register outputs back. That orchestration is arch-neutral: it was a * ~170-line near-identical copy in each of the aa64/x64/rv64 backends. It lives * here as the single source of truth, parameterized over the genuinely - * arch-specific bits via NativeAsmDirectHooks; each backend's *_direct_asm_block - * is a thin wrapper that supplies the hooks. + * arch-specific bits via NativeAsmDirectHooks; each backend's + * *_direct_asm_block is a thin wrapper that supplies the hooks. * * The shared driver depends on NativeDirectTarget only through pointers, so the * full struct is needed at the call site (the .c includes it), not here. */ @@ -129,8 +129,8 @@ typedef struct NativeAsmDirectHooks { /* Pick a free register from the arch's allocable pool for cls, honoring * allowed_mask and the running used masks (which it updates). Panics on * exhaustion. */ - Reg (*alloc_reg)(NativeDirectTarget* d, NativeAllocClass cls, u32 allowed_mask, - u32* used_int, u32* used_fp); + Reg (*alloc_reg)(NativeDirectTarget* d, NativeAllocClass cls, + u32 allowed_mask, u32* used_int, u32* used_fp); /* Parse the asm clobber list into per-class register masks (arch register * naming). */ void (*clobber_masks)(Compiler* c, SrcLoc loc, const Sym* clobbers, u32 nclob, @@ -138,21 +138,21 @@ typedef struct NativeAsmDirectHooks { /* Spill the callee-saved registers the asm clobbers, returning an opaque, * block-lived save record plus its element count. restore_one undoes element * idx; the driver replays them in reverse. */ - void* (*save_callee_clobbers)(NativeDirectTarget* d, u32 int_mask, u32 fp_mask, - u32* nsaved_out); + void* (*save_callee_clobbers)(NativeDirectTarget* d, u32 int_mask, + u32 fp_mask, u32* nsaved_out); void (*restore_one)(NativeDirectTarget* d, void* saved, u32 idx); /* Load a semantic operand's value / address into a register, or store a * register back to a semantic operand. */ void (*load_operand_to_reg)(NativeDirectTarget* d, Operand op, NativeLoc dst); void (*load_address_to_reg)(NativeDirectTarget* d, Operand op, NativeLoc dst); - void (*store_reg_to_operand)(NativeDirectTarget* d, Operand op, NativeLoc src); + void (*store_reg_to_operand)(NativeDirectTarget* d, Operand op, + NativeLoc src); /* Open the arch asm assembler, bind the resolved operands, run the template, * and close — emitting the asm body into the target's MCEmitter. */ void (*run_template)(NativeDirectTarget* d, const char* tmpl, - const AsmConstraint* outs, u32 nout, - Operand* bound_outs, const AsmConstraint* ins, - u32 nin, Operand* bound_ins, const Sym* clobbers, - u32 nclob); + const AsmConstraint* outs, u32 nout, Operand* bound_outs, + const AsmConstraint* ins, u32 nin, Operand* bound_ins, + const Sym* clobbers, u32 nclob); } NativeAsmDirectHooks; /* Drive the arch-neutral direct inline-asm orchestration: out-loop / in-loop / diff --git a/src/cg/native_direct_target.c b/src/cg/native_direct_target.c @@ -1550,9 +1550,10 @@ static void nd_binop(CgTarget* t, BinOp op, Operand dst, Operand a, Operand b) { * slips through here would silently compute only the low word, so fail * loudly instead. */ if (nd_is_wide64_int(d, a.type) || nd_is_wide64_int(d, dst.type)) { - nd_panic(d, - "64-bit integer arithmetic reached the backend un-lowered " - "(cg should emit a 2-word lane sequence or a __*di3 runtime call)"); + nd_panic( + d, + "64-bit integer arithmetic reached the backend un-lowered " + "(cg should emit a 2-word lane sequence or a __*di3 runtime call)"); } if (nd_is_soft_double(d, a.type) || nd_is_soft_double(d, dst.type)) { nd_panic(d, @@ -1668,9 +1669,8 @@ static void nd_call(CgTarget* t, const CGCallDesc* desc) { nd.fn_type = desc->fn_type; nd.callee = nd_loc_operand(d, desc->callee); if (nd.callee.kind == NATIVE_LOC_FRAME) { - callee_tmp = nd_materialize_loc(d, nd.callee, - (NativeAllocClass)nd.callee.cls, - nd.callee.type); + callee_tmp = nd_materialize_loc( + d, nd.callee, (NativeAllocClass)nd.callee.cls, nd.callee.type); nd.callee = callee_tmp; release_callee_tmp = 1; } @@ -1701,8 +1701,7 @@ static void nd_call(CgTarget* t, const CGCallDesc* desc) { for (u32 i = 0; i < plan.nrets; ++i) nd_write_loc(d, plan.rets[i].dst, plan.rets[i].src, plan.rets[i].mem); if (release_callee_tmp) - nd_scratch_release(d, (NativeAllocClass)callee_tmp.cls, - callee_tmp.v.reg); + nd_scratch_release(d, (NativeAllocClass)callee_tmp.cls, callee_tmp.v.reg); } static const char* nd_tail_call_unrealizable_reason(CgTarget* t, @@ -2045,7 +2044,8 @@ CgTarget* native_direct_backend_make(Compiler* c, ObjBuilder* o, } CgTarget* native_direct_semantic_target_new(Compiler* c, ObjBuilder* o, - MCEmitter* mc, NativeTargetCtor ctor, + MCEmitter* mc, + NativeTargetCtor ctor, const NativeOps* ops) { NativeTarget* native; NativeDirectTargetConfig cfg; diff --git a/src/cg/native_direct_target.h b/src/cg/native_direct_target.h @@ -181,7 +181,8 @@ typedef NativeTarget* (*NativeTargetCtor)(Compiler*, ObjBuilder*, MCEmitter*); * Returns NULL on any failure. Each arch backend_make is exactly a call to * this with its own (ctor, ops). */ CgTarget* native_direct_backend_make(Compiler*, ObjBuilder*, - const KitCodeOptions*, NativeTargetCtor ctor, + const KitCodeOptions*, + NativeTargetCtor ctor, const NativeOps* ops); /* Shared glue for an ArchImpl's cgtarget_new hook (semantic/assembler path). @@ -192,13 +193,13 @@ CgTarget* native_direct_semantic_target_new(Compiler*, ObjBuilder*, MCEmitter*, NativeTargetCtor ctor, const NativeOps* ops); -/* Project a semantic CGCallDesc into a NativeCallDesc whose args/results are the - * callee's incoming frame slots (the layout a sibling/tail call must land in). - * `nd` is fully overwritten (memset to zero, then its args/results buffers are - * arena-allocated from d->locals[*].home). This is the arch-neutral core the - * per-arch tail_call_unrealizable_reason hooks share; each backend wraps it with - * its own eligibility guards and call_stack_size / incoming-window comparison. - * Leaves nd.callee / flags / tail_policy / inline_policy zeroed. */ +/* Project a semantic CGCallDesc into a NativeCallDesc whose args/results are + * the callee's incoming frame slots (the layout a sibling/tail call must land + * in). `nd` is fully overwritten (memset to zero, then its args/results buffers + * are arena-allocated from d->locals[*].home). This is the arch-neutral core + * the per-arch tail_call_unrealizable_reason hooks share; each backend wraps it + * with its own eligibility guards and call_stack_size / incoming-window + * comparison. Leaves nd.callee / flags / tail_policy / inline_policy zeroed. */ void native_direct_project_tail_call_desc(NativeDirectTarget* d, const CGCallDesc* call, NativeCallDesc* nd); diff --git a/src/debug/debug_emit.c b/src/debug/debug_emit.c @@ -32,7 +32,7 @@ void abbrev_fini_heap(DebugAbbrevPool* p, Heap* h); typedef struct StrTab { Buf buf; - SymToU32 by_sym; /* Sym → byte offset within buf */ + SymToU32 by_sym; /* Sym → byte offset within buf */ SymToU32 idx_by_sym; /* Sym → insertion index (== DW_FORM_strx value) */ /* Insertion order — used to populate .debug_str_offsets. */ Sym* syms; diff --git a/src/debug/debug_form.c b/src/debug/debug_form.c @@ -84,9 +84,10 @@ size_t form_sleb_size(i64 v) { return n; } -/* LEB128 encoders into a raw fixed-size buffer (vs the Buf* form_uleb/form_sleb), - * for expression-byte builders that stage into a stack array. Caller guarantees - * room (<=10 bytes for u64, <=10 for i64). Returns the number of bytes written. */ +/* LEB128 encoders into a raw fixed-size buffer (vs the Buf* + * form_uleb/form_sleb), for expression-byte builders that stage into a stack + * array. Caller guarantees room (<=10 bytes for u64, <=10 for i64). Returns the + * number of bytes written. */ u32 form_uleb_inline(u8* buf, u64 v) { u32 n = 0; for (;;) { diff --git a/src/dist/blob.c b/src/dist/blob.c @@ -20,7 +20,8 @@ void dist_blob_id(uint8_t out[DIST_BLAKE2B_LEN], const uint8_t* data, /* The flat blob id is plain BLAKE2b of the bytes: it doubles as the CAS * content id and the package format's tree-object hash (pkg_hash), so it * must stay un-prefixed. (Domain separation from tree ids was considered - * but would require coordinated changes across the whole .kpkg/CAS format.) */ + * but would require coordinated changes across the whole .kpkg/CAS format.) + */ dist_blake2b(out, data, len); } diff --git a/src/dist/cas.c b/src/dist/cas.c @@ -190,7 +190,6 @@ int dist_cas_get_tree(DistCas* cas, const uint8_t tree[DIST_BLAKE2B_LEN], return DIST_ERR; } - int dist_cas_materialize_tree(DistCas* cas, const DistTree* tree, const char* dst) { size_t i; diff --git a/src/emu/emu.c b/src/emu/emu.c @@ -295,7 +295,8 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) { if (resolved.os->emu_init_process_private && resolved.os->emu_init_process_private(c, &e->process) != KIT_OK) { - compiler_panic(c, SRCLOC_NONE, "emu: failed to initialize OS process state"); + compiler_panic(c, SRCLOC_NONE, + "emu: failed to initialize OS process state"); } if (resolved.os->emu_init_thread_private && resolved.os->emu_init_thread_private(c, &e->process, &e->main_thread) != @@ -339,7 +340,8 @@ KitStatus kit_emu_new(KitCompiler* c, const KitEmuOptions* opts, KitEmu** out) { KitInterpHost ihost; e->interp_prog = kit_interp_program_new((KitCompiler*)c); if (!e->interp_prog) - compiler_panic(c, SRCLOC_NONE, "emu: failed to create interpreter program"); + compiler_panic(c, SRCLOC_NONE, + "emu: failed to create interpreter program"); kit_interp_program_attach(e->interp_prog, (KitCompiler*)c); memset(&ihost, 0, sizeof(ihost)); ihost.resolve_sym = emu_runtime_extern_resolver; @@ -503,7 +505,8 @@ static void* translate_block(KitEmu* e, u64 guest_pc) { st = arch->emu->lift_block(e->c, cg, insts, ninsts, &ctx); heap->free(heap, insts, sizeof(*insts) * EMU_MAX_INSTS_PER_BLOCK); insts = NULL; - if (st != KIT_OK) compiler_panic(e->c, SRCLOC_NONE, "emu: failed to lift block"); + if (st != KIT_OK) + compiler_panic(e->c, SRCLOC_NONE, "emu: failed to lift block"); st = kit_cg_end_unit(cg); if (st == KIT_OK) st = kit_cg_finish(cg, NULL); diff --git a/src/emu/emu.h b/src/emu/emu.h @@ -447,8 +447,8 @@ typedef struct EmuLiftCtx { KitArchKind arch; KitCgTypeId thread_type; /* from emu_thread_type */ KitCgTypeId block_fn_type; /* from emu_block_fn_type */ - KitCgSym block_sym; /* function symbol for this block */ - u64 guest_pc; /* PC of first instruction in the block */ + KitCgSym block_sym; /* function symbol for this block */ + u64 guest_pc; /* PC of first instruction in the block */ } EmuLiftCtx; /* ---- Code cache ------------------------------------------------- */ diff --git a/src/interp/engine.c b/src/interp/engine.c @@ -794,7 +794,8 @@ static u64 ext_call(InterpStack* st, InterpFrame* fr, u64* regs, void* host_fp, u64 dst = op_addr(st, fr->fn, regs, fr->mem_off, &desc->ret.storage); u32 k; for (k = 0; k < fi->ret.nparts && k < 2u; ++k) - mem_write(st, dst + fi->ret.parts[k].src_offset, fa.ret_size[k], out[k]); + mem_write(st, dst + fi->ret.parts[k].src_offset, fa.ret_size[k], + out[k]); } return out[0]; } @@ -877,13 +878,13 @@ static u64 ext_call(InterpStack* st, InterpFrame* fr, u64* regs, void* host_fp, #define OP(name) L_##name /* linear op: re-check the memory-fault latch, advance, dispatch the next insn */ -#define NEXT() \ - do { \ +#define NEXT() \ + do { \ if (st->mem_fault) goto fault_mem; \ - ++ip; \ - in = ip; \ - I = in->inst; \ - goto * in->handler; \ + ++ip; \ + in = ip; \ + I = in->inst; \ + goto * in->handler; \ } while (0) /* branch op: ip already retargeted, dispatch without advancing */ #define GO() \ @@ -926,22 +927,22 @@ KitInterpStatus interp_run_stack(InterpStack* st, int64_t* out_ret) { /* Per-function lazy threading: copy each opcode's handler into its record on * first entry to the function (RELOAD runs whenever the top frame changes). */ -#define RELOAD() \ - do { \ - fr = &st->frames[st->nframes - 1u]; \ - fn = fr->fn; \ - regs = (u64*)(st->regs_arena + fr->regs_off); \ - mem_off = fr->mem_off; \ - ip = fr->ip; \ - if (!fn->threaded) { \ - u32 ti_; \ - for (ti_ = 0; ti_ < fn->ncode; ++ti_) { \ - u32 o_ = fn->code[ti_].op; \ - fn->code[ti_].handler = \ +#define RELOAD() \ + do { \ + fr = &st->frames[st->nframes - 1u]; \ + fn = fr->fn; \ + regs = (u64*)(st->regs_arena + fr->regs_off); \ + mem_off = fr->mem_off; \ + ip = fr->ip; \ + if (!fn->threaded) { \ + u32 ti_; \ + for (ti_ = 0; ti_ < fn->ncode; ++ti_) { \ + u32 o_ = fn->code[ti_].op; \ + fn->code[ti_].handler = \ st->dt[o_ < (u32)IOP__COUNT ? o_ : (u32)IOP_TRAP]; \ - } \ - fn->threaded = 1; \ - } \ + } \ + fn->threaded = 1; \ + } \ } while (0) #else #define RELOAD() \ diff --git a/src/link/link.c b/src/link/link.c @@ -98,7 +98,8 @@ void link_free(Linker* l) { static LinkInput* inputs_push(Linker* l, LinkInputId* id_out) { u32 idx; LinkInput* in = LinkInputs_push(&l->inputs, &idx); - if (!in) compiler_panic(l->c, SRCLOC_NONE, "link: out of memory growing inputs"); + if (!in) + compiler_panic(l->c, SRCLOC_NONE, "link: out of memory growing inputs"); *id_out = (LinkInputId)(idx + 1u); in->id = *id_out; return in; @@ -599,7 +600,8 @@ static void link_image_cleanup(void* arg) { LinkImage* link_image_alloc(Compiler* c) { Heap* h = (Heap*)c->ctx->heap; LinkImage* img = (LinkImage*)h->alloc(h, sizeof(*img), _Alignof(LinkImage)); - if (!img) compiler_panic(c, SRCLOC_NONE, "link: out of memory allocating image"); + if (!img) + compiler_panic(c, SRCLOC_NONE, "link: out of memory allocating image"); memset(img, 0, sizeof(*img)); img->c = c; img->heap = h; diff --git a/src/link/link_arch.h b/src/link/link_arch.h @@ -38,10 +38,10 @@ typedef struct LinkArchIPltReloc { * arch rewrites the access idiom in place. The hook reads only the fields * relevant to the kinds it owns; the rest cost nothing. */ typedef struct JitRelaxCtx { - u8* site; /* write-alias bytes at the reloc site */ - u64 S; /* resolved runtime symbol address (0 when weak_undef_zero) */ - i64 addend; /* the reloc's addend */ - u64 site_pc; /* runtime address of the reloc site */ + u8* site; /* write-alias bytes at the reloc site */ + u64 S; /* resolved runtime symbol address (0 when weak_undef_zero) */ + i64 addend; /* the reloc's addend */ + u64 site_pc; /* runtime address of the reloc site */ /* Address-of a weak *undefined* symbol must read as 0. Set when the target * is weak + SK_ABS + vaddr==0; the arch zeroes the materialized register diff --git a/src/link/link_internal.h b/src/link/link_internal.h @@ -278,9 +278,8 @@ LinkRelocApply* link_append_reloc_slot(LinkImage* img); /* Emit or upsert a synthetic global boundary symbol (link_layout.c). */ void link_emit_boundary_sym(Linker* l, LinkImage* img, const char* name, u64 vaddr); -void link_emit_section_boundary_sym(Linker* l, LinkImage* img, - const char* name, LinkSectionId section_id, - u64 value); +void link_emit_section_boundary_sym(Linker* l, LinkImage* img, const char* name, + LinkSectionId section_id, u64 value); /* Detect __start_<X> / __stop_<X> with <X> a valid C identifier. * Defined in link_resolve.c; used by link_reloc_layout.c. */ @@ -306,8 +305,8 @@ u32 link_iplt_alloc_sections(LinkImage* img, u32 nsec); * Backs the GOT / JIT-call-stub / IPLT layout passes * (link_reloc_layout.c). */ LinkSectionId link_synth_region(LinkImage* img, Linker* l, Sym name, u16 perms, - u16 sem, u64 size, u32 sec_align, u64* out_vaddr, - u8** out_bytes); + u16 sem, u64 size, u32 sec_align, + u64* out_vaddr, u8** out_bytes); /* Append one fixed 8-byte ABS64 reloc-apply record targeting `target` at * `offset` within synthetic section `lsid` (write_vaddr == its file diff --git a/src/link/link_jit.c b/src/link/link_jit.c @@ -294,10 +294,10 @@ static void jit_apply_reloc(Compiler* c, LinkImage* img, KitExecMemRegion* segs, * arch-neutral, classifying ELF via RELOC_IS_TLS_LE and the COFF Windows * idiom via its terminal SECREL reloc(s). */ if (jit_reloc_is_tls_le(c, r->kind, tgt->kind)) { - u64 storage = (tgt->kind == SK_ABS) - ? tgt->vaddr + (u64)r->addend - : (u64)vaddr_to_runtime(img, segs, tgt->vaddr) + - (u64)r->addend; + u64 storage = + (tgt->kind == SK_ABS) + ? tgt->vaddr + (u64)r->addend + : (u64)vaddr_to_runtime(img, segs, tgt->vaddr) + (u64)r->addend; u8* bytes = (u8*)vaddr_to_write(img, segs, r->write_vaddr); u64 site_pc = (u64)vaddr_to_runtime(img, segs, r->write_vaddr); d = link_arch_desc_for(c); diff --git a/src/link/link_layout.c b/src/link/link_layout.c @@ -655,9 +655,8 @@ void link_emit_boundary_sym(Linker* l, LinkImage* img, const char* name, link_emit_boundary_sym_ex(l, img, name, vaddr, LINK_SEC_NONE, 0); } -void link_emit_section_boundary_sym(Linker* l, LinkImage* img, - const char* name, LinkSectionId section_id, - u64 value) { +void link_emit_section_boundary_sym(Linker* l, LinkImage* img, const char* name, + LinkSectionId section_id, u64 value) { const LinkSection* sec; u64 vaddr; if (section_id == LINK_SEC_NONE || section_id > img->nsections) diff --git a/src/link/link_reloc_desc.h b/src/link/link_reloc_desc.h @@ -41,7 +41,8 @@ static inline int reloc_kind_is_tls_got(const Compiler* c, RelocKind k) { } /* ELF Local-Exec TLS access (the per-arch tp-relative idiom). The in-process - * JIT relaxes these to in-image addressing via LinkArchDesc.jit_tls_le_relax. */ + * JIT relaxes these to in-image addressing via LinkArchDesc.jit_tls_le_relax. + */ static inline int reloc_kind_is_tls_le(const Compiler* c, RelocKind k) { const RelocDesc* d = reloc_desc(c, k); return d && (d->flags & RELOC_IS_TLS_LE) ? 1 : 0; @@ -96,7 +97,8 @@ static inline int reloc_kind_is_marker(const Compiler* c, RelocKind k) { /* Variable-width kind (RISC-V ULEB128 SET/SUB): the descriptor width is only a * nominal gate value; the true field length is read from the bytes at apply - * time, so the layout pass must bound-check the offset before the apply scan. */ + * time, so the layout pass must bound-check the offset before the apply scan. + */ static inline int reloc_kind_is_width_dyn(const Compiler* c, RelocKind k) { const RelocDesc* d = reloc_desc(c, k); return d && (d->flags & RELOC_WIDTH_DYN) ? 1 : 0; diff --git a/src/link/link_reloc_layout.c b/src/link/link_reloc_layout.c @@ -525,10 +525,9 @@ void link_require_local_tls(Compiler* c, const LinkSymbol* tgt) { if (!tgt->imported && tgt->kind == SK_TLS) return; { Slice nm = tgt->name ? pool_slice(c->global, tgt->name) : SLICE_NULL; - const char* why = tgt->imported - ? "it is imported from a shared object" - : "it resolved to a definition that is not " - "thread-local"; + const char* why = tgt->imported ? "it is imported from a shared object" + : "it resolved to a definition that is not " + "thread-local"; compiler_panic(c, SRCLOC_NONE, "link: cannot resolve thread-local access to '%.*s': %s. " "kit emits local-exec TLS only, so every thread-local must " diff --git a/src/link/link_relocatable.c b/src/link/link_relocatable.c @@ -242,7 +242,8 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps, u32 nsec; u32 in_eflags; if (in->kind == LINK_INPUT_DSO_BYTES) - compiler_panic(l->c, SRCLOC_NONE, "link -r: DSO inputs are not supported"); + compiler_panic(l->c, SRCLOC_NONE, + "link -r: DSO inputs are not supported"); if (!ob) continue; if (obj_get_elf_e_flags(ob, &in_eflags)) { if (!have_eflags) { @@ -281,7 +282,8 @@ static void rel_copy_sections(Linker* l, ObjBuilder* out, RelInputMap* maps, } else if (s->bytes.total) { u8* flat = (u8*)l->heap->alloc(l->heap, s->bytes.total, 1u); if (!flat) - compiler_panic(l->c, SRCLOC_NONE, "link -r: oom copying section bytes"); + compiler_panic(l->c, SRCLOC_NONE, + "link -r: oom copying section bytes"); buf_flatten(&s->bytes, flat); obj_write(out, out_sec, flat, s->bytes.total); l->heap->free(l->heap, flat, s->bytes.total); @@ -430,7 +432,8 @@ void link_emit_relocatable_writer(Linker* l, Writer* w) { h = l->heap; if (l->script) - compiler_panic(l->c, SRCLOC_NONE, "link -r: linker scripts are not supported"); + compiler_panic(l->c, SRCLOC_NONE, + "link -r: linker scripts are not supported"); link_ingest_archives(l); ninputs = LinkInputs_count(&l->inputs); diff --git a/src/link/link_resolve.c b/src/link/link_resolve.c @@ -930,7 +930,8 @@ static void include_archive_member(Linker* l, const LinkArchive* ar, in->kind = LINK_INPUT_DSO_BYTES; in->soname = coff_dll; /* Short-import NameType may make the DLL export name differ from the - * local symbol name (EXPORTAS etc.); carry it for import-table synthesis. */ + * local symbol name (EXPORTAS etc.); carry it for import-table synthesis. + */ { Sym coff_imp_name = 0; if (obj_get_coff_import_name(mem->obj, &coff_imp_name)) diff --git a/src/obj/bytebuf.h b/src/obj/bytebuf.h @@ -13,8 +13,8 @@ #include <string.h> -#include "core/core.h" #include "core/bytes.h" +#include "core/core.h" #include "core/util.h" #include "core/vec.h" @@ -63,7 +63,9 @@ static inline u32 objbb_append(ObjByteBuf* b, const void* src, u32 n) { return off; } -static inline u32 objbb_u8(ObjByteBuf* b, u8 v) { return objbb_append(b, &v, 1); } +static inline u32 objbb_u8(ObjByteBuf* b, u8 v) { + return objbb_append(b, &v, 1); +} static inline u32 objbb_u16(ObjByteBuf* b, u16 v) { u8 t[2]; diff --git a/src/obj/coff/read.c b/src/obj/coff/read.c @@ -115,8 +115,7 @@ static int coff_reloc_inline_addend(const u8* data, size_t len, i64* out) { if (!s || !s->size_of_raw_data) return 0; if ((u64)off + (u64)width > (u64)s->size_of_raw_data) return 0; - if ((u64)s->pointer_to_raw_data + (u64)off + (u64)width > (u64)len) - return 0; + if ((u64)s->pointer_to_raw_data + (u64)off + (u64)width > (u64)len) return 0; const u8* p = data + s->pointer_to_raw_data + off; switch (width) { case 4: @@ -282,8 +281,9 @@ static ObjBuilder* read_coff_short_import(Compiler* c, const char* name, u32 exp_len = 0; while (exp_len < exp_max && exp_p[exp_len] != '\0') ++exp_len; if (exp_len == exp_max) - compiler_panic(c, SRCLOC_NONE, - "read_coff: short-import EXPORTAS name not NUL-terminated"); + compiler_panic( + c, SRCLOC_NONE, + "read_coff: short-import EXPORTAS name not NUL-terminated"); imp_name.s = (const char*)exp_p; imp_name.len = exp_len; } @@ -352,7 +352,8 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data, if ((u64)COFF_FILE_HEADER_SIZE + (u64)nsections * (u64)COFF_SECTION_HEADER_SIZE > (u64)len) - compiler_panic(c, SRCLOC_NONE, "read_coff: section header table out of range"); + compiler_panic(c, SRCLOC_NONE, + "read_coff: section header table out of range"); /* ---- Step 1: bootstrap, locate strtab ---- */ /* Strtab is at PointerToSymbolTable + NumberOfSymbols * 18. When the @@ -419,8 +420,8 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data, } else if (s->size_of_raw_data) { u64 end = (u64)s->pointer_to_raw_data + (u64)s->size_of_raw_data; if (end > (u64)len) - compiler_panic(c, SRCLOC_NONE, "read_coff: section %u bytes out of range", - i); + compiler_panic(c, SRCLOC_NONE, + "read_coff: section %u bytes out of range", i); u8* dst = obj_reserve(ob, id, s->size_of_raw_data); memcpy(dst, data + s->pointer_to_raw_data, s->size_of_raw_data); } @@ -442,7 +443,8 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data, const u8* sym_base = data + ptr_to_symtab; if (nsymbols) { if ((u64)ptr_to_symtab + (u64)nsymbols * (u64)COFF_SYMBOL_SIZE > (u64)len) - compiler_panic(c, SRCLOC_NONE, "read_coff: symbol table body out of range"); + compiler_panic(c, SRCLOC_NONE, + "read_coff: symbol table body out of range"); } for (u32 i = 0; i < nsymbols;) { @@ -753,48 +755,40 @@ ObjBuilder* read_coff(Compiler* c, const char* name, const u8* data, i64 inline_addend = 0; switch (r_type) { case IMAGE_REL_AMD64_ADDR64: - if (coff_reloc_inline_addend(data, len, s, r_va, 8, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 8, &inline_addend)) addend = inline_addend; break; case IMAGE_REL_AMD64_ADDR32: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; break; case IMAGE_REL_AMD64_REL32: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 4; break; case IMAGE_REL_AMD64_REL32_1: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 1; break; case IMAGE_REL_AMD64_REL32_2: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 2; break; case IMAGE_REL_AMD64_REL32_3: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 3; break; case IMAGE_REL_AMD64_REL32_4: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 4; break; case IMAGE_REL_AMD64_REL32_5: - if (coff_reloc_inline_addend(data, len, s, r_va, 4, - &inline_addend)) + if (coff_reloc_inline_addend(data, len, s, r_va, 4, &inline_addend)) addend = inline_addend; addend -= 5; break; diff --git a/src/obj/coff/read_dso.c b/src/obj/coff/read_dso.c @@ -35,10 +35,12 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data, /* ---- DOS header + PE signature ---- */ if (len < COFF_DOS_HEADER_SIZE) - compiler_panic(c, SRCLOC_NONE, "read_coff_dso: input shorter than DOS header"); + compiler_panic(c, SRCLOC_NONE, + "read_coff_dso: input shorter than DOS header"); u16 e_magic = coff_rd_u16(data + 0); if (e_magic != IMAGE_DOS_SIGNATURE) - compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad DOS magic 0x%x", e_magic); + compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad DOS magic 0x%x", + e_magic); u32 e_lfanew = coff_rd_u32(data + 60); u64 nt_end = (u64)e_lfanew + 4u + COFF_FILE_HEADER_SIZE + COFF_OPT_HDR64_SIZE; @@ -48,7 +50,8 @@ ObjBuilder* read_coff_dso(Compiler* c, const char* name, const u8* data, u32 pe_sig = coff_rd_u32(data + e_lfanew); if (pe_sig != IMAGE_NT_SIGNATURE) - compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad PE signature 0x%x", pe_sig); + compiler_panic(c, SRCLOC_NONE, "read_coff_dso: bad PE signature 0x%x", + pe_sig); /* ---- IMAGE_FILE_HEADER ---- */ const u8* fh = data + e_lfanew + 4u; diff --git a/src/obj/coff/read_image.c b/src/obj/coff/read_image.c @@ -15,10 +15,9 @@ * directories) are skipped, yielding a partial-but-useful inspection view, * matching read_elf_image / read_macho_image. */ -#include <string.h> - #include <kit/cg.h> #include <kit/object.h> /* KIT_OBJ_RAW_PE_* reserved tags */ +#include <string.h> #include "core/arena.h" #include "core/heap.h" @@ -93,7 +92,8 @@ static void read_pe_exports(Compiler* c, ObjImage* im, const u8* data, memset(&ds, 0, sizeof ds); ds.name = intern(c, en, el); ds.bind = SB_GLOBAL; - ds.kind = SK_FUNC; /* forwarders point at the export-dir string; still SK_FUNC */ + ds.kind = + SK_FUNC; /* forwarders point at the export-dir string; still SK_FUNC */ ds.section = OBJ_SEC_NONE; ds.value = image_base + func_rva; obj_image_add_dynsym(im, &ds); @@ -119,9 +119,9 @@ static void read_pe_imports(Compiler* c, ObjImage* im, const u8* data, for (u32 d = 0;; ++d) { u64 desc = imp_off + (u64)d * COFF_IMPORT_DESCRIPTOR_SIZE; if (desc + COFF_IMPORT_DESCRIPTOR_SIZE > len) break; - u32 oft = coff_rd_u32(data + desc + 0); /* OriginalFirstThunk (ILT) */ + u32 oft = coff_rd_u32(data + desc + 0); /* OriginalFirstThunk (ILT) */ u32 dll_name_rva = coff_rd_u32(data + desc + 12); - u32 ft = coff_rd_u32(data + desc + 16); /* FirstThunk (IAT) */ + u32 ft = coff_rd_u32(data + desc + 16); /* FirstThunk (IAT) */ if (oft == 0 && dll_name_rva == 0 && ft == 0) break; /* null terminator */ if (dll_name_rva == 0) continue; @@ -143,7 +143,7 @@ static void read_pe_imports(Compiler* c, ObjImage* im, const u8* data, u64 te = toff + (u64)t * COFF_THUNK_DATA64_SIZE; if (te + COFF_THUNK_DATA64_SIZE > len) break; u64 thunk = coff_rd_u64(data + te); - if (thunk == 0) break; /* null-terminated table */ + if (thunk == 0) break; /* null-terminated table */ if (thunk & IMAGE_ORDINAL_FLAG64) continue; /* by-ordinal: skip (v1) */ u32 ibn_rva = (u32)(thunk & 0x7fffffffu); u64 hoff; @@ -167,7 +167,8 @@ static void read_pe_imports(Compiler* c, ObjImage* im, const u8* data, memset(&us, 0, sizeof us); us.name = isym; us.bind = SB_GLOBAL; - us.kind = SK_NOTYPE; /* PE import descriptors don't distinguish func/data */ + us.kind = + SK_NOTYPE; /* PE import descriptors don't distinguish func/data */ us.section = OBJ_SEC_NONE; obj_image_add_dynsym(im, &us); } @@ -175,7 +176,7 @@ static void read_pe_imports(Compiler* c, ObjImage* im, const u8* data, ObjImageDep dep; dep.name = dep_name; - dep.imports = imports; /* transient scratch; add_dep deep-copies */ + dep.imports = imports; /* transient scratch; add_dep deep-copies */ dep.nimports = nimports; obj_image_add_dep(im, &dep); } @@ -208,7 +209,8 @@ static void read_pe_basereloc(ObjImage* im, const u8* data, size_t len, if (pos + block_size > end) block_size = (u32)(end - pos); u32 nent = (block_size - COFF_BASE_RELOCATION_SIZE) / 2u; for (u32 e = 0; e < nent; ++e) { - u16 ent = coff_rd_u16(data + pos + COFF_BASE_RELOCATION_SIZE + (u64)e * 2u); + u16 ent = + coff_rd_u16(data + pos + COFF_BASE_RELOCATION_SIZE + (u64)e * 2u); u32 type = (u32)ent >> 12; u32 off = (u32)ent & 0x0fffu; if (type == IMAGE_REL_BASED_ABSOLUTE) continue; /* padding */ @@ -236,8 +238,7 @@ ObjBuilder* read_coff_image(Compiler* c, const char* name, const u8* data, if (coff_rd_u16(data + 0) != IMAGE_DOS_SIGNATURE) compiler_panic(c, SRCLOC_NONE, "read_coff_image: bad DOS magic"); u32 e_lfanew = coff_rd_u32(data + 60); - u64 nt_end = - (u64)e_lfanew + 4u + COFF_FILE_HEADER_SIZE + COFF_OPT_HDR64_SIZE; + u64 nt_end = (u64)e_lfanew + 4u + COFF_FILE_HEADER_SIZE + COFF_OPT_HDR64_SIZE; if (nt_end > len) compiler_panic(c, SRCLOC_NONE, "read_coff_image: PE headers extend past end of file"); @@ -270,7 +271,8 @@ ObjBuilder* read_coff_image(Compiler* c, const char* name, const u8* data, u16 subsystem = coff_rd_u16(oh + 68); u16 dllchars = coff_rd_u16(oh + 70); u32 num_dirs = coff_rd_u32(oh + 108); - if (num_dirs > COFF_NUM_DATA_DIRECTORIES) num_dirs = COFF_NUM_DATA_DIRECTORIES; + if (num_dirs > COFF_NUM_DATA_DIRECTORIES) + num_dirs = COFF_NUM_DATA_DIRECTORIES; const u8* data_dir = oh + COFF_OPT_HDR64_SIZE - COFF_NUM_DATA_DIRECTORIES * COFF_DATA_DIRECTORY_SIZE; @@ -289,9 +291,10 @@ ObjBuilder* read_coff_image(Compiler* c, const char* name, const u8* data, compiler_panic(c, SRCLOC_NONE, "read_coff_image: no arch impl for machine %#x", (u32)machine); - RelocKind relative_kind = (aops->arch == KIT_ARCH_X86_64) ? R_X64_RELATIVE - : (aops->arch == KIT_ARCH_ARM_64) ? R_AARCH64_RELATIVE - : R_X64_RELATIVE; + RelocKind relative_kind = (aops->arch == KIT_ARCH_X86_64) ? R_X64_RELATIVE + : (aops->arch == KIT_ARCH_ARM_64) + ? R_AARCH64_RELATIVE + : R_X64_RELATIVE; ObjBuilder* ob = obj_new(c); if (!ob) compiler_panic(c, SRCLOC_NONE, "read_coff_image: obj_new failed"); @@ -321,8 +324,8 @@ ObjBuilder* read_coff_image(Compiler* c, const char* name, const u8* data, int is_bss = (ch & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0; u16 sem = is_bss ? SSEM_NOBITS : SSEM_PROGBITS; - ObjSecId id = - obj_section_ex(ob, sn, (SecKind)kind, (SecSem)sem, flags, align, 0u, 0u, 0u); + ObjSecId id = obj_section_ex(ob, sn, (SecKind)kind, (SecSem)sem, flags, + align, 0u, 0u, 0u); if (id != OBJ_SEC_NONE) { obj_section_set_ext(ob, id, OBJ_EXT_COFF, ch, 0); obj_section_set_addr(ob, id, image_base + vaddr); @@ -374,7 +377,8 @@ ObjBuilder* read_coff_image(Compiler* c, const char* name, const u8* data, obj_image_add_raw(im, &r); } - read_pe_exports(c, im, data, len, shdrs, nsec, data_dir, num_dirs, image_base); + read_pe_exports(c, im, data, len, shdrs, nsec, data_dir, num_dirs, + image_base); read_pe_imports(c, im, data, len, shdrs, nsec, data_dir, num_dirs); read_pe_basereloc(im, data, len, shdrs, nsec, data_dir, num_dirs, image_base, relative_kind); diff --git a/src/obj/elf/elf.h b/src/obj/elf/elf.h @@ -255,8 +255,8 @@ static inline u8 elf_st_other(u8 vis /* SymVis */) { #define DT_FLAGS_1 0x6ffffffb #define DF_1_NOW 0x00000001 /* GNU symbol-versioning dynamic tags. */ -#define DT_VERSYM 0x6ffffff0 /* address of the .gnu.version table */ -#define DT_VERNEED 0x6ffffffe /* address of the .gnu.version_r table */ +#define DT_VERSYM 0x6ffffff0 /* address of the .gnu.version table */ +#define DT_VERNEED 0x6ffffffe /* address of the .gnu.version_r table */ #define DT_VERNEEDNUM 0x6fffffff /* number of .gnu.version_r entries */ /* ---- extra section types we need to recognize in DSO inputs ---- */ diff --git a/src/obj/elf/emu_load.c b/src/obj/elf/emu_load.c @@ -151,9 +151,10 @@ static KitStatus parse_object_dynamic(EmuLoadedImage* img, if (nneeded_offs < EMU_MAX_NEEDED) needed_offs[nneeded_offs++] = val; else - KIT_LOGW("emu: >%d DT_NEEDED entries; extra shared-library deps " - "ignored", - EMU_MAX_NEEDED); + KIT_LOGW( + "emu: >%d DT_NEEDED entries; extra shared-library deps " + "ignored", + EMU_MAX_NEEDED); break; case DT_STRTAB: strtab = ptr; diff --git a/src/obj/elf/link.c b/src/obj/elf/link.c @@ -352,9 +352,8 @@ static void shift_image_addresses(LinkImage* img, u64 delta) { static int reloc_is_tlsle(RelocKind k, int tls_variant_ii) { if (k == R_TPOFF64 && !tls_variant_ii) return 1; return k == R_AARCH64_TLSLE_ADD_TPREL_HI12 || - k == R_AARCH64_TLSLE_ADD_TPREL_LO12_NC || - k == R_RV_TPREL_HI20 || k == R_RV_TPREL_LO12_I || - k == R_RV_TPREL_LO12_S; + k == R_AARCH64_TLSLE_ADD_TPREL_LO12_NC || k == R_RV_TPREL_HI20 || + k == R_RV_TPREL_LO12_I || k == R_RV_TPREL_LO12_S; } /* Variant-I TP bias: distance from the TLS image start to where `tp` points. @@ -1469,7 +1468,8 @@ void link_emit_elf(LinkImage* img, Writer* w) { * PT_LOAD that's never made writable. */ } else if (pie) { /* dyn was nominally requested but layout_dyn early-out — no - * imports and no DSO inputs. INTERP/DYNAMIC loader headers are skipped. */ + * imports and no DSO inputs. INTERP/DYNAMIC loader headers are skipped. + */ (void)0; } (void)pi; diff --git a/src/obj/elf/read.c b/src/obj/elf/read.c @@ -272,8 +272,9 @@ static u32 elf_default_version_namelen(const char* nm, u32 nlen) { * table so .dynsym entries (whose version lives in the parallel .gnu.version) * can be labelled. Returns an arena table indexed by version index (0/1 unused, * matching VER_NDX_LOCAL/GLOBAL) and sets *out_max to the highest index seen; - * NULL when the input has no verdef. The Verdef/Verdaux wire layout is identical - * on ELFCLASS32/64 (all Half/Word fields), so this is width-agnostic. */ + * NULL when the input has no verdef. The Verdef/Verdaux wire layout is + * identical on ELFCLASS32/64 (all Half/Word fields), so this is width-agnostic. + */ static Sym* read_elf_verdefs(Compiler* c, const u8* data, size_t len, const ShdrRec* shdrs, u16 e_shnum, u32* out_max) { u32 i, verdef_idx = 0, max_ndx = 0; @@ -322,8 +323,8 @@ static Sym* read_elf_verdefs(Compiler* c, const u8* data, size_t len, if (!(vd_flags & VER_FLG_BASE) && ndx <= max_ndx && off + vd_aux + ELF_VERDAUX_SIZE <= size) { u32 nlen; - const char* nm = - strtab_lookup(strtab, strtab_sz, rd_u32_le(base + off + vd_aux), &nlen); + const char* nm = strtab_lookup(strtab, strtab_sz, + rd_u32_le(base + off + vd_aux), &nlen); if (nlen) tbl[ndx] = pool_intern_slice(c->global, (Slice){.s = nm, .len = nlen}); } @@ -496,8 +497,8 @@ static void read_elf_image(Compiler* c, ObjBuilder* ob, const u8* data, * defined entry whose versym lacks VERSYM_HIDDEN is the *default* * version of its name — the version a plain reference should bind. */ u32 verdef_max = 0; - Sym* verdef_tbl = read_elf_verdefs(c, data, len, shdrs, e_shnum, - &verdef_max); + Sym* verdef_tbl = + read_elf_verdefs(c, data, len, shdrs, e_shnum, &verdef_max); const u8* versym = NULL; u32 nversym = 0; for (u16 vi = 1; vi < e_shnum; ++vi) { @@ -1138,7 +1139,8 @@ ObjBuilder* read_elf_dso(Compiler* c, const char* name, const u8* data, u32 nversym = 0; for (u32 i = 1; i < e_shnum; ++i) { if (shdrs[i].sh_type != SHT_GNU_VERSYM) continue; - if (shdrs[i].sh_offset + shdrs[i].sh_size <= len && shdrs[i].sh_entsize == 2) + if (shdrs[i].sh_offset + shdrs[i].sh_size <= len && + shdrs[i].sh_entsize == 2) versym = data + shdrs[i].sh_offset, nversym = (u32)(shdrs[i].sh_size / 2u); break; diff --git a/src/obj/elf/reloc_riscv64.c b/src/obj/elf/reloc_riscv64.c @@ -296,10 +296,11 @@ KitFloatAbi elf_riscv_float_abi_from_e_flags(u32 e_flags) { /* Encode the float ABI into RISC-V ELF e_flags (the EF_RISCV_FLOAT_ABI_* bits; * caller masks them into e_flags with EF_RISCV_FLOAT_ABI_MASK). Inverse of * elf_riscv_float_abi_from_e_flags, kept here so the format-generic ELF writers - * (emit.c ET_REL, link.c ET_EXEC) don't inline the mapping. KIT_FLOAT_ABI_DEFAULT - * resolves to SINGLE: the rv32 ilp32/ilp32f pair shares one KitArchKind, so the - * static descriptor's float bits are a placeholder and -mabi DEFAULT means the - * rv32 default profile (ilp32f). XLEN-neutral; only the rv32 writers call it. */ + * (emit.c ET_REL, link.c ET_EXEC) don't inline the mapping. + * KIT_FLOAT_ABI_DEFAULT resolves to SINGLE: the rv32 ilp32/ilp32f pair shares + * one KitArchKind, so the static descriptor's float bits are a placeholder and + * -mabi DEFAULT means the rv32 default profile (ilp32f). XLEN-neutral; only the + * rv32 writers call it. */ u32 elf_riscv_float_abi_to_e_flags(KitFloatAbi abi) { switch (abi) { case KIT_FLOAT_ABI_SINGLE: diff --git a/src/obj/format.h b/src/obj/format.h @@ -49,7 +49,8 @@ typedef struct ObjElfArchOps { u32 r_relative; u32 r_glob_dat; u32 r_jump_slot; - u32 r_irelative; /* R_*_IRELATIVE static-IFUNC resolver reloc (__rela_iplt). */ + u32 r_irelative; /* R_*_IRELATIVE static-IFUNC resolver reloc (__rela_iplt). + */ /* Variant-I TP bias: distance from the TLS image start to where `tp` * points for a freestanding (kit start.c) layout. AArch64/RISC-V place * a 16-byte TCB ahead of the image, so this is 16 for those arches; 0 diff --git a/src/obj/macho/emit.c b/src/obj/macho/emit.c @@ -525,8 +525,8 @@ void emit_macho(Compiler* c, ObjBuilder* ob, Writer* w) { const Reloc* r = obj_reloc_at(ob, ri); if (r->removed) continue; if (r->section_id != m->obj_sec) continue; - if ((r->kind == R_ADD8 || r->kind == R_ADD16 || - r->kind == R_ADD32 || r->kind == R_ADD64) && + if ((r->kind == R_ADD8 || r->kind == R_ADD16 || r->kind == R_ADD32 || + r->kind == R_ADD64) && ri + 1u < total_relocs) { const Reloc* sub = obj_reloc_at(ob, ri + 1u); int paired = sub && sub->section_id == r->section_id && diff --git a/src/obj/macho/read.c b/src/obj/macho/read.c @@ -150,7 +150,8 @@ static void read_macho_image(Compiler* c, ObjBuilder* ob, const u8* data, const MSecRec* msecs, u32 nmsecs) { ObjImage* im = obj_image_ensure(ob, filetype == MH_DYLIB ? OBJ_KIND_DYN : OBJ_KIND_EXEC); - if (!im) compiler_panic(c, SRCLOC_NONE, "read_macho: obj_image_ensure failed"); + if (!im) + compiler_panic(c, SRCLOC_NONE, "read_macho: obj_image_ensure failed"); u32 ncmds = rd_u32_le(data + 16); u32 sizeofcmds = rd_u32_le(data + 20); @@ -529,7 +530,8 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data, obj_reserve_bss(ob, id, (u32)m->size, align); } else if (m->size) { if (m->fileoff + m->size > len) - compiler_panic(c, SRCLOC_NONE, "read_macho: section bytes out of range"); + compiler_panic(c, SRCLOC_NONE, + "read_macho: section bytes out of range"); obj_write(ob, id, data + m->fileoff, (size_t)m->size); } m->obj_sec = id; @@ -686,7 +688,8 @@ ObjBuilder* read_macho(Compiler* c, const char* name, const u8* data, MSecRec* m = &msecs[i]; if (!m->nreloc) continue; if (m->reloff + (u64)m->nreloc * MACHO_RELOC_SIZE > len) - compiler_panic(c, SRCLOC_NONE, "read_macho: relocation table out of range"); + compiler_panic(c, SRCLOC_NONE, + "read_macho: relocation table out of range"); const u8* rp = data + m->reloff; i64 pending_addend = 0; int have_pending = 0; diff --git a/src/obj/registry.c b/src/obj/registry.c @@ -491,9 +491,8 @@ typedef struct ObjFmtNameRow { } ObjFmtNameRow; static const ObjFmtNameRow obj_fmt_names[] = { - {KIT_OBJ_ELF, "elf"}, {KIT_OBJ_COFF, "coff"}, - {KIT_OBJ_COFF, "pe"}, {KIT_OBJ_MACHO, "macho"}, - {KIT_OBJ_WASM, "wasm"}, + {KIT_OBJ_ELF, "elf"}, {KIT_OBJ_COFF, "coff"}, {KIT_OBJ_COFF, "pe"}, + {KIT_OBJ_MACHO, "macho"}, {KIT_OBJ_WASM, "wasm"}, }; int obj_format_fmt_from_name(const char* name, KitObjFmt* out) { diff --git a/src/obj/reloc.c b/src/obj/reloc.c @@ -29,12 +29,18 @@ const RelocDesc* reloc_desc_row_find(const RelocDescRow* rows, u32 n, * first); this row supplies both the width fallback and the correct * "not a branch" answer on AArch64. */ static const RelocDescRow neutral_rows[] = { - {R_ABS8, {1, 0}}, {R_ABS16, {2, 0}}, - {R_ABS32, {4, 0}}, {R_ABS64, {8, 0}}, - {R_PREL16, {2, 0}}, {R_TPOFF64, {8, 0}}, - {R_REL32, {4, 0}}, {R_REL64, {8, 0}}, - {R_PC32, {4, 0}}, {R_PC64, {8, 0}}, - {R_GOT32, {4, 0}}, {R_PLT32, {4, 0}}, + {R_ABS8, {1, 0}}, + {R_ABS16, {2, 0}}, + {R_ABS32, {4, 0}}, + {R_ABS64, {8, 0}}, + {R_PREL16, {2, 0}}, + {R_TPOFF64, {8, 0}}, + {R_REL32, {4, 0}}, + {R_REL64, {8, 0}}, + {R_PC32, {4, 0}}, + {R_PC64, {8, 0}}, + {R_GOT32, {4, 0}}, + {R_PLT32, {4, 0}}, {R_COFF_SECREL, {4, RELOC_IS_SECREL}}, {R_COFF_SECTION, {2, 0}}, {R_COFF_ADDR32NB, {4, 0}}, diff --git a/src/obj/reloc.h b/src/obj/reloc.h @@ -23,21 +23,21 @@ typedef enum RelocDescFlag { RELOC_DIRECT_PAGE = 1u << 4, /* Mach-O ADRP-direct (non-GOT) page / pageoff */ RELOC_MARKER = 1u << 5, /* no bytes patched (RELAX / TPREL_ADD) */ RELOC_WIDTH_DYN = 1u << 6, /* width read from the bytes at apply (ULEB128) */ - RELOC_IS_TLS_LE = 1u << 7, /* ELF Local-Exec TLS access (tp-relative idiom), - * plus the COFF Windows SECREL12A TLS pair; the - * in-process JIT relaxes it to in-image - * addressing via LinkArchDesc.jit_tls_le_relax */ + RELOC_IS_TLS_LE = 1u << 7, /* ELF Local-Exec TLS access (tp-relative idiom), + * plus the COFF Windows SECREL12A TLS pair; the + * in-process JIT relaxes it to in-image + * addressing via LinkArchDesc.jit_tls_le_relax */ RELOC_IS_PCREL_ANCHOR = 1u << 8, /* PC-relative HI20 anchor (RISC-V AUIPC) a * paired PCREL_LO12 reloc resolves against; * the JIT recomputes its displacement */ - RELOC_IS_SECREL = 1u << 9, /* COFF section-relative value (R_COFF_SECREL); a - * TLS Local-Exec access when its target is a TLS - * symbol, which the in-process JIT relaxes */ + RELOC_IS_SECREL = 1u << 9, /* COFF section-relative value (R_COFF_SECREL); a + * TLS Local-Exec access when its target is a TLS + * symbol, which the in-process JIT relaxes */ } RelocDescFlag; typedef struct RelocDesc { - u8 width; /* patched-field width in bytes; nominal when RELOC_WIDTH_DYN */ - u16 flags; /* RelocDescFlag bitset */ + u8 width; /* patched-field width in bytes; nominal when RELOC_WIDTH_DYN */ + u16 flags; /* RelocDescFlag bitset */ } RelocDesc; /* One row of a per-arch / neutral descriptor table. `kind` holds a diff --git a/src/obj/symresolve.c b/src/obj/symresolve.c @@ -29,8 +29,9 @@ SymMergeResult symresolve_merge(SymAttrs existing, SymAttrs incoming) { new_strength == symresolve_bind_strength(SB_GLOBAL)) { /* Two strong definitions: legal only as COFF SELECTANY when both sit in * COMDAT sections (keep the first, discard the new); otherwise ODR. */ - r.kind = (existing.in_comdat && incoming.in_comdat) ? SYM_MERGE_COMDAT_DISCARD - : SYM_MERGE_ODR_ERROR; + r.kind = (existing.in_comdat && incoming.in_comdat) + ? SYM_MERGE_COMDAT_DISCARD + : SYM_MERGE_ODR_ERROR; } /* else: incoming is weaker (or weak-vs-weak); keep the first definition. */ return r; diff --git a/src/obj/symresolve.h b/src/obj/symresolve.h @@ -45,10 +45,10 @@ static inline int symresolve_sym_is_spurious_undef(const ObjSym* s) { * when the definition lives in an SF_GROUP (COMDAT/SELECTANY) section — the * caller computes it, since it requires the section table. */ typedef struct SymAttrs { - u16 bind; /* SymBind */ - u16 kind; /* SymKind */ + u16 bind; /* SymBind */ + u16 kind; /* SymKind */ u64 size; - u32 common_align; /* SK_COMMON only; 0 otherwise */ + u32 common_align; /* SK_COMMON only; 0 otherwise */ u8 in_comdat; } SymAttrs; diff --git a/src/opt/cg_ir_lower.c b/src/opt/cg_ir_lower.c @@ -192,12 +192,13 @@ static void lower_locals(CgIrLower* l) { * a memory home regardless of whether their address is taken. "Oversized" * is wider than the machine word (ptr_size): 8 on rv64/x64/aa64, 4 on rv32 * — so an 8-byte i64/double on rv32 is homed in memory like an i128 is on a - * 64-bit target (the cg layer also flags these CG_LOCAL_MEMORY_REQUIRED). */ - m->address_taken = local_needs_home(in) || - local_address_used_in_cg_ir(l->c, l->src, in->id) || - cg_type_is_aggregate(l->c, in->desc.type) || - cg_type_size(l->c, in->desc.type) > - (u64)l->c->target.ptr_size; + * 64-bit target (the cg layer also flags these CG_LOCAL_MEMORY_REQUIRED). + */ + m->address_taken = + local_needs_home(in) || + local_address_used_in_cg_ir(l->c, l->src, in->id) || + cg_type_is_aggregate(l->c, in->desc.type) || + cg_type_size(l->c, in->desc.type) > (u64)l->c->target.ptr_size; PReg r = ir_alloc_preg(l->f, in->desc.type, m->cls); if (m->address_taken) { @@ -495,9 +496,9 @@ static Reg resolve_materialized_reg(CgIrLower* l, CGLocal local, for (u32 i = 0; i < l->nmat; ++i) if (l->mat_local[i] == local && l->mat_role[i] == (u8)role) return l->mat_reg[i]; - lower_panic(l, loc, role == CG_IR_MAT_INDEX - ? "indirect index local not materialized" - : "indirect base local not materialized"); + lower_panic(l, loc, + role == CG_IR_MAT_INDEX ? "indirect index local not materialized" + : "indirect base local not materialized"); } static KitCgTypeId pointer_sized_int_type(CgIrLower* l) { @@ -530,7 +531,8 @@ static OptOperand opt_frame_operand_as(OptLocalMap* m, KitCgTypeId type) { /* Emit the pre-materialization needed for a FRAME-storage local used as an * OPK_INDIRECT base. A pointer-typed local holds the base pointer value and is - * loaded. A non-pointer local names storage, so its frame address is the base. */ + * loaded. A non-pointer local names storage, so its frame address is the base. + */ static void materialize_frame_base(CgIrLower* l, u32 block, CGLocal local, SrcLoc loc) { OptLocalMap* m = local_map(l, local, loc); @@ -822,8 +824,7 @@ static void lower_intrinsic(CgIrLower* l, Inst* out, const CgIrInst* in) { out->ndefs = ndefs; out->defs = arena_array(l->f->arena, Val, ndefs); for (u32 i = 0; i < src->ndst; ++i) - if (aux->dsts[i].kind == OPK_REG) - out->defs[d++] = aux->dsts[i].v.reg; + if (aux->dsts[i].kind == OPK_REG) out->defs[d++] = aux->dsts[i].v.reg; out->def = out->defs[0]; } out->type = aux->dsts[0].type; diff --git a/src/opt/ir.c b/src/opt/ir.c @@ -15,9 +15,8 @@ #include "opt/ir.h" -#include <string.h> - #include <kit/cg.h> +#include <string.h> #include "core/arena.h" #include "core/core.h" @@ -36,10 +35,18 @@ u8 opt_value_reg_class(Compiler* c, KitCgTypeId ty) { u32 flen; if (kit_cg_type_kind(pc, ty) != KIT_CG_TYPE_FLOAT) return RC_INT; switch (c->target.float_abi) { - case KIT_FLOAT_ABI_SINGLE: flen = 4u; break; - case KIT_FLOAT_ABI_DOUBLE: flen = 8u; break; - case KIT_FLOAT_ABI_SOFT: flen = 0u; break; - default: flen = c->target.ptr_size; break; /* DEFAULT: historical */ + case KIT_FLOAT_ABI_SINGLE: + flen = 4u; + break; + case KIT_FLOAT_ABI_DOUBLE: + flen = 8u; + break; + case KIT_FLOAT_ABI_SOFT: + flen = 0u; + break; + default: + flen = c->target.ptr_size; + break; /* DEFAULT: historical */ } return (flen && kit_cg_type_size(pc, ty) <= (uint64_t)flen) ? RC_FP : RC_INT; } diff --git a/src/opt/ir.h b/src/opt/ir.h @@ -443,10 +443,10 @@ typedef struct IRAsmAux { u32 clobber_abi_sets; /* Filled by opt_machinize from backend register-name resolution. */ u32 clobber_mask[OPT_REG_CLASSES]; - i32* out_fixed_regs; /* nout, -1 when unconstrained */ - i32* in_fixed_regs; /* nin, -1 when unconstrained */ - u8* out_fixed_cls; /* RegClass, parallel to out_fixed_regs */ - u8* in_fixed_cls; /* RegClass, parallel to in_fixed_regs */ + i32* out_fixed_regs; /* nout, -1 when unconstrained */ + i32* in_fixed_regs; /* nin, -1 when unconstrained */ + u8* out_fixed_cls; /* RegClass, parallel to out_fixed_regs */ + u8* in_fixed_cls; /* RegClass, parallel to in_fixed_regs */ u32* out_allowed_masks; /* nout, 0 when the whole class is allowed */ u32* in_allowed_masks; /* nin, 0 when the whole class is allowed */ u8* out_allowed_cls; /* RegClass, parallel to out_allowed_masks */ diff --git a/src/opt/opt.c b/src/opt/opt.c @@ -689,7 +689,8 @@ static void opt_data_sym_table_build(OptImpl* o, OptDataSymTable* t, u32 nsym) { t->by_section.slots[i].v.count = 0; } } - /* Pass 2: place symbols in their section slice, preserving iteration order. */ + /* Pass 2: place symbols in their section slice, preserving iteration order. + */ it = obj_symiter_new(o->target->obj); while (it && obj_symiter_next(it, &ent)) { const ObjSym* s = ent.sym; @@ -716,8 +717,8 @@ static void opt_data_sym_table_fini(OptDataSymTable* t) { * only an exported symbol does. Returns the first match in the section's stable * order (matching the old per-symbol scan). */ static ObjSymId opt_data_reloc_exported_root_sym(OptImpl* o, - const OptDataSymTable* t, - const Reloc* r) { + const OptDataSymTable* t, + const Reloc* r) { const Section* sec; const OptSecSlice* slice; int retained; diff --git a/src/opt/pass_cfg.c b/src/opt/pass_cfg.c @@ -78,8 +78,7 @@ static void mark_label_addr_targets_reachable(Func* f, const Inst* in, push_reachable(f, reachable, stack, sp, (u32)in->extra.imm); break; case IR_LOCAL_STATIC_DATA_LABEL_ADDR: { - CgIrLocalStaticLabelAux* aux = - (CgIrLocalStaticLabelAux*)in->extra.aux; + CgIrLocalStaticLabelAux* aux = (CgIrLocalStaticLabelAux*)in->extra.aux; if (aux) push_reachable(f, reachable, stack, sp, (u32)aux->target); break; } diff --git a/src/opt/pass_lower.c b/src/opt/pass_lower.c @@ -1102,9 +1102,8 @@ static void opt_assign_ranges(Func* f, const OptLiveRangeSet* ranges, "opt regalloc: fixed hard reg %u is clobbered", (unsigned)fixed); } - if (fixed >= 32 || - (gi.allowed_hard_regs && - (gi.allowed_hard_regs & (1u << fixed)) == 0)) { + if (fixed >= 32 || (gi.allowed_hard_regs && + (gi.allowed_hard_regs & (1u << fixed)) == 0)) { SrcLoc loc = {0, 0, 0}; compiler_panic(f->c, loc, "opt regalloc: fixed hard reg %u violates asm " diff --git a/src/opt/pass_native_emit.c b/src/opt/pass_native_emit.c @@ -522,9 +522,10 @@ static Reg loc_avoid_reg(NativeLoc l) { static int type_is_aggregate_or_large(NativeEmitCtx* e, KitCgTypeId type) { /* "Large" = wider than one machine word (ptr_size): such a value cannot move - * through a single register, so IR_COPY/IR_LOAD/IR_STORE of it must go through - * copy_bytes. 8 on rv64/x64/aa64, 4 on rv32 (so an 8-byte i64/double is large - * there and is copied as two words rather than truncated into one register). */ + * through a single register, so IR_COPY/IR_LOAD/IR_STORE of it must go + * through copy_bytes. 8 on rv64/x64/aa64, 4 on rv32 (so an 8-byte i64/double + * is large there and is copied as two words rather than truncated into one + * register). */ return type && (cg_type_is_aggregate(e->c, type) || type_size_or(e->c, type, 8u) > e->c->target.ptr_size); } @@ -1202,9 +1203,8 @@ static void emit_inst(NativeEmitCtx* e, u32 block, u32 order_index, Inst* in, * target, or an aggregate) can't pass through a scratch register; hand * the target its memory destination so it can copy the value directly. */ - e->target->va_arg_(e->target, loc_from_operand(e, &in->opnds[0], - in->loc), - ap, ty); + e->target->va_arg_(e->target, + loc_from_operand(e, &in->opnds[0], in->loc), ap, ty); return; } /* The result must land in a register distinct from the va_list pointer; @@ -1440,8 +1440,8 @@ static void plan_frame(NativeEmitCtx* e, const CGFuncDesc* fd) { } /* Gather the union of every asm block's clobber names and hard-register * operand pins. The backend resolves them with its own clobber parser - * (machinize's resolve_name is unset on every backend, so aux->clobber_mask is - * unreliable here). */ + * (machinize's resolve_name is unset on every backend, so aux->clobber_mask + * is unreliable here). */ if (nasm_clob) { u32 n = 0; asm_clobbers = arena_array(e->f->arena, Sym, nasm_clob); diff --git a/src/wasm/decode.c b/src/wasm/decode.c @@ -716,8 +716,8 @@ static void decode_body_insn(BinReader* rp, WasmModule* out, WasmFunc* f, sub <= 0xffu ? wasm_insn_by_byte(WASM_PREFIX_FE, (uint8_t)sub) : NULL; if (!info || info->operand_class != WASM_OC_MEMARG) - wasm_error(c, wasm_loc(0, 0), - "wasm: unsupported threads opcode 0x%x", sub); + wasm_error(c, wasm_loc(0, 0), "wasm: unsupported threads opcode 0x%x", + sub); decode_memarg_insn(&r, c, out, f, (WasmInsnKind)info->kind); } break; diff --git a/src/wasm/insn.c b/src/wasm/insn.c @@ -437,7 +437,8 @@ int wasm_conversion_kind(uint8_t kind, WasmValType* src, WasmValType* dst) { /* WAT mnemonic for an instruction kind. Spellings live in WASM_INSN_TABLE so * the encoder, disassembler, and WAT parser all agree. Returns ".unknown" for - * any out-of-range kind rather than NULL so callers can print unconditionally. */ + * any out-of-range kind rather than NULL so callers can print unconditionally. + */ const char* wasm_insn_mnemonic(WasmInsnKind kind) { const WasmInsnInfo* info = wasm_insn_info(kind); return info ? info->mnemonic : ".unknown"; diff --git a/src/wasm/validate.c b/src/wasm/validate.c @@ -168,8 +168,7 @@ void wasm_validate(WasmModule* m, KitCompiler* c) { if (d->mode != WASM_SEG_ACTIVE) continue; if (d->memidx >= m->nmemories) wasm_error(c, wasm_loc(0, 0), "wasm: data memory index out of range"); - if (d->offset < 0) - wasm_error(c, wasm_loc(0, 0), "wasm: bad data offset"); + if (d->offset < 0) wasm_error(c, wasm_loc(0, 0), "wasm: bad data offset"); memory_bytes = wasm_memory_initial_bytes(c, &m->memories[d->memidx]); offset = (uint64_t)d->offset; if (offset > memory_bytes || d->nbytes > memory_bytes - offset) @@ -177,14 +176,12 @@ void wasm_validate(WasmModule* m, KitCompiler* c) { } for (i = 0; i < m->nelems; ++i) { if (m->elems[i].elem_type != WASM_VAL_FUNCREF) - wasm_error(c, wasm_loc(0, 0), - "wasm: unsupported element segment type"); + wasm_error(c, wasm_loc(0, 0), "wasm: unsupported element segment type"); if (m->elems[i].mode == WASM_SEG_ACTIVE) { uint32_t table_min; uint64_t offset; if (m->elems[i].tableidx >= m->ntables) - wasm_error(c, wasm_loc(0, 0), - "wasm: element table index out of range"); + wasm_error(c, wasm_loc(0, 0), "wasm: element table index out of range"); table_min = m->tables[m->elems[i].tableidx].min; if (m->elems[i].offset < 0) wasm_error(c, wasm_loc(0, 0), "wasm: element segment out of range"); diff --git a/src/wasm/wasm_insn_table.c b/src/wasm/wasm_insn_table.c @@ -1,11 +1,11 @@ #include "wasm/wasm_insn_table.h" -/* The one map. Each row is {kind, prefix, opcode-byte, operand-class, mnemonic}. - * Rows are designated-initialized by kind so the array stays enum-indexed (the - * mnemonic helper, encode's O(1) lookup, and the byte->kind reverse index all - * rely on that). Opcode bytes and prefixes mirror the Wasm binary format; - * operand classes mirror how encode writes / decode reads / WAT parses the - * immediates. */ +/* The one map. Each row is {kind, prefix, opcode-byte, operand-class, + * mnemonic}. Rows are designated-initialized by kind so the array stays + * enum-indexed (the mnemonic helper, encode's O(1) lookup, and the byte->kind + * reverse index all rely on that). Opcode bytes and prefixes mirror the Wasm + * binary format; operand classes mirror how encode writes / decode reads / WAT + * parses the immediates. */ #define I(k, pfx, b, oc, mn) \ [k] = {(uint8_t)(k), (uint8_t)(pfx), (uint8_t)(b), (uint8_t)(oc), mn} @@ -310,13 +310,10 @@ static const WasmInsnInfo WASM_INSN_TABLE[] = { "i64.trunc_sat_f64_s"), I(WASM_INSN_I64_TRUNC_SAT_F64_U, WASM_PREFIX_FC, 0x07, WASM_OC_NONE, "i64.trunc_sat_f64_u"), - I(WASM_INSN_MEMORY_INIT, WASM_PREFIX_FC, 0x08, WASM_OC_BULK, - "memory.init"), + I(WASM_INSN_MEMORY_INIT, WASM_PREFIX_FC, 0x08, WASM_OC_BULK, "memory.init"), I(WASM_INSN_DATA_DROP, WASM_PREFIX_FC, 0x09, WASM_OC_BULK, "data.drop"), - I(WASM_INSN_MEMORY_COPY, WASM_PREFIX_FC, 0x0a, WASM_OC_BULK, - "memory.copy"), - I(WASM_INSN_MEMORY_FILL, WASM_PREFIX_FC, 0x0b, WASM_OC_BULK, - "memory.fill"), + I(WASM_INSN_MEMORY_COPY, WASM_PREFIX_FC, 0x0a, WASM_OC_BULK, "memory.copy"), + I(WASM_INSN_MEMORY_FILL, WASM_PREFIX_FC, 0x0b, WASM_OC_BULK, "memory.fill"), I(WASM_INSN_TABLE_INIT, WASM_PREFIX_FC, 0x0c, WASM_OC_BULK, "table.init"), I(WASM_INSN_ELEM_DROP, WASM_PREFIX_FC, 0x0d, WASM_OC_BULK, "elem.drop"), I(WASM_INSN_TABLE_COPY, WASM_PREFIX_FC, 0x0e, WASM_OC_BULK, "table.copy"), diff --git a/src/wasm/wasm_insn_table.h b/src/wasm/wasm_insn_table.h @@ -22,8 +22,8 @@ /* Opcode-space prefix for an instruction's encoding. */ typedef enum WasmInsnPrefix { WASM_PREFIX_NONE = 0, /* single-byte opcode, `byte` is the opcode */ - WASM_PREFIX_FC = 1, /* 0xfc-prefixed (misc: trunc_sat + bulk memory/table) */ - WASM_PREFIX_FE = 2, /* 0xfe-prefixed (threads/atomics) */ + WASM_PREFIX_FC = 1, /* 0xfc-prefixed (misc: trunc_sat + bulk memory/table) */ + WASM_PREFIX_FE = 2, /* 0xfe-prefixed (threads/atomics) */ } WasmInsnPrefix; /* Operand-class column: how an instruction's immediates are spelled. Drives diff --git a/src/wasm/wat.c b/src/wasm/wat.c @@ -355,7 +355,8 @@ static int wat_instr_kind(WasmTok t, WasmInsnKind* out, int* has_imm) { if (!info) continue; if (tok_is(t, info->mnemonic)) { *out = k; - *has_imm = wasm_operand_class_has_imm((WasmOperandClass)info->operand_class); + *has_imm = + wasm_operand_class_has_imm((WasmOperandClass)info->operand_class); return 1; } } @@ -364,8 +365,8 @@ static int wat_instr_kind(WasmTok t, WasmInsnKind* out, int* has_imm) { if (tok_is(t, WAT_INSN_ALIASES[i].mnemonic)) { const WasmInsnInfo* info = wasm_insn_info(WAT_INSN_ALIASES[i].kind); *out = WAT_INSN_ALIASES[i].kind; - *has_imm = - info && wasm_operand_class_has_imm((WasmOperandClass)info->operand_class); + *has_imm = info && wasm_operand_class_has_imm( + (WasmOperandClass)info->operand_class); return 1; } } diff --git a/test/api/abi_classify_test.c b/test/api/abi_classify_test.c @@ -569,8 +569,7 @@ static void test_apple_arm64_stack_traits(void) { EXPECT(fi->vararg_on_stack == 1, "apple arm64 variadic: vararg_on_stack=%u want 1", (unsigned)fi->vararg_on_stack); - EXPECT(fi->stack_arg_min_align == 4, - "apple arm64 fixed stack min=%u want 4", + EXPECT(fi->stack_arg_min_align == 4, "apple arm64 fixed stack min=%u want 4", (unsigned)fi->stack_arg_min_align); EXPECT(fi->vararg_stack_arg_min_align == 8, "apple arm64 vararg stack min=%u want 8", @@ -593,18 +592,16 @@ static void check_scalar_split_lane_target(KitArchKind arch, KitOSKind os, KitCgBuiltinTypes bi = kit_cg_builtin_types(c); TargetABI* abi = ((Compiler*)c)->abi; - EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I64]) == - want_i64, - "%s i64 split lane=%u want %u", tag, - (unsigned)abi_cg_scalar_split_lane_size(abi, - bi.id[KIT_CG_BUILTIN_I64]), - (unsigned)want_i64); - EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F64]) == - want_f64, - "%s f64 split lane=%u want %u", tag, - (unsigned)abi_cg_scalar_split_lane_size(abi, - bi.id[KIT_CG_BUILTIN_F64]), - (unsigned)want_f64); + EXPECT( + abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I64]) == want_i64, + "%s i64 split lane=%u want %u", tag, + (unsigned)abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I64]), + (unsigned)want_i64); + EXPECT( + abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F64]) == want_f64, + "%s f64 split lane=%u want %u", tag, + (unsigned)abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F64]), + (unsigned)want_f64); EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_I32]) == 0, "%s i32 should not be split-lane", tag); EXPECT(abi_cg_scalar_split_lane_size(abi, bi.id[KIT_CG_BUILTIN_F32]) == 0, diff --git a/test/api/cg_fp_cmp_test.c b/test/api/cg_fp_cmp_test.c @@ -268,8 +268,7 @@ static void run_emit(KitArchKind arch, KitOSKind os, KitObjFmt fmt, * otherwise the object finalizes cleanly. */ EXPECT(kit_cg_finish(cg, NULL) == KIT_OK, "%s/O%d: finish failed", tag, opt_level); - EXPECT(kit_cg_detach(cg) == KIT_OK, "%s/O%d: detach failed", tag, - opt_level); + EXPECT(kit_cg_detach(cg) == KIT_OK, "%s/O%d: detach failed", tag, opt_level); kit_cg_free(cg); kit_obj_builder_free(ob); diff --git a/test/api/cg_type_test.c b/test/api/cg_type_test.c @@ -1350,8 +1350,7 @@ static void exercise_cg_begin_end_two_objects(KitCompiler* c) { if (cg && ob2) { EXPECT(kit_cg_begin(cg, ob2, &opts) == KIT_OK, "cg begin second object failed"); - EXPECT(kit_cg_finish(cg, NULL) == KIT_OK, - "cg finish second object failed"); + EXPECT(kit_cg_finish(cg, NULL) == KIT_OK, "cg finish second object failed"); EXPECT(kit_cg_detach(cg) == KIT_OK, "cg detach second object failed"); } kit_cg_free(cg); diff --git a/test/arch/rv32_decode_test.c b/test/arch/rv32_decode_test.c @@ -225,11 +225,11 @@ static void csr_pseudos_match_full_form(KitCompiler* pub) { /* Round-trip the CSR-name table: every name maps back to itself. */ for (u32 i = 0; i < rv64_csr_names_n; ++i) { u16 num = 0; - EXPECT(rv64_csr_num_from_name( - kit_slice_cstr(rv64_csr_names[i].name), &num) && - num == rv64_csr_names[i].num, - "csr name lookup '%s' -> 0x%x", rv64_csr_names[i].name, - (unsigned)rv64_csr_names[i].num); + EXPECT( + rv64_csr_num_from_name(kit_slice_cstr(rv64_csr_names[i].name), &num) && + num == rv64_csr_names[i].num, + "csr name lookup '%s' -> 0x%x", rv64_csr_names[i].name, + (unsigned)rv64_csr_names[i].num); EXPECT(rv64_csr_name_from_num(rv64_csr_names[i].num) != NULL, "csr num 0x%x has no name", (unsigned)rv64_csr_names[i].num); } diff --git a/test/arch/rv64_decode_test.c b/test/arch/rv64_decode_test.c @@ -166,11 +166,11 @@ static void csr_pseudos_match_full_form(KitCompiler* pub) { /* Round-trip the CSR-name table. */ for (u32 i = 0; i < rv64_csr_names_n; ++i) { u16 num = 0; - EXPECT(rv64_csr_num_from_name(kit_slice_cstr(rv64_csr_names[i].name), - &num) && - num == rv64_csr_names[i].num, - "csr name lookup '%s' -> 0x%x", rv64_csr_names[i].name, - (unsigned)rv64_csr_names[i].num); + EXPECT( + rv64_csr_num_from_name(kit_slice_cstr(rv64_csr_names[i].name), &num) && + num == rv64_csr_names[i].num, + "csr name lookup '%s' -> 0x%x", rv64_csr_names[i].name, + (unsigned)rv64_csr_names[i].num); EXPECT(rv64_csr_name_from_num(rv64_csr_names[i].num) != NULL, "csr num 0x%x has no name", (unsigned)rv64_csr_names[i].num); } @@ -198,9 +198,8 @@ static void expect_cr_flags(KitCompiler* pub, unsigned word, u16 want_set, EXPECT(st == KIT_OK, "decode_one(%s) status %d", what, (int)st); EXPECT(insn.nbytes == 2, "%s nbytes = %u (want 2)", what, (unsigned)insn.nbytes); - EXPECT((insn.flags & want_set) == want_set, - "%s flags 0x%x missing 0x%x", what, (unsigned)insn.flags, - (unsigned)want_set); + EXPECT((insn.flags & want_set) == want_set, "%s flags 0x%x missing 0x%x", + what, (unsigned)insn.flags, (unsigned)want_set); EXPECT((insn.flags & want_clear) == 0, "%s flags 0x%x should clear 0x%x", what, (unsigned)insn.flags, (unsigned)want_clear); } diff --git a/test/arch/x64_inline_test.c b/test/arch/x64_inline_test.c @@ -67,13 +67,14 @@ int main(void) { { static const uint8_t syscall_bytes[] = {0x0fu, 0x05u}; InlineText sc; - IT_EXPECT(&env, - it_emit_text(&env, KIT_ARCH_X86_64, "x64_rax_pin", x64_rax_pin, - &sc), - "failed to emit rax-pinned syscall inline asm"); + IT_EXPECT( + &env, + it_emit_text(&env, KIT_ARCH_X86_64, "x64_rax_pin", x64_rax_pin, &sc), + "failed to emit rax-pinned syscall inline asm"); if (sc.data) IT_EXPECT( - &env, it_contains(sc.data, sc.len, syscall_bytes, sizeof syscall_bytes), + &env, + it_contains(sc.data, sc.len, syscall_bytes, sizeof syscall_bytes), "missing syscall encoding for rax-pinned operand"); it_text_close(&sc); } diff --git a/test/cg/native_direct_target_test.c b/test/cg/native_direct_target_test.c @@ -196,8 +196,8 @@ static void mock_emit_call(NativeTarget* t, const NativeCallPlan* plan) { } static void mock_plan_ret(NativeTarget* t, const CGFuncDesc* fd, - const NativeLoc* value, - NativeCallPlanRet** out_rets, u32* out_nrets) { + const NativeLoc* value, NativeCallPlanRet** out_rets, + u32* out_nrets) { NativeCallPlanRet* r; (void)fd; r = arena_zarray(t->c->tu, NativeCallPlanRet, 1); diff --git a/test/coff/kit-roundtrip-coff.c b/test/coff/kit-roundtrip-coff.c @@ -693,8 +693,8 @@ static void verify_rel32_inline_addend(const ObjBuilder* ob, Pool* p) { } EXPECT(found != NULL, "no reloc on .text"); if (found) { - EXPECT(found->kind == R_PC32, "reloc kind=%u (want R_PC32=%u)", - found->kind, R_PC32); + EXPECT(found->kind == R_PC32, "reloc kind=%u (want R_PC32=%u)", found->kind, + R_PC32); EXPECT(found->addend == 0x124, "reloc addend=%lld (want 0x124)", (long long)found->addend); EXPECT(found->has_explicit_addend == 0, "inline addend marked explicit"); diff --git a/test/coff/pe-image-read.c b/test/coff/pe-image-read.c @@ -77,14 +77,14 @@ static KitContext g_ctx; static int g_failures; static const char* g_case = "?"; -#define EXPECT(cond, ...) \ - do { \ - if (!(cond)) { \ +#define EXPECT(cond, ...) \ + do { \ + if (!(cond)) { \ fprintf(stderr, "FAIL [%s] %s:%d: ", g_case, __FILE__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); \ - fputc('\n', stderr); \ - g_failures++; \ - } \ + fprintf(stderr, __VA_ARGS__); \ + fputc('\n', stderr); \ + g_failures++; \ + } \ } while (0) /* ---- target / compiler ------------------------------------------- */ @@ -144,7 +144,7 @@ static void build_short_import(uint8_t buf[SHIM_TOTAL_LEN], uint16_t machine) { /* mainCRTStartup body: a single return. The exact encoding is irrelevant * to the reader; differ per arch only so the linker sees plausible code. */ -static const uint8_t TEXT_X64[1] = {0xc3}; /* ret */ +static const uint8_t TEXT_X64[1] = {0xc3}; /* ret */ static const uint8_t TEXT_AA64[4] = {0xc0, 0x03, 0x5f, 0xd6}; /* ret */ static ObjBuilder* build_program(Compiler* c, KitArchKind arch) { @@ -155,7 +155,8 @@ static ObjBuilder* build_program(Compiler* c, KitArchKind arch) { Sym main_name = pool_intern_slice(p, SLICE_LIT("mainCRTStartup")); Sym exit_name = pool_intern_slice(p, SLICE_LIT(SHIM_SYM_CSTR)); const uint8_t* text = arch == KIT_ARCH_X86_64 ? TEXT_X64 : TEXT_AA64; - u32 text_len = arch == KIT_ARCH_X86_64 ? (u32)sizeof TEXT_X64 : (u32)sizeof TEXT_AA64; + u32 text_len = + arch == KIT_ARCH_X86_64 ? (u32)sizeof TEXT_X64 : (u32)sizeof TEXT_AA64; ObjSecId tsec = obj_section(ob, text_name, SEC_TEXT, SF_ALLOC | SF_EXEC, 16); ObjSecId dsec = obj_section(ob, data_name, SEC_DATA, SF_ALLOC | SF_WRITE, 8); ObjSymId exit_sym; diff --git a/test/elf/unit/rv32_class32.c b/test/elf/unit/rv32_class32.c @@ -186,8 +186,7 @@ int main(void) { out_data[EI_CLASS], ELFCLASS32); } if (out_len >= 20) { - unsigned machine = - (unsigned)out_data[18] | ((unsigned)out_data[19] << 8); + unsigned machine = (unsigned)out_data[18] | ((unsigned)out_data[19] << 8); CHECK(machine == EM_RISCV, "e_machine=%u after emit, want EM_RISCV=%u", machine, EM_RISCV); } @@ -219,16 +218,15 @@ int main(void) { /* (c) The symbol survives: GLOBAL FUNC in .text at value 0. */ if (back) { KitObjSection text = KIT_SECTION_NONE; - CHECK(kit_obj_section_by_name(back, KIT_SLICE_LIT(".text"), &text) == - KIT_OK, - ".text not present after roundtrip"); + CHECK( + kit_obj_section_by_name(back, KIT_SLICE_LIT(".text"), &text) == KIT_OK, + ".text not present after roundtrip"); KitObjSymInfo si; if (kit_obj_symbol_by_name(back, KIT_SLICE_LIT("rv32_sym"), &si) == KIT_OK) { CHECK(si.bind == KIT_SB_GLOBAL, "rv32_sym bind=%u", si.bind); - CHECK(si.kind == KIT_SK_FUNC, "rv32_sym kind=%u (want SK_FUNC)", - si.kind); + CHECK(si.kind == KIT_SK_FUNC, "rv32_sym kind=%u (want SK_FUNC)", si.kind); CHECK(si.value == 0, "rv32_sym value=%llu, want 0", (unsigned long long)si.value); if (text != KIT_SECTION_NONE) { diff --git a/test/link/coff_weak_alias_test.c b/test/link/coff_weak_alias_test.c @@ -16,11 +16,10 @@ * * Exit 0 = pass; non-zero = fail. */ +#include <kit/core.h> #include <stdint.h> #include <string.h> -#include <kit/core.h> - #include "core/core.h" #include "core/pool.h" #include "lib/kit_unit.h" @@ -105,8 +104,7 @@ static size_t build_coff(u8* out, const char* weak_name, u32 characteristics) { } static Sym intern(Compiler* c, const char* s) { - return pool_intern_slice(c->global, - (Slice){.s = s, .len = (u32)strlen(s)}); + return pool_intern_slice(c->global, (Slice){.s = s, .len = (u32)strlen(s)}); } int main(void) { @@ -143,7 +141,8 @@ int main(void) { } } - /* Negative: SEARCH_LIBRARY (kit's own STB_WEAK emit shape) is not an alias. */ + /* Negative: SEARCH_LIBRARY (kit's own STB_WEAK emit shape) is not an alias. + */ { size_t len = build_coff(buf, "wlib", SEARCH_LIBRARY); ObjBuilder* ob = read_coff(c, "weak_lib.o", buf, len); diff --git a/test/link/harness/jit_runner.c b/test/link/harness/jit_runner.c @@ -357,8 +357,7 @@ typedef int (*WasmRunnerMainFn)(void*); #define WASM_RUNNER_MAX_INSTANCE_BYTES (64ull * 1024ull * 1024ull) #define WASM_RUNNER_MAX_TOTAL_MEMORY_BYTES (1024ull * 1024ull * 1024ull) -static int wasm_runner_u64_to_size(uint64_t n, size_t* out, - const char* what) { +static int wasm_runner_u64_to_size(uint64_t n, size_t* out, const char* what) { if (n > (uint64_t)SIZE_MAX) { fprintf(stderr, "jit-runner: wasm %s exceeds host size_t\n", what); return 1; @@ -734,9 +733,9 @@ int main(int argc, char** argv) { return 1; } { - KitStatus bind_st = kit_wasm_bind_host_imports( - c, jit, (KitWasmInstance*)alloc.instance, NULL, 0, - wasm_runner_resolve_import, NULL); + KitStatus bind_st = + kit_wasm_bind_host_imports(c, jit, (KitWasmInstance*)alloc.instance, + NULL, 0, wasm_runner_resolve_import, NULL); if (bind_st != KIT_OK) { fprintf(stderr, "jit-runner: wasm host import %s\n", bind_st == KIT_NOT_FOUND diff --git a/test/link/jit_tls_relax_test.c b/test/link/jit_tls_relax_test.c @@ -16,11 +16,10 @@ * * Exit 0 = pass; non-zero = fail. */ +#include <kit/core.h> #include <stdint.h> #include <string.h> -#include <kit/core.h> - #include "core/core.h" #include "lib/kit_unit.h" #include "obj/obj.h" @@ -137,10 +136,10 @@ static void x64_check(u32 rd) { * `kit cc -target x86_64-windows -c` disassembly. A drift in the builder (and * thus a relax tested against a fictional idiom) turns this red. */ static void x64_golden(void) { - static const u8 want[] = {0x65, 0x4c, 0x8b, 0x04, 0x25, 0x58, 0x00, 0x00, - 0x00, 0x44, 0x8b, 0x1d, 0x00, 0x00, 0x00, 0x00, - 0x4f, 0x8b, 0x04, 0xd8, 0x4d, 0x8d, 0x80, 0x00, - 0x00, 0x00, 0x00}; + static const u8 want[] = {0x65, 0x4c, 0x8b, 0x04, 0x25, 0x58, 0x00, + 0x00, 0x00, 0x44, 0x8b, 0x1d, 0x00, 0x00, + 0x00, 0x00, 0x4f, 0x8b, 0x04, 0xd8, 0x4d, + 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00}; u8 buf[40]; u32 site_off; u32 total = x64_emit_idiom(buf, 8u /* r8 */, &site_off); @@ -154,8 +153,8 @@ static void x64_golden(void) { #define AA_NOP 0xd503201fu static u32 aa_add_imm(u32 rd, u32 rn, u32 imm12, u32 sh) { - return 0x91000000u | (sh << 22) | ((imm12 & 0xfffu) << 10) | ((rn & 0x1fu) - << 5) | (rd & 0x1fu); + return 0x91000000u | (sh << 22) | ((imm12 & 0xfffu) << 10) | + ((rn & 0x1fu) << 5) | (rd & 0x1fu); } /* Emit the 7-instruction Win64/aarch64 TLS idiom for `rd` (aa_tls_addr_of_win). @@ -212,7 +211,8 @@ int main(void) { size_t i; kit_unit_init(&g_u); x64_golden(); - for (i = 0; i < sizeof x64_rds / sizeof x64_rds[0]; ++i) x64_check(x64_rds[i]); + for (i = 0; i < sizeof x64_rds / sizeof x64_rds[0]; ++i) + x64_check(x64_rds[i]); for (i = 0; i < sizeof aa_rds / sizeof aa_rds[0]; ++i) aa_check(aa_rds[i]); kit_unit_summary(&g_u, "jit_tls_relax_test"); return kit_unit_status(&g_u); diff --git a/test/link/reloc_apply_test.c b/test/link/reloc_apply_test.c @@ -98,10 +98,9 @@ static const ApplyCase kCases[] = { {"aa64 TLVP_LOAD_PAGEOFF12", KIT_ARCH_ARM_64, R_AARCH64_TLVP_LOAD_PAGEOFF12, 0xf9400000u, 4, 0x1100, 0, 0, 0xf9408000u}, /* ---- AArch64 neutral data words (kept in obj core) ---- */ - {"aa64 ABS16", KIT_ARCH_ARM_64, R_ABS16, 0x0000u, 2, 0x1234, 0, 0, - 0x1234u}, - {"aa64 PREL16", KIT_ARCH_ARM_64, R_PREL16, 0x0000u, 2, 0x2000, 0, - 0x1000, 0x1000u}, + {"aa64 ABS16", KIT_ARCH_ARM_64, R_ABS16, 0x0000u, 2, 0x1234, 0, 0, 0x1234u}, + {"aa64 PREL16", KIT_ARCH_ARM_64, R_PREL16, 0x0000u, 2, 0x2000, 0, 0x1000, + 0x1000u}, /* ---- x86-64 instruction-immediate + neutral data words ---- */ {"x64 PC8", KIT_ARCH_X86_64, R_X64_PC8, 0x00u, 1, 0x1010, -2, 0x1000, diff --git a/test/link/rv32_jit_test.c b/test/link/rv32_jit_test.c @@ -25,8 +25,9 @@ * exits 77 (the GNU autotools "skipped" convention) when this happens. * * Wired into mk/test.mk via test-rv32-jit. Always builds; calls only on - * rv32 hosts. This mirrors the rv64 JIT smoke test (test/link/rv64_jit_test.c): - * have the code path in place for the day someone runs kit on a rv32 dev box. + * rv32 hosts. This mirrors the rv64 JIT smoke test + * (test/link/rv64_jit_test.c): have the code path in place for the day someone + * runs kit on a rv32 dev box. * * The two base-ISA encodings are identical on rv32 and rv64 (they are RV32I * instructions reused unchanged by RV64I), so the encoding constants are the diff --git a/test/parse/cases/builtin_29_return_address.c b/test/parse/cases/builtin_29_return_address.c @@ -1,5 +1,6 @@ /* __builtin_return_address(0): the current function's return address, read - * from the spilled frame record. A real frame's return address is never null. */ + * from the spilled frame record. A real frame's return address is never null. + */ __attribute__((noinline)) static void* ra0(void) { return __builtin_return_address(0); } diff --git a/test/parse/cases/builtin_31_return_address_anchor.c b/test/parse/cases/builtin_31_return_address_anchor.c @@ -2,7 +2,8 @@ * must land inside its caller. callee() is defined before test_main, so its * code lies below test_main's; the return address into test_main therefore sits * at or above test_main's entry and within its (small) body. Exercised across - * the parse lanes (host JIT + ELF roundtrip + qemu/podman exec) at O0 and O1. */ + * the parse lanes (host JIT + ELF roundtrip + qemu/podman exec) at O0 and O1. + */ __attribute__((noinline)) static void* callee(void) { return __builtin_return_address(0); } diff --git a/test/parse/cases/gnu_inline_control_flow.c b/test/parse/cases/gnu_inline_control_flow.c @@ -4,7 +4,8 @@ * CG function — regression for pcg_label_new and the while/switch suppressed * paths, which mint dummy labels under suppression instead of calling the CG * label ops. The suppressed body is intentionally not referenced (an extern - * inline has no external definition to link against); test_main stands alone. */ + * inline has no external definition to link against); test_main stands alone. + */ extern inline int suppressed(int n) { int s = 0; while (n > 0) { diff --git a/test/rt/cases/print_backtrace.c b/test/rt/cases/print_backtrace.c @@ -1,4 +1,5 @@ -/* __kit_print_backtrace format test (the in-process half of the L3a round-trip). +/* __kit_print_backtrace format test (the in-process half of the L3a + * round-trip). * * Overrides the weak __kit_backtrace_write sink to capture the emitted bytes, * calls __kit_print_backtrace() from the bottom of a known @[.noinline] @@ -44,10 +45,11 @@ int test_main(void) { recurse(DEPTH); - if (g_len <= 0) return 1; /* the sink must have been called */ + if (g_len <= 0) return 1; /* the sink must have been called */ if (g_buf[g_len - 1] != '\n') return 2; /* every line is terminated */ - /* Parse each "#<dec> 0x<hex>\n" line strictly, recording index and address. */ + /* Parse each "#<dec> 0x<hex>\n" line strictly, recording index and address. + */ while (i < g_len) { int v = 0; unsigned long a = 0; @@ -84,8 +86,8 @@ int test_main(void) { /* The chain holds at least the recurse() frames plus test_main. */ if (cnt < DEPTH + 1) return 9; for (i = 0; i < cnt; i++) { - if (idx[i] != i) return 10; /* frame numbers are sequential from 0 */ - if (addr[i] == 0) return 11; /* a real frame never has a null retaddr */ + if (idx[i] != i) return 10; /* frame numbers are sequential from 0 */ + if (addr[i] == 0) return 11; /* a real frame never has a null retaddr */ } /* #1..#DEPTH all return to the single recursive call site, so consecutive * recursive frames share a return address. (#0 is the print call site.) */ diff --git a/test/wasm/harness/start_wasm.c b/test/wasm/harness/start_wasm.c @@ -72,8 +72,7 @@ typedef struct WasmStartMemoryLayout { unsigned int reserved; } WasmStartMemoryLayout; -extern const unsigned long long __kit_wasm_instance_size - __attribute__((weak)); +extern const unsigned long long __kit_wasm_instance_size __attribute__((weak)); extern const unsigned int __kit_wasm_nmemories __attribute__((weak)); extern const WasmStartMemoryLayout __kit_wasm_memory_layouts[] __attribute__((weak)); @@ -187,8 +186,7 @@ static int start_setup_dynamic_instance(void** instance_out) { void* instance; unsigned long long instance_size; unsigned long long total_memory = 0; - if (!(&__kit_wasm_instance_size) || !(&__kit_wasm_nmemories)) - return 0; + if (!(&__kit_wasm_instance_size) || !(&__kit_wasm_nmemories)) return 0; instance_size = __kit_wasm_instance_size ? __kit_wasm_instance_size : 1ull; if (instance_size > WASM_START_MAX_INSTANCE_SIZE) return -1; if (__kit_wasm_nmemories && !(&__kit_wasm_memory_layouts)) return -1;