summaryrefslogtreecommitdiff
path: root/gcc/config/aarch64/geniterators.sh
blob: 1e4c4ede8f7b19f5aec5ab44bb564ef41068a9e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
#
# Copyright (C) 2014-2017 Free Software Foundation, Inc.
# Contributed by ARM Ltd.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# Generate aarch64-builtin-iterators.h, a file containing a series of
# BUILTIN_<ITERATOR> macros, which expand to VAR<N> Macros covering the
# same set of modes as the iterator in iterators.md
#
# Find the <ITERATOR> definitions (may span several lines).
LC_ALL=C awk '
BEGIN {
	print "/* -*- buffer-read-only: t -*- */"
	print "/* Generated automatically by geniterators.sh from iterators.md.  */"
	print "#ifndef GCC_AARCH64_ITERATORS_H"
	print "#define GCC_AARCH64_ITERATORS_H"
}

{
	sub(/;.*/, "")
}

iterdef {
	s = s " " $0
}

!iterdef && /\(define_mode_iterator/ {
	iterdef = 1
	s = $0
	sub(/.*\(define_mode_iterator/, "", s)
}

iterdef {
	# Count the parentheses, the iterator definition ends
	# if there are more closing ones than opening ones.
	nopen = gsub(/\(/, "(", s)
	nclose = gsub(/\)/, ")", s)
	if (nopen >= nclose)
		next

	iterdef = 0

	gsub(/[ \t]+/, " ", s)
	sub(/ *\)[^)]*$/, "", s)
	sub(/^ /, "", s)

	# Drop the conditions.
	gsub(/ *"[^"]*" *\)/, "", s)
	gsub(/\( */, "", s)

	if (s !~ /^[A-Za-z0-9_]+ \[[A-Z0-9 ]*\]$/)
		next
	sub(/\[ */, "", s)
	sub(/ *\]/, "", s)

	n = split(s, a)
	printf "#define BUILTIN_" a[1] "(T, N, MAP) \\\n"
	printf "  VAR" (n-1) " (T, N, MAP"
	for (i = 2; i <= n; i++)
		printf ", "  tolower(a[i])
	printf ")\n"
}

END {
	print "#endif /* GCC_AARCH64_ITERATORS_H  */"
}' $1