#!/bin/bash
#
# Extract abstract syntax tree from a beam file compiled with
# debug_info flag.
#
#   ./ast.sh misc.beam

erl_file=$1
erl_script=$(cat <<EOF
    {ok, {_, [{abstract_code, {_, AST}}]}} =
        beam_lib:chunks("${erl_file}", [abstract_code]),
    io:format("~p~n", [AST]),
    init:stop(0).
EOF
)

erl -noinput -eval "${erl_script}"

Add a script to extract syntax tree from beam files.
[scripts] Add a script to extract syntax tree from beam files.

Useful for debugging parse transforms.

Change-Id: I1313265273953e7c38935706ab8d336a4b2b13b9
Reviewed-on: http://review.couchbase.org/84711
Tested-by: Aliaksey Artamonau <ce14b1c16e0fd654f926118eb8addbec5aff4ffa@couchbase.com>
Well-Formed: Build Bot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>
Reviewed-by: Artem Stemkovski <15a0730a27c69f62ab86f2b6c639fca202166c02@couchbase.com>
