diff --git a/make_machdep/alignof_fun.c b/make_machdep/alignof_fun.c index 26028f6b5a3b4e604b7dee757f85cfe3ec55b3b7..0d26a6404280d6eecfe27e0f8eba5c758df8a688 100644 --- a/make_machdep/alignof_fun.c +++ b/make_machdep/alignof_fun.c @@ -22,11 +22,11 @@ #include "make_machdep_common.h" -_Static_assert(ALIGNOF(void ()) != 1, "alignof_fun is 1"); -_Static_assert(ALIGNOF(void ()) != 2, "alignof_fun is 2"); -_Static_assert(ALIGNOF(void ()) != 3, "alignof_fun is 3"); -_Static_assert(ALIGNOF(void ()) != 4, "alignof_fun is 4"); -_Static_assert(ALIGNOF(void ()) != 5, "alignof_fun is 5"); -_Static_assert(ALIGNOF(void ()) != 6, "alignof_fun is 6"); -_Static_assert(ALIGNOF(void ()) != 7, "alignof_fun is 7"); -_Static_assert(ALIGNOF(void ()) != 8, "alignof_fun is 8"); +_Static_assert(ALIGNOF(void()) != 1, "alignof_fun is 1"); +_Static_assert(ALIGNOF(void()) != 2, "alignof_fun is 2"); +_Static_assert(ALIGNOF(void()) != 3, "alignof_fun is 3"); +_Static_assert(ALIGNOF(void()) != 4, "alignof_fun is 4"); +_Static_assert(ALIGNOF(void()) != 5, "alignof_fun is 5"); +_Static_assert(ALIGNOF(void()) != 6, "alignof_fun is 6"); +_Static_assert(ALIGNOF(void()) != 7, "alignof_fun is 7"); +_Static_assert(ALIGNOF(void()) != 8, "alignof_fun is 8"); diff --git a/make_machdep/little_endian.c b/make_machdep/little_endian.c index eeb191ac1232f6eb1391f5f1dfa8e06889e28e8c..e1a0dda9f3be407d69e7c08f4a14c26b81e55ae6 100644 --- a/make_machdep/little_endian.c +++ b/make_machdep/little_endian.c @@ -21,15 +21,13 @@ /**************************************************************************/ #if defined(__BYTE_ORDER__) -# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -__attribute__((section(".data"))) -unsigned char little_endian = 0xf4; -# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -__attribute__((section(".data"))) -unsigned char little_endian = 0x15; -# else -# error Unexpected __BYTE_ORDER__ -# endif +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +__attribute__((section(".data"))) unsigned char little_endian = 0xf4; +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +__attribute__((section(".data"))) unsigned char little_endian = 0x15; #else -# error __BYTE_ORDER__ undefined +#error Unexpected __BYTE_ORDER__ +#endif +#else +#error __BYTE_ORDER__ undefined #endif diff --git a/make_machdep/make_machdep.py b/make_machdep/make_machdep.py index 25df600d93d061346fb5cc4ae2424fe1672d1400..dd078e3988628cfe6ba0f4a185f30bd8668beb18 100755 --- a/make_machdep/make_machdep.py +++ b/make_machdep/make_machdep.py @@ -60,23 +60,37 @@ import warnings parser = argparse.ArgumentParser(prog="make_machdep") parser.add_argument("-v", "--verbose", action="store_true") -parser.add_argument("-o", default=sys.stdout,type=argparse.Filetype('w'),dest="dest_file") +parser.add_argument("-o", default=sys.stdout, type=argparse.Filetype("w"), dest="dest_file") parser.add_argument("--compiler") parser.add_argument("--compiler-version") -parser.add_argument("--cpp-arch-flags", nargs="+", default=[], help="architecture-specific flags needed for preprocessing, e.g. '-m32'") -parser.add_argument("--compiler-flags", nargs="+", default=["-c"], help="flags to be given to the compiler (other than those set by --cpp-arch-flags); by default, '-c'") +parser.add_argument( + "--cpp-arch-flags", + nargs="+", + default=[], + help="architecture-specific flags needed for preprocessing, e.g. '-m32'", +) +parser.add_argument( + "--compiler-flags", + nargs="+", + default=["-c"], + help="flags to be given to the compiler (other than those set by --cpp-arch-flags); by default, '-c'", +) parser.add_argument("--check", action="store_true") args, other_args = parser.parse_known_args() + def print_machdep(machdep): - json.dump(machdep,args.dest_file,indent=4,sort_keys=True) + json.dump(machdep, args.dest_file, indent=4, sort_keys=True) + + +fc_share = subprocess.run("frama-c-config -print-share-path", capture_output=True).output -fc_share=subprocess.run("frama-c-config -print-share-path",capture_output=True).output def check_machdep(machdep): try: from jsonschema import validate, ValidationError - with open(fc_share+"/machdeps/machdep-schema.json", "r") as schema: + + with open(fc_share + "/machdeps/machdep-schema.json", "r") as schema: validate(machdep, json.load(schema)) except ImportError: warnings.warn("jsonschema is not available: no validation will be performed") @@ -198,7 +212,9 @@ for (f, typ) in source_files: print(f"[INFO] setting const_string_literals to false") machdep["const_string_literals"] = False else: - print(f"WARNING: could not find const_string_literals in any of the expected sections, skipping") + print( + f"WARNING: could not find const_string_literals in any of the expected sections, skipping" + ) continue symbols, underscore_name = decode_object_file(objfile) if machdep["underscore_name"] is None: @@ -220,10 +236,12 @@ for (f, typ) in source_files: if name in machdep: if value == 0x15: bvalue = True - elif value == 0xf4: + elif value == 0xF4: bvalue = False else: - print(f"WARNING: unexpected value '{value} for boolean '{name}' in '{objfile}', ignoring") + print( + f"WARNING: unexpected value '{value} for boolean '{name}' in '{objfile}', ignoring" + ) continue if args.verbose: print(f"[INFO] setting {name} to {bvalue}") @@ -236,11 +254,13 @@ for (f, typ) in source_files: if not ("_IS_" in name): print(f"WARNING: unexpected symbol '{name}' in '{objfile}', ignoring") continue - if value == 0xf4: + if value == 0xF4: # Symbol found with 'false' => incompatible type, ignore continue elif value != 0x15: - print(f"WARNING: unexpected value '{value}' for symbol '{name}' in '{objfile}', ignoring") + print( + f"WARNING: unexpected value '{value}' for symbol '{name}' in '{objfile}', ignoring" + ) continue [name, original_type] = name.split("_IS_") original_type = original_type.replace("_", " ") @@ -249,7 +269,9 @@ for (f, typ) in source_files: print(f"[INFO] setting {name} to {original_type}") machdep[name] = original_type else: - print(f"WARNING: unexpected symbol '{name}' (expected '{name}' in machdep) in '{objfile}', ignoring") + print( + f"WARNING: unexpected symbol '{name}' (expected '{name}' in machdep) in '{objfile}', ignoring" + ) continue else: sys.exit(f"AssertionError: f {f} typ {typ}") @@ -266,7 +288,9 @@ else: compiler_version_command = compilation_command + ["--version"] proc = subprocess.run(compiler_version_command, capture_output=True) if proc.returncode != 0: - print(f"WARNING: option '--version' unsupported by compiler; re-run this script with --compiler and --compiler-version") + print( + f"WARNING: option '--version' unsupported by compiler; re-run this script with --compiler and --compiler-version" + ) if args.verbose: print(proc.stderr.decode("utf-8")) else: diff --git a/make_machdep/make_machdep_common.h b/make_machdep/make_machdep_common.h index 82feab58fac0cd300eef939780660a7e62433a63..2dd4ae89ff4b326c9cd32d8b72b7e8324f38c37b 100644 --- a/make_machdep/make_machdep_common.h +++ b/make_machdep/make_machdep_common.h @@ -29,19 +29,16 @@ #if __STDC_VERSION__ >= 201112L || defined(__COMPCERT__) // Assume _Generic() is supported -# define COMPATIBLE(T1, T2) _Generic(((T1){0}), \ - T2: 1, \ - default: 0 \ - ) +#define COMPATIBLE(T1, T2) _Generic(((T1){0}), T2 : 1, default : 0) #else // Expect that __builtin_types_compatible_p exists -# define COMPATIBLE(T1, T2) (__builtin_types_compatible_p(T1, T2) ? 0x15 : 0xf4) +#define COMPATIBLE(T1, T2) (__builtin_types_compatible_p(T1, T2) ? 0x15 : 0xf4) #endif // needed to ensure the message is properly expanded for TEST_TYPE_IS #define mkstr(s) #s -#define TEST_TYPE_COMPATIBLE(T1,T2) \ - _Static_assert(!COMPATIBLE(T1,T2),"" mkstr(T2) " is " #T1); +#define TEST_TYPE_COMPATIBLE(T1, T2) \ + _Static_assert(!COMPATIBLE(T1, T2), "" mkstr(T2) " is " #T1); #define TEST_TYPE_IS(type) TEST_TYPE_COMPATIBLE(type, TEST_TYPE) diff --git a/make_machdep/size_t.c b/make_machdep/size_t.c index 65bed06a2e6b281832c6727443eb9c2a7a1c3286..eeca11c8bc7a4ea7a625720cd4d83709ba8c5e75 100644 --- a/make_machdep/size_t.c +++ b/make_machdep/size_t.c @@ -20,8 +20,8 @@ /* */ /**************************************************************************/ -#include <stddef.h> #include "make_machdep_common.h" +#include <stddef.h> _Static_assert(!COMPATIBLE(unsigned int, size_t), "size_t is unsigned int"); _Static_assert(!COMPATIBLE(unsigned long, size_t), "size_t is unsigned long"); diff --git a/make_machdep/sizeof_alignof_standard.c b/make_machdep/sizeof_alignof_standard.c index ffd82d33796aaa74ecc8847e170c3a0b5ea2f1dc..50d43a1cc90a5f94abceab6e50a0c068a8cef084 100644 --- a/make_machdep/sizeof_alignof_standard.c +++ b/make_machdep/sizeof_alignof_standard.c @@ -38,7 +38,7 @@ unsigned char sizeof_short = sizeof(short); unsigned char sizeof_int = sizeof(int); unsigned char sizeof_long = sizeof(long); unsigned char sizeof_longlong = sizeof(long long); -unsigned char sizeof_ptr = sizeof(void*); +unsigned char sizeof_ptr = sizeof(void *); unsigned char sizeof_float = sizeof(float); unsigned char sizeof_double = sizeof(double); @@ -46,6 +46,6 @@ unsigned char alignof_short = ALIGNOF(short); unsigned char alignof_int = ALIGNOF(int); unsigned char alignof_long = ALIGNOF(long); unsigned char alignof_longlong = ALIGNOF(long long); -unsigned char alignof_ptr = ALIGNOF(void*); +unsigned char alignof_ptr = ALIGNOF(void *); unsigned char alignof_float = ALIGNOF(float); unsigned char alignof_double = ALIGNOF(double); diff --git a/make_machdep/sizeof_fun.c b/make_machdep/sizeof_fun.c index 0a8af7f1e69ba5b1db06d0f218b8d71431d4d316..daa499b72c920df365de255e1781bddbd0835802 100644 --- a/make_machdep/sizeof_fun.c +++ b/make_machdep/sizeof_fun.c @@ -20,4 +20,4 @@ /* */ /**************************************************************************/ -_Static_assert(sizeof(void ()) != 1, "sizeof_fun is 1"); +_Static_assert(sizeof(void()) != 1, "sizeof_fun is 1"); diff --git a/make_machdep/sizeof_void.c b/make_machdep/sizeof_void.c index bac4d738ffd58543d42c3b6b346897b393ff5cfc..76db3124db00720802a827e9f7b0cf54d836d7bf 100644 --- a/make_machdep/sizeof_void.c +++ b/make_machdep/sizeof_void.c @@ -20,4 +20,4 @@ /* */ /**************************************************************************/ -_Static_assert(sizeof(void)!=1,"sizeof_void is 1"); +_Static_assert(sizeof(void) != 1, "sizeof_void is 1");