Commit fdc93fde

fdc93fdef75aMerged

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

Description

Merge pull request #1276 from OriPekelman/pr/emit-rbs

Add spinel --emit-rbs: export whole-program inferred types as RBS

Details

Commit
fdc93fdef75a
Parent
507158f61403
Merge parent
5a899bc3c3f8

spinelmodifiedView file

@@ -43,6 +43,7 @@
4343 SOURCE=""
4444 OUTPUT=""
4545 C_ONLY=0
46+EMIT_RBS=0
4647 STDOUT_MODE=0
4748 RUN_MODE=0
4849 OPT_LEVEL="2"
@@ -107,6 +108,8 @@
107108 EVAL_USED=1
108109 shift ;;
109110 -c) C_ONLY=1; shift ;;
111+ --emit-rbs) # Analyze-only: dump inferred signatures as RBS, no binary.
112+ EMIT_RBS=1; shift ;;
110113 -S) STDOUT_MODE=1; shift ;;
111114 -E) RUN_MODE=1; shift ;;
112115 *.rb)
@@ -145,6 +148,23 @@
145148 fi
146149 fi
147150
151+# --emit-rbs is analyze-only (stops before codegen), so the binary/C-output
152+# modes would be silently ignored alongside it — reject the conflict up front.
153+if [ "$EMIT_RBS" -eq 1 ]; then
154+ if [ "$RUN_MODE" -eq 1 ]; then
155+ echo "spinel: --emit-rbs cannot be combined with -E (run)" >&2
156+ exit 2
157+ fi
158+ if [ "$C_ONLY" -eq 1 ]; then
159+ echo "spinel: --emit-rbs cannot be combined with -c (C source only)" >&2
160+ exit 2
161+ fi
162+ if [ "$STDOUT_MODE" -eq 1 ]; then
163+ echo "spinel: --emit-rbs cannot be combined with -S (stdout)" >&2
164+ exit 2
165+ fi
166+fi
167+
148168 # `-e` mode: write the accumulated inline script to a temp file and
149169 # treat it as the source. Default output name is `a` since the
150170 # inline form has no .rb basename to derive from. If both -e and a
@@ -173,6 +193,7 @@
173193 echo "Options:" >&2
174194 echo " -o FILE Output file" >&2
175195 echo " -c C source only (don't compile)" >&2
196+ echo " --emit-rbs Dump inferred type signatures as RBS (-> app.rbs), no binary" >&2
176197 echo " -S Print C to stdout" >&2
177198 echo " -E Run the compiled binary; leftover args become its ARGV" >&2
178199 echo " -O LEVEL Optimization level (default: 2)" >&2
@@ -239,6 +260,12 @@
239260 # int locals as bigint when mode == promote. Raise / wrap modes
240261 # only care about the cc-time preprocessor switch added below.
241262 export SPINEL_INT_OVERFLOW="$INT_OVERFLOW"
263+# RBS export mode: tell the analyzer to also dump inferred signatures.
264+# (Conflicting-mode checks are done up front with the other mode-conflict guards.)
265+if [ "$EMIT_RBS" -eq 1 ]; then
266+ RBS_OUT="${OUTPUT:-$BASENAME.rbs}"
267+ export SPINEL_EMIT_RBS="$RBS_OUT"
268+fi
242269 if [ -x "$ANALYZE_BIN" ]; then
243270 "$ANALYZE_BIN" "$AST_TMP" "$IR_TMP" $SEED_TMP
244271 else
@@ -249,6 +276,12 @@
249276 exit 1
250277 fi
251278
279+# --emit-rbs is analyze-only: the signatures are written, stop before codegen.
280+if [ "$EMIT_RBS" -eq 1 ]; then
281+ echo "Wrote $RBS_OUT" >&2
282+ exit 0
283+fi
284+
252285 # Step 3: Codegen
253286 if [ $STDOUT_MODE -eq 1 ]; then
254287 if [ -x "$CODEGEN_BIN" ]; then