Commit 0c73e84f

0c73e84ffa0eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

spinelc: --emit-symbol-map (emitted C symbol -> Ruby name JSON)

Restores the legacy backend's symbol-map dump in the C driver. Gated on SPINEL_EMIT_SYMBOL_MAP (set by spinel --emit-symbol-map), codegen walks the analyzed scopes after analyze_program and writes

{"symbols":[{"c","ruby","kind","file","line"}, ...]}

then short-circuits codegen (no binary). The C symbol comes from emit_method_cname so it matches what codegen actually emits -- note the C path mangles singleton methods as sp_<Class>_s_<m> (not the legacy _cls_). Ruby names are name / Class#m / Class.m; file/line come from the def node and are null unless positions were stamped. The driver sets SPINEL_DEBUG so they are.

make check: 846 pass, 0 fail.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
0c73e84ffa0e
Parent
f14172a22bcf

spinelmodifiedView file

@@ -18,6 +18,7 @@
1818 # Options:
1919 # -o FILE Output file (binary, or C when combined with -c)
2020 # -c Generate C source only, don't compile
21+# --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary
2122 # -S Print generated C to stdout
2223 # -E Run the compiled binary instead of saving it; the
2324 # first .rb file ends spinel-flag parsing, and the rest
@@ -51,6 +52,7 @@
5152 C_ONLY=0
5253 STDOUT_MODE=0
5354 RUN_MODE=0
55+EMIT_SYMBOL_MAP=0
5456 OPT_LEVEL="2"
5557 CC_CMD="cc"
5658 EXTRA_FLAGS=""
@@ -115,6 +117,9 @@
115117 EVAL_USED=1
116118 shift ;;
117119 -c) C_ONLY=1; shift ;;
120+ --emit-symbol-map) # Dump emitted-C-symbol -> Ruby-name map as JSON
121+ # (-> app.symbols.json). Analyze-only; writes no binary.
122+ EMIT_SYMBOL_MAP=1; shift ;;
118123 -S) STDOUT_MODE=1; shift ;;
119124 -E) RUN_MODE=1; shift ;;
120125 *.rb)
@@ -175,6 +180,7 @@
175180 echo "Options:" >&2
176181 echo " -o FILE Output file" >&2
177182 echo " -c C source only (don't compile)" >&2
183+ echo " --emit-symbol-map Dump emitted-symbol -> Ruby-name map as JSON, no binary" >&2
178184 echo " -S Print C to stdout" >&2
179185 echo " -E Run the compiled binary; leftover args become its ARGV" >&2
180186 echo " -O LEVEL Optimization level (default: 2)" >&2
@@ -223,6 +229,21 @@
223229 export SPINEL_LINE_MAP=1
224230 fi
225231
232+# --emit-symbol-map: analyze-only. spinelc writes the JSON itself (driven by
233+# SPINEL_EMIT_SYMBOL_MAP) and emits an empty translation unit; SPINEL_DEBUG
234+# makes the parser stamp node positions so each symbol carries its file/line.
235+if [ "$EMIT_SYMBOL_MAP" -eq 1 ]; then
236+ SYM_OUT="${OUTPUT:-$BASENAME.symbols.json}"
237+ export SPINEL_DEBUG=1
238+ export SPINEL_EMIT_SYMBOL_MAP="$SYM_OUT"
239+ if ! "$SPINELC" "$SOURCE" >/dev/null; then
240+ echo "spinel: emit-symbol-map failed" >&2
241+ exit 1
242+ fi
243+ echo "Wrote $SYM_OUT" >&2
244+ exit 0
245+fi
246+
226247 # Step 1: Compile (parse + analyze + codegen) — spinelc emits C.
227248 if [ "$STDOUT_MODE" -eq 1 ]; then
228249 "$SPINELC" "$SOURCE"