From a7877d771ff364ac1d7f5189714bc22d13c72ac1 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 26 Nov 2023 19:11:35 -0800 Subject: [PATCH] add ppc_flags.py so we can get the ppc versions of all the flags we need tells gcc to dump all #defines, and parses that. --- src/openpower/syscalls/ppc_flags.py | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/openpower/syscalls/ppc_flags.py diff --git a/src/openpower/syscalls/ppc_flags.py b/src/openpower/syscalls/ppc_flags.py new file mode 100644 index 00000000..b92971fc --- /dev/null +++ b/src/openpower/syscalls/ppc_flags.py @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: LGPLv3+ +# Copyright (C) 2023 Jacob Lifshay +# Funded by NLnet http://nlnet.nl +""" flags for PowerPC syscalls + +related bugs: + +* https://bugs.libre-soc.org/show_bug.cgi?id=1169 +""" + +def parse_defines(flags, compiler): + """ parse `#define`s into the dict `flags` using the given `compiler` + """ + from subprocess import run, PIPE + inp = """ +#include +#include +#include +#include +""" + if isinstance(compiler, str): + compiler = [compiler] + out = run([*compiler, '-E', '-dM', '-'], input=inp, + check=True, stdout=PIPE, encoding='utf-8').stdout + def_start = '#define ' + defines = {} + for define in out.splitlines(): + assert define.startswith(def_start) + define = define[len(def_start):] + name, space, value = define.partition(' ') + assert space == ' ' + if not name.isidentifier(): + continue + defines[name] = value + # resolve things defined in terms of other things + more_substitutions = True + while more_substitutions: + more_substitutions = False + for name, value in defines.items(): + new_value = defines.get(value) + if new_value is not None and new_value != value: + defines[name] = new_value + more_substitutions = True + for name, value in defines.items(): + if value.startswith('(') and value.endswith(')'): + value = value[1:-2] + if len(value) > 1 and value.startswith('0') and value[1].isdigit(): + value = '0o' + value[1:] + try: + flags[name] = int(value, 0) + except ValueError: + pass + return flags + +parse_defines(globals(), 'powerpc64le-linux-gnu-gcc') + +def _host_defines(): + import sysconfig + return parse_defines({}, sysconfig.get_config_var('CC').split(' ')) + +host_defines = _host_defines() +del _host_defines -- 2.30.2