boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

prune-p1-table.sh (968B)


      1 #!/bin/sh
      2 ## prune-p1-table.sh — emit a pruned P1 backend table.
      3 ##
      4 ## One-time host-side helper. Reads the full per-arch P1 DEFINE table
      5 ## generated by P1/gen/p1_gen.py (~7,300 DEFINEs) and keeps only the
      6 ## DEFINEs whose names appear as whitespace-separated tokens in the given
      7 ## source files. Result is checked in as P1/P1-<arch>.M1 so routine
      8 ## builds skip the prune step.
      9 ##
     10 ## The match is conservative: any token that lexically equals a DEFINE
     11 ## name keeps that DEFINE. False positives (extra DEFINEs) are harmless;
     12 ## only false negatives would cause a SIGILL binary, and the lexical
     13 ## match cannot produce them.
     14 ##
     15 ## Usage: prune-p1-table.sh <full-table.M1> <output> <src...>
     16 
     17 set -eu
     18 
     19 [ "$#" -ge 3 ] || { echo "usage: $0 <full-table.M1> <output> <src...>" >&2; exit 2; }
     20 
     21 FULL=$1
     22 OUT=$2
     23 shift 2
     24 
     25 cat "$@" | awk '
     26   NR==FNR { for (i = 1; i <= NF; i++) used[$i] = 1; next }
     27   /^DEFINE / { if ($2 in used) print; next }
     28   { print }
     29 ' - "$FULL" > "$OUT"