Skip to content
Snippets Groups Projects
Commit 09de65aa authored by Virgile Prevosto's avatar Virgile Prevosto Committed by Andre Maroneze
Browse files

[machdep] lint files in make_machdep

parent b7b3b03b
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......@@ -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
......@@ -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:
......
......@@ -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)
......@@ -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");
......@@ -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);
......@@ -20,4 +20,4 @@
/* */
/**************************************************************************/
_Static_assert(sizeof(void ()) != 1, "sizeof_fun is 1");
_Static_assert(sizeof(void()) != 1, "sizeof_fun is 1");
......@@ -20,4 +20,4 @@
/* */
/**************************************************************************/
_Static_assert(sizeof(void)!=1,"sizeof_void is 1");
_Static_assert(sizeof(void) != 1, "sizeof_void is 1");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment