linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: [PATCH 2/6] Hardcode actual type sizes, add -m32 support
Date: Thu, 28 Jun 2007 01:39:59 -0400	[thread overview]
Message-ID: <20070628053959.30704.91680.stgit@dv.roinet.com> (raw)
In-Reply-To: <20070628053954.30704.66440.stgit@dv.roinet.com>

Use the actual sizeof values at the compile time to describe the default
target.  If sparse is compiled on a 64-bit system, it will default to a
64-bit system now.

To force 32-bit operation on 64-bit systems, recognize -m32.  Reject
machine options other than -m32 and -m64.

Signed-off-by: Pavel Roskin <proski@gnu.org>
---

 lib.c    |   13 +++++++------
 target.c |   45 +++++++++++++++++++++++++++++++--------------
 target.h |    6 ++++++
 3 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/lib.c b/lib.c
index 7fea474..e695f1c 100644
--- a/lib.c
+++ b/lib.c
@@ -320,12 +320,13 @@ static char **handle_switch_M(char *arg, char **next)
 
 static char **handle_switch_m(char *arg, char **next)
 {
-	if (!strcmp(arg, "m64")) {
-		bits_in_long = 64;
-		max_int_alignment = 8;
-		bits_in_pointer = 64;
-		pointer_alignment = 8;
-	}
+	if (!strcmp(arg, "m32"))
+		target_set_m32();
+	else if (!strcmp(arg, "m64"))
+		target_set_m64();
+	else
+		die("unsupported machine specification: -%s", arg);
+
 	return next;
 }
 
diff --git a/target.c b/target.c
index 22e948e..1d0912d 100644
--- a/target.c
+++ b/target.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <sys/param.h>
 
 #include "symbol.h"
 #include "target.h"
@@ -15,31 +16,47 @@ int max_alignment = 16;
  * Integer data types
  */
 int bits_in_bool = 1;
-int bits_in_char = 8;
-int bits_in_short = 16;
-int bits_in_int = 32;
-int bits_in_long = 32;
-int bits_in_longlong = 64;
+int bits_in_char = NBBY * sizeof(char);
+int bits_in_short = NBBY * sizeof(short);
+int bits_in_int = NBBY * sizeof(int);
+int bits_in_long = NBBY * sizeof(long);
+int bits_in_longlong = NBBY * sizeof(long long);
 
-int max_int_alignment = 4;
+int max_int_alignment = sizeof(int);
 
 /*
  * Floating point data types
  */
-int bits_in_float = 32;
-int bits_in_double = 64;
-int bits_in_longdouble = 80;
+int bits_in_float = NBBY * sizeof(float);
+int bits_in_double = NBBY * sizeof(double);
+int bits_in_longdouble = NBBY * sizeof(long double);
 
-int max_fp_alignment = 8;
+int max_fp_alignment = sizeof(double);
 
 /*
  * Pointer data type
  */
-int bits_in_pointer = 32;
-int pointer_alignment = 4;
+int bits_in_pointer = NBBY * sizeof(void *);
+int pointer_alignment = sizeof(void *);
 
 /*
  * Enum data types
  */
-int bits_in_enum = 32;
-int enum_alignment = 4;
+int bits_in_enum = NBBY * sizeof(enum {ENUM_BITS});
+int enum_alignment = sizeof(enum {ENUM_ALIGN});
+
+void target_set_m32(void)
+{
+	bits_in_long = 32;
+	max_int_alignment = 4;
+	bits_in_pointer = 32;
+	pointer_alignment = 4;
+}
+
+void target_set_m64(void)
+{
+	bits_in_long = 64;
+	max_int_alignment = 8;
+	bits_in_pointer = 64;
+	pointer_alignment = 8;
+}
diff --git a/target.h b/target.h
index 25f7948..94e182f 100644
--- a/target.h
+++ b/target.h
@@ -42,4 +42,10 @@ extern int pointer_alignment;
 extern int bits_in_enum;
 extern int enum_alignment;
 
+/*
+ * Functions
+ */
+void target_set_m32(void);
+void target_set_m64(void);
+
 #endif

  reply	other threads:[~2007-06-28  5:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-28  5:39 [PATCH 1/6] Bitfield without explicit sign should be a warning, not an error Pavel Roskin
2007-06-28  5:39 ` Pavel Roskin [this message]
2007-06-28  5:58   ` [PATCH 2/6] Hardcode actual type sizes, add -m32 support Al Viro
2007-06-28  6:05     ` Josh Triplett
2007-06-28  6:23       ` Al Viro
2007-06-28  6:27         ` Jeff Garzik
2007-06-28  6:46         ` Josh Triplett
2007-06-28  6:25       ` Jeff Garzik
2007-06-28  6:44         ` Pavel Roskin
2007-06-28  6:47           ` Jeff Garzik
2007-06-28  6:55             ` Josh Triplett
2007-06-28  6:54         ` Josh Triplett
2007-06-28  7:01           ` Jeff Garzik
2007-06-28  7:38             ` Josh Triplett
2007-06-28  6:27       ` Pavel Roskin
2007-06-28  5:40 ` [PATCH 3/6] cgcc: preserve sparse exit code if -no-compile is used Pavel Roskin
2007-06-28  6:12   ` Josh Triplett
2007-06-28  5:40 ` [PATCH 4/6] Avoid use of libc headers in the validation suite Pavel Roskin
2007-06-28  6:14   ` Josh Triplett
2007-06-28  5:40 ` [PATCH 5/6] Fix warnings about undeclared globals, they are irrelevant to the test Pavel Roskin
2007-06-28  6:18   ` Josh Triplett
2007-06-28  5:40 ` [PATCH 6/6] Add a simple test script, embed expected results into test files Pavel Roskin
2007-06-28  7:20   ` Josh Triplett
2007-06-28 18:59     ` Damien Lespiau
2007-06-28 21:21       ` Pavel Roskin
2007-06-28 21:38       ` Josh Triplett
2007-06-29  0:13         ` Damien Lespiau
2007-06-29  0:29           ` Josh Triplett
2007-07-02  4:59             ` Damien Lespiau
2007-07-02  5:19               ` Josh Triplett
2007-07-08 21:52               ` Josh Triplett
2007-07-09  2:15                 ` Josh Triplett
2007-07-09 21:27                   ` Damien Lespiau
2007-07-11  0:48                     ` Anderson Lizardo
2007-06-28  6:09 ` [PATCH 1/6] Bitfield without explicit sign should be a warning, not an error Josh Triplett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070628053959.30704.91680.stgit@dv.roinet.com \
    --to=proski@gnu.org \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).