/******************************************************************************
* Copyright (C) 2009-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
#include "unicode/utypes.h"
#if U_PLATFORM_HAS_WIN32_API
# define VC_EXTRALEAN
# define WIN32_LEAN_AND_MEAN
# define NOUSER
# define NOSERVICE
# define NOIME
# define NOMCX
#include <windows.h>
#include <time.h>
# ifdef __GNUC__
# define WINDOWS_WITH_GNUC
# endif
#endif
#if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H
# define U_ELF
#endif
#ifdef U_ELF
# include <elf.h>
# if defined(ELFCLASS64)
# define U_ELF64
# endif
/* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */
# ifndef EM_X86_64
# define EM_X86_64 62
# endif
# define ICU_ENTRY_OFFSET 0
#endif
#include <stdio.h>
#include <stdlib.h>
#include "unicode/putil.h"
#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
#include "toolutil.h"
#include "unicode/uclean.h"
#include "uoptions.h"
#include "pkg_genc.h"
#define MAX_COLUMN ((uint32_t)(0xFFFFFFFFU))
#define HEX_0X 0 /* 0x1234 */
#define HEX_0H 1 /* 01234h */
/* prototypes --------------------------------------------------------------- */
static void
getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix, const char *optFilename);
static uint32_t
write8(FileStream *out, uint8_t byte, uint32_t column);
static uint32_t
write32(FileStream *out, uint32_t byte, uint32_t column);
#if U_PLATFORM == U_PF_OS400
static uint32_t
write8str(FileStream *out, uint8_t byte, uint32_t column);
#endif
/* -------------------------------------------------------------------------- */
/*
Creating Template Files for New Platforms
Let the cc compiler help you get started.
Compile this program
const unsigned int x[5] = {1, 2, 0xdeadbeef, 0xffffffff, 16};
with the -S option to produce assembly output.
For example, this will generate array.s:
gcc -S array.c
This will produce a .s file that may look like this:
.file "array.c"
.version "01.01"
gcc2_compiled.:
.globl x
.section .rodata
.align 4
.type x,@object
.size x,20
x:
.long 1
.long 2
.long -559038737
.long -1
.long 16
.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-85)"
which gives a starting point that will compile, and can be transformed
to become the template, generally with some consulting of as docs and
some experimentation.
If you want ICU to automatically use this assembly, you should
specify "GENCCODE_ASSEMBLY=-a name" in the specific config/mh-* file,
where the name is the compiler or platform that you used in this
assemblyHeader data structure.
*/
static const struct AssemblyType {
const char *name;
const char *header;
const char *beginLine;
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.balign 16\n"
"\t.type %s,%%object\n"
"%s:\n\n",
".long ","",HEX_0X
},
{"gcc-darwin",
/*"\t.section __TEXT,__text,regular,pure_instructions\n"
"\t.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n"*/
".globl _%s\n"
"\t.data\n"
"\t.const\n"
"\t.balign 16\n"
"_%s:\n\n",
".long ","",HEX_0X
},
{"gcc-cygwin",
".globl _%s\n"
"\t.section .rodata\n"
"\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 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 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"
"%s:\n"
"\t.csect %s{RO}, 4\n",
".long ","",HEX_0X
},
{"aCC-ia64",
"\t.file \"%s.s\"\n"
"\t.type %s,@object\n"
"\t.global %s\n"
"\t.secalias .abe$0.rodata, \".rodata\"\n"
"\t.section .abe$0.rodata = \"a\", \"progbits\"\n"
"\t.align 16\n"
"%s::\t",
"data4 ","",HEX_0X
},
{"aCC-parisc",
"\t.SPACE $TEXT$\n"
"\t.SUBSPA $LIT$\n"
"%s\n"
"\t.EXPORT %s\n"
"\t.ALIGN 16\n",
".WORD ","",HEX_0X
},
// align 16 bytes
// http://msdn.microsoft.com/en-us/library/dwa9fwef.aspx
{ "masm",
"\tTITLE %s\n"
"; generated by genccode\n"
".386\n"
".model flat\n"
"\tPUBLIC _%s\n"
"ICUDATA_%s\tSEGMENT READONLY PARA PUBLIC FLAT 'DATA'\n"
"\tALIGN 16\n"
"_%s\tLABEL DWORD\n",
"\tDWORD ","\nICUDATA_%s\tENDS\n\tEND\n",HEX_0H
}
};
static int32_t assemblyHeaderIndex = -1;
static int32_t hexType = HEX_0X;
U_CAPI UBool U_EXPORT2
checkAssemblyHeaderName(const char* optAssembly) {
int32_t idx;
assemblyHeaderIndex = -1;
for (idx = 0; idx < (int32_t)(sizeof(assemblyHeader)/sizeof(assemblyHeader[0])); idx++) {
if (uprv_strcmp(optAssembly, assemblyHeader[idx].name) == 0) {
assemblyHeaderIndex = idx;
hexType = assemblyHeader[idx].hexType; /* set the hex type */
return TRUE;
}
}
return FALSE;
}
U_CAPI void U_EXPORT2
printAssemblyHeadersToStdErr(void) {
int32_t idx;
fprintf(stderr, "%s", assemblyHeader[0].name);
for (idx = 1; idx < (int32_t)(sizeof(assemblyHeader)/sizeof(assemblyHeader[0])); idx++) {
fprintf(stderr, ", %s", assemblyHeader[idx].name);
}
fprintf(stderr,
")\n");
}
U_CAPI void U_EXPORT2
writeAssemblyCode(const char *filename, const char *destdir, const char *optEntryPoint, const char *optFilename, char *outFilePath) {
uint32_t column = MAX_COLUMN;
char entry[64];
uint32_t buffer[1024];
char *bufferStr = (char *)buffer;
FileStream *in, *out;
size_t i, length;
in=T_FileStream_open(filename, "rb");
if(in==NULL) {
fprintf(stderr, "genccode: unable to open input file %s\n", filename);
exit(U_FILE_ACCESS_ERROR);
}
getOutFilename(filename, destdir, bufferStr, entry, ".s", optFilename);
out=T_FileStream_open(bufferStr, "w");
if(out==NULL) {
fprintf(stderr, "genccode: unable to open output file %s\n", bufferStr);
exit(U_FILE_ACCESS_ERROR);
}
if (outFilePath != NULL) {
uprv_strcpy(outFilePath, bufferStr);
}
#ifdef WINDOWS_WITH_GNUC
/* Need to fix the file seperator character when using MinGW. */
swapFileSepChar(outFilePath, U_FILE_SEP_CHAR, '/');
#endif
if(optEntryPoint != NULL) {
uprv_strcpy(entry, optEntryPoint);
uprv_strcat(entry, "_dat");
}
/* turn dashes or dots in the entry name into underscores */
length=uprv_strlen(entry);
for(i=0; i<length; ++i) {
if(entry[i]=='-' || entry[i]=
pkg_genc.rar_elf
版权申诉
88 浏览量
2022-09-23
17:21:46
上传
评论
收藏 9KB RAR 举报
朱moyimi
- 粉丝: 63
- 资源: 1万+