code wiki / _hdl_build / nx_dupfunc.nx

nx_dupfunc.nx

buildroot/runtime/_hdl_build/nx_dupfunc.nx

16319 B373 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_dupfunc.nx -- WHICH FUNCTION BODIES ARE WRITTEN MORE THAN ONCE? ===== WHY THIS EXISTS ============================================ The tree already has nx_dup_source_check, and it is a good tool, but it answers a different question: it detects the SAME FILE existing in two source trees. It is file-level and cross-tree by construction, so it cannot see two files in the same directory that happen to contain the same function written twice. That gap is not theoretical. Building nx_gatescan and nx_gatequality I duplicated NINE functions between them -- the tree walk, file read, path join, the file-type predicates, the attribution rule -- while holding two tools designed to find exactly this class of problem. Nothing in the ecosystem could have told me. This organ closes that. ===== THE DESIGN DECISION THAT MAKES IT WORK ===================== ★NAMES ARE IGNORED. My nine duplicates were called gs_len and gq_len, gs_walk and gq_walk -- identical bodies behind different prefixes, which is what copying into a new file naturally produces. A detector keyed on names would have found none of them. So a function is reduced to its BODY, and the body alone decides identity. Normalisation before comparison, each for a reason: - comments stripped : a copied function usually keeps the code and rewrites the comment, or vice versa - whitespace collapsed : re-indentation is not a difference - the signature line dropped: that is where the name lives ===== RANKED BY COST, NOT BY COUNT =============================== Two copies of a 60-line walk are a different problem from two copies of a one-line helper. Severity is therefore (copies - 1) x body size: what you would actually save, and what is actually at risk of drifting apart. ⚠WHAT IT DOES NOT MEAN. Identical bodies are not automatically a defect. This tree deliberately keeps independent re-derivations of a rule inside gates, because a test that calls the code under test can only confirm self-consistency -- and that decision is what caught a dead primitive

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_eco_graph.nx nx_gatelib.nx nx_dupfunc.nx

imports: nx_syscalls.nxnx_eco_graph.nxnx_gatelib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main eg_new sys_mmap sys_mmap ↻ gl_walk sys_openat_rd sys_mmap ↻ sys_getdents64 dirent_type dirent_name gl_isdotdot gl_join gl_walk ↻ gl_len gl_is_nx eg_intern eg_hash eg_name_eq gl_read sys_openat_rd ↻ sys_read sys_close nis_scan nis_is_ws eg_add_edge dirent_reclen sys_close ↻ dw sys_write dn sys_mmap ↻ sys_write ↻ gl_read ↻ gl_strip_comments gl_extract_funcs gl_is_ident df_hash gl_is_gate_name gl_ends gl_len ↻

structs

none

consts

52const DF_MAGIC_1469598103934665603: i64 = 1469598103934665603
53const DF_MAGIC_1099511628211: i64 = 1099511628211
54const DF_MAGIC_4096: i64 = 4096
55const DF_MAGIC_262144: i64 = 262144
57const DF_MAXNODE: i64 = 24000
58const DF_ARENA: i64 = 4194304
59const DF_HASH: i64 = 65536
60const DF_PATHARENA: i64 = 4194304
61const DF_MAXFUNCS: i64 = 64
63const DF_MAXTOTAL: i64 = 120000

functions

65func dw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
66func dn(v: i64) -> i64 { let b: *u8 = sys_mmap(24); var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, b, k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
73func df_hash(buf: *u8, n: i64) -> i64
called by 1: main
84func main(argc: i64, argv: *i64) -> i64