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
14BEGIN {
15	print "/*"
16	print " * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk"
17	print " * from insn-x86-dat-src.c for inclusion by insn-x86.c"
18	print " * Do not change this code."
19	print "*/\n"
20	op = ""
21	branch = ""
22	rel = 0
23	going = 0
24}
25
26/ Start here / {
27	going = 1
28}
29
30/ Stop here / {
31	going = 0
32}
33
34/^\s*[0-9a-fA-F]+\:/ {
35	if (going) {
36		colon_pos = index($0, ":")
37		useful_line = substr($0, colon_pos + 1)
38		first_pos = match(useful_line, "[0-9a-fA-F]")
39		useful_line = substr(useful_line, first_pos)
40		gsub("\t", "\\t", useful_line)
41		printf "{{"
42		len = 0
43		for (i = 2; i <= NF; i++) {
44			if (match($i, "^[0-9a-fA-F][0-9a-fA-F]$")) {
45				printf "0x%s, ", $i
46				len += 1
47			} else {
48				break
49			}
50		}
51		printf "}, %d, %s, \"%s\", \"%s\",", len, rel, op, branch
52		printf "\n\"%s\",},\n", useful_line
53		op = ""
54		branch = ""
55		rel = 0
56	}
57}
58
59/ Expecting: / {
60	expecting_str = " Expecting: "
61	expecting_len = length(expecting_str)
62	expecting_pos = index($0, expecting_str)
63	useful_line = substr($0, expecting_pos + expecting_len)
64	for (i = 1; i <= NF; i++) {
65		if ($i == "Expecting:") {
66			i++
67			op = $i
68			i++
69			branch = $i
70			i++
71			rel = $i
72			break
73		}
74	}
75}
76