xref: /linux/tools/perf/arch/x86/tests/gen-insn-x86-dat.awk (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1d8b167f9SMatt Fleming#!/bin/awk -f
2*2025cf9eSThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
3d8b167f9SMatt Fleming# gen-insn-x86-dat.awk: script to convert data for the insn-x86 test
4d8b167f9SMatt Fleming# Copyright (c) 2015, Intel Corporation.
5d8b167f9SMatt Fleming#
6d8b167f9SMatt Fleming
7d8b167f9SMatt FlemingBEGIN {
8d8b167f9SMatt Fleming	print "/*"
9d8b167f9SMatt Fleming	print " * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk"
10d8b167f9SMatt Fleming	print " * from insn-x86-dat-src.c for inclusion by insn-x86.c"
11d8b167f9SMatt Fleming	print " * Do not change this code."
12d8b167f9SMatt Fleming	print "*/\n"
13d8b167f9SMatt Fleming	op = ""
14d8b167f9SMatt Fleming	branch = ""
15d8b167f9SMatt Fleming	rel = 0
16d8b167f9SMatt Fleming	going = 0
17d8b167f9SMatt Fleming}
18d8b167f9SMatt Fleming
19d8b167f9SMatt Fleming/ Start here / {
20d8b167f9SMatt Fleming	going = 1
21d8b167f9SMatt Fleming}
22d8b167f9SMatt Fleming
23d8b167f9SMatt Fleming/ Stop here / {
24d8b167f9SMatt Fleming	going = 0
25d8b167f9SMatt Fleming}
26d8b167f9SMatt Fleming
27d8b167f9SMatt Fleming/^\s*[0-9a-fA-F]+\:/ {
28d8b167f9SMatt Fleming	if (going) {
29d8b167f9SMatt Fleming		colon_pos = index($0, ":")
30d8b167f9SMatt Fleming		useful_line = substr($0, colon_pos + 1)
31d8b167f9SMatt Fleming		first_pos = match(useful_line, "[0-9a-fA-F]")
32d8b167f9SMatt Fleming		useful_line = substr(useful_line, first_pos)
33d8b167f9SMatt Fleming		gsub("\t", "\\t", useful_line)
34d8b167f9SMatt Fleming		printf "{{"
35d8b167f9SMatt Fleming		len = 0
36d8b167f9SMatt Fleming		for (i = 2; i <= NF; i++) {
37d8b167f9SMatt Fleming			if (match($i, "^[0-9a-fA-F][0-9a-fA-F]$")) {
38d8b167f9SMatt Fleming				printf "0x%s, ", $i
39d8b167f9SMatt Fleming				len += 1
40d8b167f9SMatt Fleming			} else {
41d8b167f9SMatt Fleming				break
42d8b167f9SMatt Fleming			}
43d8b167f9SMatt Fleming		}
44d8b167f9SMatt Fleming		printf "}, %d, %s, \"%s\", \"%s\",", len, rel, op, branch
45d8b167f9SMatt Fleming		printf "\n\"%s\",},\n", useful_line
46d8b167f9SMatt Fleming		op = ""
47d8b167f9SMatt Fleming		branch = ""
48d8b167f9SMatt Fleming		rel = 0
49d8b167f9SMatt Fleming	}
50d8b167f9SMatt Fleming}
51d8b167f9SMatt Fleming
52d8b167f9SMatt Fleming/ Expecting: / {
53d8b167f9SMatt Fleming	expecting_str = " Expecting: "
54d8b167f9SMatt Fleming	expecting_len = length(expecting_str)
55d8b167f9SMatt Fleming	expecting_pos = index($0, expecting_str)
56d8b167f9SMatt Fleming	useful_line = substr($0, expecting_pos + expecting_len)
57d8b167f9SMatt Fleming	for (i = 1; i <= NF; i++) {
58d8b167f9SMatt Fleming		if ($i == "Expecting:") {
59d8b167f9SMatt Fleming			i++
60d8b167f9SMatt Fleming			op = $i
61d8b167f9SMatt Fleming			i++
62d8b167f9SMatt Fleming			branch = $i
63d8b167f9SMatt Fleming			i++
64d8b167f9SMatt Fleming			rel = $i
65d8b167f9SMatt Fleming			break
66d8b167f9SMatt Fleming		}
67d8b167f9SMatt Fleming	}
68d8b167f9SMatt Fleming}
69