Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / tools / toolutil / pkg_genc.c
index a65defc..7b14807 100644 (file)
@@ -1,11 +1,11 @@
 /******************************************************************************
- *   Copyright (C) 2009-2010, International Business Machines
+ *   Copyright (C) 2009-2013, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
 #include "unicode/utypes.h"
 
-#ifdef U_WINDOWS
+#if U_PLATFORM_HAS_WIN32_API
 #   define VC_EXTRALEAN
 #   define WIN32_LEAN_AND_MEAN
 #   define NOUSER
@@ -19,7 +19,7 @@
 #   endif
 #endif
 
-#ifdef U_LINUX
+#if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H
 #   define U_ELF
 #endif
 
 #define HEX_0X 0 /*  0x1234 */
 #define HEX_0H 1 /*  01234h */
 
-#if defined(U_WINDOWS) || defined(U_ELF)
-#define CAN_GENERATE_OBJECTS
-#endif
-
 /* prototypes --------------------------------------------------------------- */
 static void
 getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix, const char *optFilename);
@@ -65,7 +61,7 @@ write8(FileStream *out, uint8_t byte, uint32_t column);
 static uint32_t
 write32(FileStream *out, uint32_t byte, uint32_t column);
 
-#ifdef OS400
+#if U_PLATFORM == U_PF_OS400
 static uint32_t
 write8str(FileStream *out, uint8_t byte, uint32_t column);
 #endif
