Commit 2516ddf9

2516ddf9d780Merged

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

Description

Merge pull request #1345 from matz/emit-symbol-map

Add --emit-symbol-map: export emitted-symbol → Ruby-name map (#1334)

Details

Commit
2516ddf9d780
Parent
abc369aebf68
Merge parent
7ae3c4810fed

spinelmodifiedView file

@@ -48,6 +48,7 @@
4848 C_ONLY=0
4949 EMIT_RBS=0
5050 EMIT_TYPES=0
51+EMIT_SYMBOL_MAP=0
5152 STDOUT_MODE=0
5253 RUN_MODE=0
5354 # #line directives are on by default: they cost nothing at runtime (purely a
@@ -140,6 +141,10 @@
140141 # diagnostics as JSON (for the ruby-lsp addon). Needs node
141142 # positions, so it turns on SPINEL_DEBUG below.
142143 EMIT_TYPES=1; DEBUG=1; shift ;;
144+ --emit-symbol-map) # Dump emitted-symbol -> Ruby-name map as JSON (#1334).
145+ # Runs codegen (the mangling lives there) but writes no
146+ # binary. DEBUG on so node positions (file/line) are stamped.
147+ EMIT_SYMBOL_MAP=1; DEBUG=1; shift ;;
143148 -S) STDOUT_MODE=1; shift ;;
144149 -E) RUN_MODE=1; shift ;;
145150 *.rb)
@@ -367,6 +372,28 @@
367372 exit 0
368373 fi
369374
375+# --emit-symbol-map needs codegen (the C name-mangling lives there) but emits
376+# no binary: run codegen with SPINEL_EMIT_SYMBOL_MAP set, route the C output
377+# to a temp, and stop.
378+if [ "$EMIT_SYMBOL_MAP" -eq 1 ]; then
379+ SYM_OUT="${OUTPUT:-$BASENAME.symbols.json}"
380+ export SPINEL_EMIT_SYMBOL_MAP="$SYM_OUT"
381+ SYM_C_TMP="$(mktemp /tmp/spinel_symc.XXXXXX)"
382+ if [ -x "$CODEGEN_BIN" ]; then
383+ "$CODEGEN_BIN" "$AST_TMP" "$IR_TMP" "$SYM_C_TMP"
384+ else
385+ ruby "$CODEGEN_RB" "$AST_TMP" "$IR_TMP" "$SYM_C_TMP"
386+ fi
387+ cg_rc=$?
388+ rm -f "$SYM_C_TMP"
389+ if [ $cg_rc -ne 0 ]; then
390+ echo "spinel: codegen failed" >&2
391+ exit 1
392+ fi
393+ echo "Wrote $SYM_OUT" >&2
394+ exit 0
395+fi
396+
370397 # Step 3: Codegen
371398 if [ $STDOUT_MODE -eq 1 ]; then
372399 if [ -x "$CODEGEN_BIN" ]; then