logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

opcode.sh (1225B)


  1. #!/bin/sh -e
  2. # SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
  3. #
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. # This file replaces opcode.pl
  6. sed -e '1,/__END__/ d; s/[#].*$//g; /^$/d' opcode.pl | tr -s '\t' '\t' > data
  7. exec 1> opcode.h
  8. # Emit defines.
  9. echo "typedef enum {";
  10. awk '{print "\tOP_"toupper($1)","}' data
  11. echo " OP_max"
  12. echo "} opcode;"
  13. echo "#define MAXO " $(wc -l data | awk '{print $1}')
  14. # Emit opnames.
  15. printf "
  16. #ifndef DOINIT
  17. EXT char *op_name[];
  18. #else
  19. EXT char *op_name[] = {
  20. "
  21. awk -F'\t' '{print "\t\""$2"\","}' data
  22. printf "};
  23. #endif
  24. "
  25. # Emit function declarations.
  26. awk -F'\t' '{print "OP *\t"$3"\t_((OP* op));"}' data | sort | uniq
  27. awk '{print "OP *\tpp_"$1"\t_((void));"}' data
  28. # Emit ppcode switch array.
  29. printf "
  30. #ifndef DOINIT
  31. EXT OP * (*ppaddr[])();
  32. #else
  33. EXT OP * (*ppaddr[])() = {
  34. "
  35. awk '{print "\tpp_"$1","}' data
  36. printf "};
  37. #endif
  38. "
  39. # Emit check routines.
  40. printf "
  41. #ifndef DOINIT
  42. EXT OP * (*check[])();
  43. #else
  44. EXT OP * (*check[])() = {
  45. "
  46. awk -F'\t' '{print "\t"$3",\t/* "$1" */"}' data
  47. printf "};
  48. #endif
  49. "
  50. # Emit allowed argument types.
  51. printf "
  52. #ifndef DOINIT
  53. EXT U32 opargs[];
  54. #else
  55. EXT U32 opargs[] = {
  56. "
  57. awk -F'\t' -f opcode.awk data
  58. printf "};
  59. #endif
  60. "
  61. rm data