@@ -116,11 +112,14 @@ static const struct AssemblyType {
     const char *footer;
     int8_t      hexType; /* HEX_0X or HEX_0h */
 } assemblyHeader[] = {
+    // For gcc assemblers, the meaning of .align changes depending on the
+    // hardware, so we use .balign 16 which always means 16 bytes.
+    // https://sourceware.org/binutils/docs/as/Pseudo-Ops.html
     {"gcc",
         ".globl %s\n"
         "\t.section .note.GNU-stack,\"\",%%progbits\n"
         "\t.section .rodata\n"
-        "\t.align 8\n" /* Either align 8 bytes or 2^8 (256) bytes. 8 bytes is needed. */
+        "\t.balign 16\n"
         /* The 3 lines below are added for Chrome. */
         "#ifdef U_HIDE_DATA_SYMBOL\n"
         "\t.hidden %s\n"
@@ -140,7 +139,7 @@ static const struct AssemblyType {
         "#endif\n"
         "\t.data\n"
         "\t.const\n"
-        "\t.align 4\n"  /* 1<<4 = 16 */
+        "\t.balign 16\n"
         "_%s:\n\n",
 
         ".long ","",HEX_0X
@@ -148,29 +147,43 @@ static const struct AssemblyType {
     {"gcc-cygwin",
         ".globl _%s\n"
         "\t.section .rodata\n"
-        "\t.align 8\n" /* Either align 8 bytes or 2^8 (256) bytes. 8 bytes is needed. */
+        "\t.balign 16\n"
         "_%s:\n\n",
 
         ".long ","",HEX_0X
     },
+    {"gcc-mingw64",
+        ".globl %s\n"
+        "\t.section .rodata\n"
+        "\t.balign 16\n"
+        "%s:\n\n",
+
+        ".long ","",HEX_0X
+    },
+// 16 bytes alignment.
+// http://docs.oracle.com/cd/E19641-01/802-1947/802-1947.pdf
     {"sun",
         "\t.section \".rodata\"\n"
-        "\t.align   8\n"
+        "\t.align   16\n"
         ".globl     %s\n"
         "%s:\n",
 
         ".word ","",HEX_0X
     },
+// 16 bytes alignment for sun-x86.
+// http://docs.oracle.com/cd/E19963-01/html/821-1608/eoiyg.html
     {"sun-x86",
         "Drodata.rodata:\n"
         "\t.type   Drodata.rodata,@object\n"
         "\t.size   Drodata.rodata,0\n"
         "\t.globl  %s\n"
-        "\t.align  8\n"
+        "\t.align  16\n" 
         "%s:\n",
 
         ".4byte ","",HEX_0X
     },
+// 1<<4 bit alignment for aix.
+// http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.aixassem%2Fdoc%2Falangref%2Fidalangref_csect_pseudoop.htm
     {"xlc",
         ".globl %s{RO}\n"
         "\t.toc\n"
@@ -199,6 +212,8 @@ static const struct AssemblyType {
 
         ".WORD ","",HEX_0X
     },
+// align 16 bytes
+//  http://msdn.microsoft.com/en-us/library/dwa9fwef.aspx
     { "masm",
       "\tTITLE %s\n"
       "; generated by genccode\n"
@@ -367,7 +382,7 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const
         }
     }
 
-#ifdef OS400
+#if U_PLATFORM == U_PF_OS400
     /*
     TODO: Fix this once the compiler implements this feature. Keep in sync with udatamem.c
 
@@ -381,8 +396,11 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const
     [grhoten 4/24/2003]
     */
     sprintf(buffer,
+        "#ifndef IN_GENERATED_CCODE\n"
+        "#define IN_GENERATED_CCODE\n"
         "#define U_DISABLE_RENAMING 1\n"
         "#include \"unicode/umachine.h\"\n"
+        "#endif\n"
         "U_CDECL_BEGIN\n"
         "const struct {\n"
         "    double bogus;\n"
@@ -405,8 +423,11 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const
 #else
     /* Function renaming shouldn't be done in data */
     sprintf(buffer,
+        "#ifndef IN_GENERATED_CCODE\n"
+        "#define IN_GENERATED_CCODE\n"
         "#define U_DISABLE_RENAMING 1\n"
         "#include \"unicode/umachine.h\"\n"
+        "#endif\n"
         "U_CDECL_BEGIN\n"
         "const struct {\n"
         "    double bogus;\n"
@@ -539,7 +560,7 @@ write8(FileStream *out, uint8_t byte, uint32_t column) {
     return column;
 }
 
-#ifdef OS400
+#if U_PLATFORM == U_PF_OS400
 static uint32_t
 write8str(FileStream *out, uint8_t byte, uint32_t column) {
     char s[8];
@@ -636,7 +657,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char
 #ifdef U_ELF
         Elf32_Ehdr  header32;
         /* Elf32_Ehdr and ELF64_Ehdr are identical for the necessary fields. */
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
         IMAGE_FILE_HEADER header;
 #endif
     } buffer;
@@ -647,7 +668,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char
 
 #ifdef U_ELF
 
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
     const IMAGE_FILE_HEADER *pHeader;
 #else
 #   error "Unknown platform for CAN_GENERATE_OBJECTS."
@@ -662,7 +683,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char
         *pCPU=EM_386;
         *pBits=32;
         *pIsBigEndian=(UBool)(U_IS_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB);
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
 /* _M_IA64 should be defined in windows.h */
 #   if defined(_M_IA64)
         *pCPU=IMAGE_FILE_MACHINE_IA64;
@@ -723,7 +744,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char
     /* TODO: Support byte swapping */
 
     *pCPU=buffer.header32.e_machine;
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
     if(length<sizeof(IMAGE_FILE_HEADER)) {
         fprintf(stderr, "genccode: match-arch file %s is too short\n", filename);
         exit(U_UNSUPPORTED_ERROR);
@@ -983,7 +1004,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP
 
     newSuffix=".o";
 
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
     struct {
         IMAGE_FILE_HEADER fileHeader;
         IMAGE_SECTION_HEADER sections[2];
@@ -1009,8 +1030,8 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP
 
     /* deal with options, files and the entry point name */
     getArchitecture(&cpu, &bits, &makeBigEndian, optMatchArch);
-    printf("genccode: --match-arch cpu=%hu bits=%hu big-endian=%hu\n", cpu, bits, makeBigEndian);
-#ifdef U_WINDOWS
+    printf("genccode: --match-arch cpu=%hu bits=%hu big-endian=%d\n", cpu, bits, makeBigEndian);
+#if U_PLATFORM_HAS_WIN32_API
     if(cpu==IMAGE_FILE_MACHINE_I386) {
         entryOffset=1;
     }
@@ -1095,7 +1116,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP
     if(paddingSize!=0) {
         T_FileStream_write(out, padding, paddingSize);
     }
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
     /* populate the .obj headers */
     uprv_memset(&objHeader, 0, sizeof(objHeader));
     uprv_memset(&symbols, 0, sizeof(symbols));
@@ -1156,7 +1177,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP
         T_FileStream_write(out, buffer, (int32_t)length);
     }
 
-#ifdef U_WINDOWS
+#if U_PLATFORM_HAS_WIN32_API
     /* write the symbol table */
     T_FileStream_write(out, symbols, IMAGE_SIZEOF_SYMBOL);
     T_FileStream_write(out, &symbolNames, symbolNames.sizeofLongNames);