gen-insn-x86-dat.awk 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/awk -f
  2. # gen-insn-x86-dat.awk: script to convert data for the insn-x86 test
  3. # Copyright (c) 2015, Intel Corporation.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms and conditions of the GNU General Public License,
  7. # version 2, as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. # more details.
  13. BEGIN {
  14. print "/*"
  15. print " * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk"
  16. print " * from insn-x86-dat-src.c for inclusion by insn-x86.c"
  17. print " * Do not change this code."
  18. print "*/\n"
  19. op = ""
  20. branch = ""
  21. rel = 0
  22. going = 0
  23. }
  24. / Start here / {
  25. going = 1
  26. }
  27. / Stop here / {
  28. going = 0
  29. }
  30. /^\s*[0-9a-fA-F]+\:/ {
  31. if (going) {
  32. colon_pos = index($0, ":")
  33. useful_line = substr($0, colon_pos + 1)
  34. first_pos = match(useful_line, "[0-9a-fA-F]")
  35. useful_line = substr(useful_line, first_pos)
  36. gsub("\t", "\\t", useful_line)
  37. printf "{{"
  38. len = 0
  39. for (i = 2; i <= NF; i++) {
  40. if (match($i, "^[0-9a-fA-F][0-9a-fA-F]$")) {
  41. printf "0x%s, ", $i
  42. len += 1
  43. } else {
  44. break
  45. }
  46. }
  47. printf "}, %d, %s, \"%s\", \"%s\",", len, rel, op, branch
  48. printf "\n\"%s\",},\n", useful_line
  49. op = ""
  50. branch = ""
  51. rel = 0
  52. }
  53. }
  54. / Expecting: / {
  55. expecting_str = " Expecting: "
  56. expecting_len = length(expecting_str)
  57. expecting_pos = index($0, expecting_str)
  58. useful_line = substr($0, expecting_pos + expecting_len)
  59. for (i = 1; i <= NF; i++) {
  60. if ($i == "Expecting:") {
  61. i++
  62. op = $i
  63. i++
  64. branch = $i
  65. i++
  66. rel = $i
  67. break
  68. }
  69. }
  70. }