1#!/bin/bash 2# Copyright (c) 2021-2022 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 "$@" 23do 24case "$ARGUMENT" in 25 --binary-dir=*) 26 PANDA_BINARY_ROOT="${ARGUMENT#*=}" 27 ;; 28 --root-dir=*) 29 PANDA_ROOT="${ARGUMENT#*=}" 30 ;; 31esac 32done 33 34ISA=$PANDA_ROOT/isa/isa.yaml 35DOC=$PANDA_ROOT/docs/PBC2IR.md 36OLD_DOC=$PANDA_BINARY_ROOT/PBC2IR_OLD.md 37 38[ -e "$OLD_DOC" ] && rm $OLD_DOC 39 40[ -e "$DOC" ] && cp $DOC $OLD_DOC && rm $DOC 41 42test $DOC 43 44exec 1>$DOC 45 46# Get signatures of all instructions 47all_insts=$(grep "sig:" $ISA | cut -f2 -d':' | cut -f2 -d' ') 48# Ignore repeated instructions 49pbc_instructions=$(echo $all_insts | awk '{delete seen; c=0; for (i=1;i<=NF;i++) \ 50 if (!seen[$i]++) printf "%s%s", (++c>1?OFS:""), $i; print ""}') 51 52echo "| PBC | IR |" 53echo "|-----|----|" 54 55for inst_name in $pbc_instructions 56do 57 descr=$(grep "| $inst_name |" $OLD_DOC | cut -f3 -d"|") 58 echo "| $inst_name |$descr|" 59done 60 61echo 62echo "This document generated by compiler/tools/pbc_2_ir_doc_gen.sh." 63 64[ -e "$OLD_DOC" ] && rm $OLD_DOC 65