• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# This script generates template for docs/PBC2IR.md
15# 1. If PBC2IR.md already exists, it is copied to PBC2IR_OLD.md.
16# 2. The new one PBC2IR.md is generated.
17# 3. IR column is empty by default. PBC2IR_OLD.md is used to copy existing IR instructions to corresponds cells in PBC2IR.md.
18# Another information isn't copied!
19
20set -e
21
22for ARGUMENT in "$@"; do
23case "$ARGUMENT" in
24    --binary-dir=*)
25    PANDA_BINARY_ROOT="${ARGUMENT#*=}"
26    ;;
27    --root-dir=*)
28    PANDA_ROOT="${ARGUMENT#*=}"
29    ;;
30esac
31done
32
33ISA=$PANDA_ROOT/isa/isa.yaml
34DOC=$PANDA_ROOT/docs/PBC2IR.md
35OLD_DOC=$PANDA_BINARY_ROOT/PBC2IR_OLD.md
36
37[ -e "$OLD_DOC" ] && rm "$OLD_DOC"
38
39[ -e "$DOC" ] && cp "$DOC" "$OLD_DOC" && rm "$DOC"
40
41test "$DOC"
42
43exec 1>"$DOC"
44
45# Get signatures of all instructions
46all_insts=$(grep "sig:" "$ISA" | cut -f2 -d':' | cut -f2 -d' ')
47# Ignore repeated instructions
48pbc_instructions=$(echo "$all_insts" | awk '{delete seen; c=0; for (i=1;i<=NF;i++) \
49    if (!seen[$i]++) printf "%s%s", (++c>1?OFS:""), $i; print ""}')
50
51echo "| PBC | IR |"
52echo "|-----|----|"
53
54for inst_name in $pbc_instructions; do
55    descr=$(grep "| $inst_name |" "$OLD_DOC" | cut -f3 -d"|")
56    echo "| $inst_name |$descr|"
57done
58
59echo
60echo "This document generated by compiler/tools/pbc_2_ir_doc_gen.sh."
61
62[ -e "$OLD_DOC" ] && rm "$OLD_DOC"
63