]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/gen-py-const.awk
XFAIL libm-test.inc tests as needed for ibm128.
[thirdparty/glibc.git] / scripts / gen-py-const.awk
CommitLineData
23b5cae1
MG
1# Script to generate constants for Python pretty printers.
2#
bfff8b1b 3# Copyright (C) 2016-2017 Free Software Foundation, Inc.
23b5cae1
MG
4# This file is part of the GNU C Library.
5#
6# The GNU C Library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with the GNU C Library; if not, see
18# <http://www.gnu.org/licenses/>.
19
20# This script is a smaller version of the clever gen-asm-const.awk hack used to
21# generate ASM constants from .sym files. We'll use this to generate constants
22# for Python pretty printers.
23#
24# The input to this script are .pysym files that look like:
25# #C_Preprocessor_Directive...
26# NAME1
27# NAME2 expression...
28#
29# A line giving just a name implies an expression consisting of just that name.
30# Comments start with '--'.
31#
32# The output of this script is a 'dummy' function containing 'asm' declarations
33# for each non-preprocessor line in the .pysym file. The expression values
34# will appear as input operands to the 'asm' declaration. For example, if we
35# have:
36#
37# /* header.h */
38# #define MACRO 42
39#
40# struct S {
41# char c1;
42# char c2;
43# char c3;
44# };
45#
46# enum E {
47# ZERO,
48# ONE
49# };
50#
51# /* symbols.pysym */
52# #include <stddef.h>
53# #include "header.h"
54# -- This is a comment
55# MACRO
56# C3_OFFSET offsetof(struct S, c3)
57# E_ONE ONE
58#
59# the output will be:
60#
61# #include <stddef.h>
62# #include "header.h"
63# void dummy(void)
64# {
65# asm ("@name@MACRO@value@%0@" : : "i" (MACRO));
66# asm ("@name@C3_OFFSET@value@%0@" : : "i" (offsetof(struct S, c3)));
67# asm ("@name@E_ONE@value@%0@" : : "i" (ONE));
68# }
69#
70# We'll later feed this output to gcc -S. Since '-S' tells gcc to compile but
71# not assemble, gcc will output something like:
72#
73# dummy:
74# ...
75# @name@MACRO@value@$42@
76# @name@C3_OFFSET@value@$2@
77# @name@E_ONE@value@$1@
78#
79# Finally, we can process that output to extract the constant values.
80# Notice gcc may prepend a special character such as '$' to each value.
81
82# found_symbol indicates whether we found a non-comment, non-preprocessor line.
83BEGIN { found_symbol = 0 }
84
85# C preprocessor directives go straight through.
86/^#/ { print; next; }
87
88# Skip comments.
89/--/ { next; }
90
91# Trim leading whitespace.
92{ sub(/^[[:blank:]]*/, ""); }
93
94# If we found a non-comment, non-preprocessor line, print the 'dummy' function
95# header.
96NF > 0 && !found_symbol {
97 print "void dummy(void)\n{";
98 found_symbol = 1;
99}
100
101# If the line contains just a name, duplicate it so we can use that name
102# as the value of the expression.
103NF == 1 { sub(/^.*$/, "& &"); }
104
105# If a line contains a name and an expression...
106NF > 1 {
107 name = $1;
108
109 # Remove any characters before the second field.
110 sub(/^[^[:blank:]]+[[:blank:]]+/, "");
111
112 # '$0' ends up being everything that appeared after the first field
113 # separator.
114 printf " asm (\"@name@%s@value@%0@\" : : \"i\" (%s));\n", name, $0;
115}
116
117# Close the 'dummy' function.
118END { if (found_symbol) print "}"; }