/******************************************************************************
- * 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
# 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);
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
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"
"#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
{"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"
".WORD ","",HEX_0X
},
+// align 16 bytes
+// http://msdn.microsoft.com/en-us/library/dwa9fwef.aspx
{ "masm",
"\tTITLE %s\n"
"; generated by genccode\n"
}
}
-#ifdef OS400
+#if U_PLATFORM == U_PF_OS400
/*
TODO: Fix this once the compiler implements this feature. Keep in sync with udatamem.c
[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"
#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"
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];
#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;
#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."
*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;
/* 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);
newSuffix=".o";
-#elif defined(U_WINDOWS)
+#elif U_PLATFORM_HAS_WIN32_API
struct {
IMAGE_FILE_HEADER fileHeader;
IMAGE_SECTION_HEADER sections[2];
/* 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;
}
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));
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);