From: Jacob Lifshay Date: Mon, 27 Nov 2023 03:11:35 +0000 (-0800) Subject: add ppc_flags.py so we can get the ppc versions of all the flags we need X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5f21b2e6093390c1f4c48331781d395357c58386;p=openpower-isa.git 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. --- 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