gen_matypes: fix cross-compiling with gcc
[mesa.git] / src / mesa / x86 / gen_matypes.c
index 80ee61aa89134b2d958b377d03a4786ece833aac..1e904aa0b1370876b857bdf034254f1a293ca7c8 100644 (file)
@@ -52,7 +52,7 @@ do {                                                                  \
    printf( "\n" );                                                     \
    printf( "/* ====================================================="  \
           "========\n" );                                              \
-   printf( " * Offsets for %s\n", x );                                 \
+   printf( " * Offsets for " x "\n" );                                 \
    printf( " */\n" );                                                  \
    printf( "\n" );                                                     \
 } while (0)
@@ -61,20 +61,43 @@ do {                                                                        \
 do {                                                                   \
    printf( "\n" );                                                     \
    printf( "/*\n" );                                                   \
-   printf( " * Flags for %s\n", x );                                   \
+   printf( " * Flags for " x "\n" );                                   \
    printf( " */\n" );                                                  \
    printf( "\n" );                                                     \
 } while (0)
 
-#define OFFSET( s, t, m )                                              \
-   printf( "#define %s\t%lu\n", s, (unsigned long) offsetof( t, m ) );
+#ifdef ASM_OFFSETS
 
-#define SIZEOF( s, t )                                                 \
-   printf( "#define %s\t%lu\n", s, (unsigned long) sizeof(t) );
+/*
+ * Format the asm output in a special way that we can manipulate
+ * after the fact and turn into the final header for the target.
+ */
+
+#define DEFINE_UL( s, ul )                                             \
+   __asm__ __volatile__ ( "\n->" s " %0" : : "i" (ul) )
+
+#define DEFINE( s, d )                                                 \
+   DEFINE_UL( s, d )
+
+#define printf( x )                                                    \
+   __asm__ __volatile__ ( "\n->" x )
+
+#else
+
+#define DEFINE_UL( s, ul )                                             \
+   printf( "#define %s\t%lu\n", s, (unsigned long) (ul) );
 
 #define DEFINE( s, d )                                                 \
    printf( "#define %s\t0x%" PRIx64 "\n", s, (uint64_t) d );
 
+#endif
+
+#define OFFSET( s, t, m )                                              \
+   DEFINE_UL( s, offsetof( t, m ) )
+
+#define SIZEOF( s, t )                                                 \
+   DEFINE_UL( s, sizeof(t) )
+
 
 
 int main( int argc, char **argv )