Added alignment checking to sztest.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 24 Feb 2011 09:41:43 +0000 (10:41 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 24 Feb 2011 09:41:43 +0000 (10:41 +0100)
sztest

diff --git a/sztest b/sztest
index ca7182c..dcb2982 100755 (executable)
--- a/sztest
+++ b/sztest
@@ -1,9 +1,10 @@
 #!/bin/sh
 
 usage() {
-    echo "usage: sztest [-h] [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]"
+    echo "usage: sztest [-hab] [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]"
 }
 
+mode=size
 sheaders=
 lheaders=
 while [ "${1:0:1}" = "-" ]; do
@@ -14,6 +15,12 @@ while [ "${1:0:1}" = "-" ]; do
            usage
            exit 0
            ;;
+       "-a")
+           mode=align
+           ;;
+       "-b")
+           mode=both
+           ;;
        "-H")
            sheaders="$sheaders $1"
            shift
@@ -47,7 +54,19 @@ done
 cat >>"$file.c" <<EOF
 int main(int argc, char **argv)
 {
-    printf("%zi\n", sizeof($type));
+EOF
+case "$mode" in
+    size)
+       echo "    printf(\"%zi\\n\", sizeof($type));" >>"$file.c"
+       ;;
+    align)
+       echo "    printf(\"%zi\\n\", __alignof__($type));" >>"$file.c"
+       ;;
+    both)
+       echo "    printf(\"%zi %zi\\n\", sizeof($type), __alignof__($type));" >>"$file.c"
+       ;;
+esac
+cat >>"$file.c" <<EOF
     return(0);
 }
 EOF