OILS / asdl / old.sh View on Github | oilshell.org

116 lines, 63 significant
1#!/usr/bin/env bash
2#
3# Junk drawer for ASDL.
4#
5# Usage:
6# asdl/run.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
13readonly REPO_ROOT
14
15source build/common.sh
16
17export PYTHONPATH='.:vendor/'
18
19#
20# Native Code
21#
22
23# http://www.commandlinefu.com/commands/view/6004/print-stack-trace-of-a-core-file-without-needing-to-enter-gdb-interactively
24# http://stackoverflow.com/questions/4521015/how-to-pass-arguments-and-redirect-stdin-from-a-file-to-program-run-in-gdb
25gdb-trace() {
26 # -args goes before the executable
27 gdb -batch -ex "run" -ex "bt" -args "$@" 2>&1
28}
29
30# http://stackoverflow.com/questions/22769246/disassemble-one-function-using-objdump
31# It would be nice to disassemble a single function.
32
33disassemble() {
34 local opt_flag=${1:-'-O0'}
35 local out=_tmp/typed_arith_demo$opt_flag.S
36 $CLANGXX -std='c++11' $opt_flag -I _tmp -o $out -S \
37 -mllvm --x86-asm-syntax=intel asdl/typed_arith_demo.cc
38 #cat $out
39}
40
41llvm() {
42 local opt_flag=${1:-'-O0'}
43 local out=_tmp/typed_arith_demo$opt_flag.ll
44 $CLANGXX -std='c++11' $opt_flag -I _tmp -o $out -S \
45 -emit-llvm asdl/typed_arith_demo.cc
46 #cat $out
47}
48
49# With -O0, you can see all the functions. With -O2, they ARE inlined.
50objdump-arith() {
51 # NOTE: This doesn't take into account different optimization levels
52 objdump -d _tmp/typed_arith_demo | grep '^0'
53}
54# https://sourceware.org/ml/binutils/2010-04/msg00447.html
55# http://stackoverflow.com/questions/4274804/query-on-ffunction-section-fdata-sections-options-of-gcc
56# Hm you can force a function. Write it inline with typed_arith_demo.cc then.
57
58# TODO: Is there a pattern we can grep for to test if ANY accessor was NOT
59# inlined? Demangle names I guess.
60nm-arith() {
61 nm _tmp/typed_arith_demo
62}
63
64opt-stats() {
65 wc -l _tmp/*.S
66 echo
67 wc -l _tmp/*.ll
68 echo
69 md5sum _tmp/*.S
70 echo
71 md5sum _tmp/*.ll
72}
73
74compare-opts() {
75 # http://stackoverflow.com/questions/15548023/clang-optimization-levels
76 # Says -Os is identical to -O2? But not according to my test!
77
78 for opt in -Os -O0 -O1 -O2 -O3 -O4; do
79 echo $opt
80 disassemble $opt
81 llvm $opt
82 done
83 opt-stats
84}
85
86regress() {
87 bin/osh -n configure > _tmp/configure-tree-abbrev.txt
88 bin/osh --ast-format text -n configure > _tmp/configure-tree-full.txt
89 { wc -l _tmp/configure*.txt
90 md5sum _tmp/configure*.txt
91 } #| tee _tmp/gold.txt
92}
93
94# To check if the lines go over 100 characters.
95line-length-hist() {
96 for f in _tmp/configure*.txt; do
97 echo $f
98 awk '{ print length($0) } ' $f | sort -n | uniq -c | tail
99 done
100}
101
102gen-cpp-errors() {
103
104 # This doesn't produce an error, even though 'int?' isn't representable in C++
105 cat >_tmp/bad.asdl <<EOF
106module bad {
107 foo = (int? x, int y)
108}
109EOF
110
111 asdl/asdl_main.py cpp _tmp/bad.asdl _tmp/asdl_bad
112
113 ls -l _tmp/asdl_bad*
114}
115
116"$@"