brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · cb4c792 Raw
101 lines · bash
1#!/usr/bin/env bash2 3# This script is intended as a FileCheck replacement to update the test4# expectations in a -ast-dump test.5#6# Usage (to generate normal AST dump tests):7#8# $ lit -DFileCheck=$PWD/utils/make-ast-dump-check.sh test/AST/ast-dump-openmp-*9#10# Usage (to generate serialization AST dump tests):11#12# $ lit -DFileCheck="generate_serialization_test=1 $PWD/utils/make-ast-dump-check.sh"13#     test/AST/ast-dump-openmp-*14 15prefix=CHECK16 17if [ -z ${generate_serialization_test+x} ];18  then generate_serialization_test=0;19fi20 21while [[ "$#" -ne 0 ]]; do22  case "$1" in23  --check-prefix)24    shift25    prefix="$1"26    ;;27  --implicit-check-not)28    shift29    ;;30  -*)31    ;;32  *)33    file="$1"34    ;;35  esac36  shift37done38 39testdir="$(dirname "$file")"40 41read -r -d '' script <<REWRITE42BEGIN {43  skipping_builtins = 044  matched_last_line = 045}46 47/^[\`|].* line:/ {48  skipping_builtins = 049}50 51/^[\`|].* col:/ {52  skipping_builtins = 053}54 55{56  if (skipping_builtins == 1) {57    matched_last_line = 058    next59  }60}61 62/TranslationUnitDecl/ {63  skipping_builtins = 164}65 66{67  s = \$068  gsub("0x[0-9a-fA-F]+", "{{.*}}", s)69  gsub("$testdir/", "{{.*}}", s)70  if ($generate_serialization_test == 1) {71    gsub(" imported", "{{( imported)?}}", s)72    gsub(" <undeserialized declarations>", "{{( <undeserialized declarations>)?}}", s)73    gsub("line:[0-9]+:[0-9]+", "line:{{.*}}", s)74    gsub("line:[0-9]+", "line:{{.*}}", s)75    gsub("col:[0-9]+", "col:{{.*}}", s)76    gsub(":[0-9]+:[0-9]+", "{{.*}}", s)77  }78}79 80matched_last_line == 0 {81  print "// ${prefix}:" s82}83 84matched_last_line == 1 {85  print "// ${prefix}-NEXT:" s86}87 88{89  matched_last_line = 190}91REWRITE92 93echo "$script"94 95{96  cat "$file" | grep -v "$prefix"97  awk "$script"98} > "$file.new"99 100mv "$file.new" "$file"101