├── com ├── example │ ├── build.sh │ ├── build_with_pool.sh │ ├── README.txt │ ├── use_vector.cpp │ ├── use_tmap.cpp │ ├── use_bs.cpp │ ├── use_list.cpp │ ├── use_ttab.cpp │ └── use_slist.cpp ├── build.sh ├── linsys.h ├── lpsol.h ├── linsys.cpp ├── sgraph.cpp ├── README.txt ├── Makefile ├── ltype.cpp └── strbuf.h ├── opt ├── md.h ├── ir_aa.cpp ├── ir_high_opt.h ├── ir_middle_opt.h ├── goto_opt.h ├── goto_opt.cpp ├── targ_const_info.h ├── cdg.h ├── comopt.h ├── commoninc.h ├── cominc.h ├── du.cpp ├── pass.h ├── dbg.h ├── cfs_opt.h ├── ir_rce.h ├── targ_info.h ├── du.h ├── ir_loop_cvt.h ├── loop.h └── ipa.h ├── doc └── Manual.txt ├── dex ├── clibs │ └── basic │ │ ├── include │ │ ├── utils │ │ │ ├── ccrc32.h │ │ │ ├── cbuf.h │ │ │ ├── clbe.h │ │ │ ├── cbytestream.h │ │ │ └── chashtable.h │ │ ├── config │ │ │ ├── clibconfig_unix.h │ │ │ ├── clibconfig_brew.h │ │ │ ├── clibconfig_iphone.h │ │ │ ├── clibconfig_android.h │ │ │ ├── clibconfig_wince.h │ │ │ ├── clibconfig_win32.h │ │ │ ├── clibconfig_mtk.h │ │ │ ├── clibconfig_symbian.h │ │ │ └── clibplatform.h │ │ ├── dl │ │ │ └── cdlfcn.h │ │ ├── zip │ │ │ ├── cziputils.h │ │ │ └── czip.h │ │ ├── thread │ │ │ └── cthread.h │ │ ├── trace │ │ │ └── ctrace.h │ │ ├── utf │ │ │ └── cutf.h │ │ ├── clibconfig.h │ │ ├── mem │ │ │ └── cmem.h │ │ ├── sys │ │ │ └── csys.h │ │ ├── str │ │ │ └── cstr.h │ │ ├── math │ │ │ └── cfdlibm.h │ │ ├── std │ │ │ └── cstd.h │ │ ├── errno │ │ │ └── cerrno.h │ │ └── time │ │ │ └── ctime.h │ │ └── arch │ │ ├── common │ │ ├── str │ │ │ ├── cstrport.h │ │ │ └── cstr.c │ │ ├── errno │ │ │ └── cerrno.c │ │ ├── sys │ │ │ ├── cmainport.h │ │ │ ├── csysport.h │ │ │ └── csys.c │ │ ├── trace │ │ │ └── ctraceport.h │ │ ├── thread │ │ │ ├── cthread.c │ │ │ └── cthreadport.h │ │ ├── zip │ │ │ └── czipport.h │ │ ├── time │ │ │ └── ctimeport.h │ │ ├── mem │ │ │ ├── cmemport.h │ │ │ └── cmem.c │ │ ├── utils │ │ │ ├── clbe.c │ │ │ └── cbuf.c │ │ └── io │ │ │ └── cioport.h │ │ ├── android │ │ ├── math │ │ │ └── cmathport.c │ │ ├── dl │ │ │ └── cdlfcn.c │ │ ├── trace │ │ │ └── ctraceport.c │ │ ├── sys │ │ │ └── csysport.c │ │ ├── time │ │ │ └── ctimeport.c │ │ ├── thread │ │ │ └── cthreadport.c │ │ ├── zip │ │ │ └── czipport.c │ │ └── mem │ │ │ └── cmemport.c │ │ ├── unix │ │ ├── math │ │ │ └── cmathport.c │ │ ├── trace │ │ │ └── ctraceport.c │ │ ├── time │ │ │ └── ctimeport.c │ │ ├── zip │ │ │ └── czipport.c │ │ └── mem │ │ │ └── cmemport.c │ │ └── windows │ │ ├── math │ │ └── cmathport.c │ │ ├── dl │ │ └── cdlfcn.c │ │ ├── trace │ │ └── ctraceport.c │ │ ├── time │ │ └── ctimeport.c │ │ ├── zip │ │ └── czipport.c │ │ └── mem │ │ └── cmemport.c ├── README.txt ├── include │ ├── aot.h │ └── xassert.h ├── linealloc │ ├── drAlloc.h │ └── drAlloc.cpp ├── dex_hook.h ├── dex2dex │ ├── cmdline.h │ ├── d2d_dexlib.h │ ├── d2d_comm.h │ ├── d2d_main.h │ ├── d2d_d2l.h │ └── main.cpp ├── lir │ ├── drcode.h │ └── lir.h ├── dex_pass_mgr.h ├── dex_driver.h ├── dex_cp.h ├── trycatch_info.h ├── config.mk ├── aoc_dx_mgr.h ├── dex_call_graph.h ├── dex_cfg.h ├── dex_call_graph.cpp ├── dex_region_mgr.cpp ├── dex.cpp └── dex_region_mgr.h ├── Roadmap.txt ├── AUTHORS.txt ├── README.md ├── win ├── misc.h └── misc.cpp └── Makefile /com/example/build.sh: -------------------------------------------------------------------------------- 1 | g++ $1 -I.. 2 | -------------------------------------------------------------------------------- /com/build.sh: -------------------------------------------------------------------------------- 1 | make clean 2 | make all 3 | 4 | -------------------------------------------------------------------------------- /opt/md.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/opt/md.h -------------------------------------------------------------------------------- /com/example/build_with_pool.sh: -------------------------------------------------------------------------------- 1 | g++ $1 ../smempool.cpp -O0 -g -I.. 2 | -------------------------------------------------------------------------------- /com/linsys.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/com/linsys.h -------------------------------------------------------------------------------- /com/lpsol.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/com/lpsol.h -------------------------------------------------------------------------------- /opt/ir_aa.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/opt/ir_aa.cpp -------------------------------------------------------------------------------- /com/linsys.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/com/linsys.cpp -------------------------------------------------------------------------------- /com/sgraph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/com/sgraph.cpp -------------------------------------------------------------------------------- /doc/Manual.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/xoc/HEAD/doc/Manual.txt -------------------------------------------------------------------------------- /dex/clibs/basic/include/utils/ccrc32.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CRC32_H 3 | #define CLIBS_CRC32_H 4 | 5 | #include "std/cstd.h" 6 | 7 | EXTERN_C UInt32 ccrc32(BYTE* message, UInt32 msgsize, UInt32 crc); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /dex/README.txt: -------------------------------------------------------------------------------- 1 | * How to add XOC module into Android ? 2 | Add two modules into Android to compile XOC and Clibs. 3 | xoc/dex/clibs/Android.mk 4 | xoc/dex/Android.mk 5 | The output libraries are libaoc_xoc.so and libaoc_clibs.so 6 | 7 | 8 | -------------------------------------------------------------------------------- /Roadmap.txt: -------------------------------------------------------------------------------- 1 | 2016 - 2017 2 | *. Correctness. 3 | *. New analysis module: Induction Variable Recognization 4 | *. SSA-back translation for exception block. 5 | *. Complete and refine test environment. 6 | *. Enable a new code generation module for arm, x86 target. 7 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_unix.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_UNIX_H 3 | #define CLIBS_CONFIG_UNIX_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #ifdef _DEBUG 8 | #define C_MAX_TRACE_SIZE (10*1024) 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/str/cstrport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cstrport.h 4 | * 5 | * Created on: Apr 19, 2009 6 | * Author: misa 7 | */ 8 | 9 | #ifndef CLIBS_STR_PORT_H 10 | #define CLIBS_STR_PORT_H 11 | 12 | #include "str/cstr.h" 13 | 14 | 15 | #endif /* CSTRPORT_H_ */ 16 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_brew.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_BREW_H 3 | #define CLIBS_CONFIG_BREW_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #define USE_SYSTEM_FONT 8 | 9 | #if 1 10 | #define C_MAX_TRACE_SIZE (10*1024) 11 | #endif 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/errno/cerrno.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cerrno.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "errno/cerrno.h" 12 | 13 | Int32 _cerrno = ERROR_NOTHING; 14 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_iphone.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_UNIX_H 3 | #define CLIBS_CONFIG_UNIX_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | //#define USE_SYSTEM_CANVAS 8 | //#define USE_SYSTEM_FONT 9 | 10 | #if 1//def _DEBUG 11 | #define C_MAX_TRACE_SIZE (10*1024) 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /com/example/README.txt: -------------------------------------------------------------------------------- 1 | Build the example: 2 | g++ use_vector.cpp -I.. -o a.out 3 | or 4 | ./build.sh use_vector.cpp 5 | 6 | If the example invokes functions in smempool.cpp, you can run example files by build_with_pool.sh. 7 | 8 | If you are building use_bs.cpp, the macro -D_LINUX_ is needed. 9 | e.g: g++ use_bs.cpp ../smempool.cpp ../bs.cpp -I.. -D_LINUX_ 10 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/dl/cdlfcn.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_DL_FUNC_H 3 | #define CLIBS_DL_FUNC_H 4 | 5 | #include "std/cstd.h" 6 | 7 | EXTERN_C ULong cdlopen(const char* name); 8 | 9 | EXTERN_C void cdlclose(ULong handle); 10 | 11 | EXTERN_C void* cdlsym(ULong handle, const char* symname); 12 | 13 | EXTERN_C const char* cdlerror(); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/zip/cziputils.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef C_ZIP_UTILS_H 3 | #define C_ZIP_UTILS_H 4 | 5 | #include "zip/czip.h" 6 | 7 | EXTERN_C bool cZipUnpack(ZipHandle zip, const char* path); 8 | 9 | EXTERN_C bool cZipUnpackFile(const char* zipFname, const char* targetPath); 10 | 11 | EXTERN_C bool cZipPackDir(const char* zipFname, const char* aSrcPath); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/math/cmathport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmathport.c 4 | * iplug.iphone 5 | * 6 | * Created by Misa.Z on 3/31/10. 7 | * Copyright 2010 VMKid. All rights reserved. 8 | * 9 | */ 10 | 11 | #include 12 | #include "std/cstd.h" 13 | 14 | Int32 cRandPort() { 15 | return rand(); 16 | } 17 | 18 | void cSRandPort(UInt32 seed) { 19 | srand(seed); 20 | } 21 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/unix/math/cmathport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmathport.c 4 | * iplug.iphone 5 | * 6 | * Created by Misa.Z on 3/31/10. 7 | * Copyright 2010 VMKid. All rights reserved. 8 | * 9 | */ 10 | 11 | #include 12 | #include "std/cstd.h" 13 | 14 | Int32 cRandPort() { 15 | return rand(); 16 | } 17 | 18 | void cSRandPort(UInt32 seed) { 19 | srand(seed); 20 | } 21 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_android.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_ANDROID_H 3 | #define CLIBS_CONFIG_ANDROID_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #ifdef _DEBUG 8 | #define MADA_DEBUG 9 | #define C_MAX_TRACE_SIZE (10*1024) 10 | #endif 11 | 12 | #define MADA_LINE_SEPERATOR "\n" 13 | 14 | #define CONFIG_PLATFORM_FILENAME "platform_unix.config" 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/math/cmathport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmathport.c 4 | * iplug.iphone 5 | * 6 | * Created by Misa.Z on 3/31/10. 7 | * Copyright 2010 VMKid. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "math/cmathport.h" 12 | #include 13 | #include "std/cstd.h" 14 | 15 | Int32 cRandPort() { 16 | return rand(); 17 | } 18 | 19 | void cSRandPort(UInt32 seed) { 20 | srand(seed); 21 | } 22 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | The file lists people who have have contributed to XOC project. 2 | If you have contributed a patch or made some other contribution to XOC, 3 | please submit a patch to this file to add yourself, and it will be done! 4 | 5 | Su Zhenyu, steven.known@gmail.com, primary architect of XOC 6 | GongKai, gong_k@126.com, dex2dex and LIR convertor 7 | JinYue, fionaking930@gmail.com, dex2dex and LIR convertor 8 | Guo XiaoXin, guonic@gmail.com, 9 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/dl/cdlfcn.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "dl/cdlfcn.h" 3 | #include 4 | 5 | ULong cdlopen(const char* name) { 6 | return (ULong)dlopen(name, RTLD_LAZY); 7 | } 8 | 9 | void cdlclose(ULong handle) { 10 | dlclose((void*)handle); 11 | } 12 | 13 | void* cdlsym(ULong handle, const char* symname) { 14 | return dlsym((void*)handle, symname); 15 | } 16 | 17 | const char* cdlerror() { 18 | return dlerror(); 19 | } 20 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/sys/cmainport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmainport.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_MAIN_H 12 | #define CLIBS_MAIN_H 13 | 14 | //this function didn't be implemented in arch source folder, that means you should implement it in your application's source !! 15 | extern int cMain(int argc, char** argv); 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/trace/ctraceport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * ctraceport.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_TRACE_PORT_H 12 | #define CLIBS_TRACE_PORT_H 13 | 14 | #include "trace/ctrace.h" 15 | 16 | #ifdef MADA_DEBUG 17 | 18 | EXTERN_C void rawErrorPrint(const char* msg); 19 | EXTERN_C void rawTracePrint(const char* msg); 20 | 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /com/README.txt: -------------------------------------------------------------------------------- 1 | libxcom.a is a concise and readable C++ template library. 2 | 3 | The template library includes vector, list, stack, hash, map, bitset, graph, matrix, 4 | 5 | There is also several linear programming solvers, include 6 | exact simplex based on rational arithmetic, 7 | the approximate method based on double/float arithmetic, 8 | the 0-1 integer programming solver, 9 | and the mixed integer programming solver. 10 | 11 | It is well implemented and able to build whole compiler, or anyother project. 12 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_wince.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_WINCE_H 3 | #define CLIBS_CONFIG_WINCE_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #define strdup _strdup 8 | #define stricmp _stricmp 9 | #define snprintf _snprintf 10 | #define vsnprintf _vsnprintf 11 | #define strcasecmp stricmp 12 | #define strncasecmp _strnicmp 13 | 14 | #define USE_SYSTEM_CANVAS 1 15 | #define USE_SYSTEM_FONT 1 16 | 17 | #ifdef _DEBUG 18 | #define C_MAX_TRACE_SIZE (10*1024) 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/thread/cthread.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cthread.c 4 | * 5 | * Created on: Apr 17, 2009 6 | * Author: misa 7 | */ 8 | 9 | #include "thread/cthreadport.h" 10 | 11 | void cMutexInit(MutexT * mt) { 12 | cMutexInitPort(mt); 13 | } 14 | 15 | void cMutexLock(MutexT * mt) { 16 | cMutexLockPort(mt); 17 | } 18 | 19 | void cMutexUnlock(MutexT * mt) { 20 | cMutexUnlockPort(mt); 21 | } 22 | 23 | void cMutexDestroy(MutexT *mt) { 24 | cMutexDestroyPort(mt); 25 | } 26 | 27 | void cSleep(Int32 ms) { 28 | cSleepPort(ms); 29 | } 30 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/zip/czipport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_ZIP_PORT_H 3 | #define CLIBS_ZIP_PORT_H 4 | 5 | #include "std/cstd.h" 6 | 7 | EXTERN_C UInt32 cZipCompFlateInit(); 8 | 9 | EXTERN_C void cZipCompFlateEnd(UInt32 id); 10 | 11 | EXTERN_C Int32 cZipDeflate(UInt32 compID, BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize); 12 | 13 | EXTERN_C Int32 cZipDeflateFinish(UInt32 compID, BYTE* out, UInt32 bufSize, UInt32* outSize); 14 | 15 | EXTERN_C Int32 cZipInflate(UInt32 compID, const BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/thread/cthreadport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cthread.h 4 | * madagascar 5 | * 6 | * Created by Aaron Wang on 4/15/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_THREAD_PORT_H 12 | #define CLIBS_THREAD_PORT_H 13 | 14 | #include "thread/cthread.h" 15 | 16 | 17 | EXTERN_C void cSleepPort(Int32 ms); 18 | 19 | EXTERN_C void cMutexInitPort(MutexT* mt); 20 | 21 | EXTERN_C void cMutexLockPort(MutexT* mt); 22 | 23 | EXTERN_C void cMutexUnlockPort(MutexT* mt); 24 | 25 | EXTERN_C void cMutexDestroyPort(MutexT* mt); 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/unix/trace/ctraceport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * ctraceport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "trace/ctraceport.h" 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef MADA_DEBUG 17 | 18 | EXTERN_C void rawErrorPrint(const char* msg) { 19 | fprintf(stderr, "%s", msg); 20 | fflush(stderr); 21 | } 22 | 23 | EXTERN_C void rawTracePrint(const char* msg) { 24 | fprintf(stdout, "%s", msg); 25 | fflush(stdout); 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/trace/ctraceport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * ctraceport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "trace/ctraceport.h" 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef MADA_DEBUG 17 | 18 | EXTERN_C void rawErrorPrint(const char* msg) { 19 | fprintf(stderr, "%s", msg); 20 | fflush(stderr); 21 | } 22 | 23 | EXTERN_C void rawTracePrint(const char* msg) { 24 | fprintf(stdout, "%s", msg); 25 | fflush(stdout); 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/dl/cdlfcn.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "dl/cdlfcn.h" 3 | #include 4 | #include "str/cstr.h" 5 | 6 | UInt32 cdlopen(const char* name) { 7 | return (UInt32)LoadLibrary(name); 8 | } 9 | 10 | void cdlclose(UInt32 handle) { 11 | FreeLibrary((HMODULE)handle); 12 | } 13 | 14 | void* cdlsym(UInt32 handle, const char* symname) { 15 | return (void*)GetProcAddress((HMODULE)handle, symname); 16 | } 17 | 18 | const char* cdlerror() { 19 | static char msg[64]; 20 | UInt32 err; 21 | 22 | err = GetLastError(); 23 | cSnprintf(msg, sizeof(msg), "win32 error: %u\n", err); 24 | return msg; 25 | } 26 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_win32.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_WIN32_H 3 | #define CLIBS_CONFIG_WIN32_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #define snprintf _snprintf 8 | #define vsnprintf _vsnprintf 9 | #define strcasecmp stricmp 10 | #define strncasecmp strnicmp 11 | 12 | #ifdef _DEBUG 13 | #define MADA_DEBUG 14 | #define C_MAX_TRACE_SIZE (10*1024) 15 | #endif 16 | 17 | #define HAVE_NO_SYSTEM_NEXTAFTER 18 | #define HAVE_NO_SYSTEM_NEXTAFTERF 19 | #define HAVE_NO_SYSTEM_RINT 20 | #define HAVE_NO_SYSTEM_REMAINDER 21 | #define HAVE_NO_SYSTEM_CBRT 22 | #define HAVE_NO_SYSTEM_EXPM1 23 | #define HAVE_NO_SYSTEM_LOG1P 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/time/ctimeport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * ctimeport.h 4 | * 5 | * Created on: Apr 17, 2009 6 | * Author: misa 7 | */ 8 | 9 | #ifndef CLIBS_TIME_PORT_H 10 | #define CLIBS_TIME_PORT_H 11 | 12 | #include "time/ctime.h" 13 | 14 | //get time in milliseconds since GMT 1970-01-01 00:00:00 000 15 | EXTERN_C CTimeT cTimeGetTimePort(void); 16 | 17 | EXTERN_C CTimeT cTimeGetNanoTimePort(void); 18 | 19 | /** return ticks in milliseconds since the system starting */ 20 | EXTERN_C UInt32 cTimeTicksPort(void); 21 | 22 | //from -12.00 to +12.00 23 | EXTERN_C void cTimeSetTimeZonePort(Float32 tz); 24 | 25 | EXTERN_C Float32 cTimeGetTimeZonePort(void); 26 | 27 | #endif /* CTIMEPORT_H_ */ 28 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_mtk.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_MTK_H 3 | #define CLIBS_CONFIG_MTK_H 4 | 5 | 6 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 7 | 8 | 9 | #ifdef WIN32 10 | 11 | #define snprintf _snprintf 12 | #define vsnprintf _vsnprintf 13 | #define strcasecmp stricmp 14 | #define strncasecmp strnicmp 15 | 16 | #else 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | char* strdup(const char*); 23 | int strcasecmp(const char *str1, const char *str2); 24 | int strncasecmp(const char *str1, const char *str2, int count); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | 32 | #if 1 33 | #define C_MAX_TRACE_SIZE (10*1024) 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/utils/cbuf.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef MADA_CBUFFER_H 3 | #define MADA_CBUFFER_H 4 | 5 | #include "std/cstd.h" 6 | 7 | typedef struct STBufStruct { 8 | char *buffer; 9 | UInt32 usedLen; 10 | UInt32 size; 11 | } CBufferT; 12 | 13 | EXTERN_C bool cBufExpand(CBufferT *mem, int size); 14 | EXTERN_C Int32 cBufFormatString(CBufferT *mem, const char* format, ...); 15 | EXTERN_C void cBufClear(CBufferT *mem); 16 | EXTERN_C void cBufFree(CBufferT *mem); 17 | EXTERN_C bool cBufAppend(CBufferT *mem, const void *data, UInt32 len); 18 | EXTERN_C bool cBufAppendString(CBufferT *mem, const char* str); 19 | EXTERN_C bool cBufSetValue(CBufferT *mem, const void *data, UInt32 size); 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/mem/cmemport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmemport.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | #ifndef CLIBS_MEM_PORT_H 11 | #define CLIBS_MEM_PORT_H 12 | 13 | #include "mem/cmem.h" 14 | 15 | EXTERN_C bool cMemInitPort(); 16 | 17 | EXTERN_C void cMemFinalPort(); 18 | 19 | EXTERN_C void* cMallocPort(UInt32 size); 20 | 21 | EXTERN_C void cFreePort(void* p); 22 | 23 | EXTERN_C UInt32 cMemTotalSizePort(void); 24 | 25 | EXTERN_C UInt32 cMemUsedSizePort(void); 26 | 27 | 28 | //** added by raymond 29 | void *cMmapPort(Int32 fd, Int32 alignment, Int32 size, Int32 mode); 30 | void cMunmapPort(void *address, Int32 length); 31 | //** end 32 | #endif 33 | -------------------------------------------------------------------------------- /com/example/use_vector.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | using namespace xcom; 7 | int main() 8 | { 9 | Vector SS; 10 | 11 | SS.set(0, "The number is 10"); 12 | SS.set(1, "The number is 20"); 13 | SS.set(2, "The number is 30"); 14 | 15 | printf("Loop by index:\n"); 16 | 17 | for(int i = 0; i <= SS.get_last_idx(); i++) { 18 | printf("%s\n", SS[i]); 19 | } 20 | 21 | printf("\nReverse Iterator:\n"); 22 | 23 | for(int i = SS.get_last_idx(); i >= 0; i--) { 24 | printf("%s\n", SS[i]); 25 | } 26 | 27 | printf("\nSample Output:\n"); 28 | 29 | printf("%d\n", SS.get_last_idx()); 30 | printf("%s\n", SS[2]); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibconfig_symbian.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_SYMBIAN_H 3 | #define CLIBS_CONFIG_SYMBIAN_H 4 | 5 | #define C_BYTE_ORDER C_LITTLE_ENDIAN 6 | 7 | #define USE_SYSTEM_BLT 0 8 | #define USE_SYSTEM_CANVAS 1 9 | #define USE_SYSTEM_FONT 1 10 | 11 | //temploray mark this #ifdef, when release, should open this macro 12 | //#ifdef _DEBUG 13 | #define C_MAX_TRACE_SIZE (10*1024) 14 | //#endif 15 | 16 | #ifndef __WINSCW__ 17 | #include 18 | //symbain, gcce or armv5 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | int snprintf(char *buf, size_t n, const char *format, ...); 24 | int vsnprintf(char* buf, size_t n, const char *format, va_list list); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/thread/cthread.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cthread.h 4 | * madagascar 5 | * 6 | * Created by Aaron Wang on 4/15/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_THREAD_H 12 | #define CLIBS_THREAD_H 13 | 14 | #include "std/cstd.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct STMutex { 21 | volatile void* mutex; 22 | volatile Int32 cnt; 23 | volatile UInt32 tid; 24 | } MutexT; 25 | 26 | EXTERN_C void cSleep(Int32 ms); 27 | 28 | EXTERN_C void cMutexInit(MutexT* mt); 29 | 30 | EXTERN_C void cMutexLock(MutexT* mt); 31 | 32 | EXTERN_C void cMutexUnlock(MutexT* mt); 33 | 34 | EXTERN_C void cMutexDestroy(MutexT* mt); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/utils/clbe.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_LITTLE_BIG_ENDIAN_H 3 | #define CLIBS_LITTLE_BIG_ENDIAN_H 4 | 5 | #include "std/cstd.h" 6 | 7 | #define cReadLE32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) 8 | #define cReadLE16(p) ((p)[0]|((p)[1]<<8)) 9 | EXTERN_C UInt64 cReadLE64(BYTE* p); 10 | EXTERN_C void cWriteLE32(BYTE* dst, UInt32 num); 11 | EXTERN_C void cWriteLE16(BYTE* dst, UInt16 num); 12 | EXTERN_C void cWriteLE64(BYTE* dst, UInt64 num); 13 | 14 | #define cReadBE32(p) (((p)[0]<<24) | ((p)[1]<<16) | ((p)[2]<<8) | (p)[3]) 15 | #define cReadBE16(p) (((p)[0]<<8) | (p)[1]) 16 | EXTERN_C UInt64 cReadBE64(BYTE* p); 17 | EXTERN_C void cWriteBE32(BYTE* dst, UInt32 num); 18 | EXTERN_C void cWriteBE16(BYTE* dst, UInt16 num); 19 | EXTERN_C void cWriteBE64(BYTE* dst, UInt64 num); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/unix/time/ctimeport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include 3 | #include "time/ctimeport.h" 4 | 5 | static Float32 _sysTimeZone = 8.00; 6 | 7 | UInt32 cTimeTicksPort(void) { 8 | struct timeval tv; 9 | gettimeofday(&tv, NULL); 10 | return ((UInt64)tv.tv_sec)*1000+tv.tv_usec/1000; 11 | } 12 | 13 | //get time in milliseconds since GMT 1970-01-01 00:00:00 000 14 | CTimeT cTimeGetTimePort(void) { 15 | struct timeval tv; 16 | gettimeofday(&tv, NULL); 17 | return ((UInt64)tv.tv_sec)*1000+tv.tv_usec/1000; 18 | } 19 | 20 | //from -12.00 to +12.00 21 | void cTimeSetTimeZonePort(Float32 tz) { 22 | _sysTimeZone = tz; 23 | } 24 | 25 | Float32 cTimeGetTimeZonePort(void) { 26 | return _sysTimeZone; 27 | } 28 | 29 | void cStopSystemTimerPort() { 30 | } 31 | 32 | void cStartSystemTimerPort(Int32 pre, void* args) { 33 | } 34 | -------------------------------------------------------------------------------- /com/example/use_tmap.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | using namespace xcom; 7 | int main() 8 | { 9 | TMap map; 10 | map.set(123, "Mike"); 11 | map.set(234, "Charlie"); 12 | map.set(345, "Tom"); 13 | 14 | printf("\nIterate map via string pointer:\n"); 15 | TMapIter iter; 16 | char const* str; 17 | for (int v = map.get_first(iter, &str); 18 | str != NULL; v = map.get_next(iter, &str)) { 19 | printf("%d->%s\n", v, str); 20 | } 21 | 22 | printf("\nIterate map via iter itself:\n"); 23 | for (int v = map.get_first(iter, &str); 24 | iter.get_elem_count() != 0; v = map.get_next(iter, &str)) { 25 | printf("%d->%s\n", v, str); 26 | } 27 | 28 | printf("%d\n", map.get_elem_count()); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/trace/ctrace.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2012 Alibaba Group*/ 2 | #ifndef CLIBS_TRACE_H 3 | #define CLIBS_TRACE_H 4 | 5 | #include "clibconfig.h" 6 | #include "std/cstd.h" 7 | 8 | 9 | typedef enum { 10 | TRACE_LEVEL_UNKNOWN = 0, 11 | TRACE_LEVEL_VERBOSE, 12 | TRACE_LEVEL_DEBUG, 13 | TRACE_LEVEL_INFO, 14 | TRACE_LEVEL_WARN, 15 | TRACE_LEVEL_ERROR, 16 | TRACE_LEVEL_NONE, 17 | } TraceLevelT; 18 | 19 | EXTERN_C bool cTraceOut(TraceLevelT level, const char* fmt, ...); 20 | 21 | #if defined(ANDROID) && !HOST_LEMUR 22 | //TODO: define LOG_TAG in Android.mk 23 | #include "cutils/log.h" 24 | #ifndef LOGD 25 | #define LOGV ALOGV 26 | #define LOGD ALOGD 27 | #define LOGI ALOGI 28 | #define LOGW ALOGW 29 | #define LOGE ALOGE 30 | #endif 31 | 32 | #else 33 | 34 | #define LOGV printf 35 | #define LOGD printf 36 | #define LOGI printf 37 | #define LOGW printf 38 | #define LOGE printf 39 | 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /com/Makefile: -------------------------------------------------------------------------------- 1 | COM_OBJS +=\ 2 | ltype.o \ 3 | xmat.o \ 4 | comf.o \ 5 | smempool.o \ 6 | agraph.o \ 7 | sgraph.o \ 8 | rational.o \ 9 | testbs.o \ 10 | flty.o \ 11 | linsys.o \ 12 | bs.o 13 | 14 | CFLAGS = -DFOR_PAC -D_LINUX_ -Wno-write-strings -Wsign-promo -Werror=pointer-to-int-cast -Wparentheses \ 15 | -Wformat -Wsign-compare -Wpointer-arith -Wno-multichar -Winit-self -Wuninitialized -Wmaybe-uninitialized -Wtype-limits -Wstrict-overflow \ 16 | -Wstrict-aliasing=3 -finline-limit=10000000 -Wswitch -O3 -g2 -Wall #-fprofile-arcs -ftest-coverage #-D_DEBUG_ # 17 | 18 | INC=. 19 | %.o:%.cpp 20 | @echo "build $<" 21 | $(INFER) gcc $(CFLAGS) $(INC) -c $< -o $@ 22 | 23 | com_objs: $(COM_OBJS) 24 | 25 | all: com_objs 26 | ar rvs libxcom.a $(COM_OBJS) 27 | @echo "success!!" 28 | 29 | clean: 30 | @find -name "*.a" | xargs rm -f 31 | @find -name "*.o" | xargs rm -f 32 | @find -name "*.tmp" | xargs rm -f 33 | @find -name "tags" | xargs rm -f 34 | 35 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/utf/cutf.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cutf.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/28/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_UTF_H 12 | #define CLIBS_UTF_H 13 | 14 | #include "std/cstd.h" 15 | 16 | EXTERN_C UInt32 cUtf8Chars(const char* p, UInt32 size); 17 | 18 | EXTERN_C UInt32 cUtf8LengthOfUtf16(const UInt16* p, UInt32 size); 19 | 20 | EXTERN_C UInt32 cUtf8ToUtf16(const char* utf8, UInt32 utf8Size, UInt16* utf16, UInt32 utf16Size); 21 | 22 | EXTERN_C UInt32 cUtf16ToUtf8(const UInt16* utf16, UInt32 utf16Size, char* utf8, UInt32 utf8Size); 23 | 24 | // need free with cFree, len is the number of unichar in result 25 | EXTERN_C UInt16* cUTF16FromUTF8(const char* utf8, UInt32 utf8Size, Int32 *len); 26 | 27 | // need free with cFree, len is the size of bytes in result 28 | EXTERN_C char* cUTF8FromUTF16(const UInt16* utf16, UInt32 utf16Size, Int32 *len); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/sys/csysport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cesysport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/24/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "sys/csysport.h" 12 | #include 13 | //#include 14 | #include 15 | 16 | bool cSysInitPort(void) { 17 | //SDL_Init(SDL_INIT_VIDEO); 18 | return true; 19 | } 20 | 21 | void cSysFinalPort(void) { 22 | //SDL_Quit(); 23 | } 24 | 25 | Int32 cSysProcessorNumberPort() 26 | { 27 | return sysconf(_SC_NPROCESSORS_CONF); 28 | } 29 | 30 | 31 | const char** cSysGetEnvBlockPort(UInt32 *blockSize) 32 | { 33 | //TODO 34 | return NULL; 35 | } 36 | 37 | const char* cSysGetEnvValuePort(const char *name) 38 | { 39 | //TODO 40 | return NULL; 41 | } 42 | 43 | void cSysExitPort(Int32 status) 44 | { 45 | exit(status); 46 | } 47 | 48 | const struct Property *cSystemInitPlatformPropertiesPort(int *num) 49 | { 50 | *num = 0; 51 | return NULL; 52 | } 53 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/utils/cbytestream.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_BYTESTREAM_H 3 | #define CLIBS_BYTESTREAM_H 4 | 5 | #include "std/cstd.h" 6 | 7 | typedef ULong CBSHandle; 8 | 9 | EXTERN_C CBSHandle cbsInitialize(UInt32 size); 10 | 11 | EXTERN_C void cbsDestroy(CBSHandle bsh); 12 | 13 | EXTERN_C Int32 cbsWrite8(CBSHandle bsh, UInt8 d); 14 | 15 | EXTERN_C Int32 cbsWrite16(CBSHandle bsh, UInt16 d); 16 | 17 | EXTERN_C Int32 cbsWrite32(CBSHandle bsh, UInt32 d); 18 | 19 | EXTERN_C Int32 cbsWrite64(CBSHandle bsh, UInt64 d); 20 | 21 | EXTERN_C Int32 cbsWrite(CBSHandle bsh, const void* data, UInt32 size); 22 | 23 | EXTERN_C Int32 cbsSeek(CBSHandle bsh, UInt32 offset); 24 | 25 | EXTERN_C UInt32 cbsGetSize(CBSHandle bsh); 26 | EXTERN_C UInt32 cbsGetPos(CBSHandle bsh); 27 | 28 | EXTERN_C BYTE* cbsGetData(CBSHandle bsh); 29 | 30 | EXTERN_C void cbsCopyData(CBSHandle bsh, void* data, UInt32 bufSize); 31 | 32 | EXTERN_C void cbsReset(CBSHandle bsh); 33 | 34 | EXTERN_C bool cbsSetCapacity(CBSHandle bsh, UInt32 size); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/trace/ctraceport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * ctraceport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "trace/ctraceport.h" 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef MADA_DEBUG 17 | 18 | extern int UTF8ToANSI(const char* src,int cbSrc, char *dst, int cbDst); 19 | static char _ansiBuffer[C_MAX_TRACE_SIZE]; 20 | 21 | EXTERN_C void rawErrorPrint(const char* msg) { 22 | memset(_ansiBuffer, 0, sizeof(_ansiBuffer)); 23 | UTF8ToANSI(msg, strlen(msg), _ansiBuffer, sizeof(_ansiBuffer)-1); 24 | fprintf(stderr, "%s", _ansiBuffer); 25 | fflush(stderr); 26 | } 27 | 28 | EXTERN_C void rawTracePrint(const char* msg) { 29 | memset(_ansiBuffer, 0, sizeof(_ansiBuffer)); 30 | UTF8ToANSI(msg, strlen(msg), _ansiBuffer, sizeof(_ansiBuffer)-1); 31 | fprintf(stdout, "%s", _ansiBuffer); 32 | fflush(stdout); 33 | } 34 | 35 | #endif 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/clibconfig.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_CONFIG_H 3 | #define CLIBS_CONFIG_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "config/clibplatform.h" 10 | 11 | /* Add any platform that doesn't build using the configure system */ 12 | #if defined(ANDROID) 13 | #include "config/clibconfig_android.h" 14 | #elif defined(__UNIX_LIKE__) 15 | #include "config/clibconfig_unix.h" 16 | #elif defined(WINCE) 17 | #include "config/clibconfig_wince.h" 18 | #elif defined(__SYMBIAN32__) 19 | #include "config/clibconfig_symbian.h" 20 | #elif defined(__MTK__) 21 | #include "config/clibconfig_mtk.h" 22 | #elif defined(__BREW__) 23 | #include "config/clibconfig_brew.h" //phone platforms(wince/symbian/mtk) must before win32 for pc simulator 24 | #elif defined(__WIN32__) 25 | #include "config/clibconfig_win32.h" //phone platforms(wince/symbian/mtk) must before win32 for pc simulator 26 | #elif defined(__IPHONE__) 27 | #include "config/clibconfig_iphone.h" 28 | #else 29 | #error "unkown platform" 30 | #endif /* platform config */ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/time/ctimeport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include 3 | #include 4 | #include "time/ctimeport.h" 5 | 6 | static Float32 _sysTimeZone = 8.00; 7 | 8 | UInt32 cTimeTicksPort(void) { 9 | struct timeval tv; 10 | gettimeofday(&tv, NULL); 11 | return ((UInt64)tv.tv_sec)*1000+tv.tv_usec/1000; 12 | } 13 | 14 | //get time in milliseconds since GMT 1970-01-01 00:00:00 000 15 | CTimeT cTimeGetTimePort(void) { 16 | struct timeval tv; 17 | gettimeofday(&tv, NULL); 18 | return ((UInt64)tv.tv_sec)*1000+tv.tv_usec/1000; 19 | } 20 | 21 | CTimeT cTimeGetNanoTimePort(void) { 22 | #ifdef HAVE_POSIX_CLOCKS 23 | struct timespec now; 24 | clock_gettime(CLOCK_MONOTONIC, &now); 25 | return (UInt64)now.tv_sec*1000000000LL + now.tv_nsec; 26 | #else 27 | CTimeT t; 28 | t = cTimeGetTimePort(); 29 | return ((UInt64)t)*1000000; 30 | #endif 31 | } 32 | 33 | //from -12.00 to +12.00 34 | void cTimeSetTimeZonePort(Float32 tz) { 35 | _sysTimeZone = tz; 36 | } 37 | 38 | Float32 cTimeGetTimeZonePort(void) { 39 | return _sysTimeZone; 40 | } 41 | 42 | void cStopSystemTimerPort() { 43 | } 44 | 45 | void cStartSystemTimerPort(Int32 pre, void* args) { 46 | } 47 | -------------------------------------------------------------------------------- /com/example/use_bs.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | #include "bs.h" 7 | #include "sbs.h" 8 | using namespace xcom; 9 | void bs() 10 | { 11 | BitSet bs; 12 | bs.bunion(1); 13 | bs.bunion(2); 14 | bs.bunion(3); 15 | 16 | printf("Iter element:\n"); 17 | for (int elem = bs.get_first(); elem != -1; elem = bs.get_next(elem)) { 18 | printf("%d\n", elem); 19 | } 20 | 21 | printf("\n"); 22 | printf("%d\n", bs.get_elem_count()); 23 | } 24 | 25 | void sparse_bs() 26 | { 27 | MiscBitSetMgr<100> mbsm; 28 | SBitSetCore<100> sbs; 29 | sbs.bunion(1, mbsm); 30 | sbs.bunion(99, mbsm); 31 | sbs.bunion(99, mbsm); 32 | sbs.bunion(99999, mbsm); 33 | 34 | printf("Iter element:\n"); 35 | SC*> * iter; 36 | for (int elem = sbs.get_first(&iter); 37 | elem != -1; elem = sbs.get_next(elem, &iter)) { 38 | printf("%d\n", elem); 39 | } 40 | 41 | printf("\n"); 42 | printf("%d\n", sbs.get_elem_count()); 43 | 44 | sbs.clean(mbsm); 45 | } 46 | 47 | 48 | int main() 49 | { 50 | bs(); 51 | sparse_bs(); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/sys/csysport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * csysport.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_SYS_PORT_H 12 | #define CLIBS_SYS_PORT_H 13 | 14 | #include "sys/csys.h" 15 | 16 | EXTERN_C bool cSysInitPort(void); 17 | 18 | EXTERN_C void cSysFinalPort(void); 19 | 20 | EXTERN_C Int32 cSysProcessorNumberPort(); 21 | 22 | /* Retrieves the environment variables for the current process. 23 | * @param[out]: blockSize size of the environment block 24 | * @return: If ok, return the environment block. If failed, return NULL. 25 | * remark: 26 | * the format of the environment block is 27 | * Var1=Value1\0 28 | * Var2=Value2\0 29 | * Var3=Value3\0 30 | * ... 31 | * VarN=ValueN\0\0 32 | */ 33 | EXTERN_C const char** cSysGetEnvBlockPort(UInt32 *blockSize); 34 | 35 | /* Retrieves the contents of the specified variable from the environment block of the calling process. 36 | * @param name[in]: The name of the environment variable. 37 | * @return: the value of name if ok, or NULL. 38 | */ 39 | EXTERN_C const char* cSysGetEnvValuePort(const char *name); 40 | 41 | EXTERN_C void cSysExitPort(Int32 status); 42 | 43 | EXTERN_C const struct Property *cSystemInitPlatformPropertiesPort(int *num); 44 | #endif 45 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/mem/cmem.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmem.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_MEM_H 12 | #define CLIBS_MEM_H 13 | 14 | #include "std/cstd.h" 15 | 16 | 17 | typedef void (*CMemAllocFailProc)(); 18 | 19 | EXTERN_C void cMemSetAllocFailProc(CMemAllocFailProc proc); 20 | 21 | EXTERN_C bool cMemInit(); 22 | 23 | EXTERN_C void cMemFinal(); 24 | 25 | 26 | EXTERN_C void* cMallocRaw(UInt32 size); 27 | #define cMalloc(size) cMallocRaw(size) 28 | 29 | EXTERN_C void cFree(void* p); 30 | 31 | EXTERN_C UInt32 cMemTotalSize(void); 32 | 33 | EXTERN_C UInt32 cMemFreeSize(void); 34 | 35 | EXTERN_C UInt32 cMemUsedSize(void); 36 | 37 | #ifdef __BREW__ 38 | #include "aeestdlib.h" 39 | #define cMemchr MEMCHR 40 | #define cMemmove MEMMOVE 41 | #define cMemcmp MEMCMP 42 | #define cMemcpy MEMCPY 43 | #define cMemset MEMSET 44 | 45 | #else 46 | #define cMemchr memchr 47 | #define cMemmove memmove 48 | #define cMemcmp memcmp 49 | #define cMemcpy memcpy 50 | #define cMemset memset 51 | #endif 52 | 53 | //** added by raymond 54 | void *cMmap(Int32 fd, Int32 alignment, Int32 size, Int32 mode); 55 | void cMunmap(void *address, Int32 length); 56 | 57 | 58 | //** end 59 | #endif 60 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/time/ctimeport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include 3 | #include "time/ctimeport.h" 4 | 5 | //for win32 platforms that need gettimeofday 6 | 7 | /* FILETIME of Jan 1 1970 00:00:00. */ 8 | static const UInt64 epoch = LLValue(116444736000000000); 9 | 10 | int gettimeofday(struct timeval * tp, struct timezone * tzp) { 11 | FILETIME file_time; 12 | SYSTEMTIME system_time; 13 | ULARGE_INTEGER ularge; 14 | 15 | GetSystemTime(&system_time); 16 | SystemTimeToFileTime(&system_time, &file_time); 17 | ularge.LowPart = file_time.dwLowDateTime; 18 | ularge.HighPart = file_time.dwHighDateTime; 19 | 20 | tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); 21 | tp->tv_usec = (long) (system_time.wMilliseconds * 1000); 22 | 23 | return 0; 24 | } 25 | 26 | static Float32 _sysTimeZone = 8.00; 27 | 28 | UInt32 cTimeTicksPort(void) { 29 | return clock(); 30 | } 31 | 32 | //get time in milliseconds since GMT 1970-01-01 00:00:00 000 33 | CTimeT cTimeGetTimePort(void) { 34 | struct timeval tv; 35 | gettimeofday(&tv, NULL); 36 | return ((UInt64)tv.tv_sec)*1000+tv.tv_usec/1000; 37 | } 38 | 39 | //from -12.00 to +12.00 40 | void cTimeSetTimeZonePort(Float32 tz) { 41 | _sysTimeZone = tz; 42 | } 43 | 44 | Float32 cTimeGetTimeZonePort(void) { 45 | return _sysTimeZone; 46 | } 47 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/thread/cthreadport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cthreadport.c 4 | * 5 | * Created on: Apr 17, 2009 6 | * Author: misa 7 | */ 8 | 9 | #include "thread/cthreadport.h" 10 | #include "mem/cmemport.h" 11 | #include 12 | #include 13 | 14 | static pthread_mutexattr_t g_mutex_attr; 15 | 16 | void cSleepPort(int ms) { 17 | usleep(ms*1000); 18 | } 19 | 20 | void cMutexInitPort(MutexT * mt) { 21 | int ret; 22 | if(mt) { 23 | pthread_mutexattr_init(&g_mutex_attr); 24 | pthread_mutexattr_settype(&g_mutex_attr, PTHREAD_MUTEX_RECURSIVE); 25 | 26 | mt->mutex = (void*)cMalloc(sizeof(pthread_mutex_t)); 27 | pthread_mutex_init((pthread_mutex_t*)mt->mutex, &g_mutex_attr); 28 | } 29 | } 30 | 31 | void cMutexLockPort(MutexT * mt) { 32 | if(mt && mt->mutex) { 33 | pthread_mutex_lock((pthread_mutex_t*)mt->mutex); 34 | } 35 | } 36 | 37 | void cMutexUnlockPort(MutexT * mt) { 38 | if(mt && mt->mutex) { 39 | pthread_mutex_unlock((pthread_mutex_t*)mt->mutex); 40 | } 41 | } 42 | 43 | void cMutexDestroyPort(MutexT *mt) { 44 | if(mt && mt->mutex) { 45 | pthread_mutex_destroy((pthread_mutex_t*)mt->mutex); 46 | pthread_mutexattr_destroy(&g_mutex_attr); 47 | cFree((void*)mt->mutex); 48 | mt->mutex = NULL; 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /com/example/use_list.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | using namespace xcom; 7 | int main() 8 | { 9 | List l; 10 | 11 | l.append_tail(0); //append a new element at the end. 12 | C * ct = l.append_head(1); //append a new element at the beginning. 13 | 14 | //Insert "2" after position of first element 15 | //place before second element. 16 | l.insert_after(2, ct); 17 | 18 | //Insert "3" before the last element. 19 | //Note this function will more slower than the above. 20 | l.insert_before(3, 0); 21 | 22 | printf("Iter list element by internal iter:\n"); 23 | int i = 0; 24 | for (int e = l.get_head(); i < l.get_elem_count(); i++, e = l.get_next()) { 25 | printf("%d\n", e); 26 | } 27 | 28 | printf("Iter list element by user declared iter:\n"); 29 | C * iter; 30 | for (l.get_head(&iter); iter != NULL; l.get_next(&iter)) { 31 | printf("%d\n", iter->val()); 32 | } 33 | 34 | printf("\nReverse Iterator:\n"); 35 | for (l.get_tail(&iter); iter != NULL; l.get_prev(&iter)) { 36 | printf("%d\n", iter->val()); 37 | } 38 | 39 | printf("\n\n\n"); 40 | printf("%d\n", l.get_elem_count()); 41 | printf("%d\n", l.get_head_nth(2)); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/mem/cmem.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmem.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "mem/cmem.h" 12 | #include "mem/cmemport.h" 13 | 14 | 15 | static CMemAllocFailProc _allocFailProc = NULL; 16 | 17 | void cMemSetAllocFailProc(CMemAllocFailProc proc) { 18 | _allocFailProc = proc; 19 | } 20 | 21 | bool cMemInit() { 22 | return cMemInitPort(); 23 | } 24 | 25 | void cMemFinal() { 26 | cMemFinalPort(); 27 | _allocFailProc = NULL; 28 | } 29 | 30 | UInt32 cMemTotalSize(void) { 31 | return cMemTotalSizePort(); 32 | } 33 | 34 | UInt32 cMemFreeSize(void) { 35 | return cMemTotalSize()-cMemUsedSize(); 36 | } 37 | 38 | UInt32 cMemUsedSize(void) { 39 | return cMemUsedSizePort(); 40 | } 41 | 42 | void* cMallocRaw(UInt32 size) { 43 | void* p = cMallocPort(size); 44 | if(p == NULL && _allocFailProc) { 45 | _allocFailProc(); 46 | p = cMallocPort(size); 47 | } 48 | return p; 49 | } 50 | 51 | void cFree(void* p) { 52 | cFreePort(p); 53 | } 54 | 55 | //** added by raymond 56 | 57 | void *cMmap(Int32 fd, Int32 alignment, Int32 size, Int32 mode) 58 | { 59 | return cMmapPort(fd, alignment, size, mode); 60 | } 61 | 62 | void cMunmap(void *address, Int32 length) 63 | { 64 | return cMunmapPort(address, length); 65 | } 66 | //** end 67 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/zip/czipport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "zip/czipport.h" 3 | #include 4 | #include "mem/cmem.h" 5 | 6 | static z_stream zstrm; 7 | 8 | UInt32 cZipCompFlateInit() { 9 | cMemset(&zstrm, 0, sizeof(zstrm)); 10 | if(deflateInit2(&zstrm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) 11 | return 0; 12 | return 1; 13 | } 14 | 15 | void cZipCompFlateEnd(UInt32 id) { 16 | deflate(&zstrm, Z_FINISH); 17 | deflateEnd(&zstrm); 18 | } 19 | 20 | Int32 cZipDeflate(UInt32 compID, BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 21 | zstrm.next_in = in; 22 | zstrm.avail_in = inSize; 23 | zstrm.next_out = out; 24 | zstrm.avail_out = bufSize; 25 | if(deflate(&zstrm, Z_NO_FLUSH) != Z_OK) 26 | return 0; 27 | *outSize = zstrm.next_out - out; 28 | return inSize - zstrm.avail_in; 29 | } 30 | 31 | Int32 cZipDeflateFinish(UInt32 compID, BYTE* out, UInt32 bufSize, UInt32* outSize) { 32 | Int32 ret; 33 | zstrm.next_out = out; 34 | zstrm.avail_out = bufSize; 35 | ret = deflate(&zstrm, Z_FINISH); 36 | *outSize = zstrm.next_out - out; 37 | if(ret == Z_STREAM_END) 38 | return 0; 39 | if(ret == Z_OK) 40 | return 1; 41 | return -1; 42 | } 43 | 44 | Int32 cZipInflate(UInt32 compID, const BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/unix/zip/czipport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "zip/czipport.h" 3 | #include 4 | #include "mem/cmem.h" 5 | 6 | static z_stream zstrm; 7 | 8 | UInt32 cZipCompFlateInit() { 9 | cMemset(&zstrm, 0, sizeof(zstrm)); 10 | if(deflateInit2(&zstrm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) 11 | return 0; 12 | return 1; 13 | } 14 | 15 | void cZipCompFlateEnd(UInt32 id) { 16 | deflate(&zstrm, Z_FINISH); 17 | deflateEnd(&zstrm); 18 | } 19 | 20 | Int32 cZipDeflate(UInt32 compID, BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 21 | zstrm.next_in = in; 22 | zstrm.avail_in = inSize; 23 | zstrm.next_out = out; 24 | zstrm.avail_out = bufSize; 25 | if(deflate(&zstrm, Z_NO_FLUSH) != Z_OK) 26 | return 0; 27 | *outSize = zstrm.next_out - out; 28 | return inSize - zstrm.avail_in; 29 | } 30 | 31 | Int32 cZipDeflateFinish(UInt32 compID, BYTE* out, UInt32 bufSize, UInt32* outSize) { 32 | Int32 ret; 33 | zstrm.next_out = out; 34 | zstrm.avail_out = bufSize; 35 | ret = deflate(&zstrm, Z_FINISH); 36 | *outSize = zstrm.next_out - out; 37 | if(ret == Z_STREAM_END) 38 | return 0; 39 | if(ret == Z_OK) 40 | return 1; 41 | return -1; 42 | } 43 | 44 | Int32 cZipInflate(UInt32 compID, const BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/zip/czipport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "zip/czipport.h" 3 | #include 4 | #include "mem/cmem.h" 5 | 6 | static z_stream zstrm; 7 | 8 | UInt32 cZipCompFlateInit() { 9 | cMemset(&zstrm, 0, sizeof(zstrm)); 10 | if(deflateInit2(&zstrm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) 11 | return 0; 12 | return 1; 13 | } 14 | 15 | void cZipCompFlateEnd(UInt32 id) { 16 | deflate(&zstrm, Z_FINISH); 17 | deflateEnd(&zstrm); 18 | } 19 | 20 | Int32 cZipDeflate(UInt32 compID, BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 21 | zstrm.next_in = in; 22 | zstrm.avail_in = inSize; 23 | zstrm.next_out = out; 24 | zstrm.avail_out = bufSize; 25 | if(deflate(&zstrm, Z_NO_FLUSH) != Z_OK) 26 | return 0; 27 | *outSize = zstrm.next_out - out; 28 | return inSize - zstrm.avail_in; 29 | } 30 | 31 | Int32 cZipDeflateFinish(UInt32 compID, BYTE* out, UInt32 bufSize, UInt32* outSize) { 32 | Int32 ret; 33 | zstrm.next_out = out; 34 | zstrm.avail_out = bufSize; 35 | ret = deflate(&zstrm, Z_FINISH); 36 | *outSize = zstrm.next_out - out; 37 | if(ret == Z_STREAM_END) 38 | return 0; 39 | if(ret == Z_OK) 40 | return 1; 41 | return -1; 42 | } 43 | 44 | Int32 cZipInflate(UInt32 compID, const BYTE* in, UInt32 inSize, BYTE* out, UInt32 bufSize, UInt32* outSize) { 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/utils/chashtable.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_HASHTABLE_H 3 | #define CLIBS_HASHTABLE_H 4 | 5 | #include "std/cstd.h" 6 | 7 | typedef ULong HashTableHandle; 8 | typedef UInt32 (*HashCodeFunc)(const void* data, UInt32 len); 9 | typedef bool (*TraversalActionFunc)(void* key, UInt32 keySize, void* value, UInt32 size, void* arg); 10 | typedef void* (*HashMallocFunc)(UInt32 size); 11 | typedef void (*HashFreeFunc)(void* ptr); 12 | 13 | #define CHASH_MODE_STORE_NONE 0 14 | #define CHASH_MODE_STORE_KEY 1 15 | #define CHASH_MODE_STORE_ALL 2 16 | EXTERN_C HashTableHandle cHashCreate(HashCodeFunc hashFunc, UInt32 initCapacity, Float32 loadFactor, UInt32 mode); 17 | 18 | EXTERN_C HashTableHandle cHashCreateEx(HashCodeFunc hashFunc, HashMallocFunc mallocFunc, HashFreeFunc freeFunc, 19 | UInt32 initCapacity, Float32 loadFactor, UInt32 mode); 20 | 21 | EXTERN_C bool cHashInsert(HashTableHandle hth, const void* key, UInt32 keySize, const void* data, UInt32 dataSize); 22 | 23 | EXTERN_C void* cHashGet(HashTableHandle hth, const void* key, UInt32 keySize, UInt32* dataSize); 24 | 25 | EXTERN_C void cHashRemove(HashTableHandle hth, const void* key, UInt32 keySize); 26 | 27 | EXTERN_C void cHashTraversal(HashTableHandle hth, TraversalActionFunc action, void* arg); 28 | 29 | EXTERN_C void cHashFree(HashTableHandle hth); 30 | 31 | EXTERN_C UInt32 cHashCount(HashTableHandle hth); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | xoc 2 | ===== 3 | 4 | Welcome to use XOC 5 | 6 | What does XOC mean? 7 | eXtremely Optimizing Compiler. 8 | We build XOC compiler that intent to be a finely honed tool to squeezing 9 | the last performance out of ordinary code. 10 | 11 | Contribution and License Agreement. 12 | If you contribute code to this project, you are implicitly allowing your 13 | code to be distributed under the BSD license. 14 | 15 | Your ideas have no limits. 16 | Surprisingly powerful. 17 | Why let programming tools shackle your mind? 18 | XOC was designed for extensibility. 19 | Tailoring and retargeting the compiler is easy, and fun. 20 | 21 | Truly open. 22 | XOC is not just open-source, it is open from end to end. 23 | You can tune its syntax, add new instructions, integrate arbitrary system 24 | capabilities, enforce custom policies, add specific optimizations ... 25 | 26 | XOC is a compiler infrastructure that provides multi-level IR operations, 27 | flexibility, and the capability of representing almost all popular languages. 28 | There are two level IR representations used throughout all phases of the 29 | compilation. You can use XOC to perform optimization, program analysis or build diagnostic tools. 30 | 31 | Build : 32 | cd xoc & 33 | make all 34 | 35 | 36 | How to Contribute : 37 | All contributors must sign a contributor license agreement (CLA). A CLA 38 | basically says that you own the rights to any code you contribute, and 39 | that you give us permission to use that code in XOC. 40 | You maintain the copyright on that code. 41 | Submit a pull request for your changes. A project developer will review 42 | your work and then merge your request into the project. 43 | -------------------------------------------------------------------------------- /opt/ir_high_opt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __IR_HIGH_OPT_H__ 35 | #define __IR_HIGH_OPT_H__ 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /opt/ir_middle_opt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __IR_MIDDLE_OPT_H__ 35 | #define __IR_MIDDLE_OPT_H__ 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /win/misc.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _MISC_ 35 | #define _MISC_ 36 | void tstart(); 37 | char * tend(); 38 | #endif 39 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/sys/csys.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * csys.h 4 | * madagascar 5 | * 6 | * Created by Aaron Wang on 4/15/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_SYS_H 12 | #define CLIBS_SYS_H 13 | 14 | #include "std/cstd.h" 15 | 16 | struct Property { 17 | const char *key; 18 | const char *value; 19 | }; 20 | 21 | typedef struct STPlatformInfo { 22 | const char* os; 23 | const char* osVersion; 24 | Int64 CPUFrequency; 25 | bool isSupportCamera; 26 | bool isSupportGPS; 27 | bool isSupportGravity; 28 | } CPlatformInfoT; 29 | 30 | EXTERN_C bool cSysInit(void); 31 | 32 | EXTERN_C void cSysFinal(void); 33 | 34 | EXTERN_C void cSysGetPlatform(CPlatformInfoT* info); 35 | 36 | EXTERN_C void cSysSetRootPath(const char* path); 37 | 38 | EXTERN_C const char* cSysGetRootPath(); 39 | 40 | EXTERN_C Int32 cSysProcessorNumber(); 41 | 42 | /* Retrieves the environment variables for the current process. 43 | * @param[out]: blockSize size of the environment block 44 | * @return: If ok, return the environment block. If failed, return NULL. 45 | * remark: 46 | * the format of the environment block is 47 | * Var1=Value1\0 48 | * Var2=Value2\0 49 | * Var3=Value3\0 50 | * ... 51 | * VarN=ValueN\0\0 52 | */ 53 | EXTERN_C const char** cSysGetEnvBlock(UInt32 *blockSize); 54 | 55 | /* Retrieves the contents of the specified variable from the environment block of the calling process. 56 | * @param name[in]: The name of the environment variable. 57 | * @return: the value of name if ok, or NULL. 58 | */ 59 | EXTERN_C const char* cSysGetEnvValue(const char *name); 60 | 61 | EXTERN_C void cSysExit(Int32 status); 62 | 63 | EXTERN_C const struct Property *cSystemInitPlatformProperties(int *num); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /dex/include/aot.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef __AOT_H__ 35 | #define __AOT_H__ 36 | 37 | bool aotDrGenCode(const DexFile* pDexFile, DexMethod* pDexMethod, LCodeData* codeData); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dex/include/xassert.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef _XASSERT_ 35 | #define _XASSERT_ 36 | #define ABORT()\ 37 | do {\ 38 | *(UInt32*)(0x0)=0xdeaddaad;\ 39 | } while (0) 40 | #endif 41 | 42 | #include "trace/ctrace.h" 43 | -------------------------------------------------------------------------------- /opt/goto_opt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _GOTO_OPT_H_ 35 | #define _GOTO_OPT_H_ 36 | 37 | namespace xoc { 38 | 39 | bool goto_opt(IR_CFG * cfg, IRBB * bb); 40 | 41 | } //namespace xoc 42 | #endif 43 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/sys/csys.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | 3 | #include "sys/csys.h" 4 | #include "sys/csysport.h" 5 | #include "str/cstr.h" 6 | 7 | static char _sysRootPath[512]; 8 | 9 | bool cSysInit(void) { 10 | return cSysInitPort(); 11 | } 12 | 13 | void cSysFinal(void) { 14 | cSysFinalPort(); 15 | } 16 | char* str_osVersion[20]; 17 | char* str_osName[40]; 18 | void cSysGetPlatform(CPlatformInfoT* info) { 19 | if(info) { 20 | #if defined(__IPHONEOS__) 21 | cSysGetPlatformPort(info); 22 | #elif defined(WINCE) 23 | info->os = "WINCE"; 24 | #elif defined(__SYMBIAN32__) 25 | info->os = "SYMBIAN"; 26 | #elif defined(__BREW__) 27 | info->os = "SYMBIAN"; 28 | #elif defined(__MTK__) 29 | info->os = "MTK"; 30 | #elif defined(__UNIX_LIKE__) 31 | info->os = "UNIX"; 32 | #elif defined(__WIN32__) 33 | info->os = "IPHONEOS"; 34 | info->CPUFrequency=400000; 35 | info->osVersion="V1"; 36 | info->isSupportCamera=true; 37 | info->isSupportGPS=true; 38 | info->isSupportGravity=true; 39 | #else 40 | info->os = "UNKNOWN"; 41 | #endif 42 | 43 | } 44 | } 45 | 46 | void cSysSetRootPath(const char* path) { 47 | cStrncpy(_sysRootPath, path, 511); 48 | } 49 | 50 | const char* cSysGetRootPath() { 51 | return _sysRootPath; 52 | } 53 | 54 | Int32 cSysProcessorNumber() 55 | { 56 | return cSysProcessorNumberPort(); 57 | } 58 | 59 | const char** cSysGetEnvBlock(UInt32 *blockSize) 60 | { 61 | return cSysGetEnvBlockPort(blockSize); 62 | } 63 | 64 | const char* cSysGetEnvValue(const char *name) 65 | { 66 | return cSysGetEnvValuePort(name); 67 | } 68 | 69 | void cSysExit(Int32 status) 70 | { 71 | cSysExitPort(status); 72 | } 73 | 74 | const struct Property *cSystemInitPlatformProperties(Int32 *num) 75 | { 76 | return cSystemInitPlatformPropertiesPort(num); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /dex/linealloc/drAlloc.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef DEX_READER_ALLOC 35 | #define DEX_READER_ALLOC 36 | 37 | bool drLinearInit(void); 38 | void* drLinearAlloc(size_t size); 39 | void drLinearFree(void); 40 | #endif 41 | -------------------------------------------------------------------------------- /opt/goto_opt.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "cominc.h" 35 | 36 | namespace xoc { 37 | 38 | bool IR_CFG::goto_opt(IRBB * bb) 39 | { 40 | UNUSED(bb); 41 | return false; 42 | } 43 | 44 | } //namespace xoc 45 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/unix/mem/cmemport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmemport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "mem/cmemport.h" 12 | #include "errno/cerrno.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | bool cMemInitPort() { 21 | return true; 22 | } 23 | 24 | void cMemFinalPort() { 25 | } 26 | 27 | void* cMallocPort(UInt32 size) { 28 | void* ret = NULL; 29 | 30 | ret = malloc(size); 31 | if(ret == NULL) { 32 | _cerrno = ERROR_MEM_ALLOC; 33 | return NULL; 34 | } 35 | 36 | return ret; 37 | } 38 | 39 | void cFreePort(void* p) { 40 | if(p == NULL) 41 | return; 42 | 43 | free(p); 44 | } 45 | 46 | UInt32 cMemTotalSizePort(void) { 47 | return 64*1024*1024; 48 | } 49 | 50 | UInt32 cMemUsedSizePort(void) { 51 | return 1*1024*1024; 52 | } 53 | 54 | void *cMmapPort(Int32 fd, Int32 alignment, Int32 size, Int32 mode) 55 | { 56 | void *result; 57 | Int32 prot; 58 | Int32 flags; 59 | 60 | switch (mode) { 61 | case 1: 62 | prot = PROT_READ; 63 | flags = MAP_SHARED; 64 | break; 65 | case 2: 66 | prot = PROT_READ | PROT_WRITE; 67 | flags = MAP_SHARED; 68 | break; 69 | case 4: 70 | prot = PROT_READ; 71 | flags = MAP_PRIVATE; 72 | break; 73 | default: 74 | return -1; 75 | } 76 | 77 | result = mmap(NULL, (size_t) (size & 0x7fffffff), prot, flags, fd, (off_t) (alignment & 0x7fffffff)); 78 | 79 | if (result == MAP_FAILED) 80 | return -1; 81 | 82 | return result; 83 | } 84 | 85 | void cMunmapPort(void *address, Int32 length) 86 | { 87 | munmap(address, length); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/android/mem/cmemport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmemport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "mem/cmemport.h" 17 | #include "errno/cerrno.h" 18 | 19 | bool cMemInitPort() { 20 | return true; 21 | } 22 | 23 | void cMemFinalPort() { 24 | } 25 | 26 | void* cMallocPort(UInt32 size) { 27 | void* ret = NULL; 28 | 29 | ret = malloc(size); 30 | if(ret == NULL) { 31 | _cerrno = ERROR_MEM_ALLOC; 32 | return NULL; 33 | } 34 | 35 | return ret; 36 | } 37 | 38 | void cFreePort(void* p) { 39 | if(p == NULL) 40 | return; 41 | 42 | free(p); 43 | } 44 | 45 | UInt32 cMemTotalSizePort(void) { 46 | return 64*1024*1024; 47 | } 48 | 49 | UInt32 cMemUsedSizePort(void) { 50 | return 1*1024*1024; 51 | } 52 | 53 | 54 | 55 | 56 | void *cMmapPort(Int32 fd, Int32 alignment, Int32 size, Int32 mode) 57 | { 58 | void *result; 59 | Int32 prot; 60 | Int32 flags; 61 | 62 | switch (mode) { 63 | case 1: 64 | prot = PROT_READ; 65 | flags = MAP_SHARED; 66 | break; 67 | case 2: 68 | prot = PROT_READ | PROT_WRITE; 69 | flags = MAP_SHARED; 70 | break; 71 | case 4: 72 | prot = PROT_READ; 73 | flags = MAP_PRIVATE; 74 | break; 75 | default: 76 | return NULL; 77 | } 78 | result = mmap(NULL, (size_t) (size & 0x7fffffff), prot, flags, fd, (off_t) (alignment & 0x7fffffff)); 79 | if (result == MAP_FAILED) 80 | return NULL; 81 | 82 | return result; 83 | } 84 | 85 | void cMunmapPort(void *address, Int32 length) 86 | { 87 | munmap(address, length); 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /com/example/use_ttab.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | using namespace xcom; 7 | class CompareString { 8 | public: 9 | bool is_equ(char const* s1, char const* s2) const 10 | { 11 | return strcmp(s1, s2) == 0; 12 | } 13 | 14 | bool is_less(char const* s1, char const* s2) const 15 | { 16 | while (s1 != NULL && s2 != NULL) { 17 | if (*s1 < *s2) { return true; } 18 | s1++; 19 | s2++; 20 | } 21 | if (s1 == NULL) { return true; } 22 | return false; 23 | } 24 | }; 25 | void string_tab() 26 | { 27 | TTab tab; 28 | tab.append("Mike"); 29 | tab.append("Tom"); 30 | tab.append("Jerry"); 31 | 32 | printf("\nIterate tab:\n"); 33 | TabIter iter; 34 | 35 | for (char const* v = tab.get_first(iter); 36 | v != NULL; v = tab.get_next(iter)) { 37 | printf("%s\n", v); 38 | } 39 | 40 | printf("%d\n", tab.get_elem_count()); 41 | } 42 | 43 | 44 | void int_tab() 45 | { 46 | TTab tab; 47 | tab.append(123); 48 | tab.append(234); 49 | tab.append(345); 50 | 51 | printf("\nIterate tab:\n"); 52 | TabIter iter; 53 | 54 | //If you are going to use integer to judge if the iteration 55 | //determinate, you should guarantee 0 is not in the TTab. 56 | for (int v = tab.get_first(iter); 57 | v != 0; v = tab.get_next(iter)) { 58 | printf("%d\n", v); 59 | } 60 | 61 | printf("\nIterate tab via iter itself:\n"); 62 | for (int v = tab.get_first(iter); 63 | iter.get_elem_count() != 0; v = tab.get_next(iter)) { 64 | printf("%d\n", v); 65 | } 66 | 67 | printf("%d\n", tab.get_elem_count()); 68 | } 69 | 70 | 71 | int main() 72 | { 73 | int_tab(); 74 | string_tab(); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/str/cstr.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cstring.h 4 | * madagascar 5 | * 6 | * Created by Aaron Wang on 4/15/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_STRING_H 12 | #define CLIBS_STRING_H 13 | 14 | #include "std/cstd.h" 15 | 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef __BREW__ 26 | #define cStrcat strcat 27 | #define cStrchr strchr 28 | #define cStrrchr strrchr 29 | #define cStrcmp strcmp 30 | #define cStrcpy strcpy 31 | #define cStrlen strlen 32 | #define cStrncat strncat 33 | #define cStrncmp strncmp 34 | #define cStrncpy strncpy 35 | #define cStrstr strstr 36 | #define cStrcasecmp strcasecmp 37 | #define cStrncasecmp strncasecmp 38 | #define cSnprintf snprintf 39 | #define cVsnprintf vsnprintf 40 | #define cSprintf sprintf 41 | #define cStrdup strdup 42 | #define cIsspace isspace 43 | 44 | #define cAtoi atoi 45 | #define cAtof atof 46 | #else /* !__BREW__ */ 47 | #include "AEEStdLib.h" 48 | #define cStrcat STRCAT 49 | #define cStrchr STRCHR 50 | #define cStrrchr STRRCHR 51 | #define cStrcmp STRCMP 52 | #define cStrcpy STRCPY 53 | #define cStrlen STRLEN 54 | #define cStrncat(src,dst,len) STRCAT((src),(dst)) 55 | #define cStrncmp STRNCMP 56 | #define cStrncpy STRNCPY 57 | #define cStrstr STRSTR 58 | #define cStrcasecmp STRICMP 59 | #define cStrncasecmp STRNICMP 60 | #define cSnprintf SNPRINTF 61 | #define cVsnprintf VSNPRINTF 62 | #define cSprintf SPRINTF 63 | #define cStrdup STRDUP 64 | #define cIsspace(c) ((c) == ' ' || (c) == '\r' || (c) == '\n' || (c) == '\t' || (c) == '\v') 65 | 66 | #define cAtoi ATOI 67 | #define cAtof ATOF 68 | #endif /* __BREW__ */ 69 | 70 | /** replace all 'pat' to 'rep' in 'str' */ 71 | void cStrcrep(char* str, char pat, char rep); 72 | 73 | Int32 cStrLastIndexOf(const char* str, char c); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /dex/dex_hook.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_HOOK_H_ 35 | #define _DEX_HOOK_H_ 36 | 37 | #include "dex_pass_mgr.h" 38 | #include "dex_call_graph.h" 39 | #include "dex_region.h" 40 | #include "dex_region_mgr.h" 41 | #include "dex_cp.h" 42 | #include "dex_rp.h" 43 | #include "dex_aa.h" 44 | #include "dex_cfg.h" 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/utils/clbe.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "utils/clbe.h" 3 | #include "mem/cmem.h" 4 | 5 | UInt64 cReadLE64(BYTE* p) { 6 | UInt64 ret = 0; 7 | 8 | /** 9 | ret |= p[4]; 10 | ret |= p[5] << 8; 11 | ret |= p[6] << 16; 12 | ret |= p[7] << 24; 13 | ret <<= 32; 14 | ret |= p[0]; 15 | ret |= p[1] << 8; 16 | ret |= p[2] << 16; 17 | ret |= p[3] << 24; 18 | */ 19 | cMemcpy(&ret, p, 8); 20 | return ret; 21 | } 22 | 23 | void cWriteLE32(BYTE* dst, UInt32 num) { 24 | if(dst == NULL) 25 | return; 26 | dst[0] = num & 0xff; 27 | dst[1] = (num >> 8) & 0xff; 28 | dst[2] = (num >> 16) & 0xff; 29 | dst[3] = num >> 24; 30 | } 31 | 32 | void cWriteLE16(BYTE* dst, UInt16 num) { 33 | if(dst == NULL) 34 | return; 35 | dst[0] = num & 0xff; 36 | dst[1] = num >> 8; 37 | } 38 | 39 | void cWriteLE64(BYTE* dst, UInt64 num) { 40 | if(dst == NULL) 41 | return; 42 | cMemcpy(dst, &num, 8); 43 | } 44 | 45 | UInt64 cReadBE64(BYTE* p) { 46 | UInt64 ret = 0; 47 | 48 | ret |= p[3]; 49 | ret |= p[2] << 8; 50 | ret |= p[1] << 16; 51 | ret |= (UInt32)p[0] << 24; 52 | ret <<= 32; 53 | ret |= p[7]; 54 | ret |= p[6] << 8; 55 | ret |= p[5] << 16; 56 | ret |= (UInt32)(p[4] << 24); 57 | return ret; 58 | } 59 | 60 | void cWriteBE32(BYTE* dst, UInt32 num) { 61 | if(dst == NULL) 62 | return; 63 | dst[0] = num >> 24; 64 | dst[1] = (num >> 16) & 0xff; 65 | dst[2] = (num >> 8) & 0xff; 66 | dst[3] = num & 0xff; 67 | } 68 | 69 | void cWriteBE16(BYTE* dst, UInt16 num) { 70 | if(dst == NULL) 71 | return; 72 | dst[0] = num >> 8; 73 | dst[1] = num & 0xff; 74 | } 75 | 76 | void cWriteBE64(BYTE* dst, UInt64 num) { 77 | BYTE* p; 78 | 79 | if(dst == NULL) 80 | return; 81 | p = (BYTE*)# 82 | dst[0] = p[7]; 83 | dst[1] = p[6]; 84 | dst[2] = p[5]; 85 | dst[3] = p[4]; 86 | dst[4] = p[3]; 87 | dst[5] = p[2]; 88 | dst[6] = p[1]; 89 | dst[7] = p[0]; 90 | } 91 | -------------------------------------------------------------------------------- /dex/dex2dex/cmdline.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _CMD_LINE_ 35 | #define _CMD_LINE_ 36 | 37 | bool processCommandLine(UINT argc, CHAR const* argv[]); 38 | 39 | extern CHAR const* g_dex_file_path; 40 | extern INT g_output_file_handler; 41 | extern INT g_source_file_handler; 42 | 43 | //Set true to disable all auxiliary informations which will output to stdout. 44 | extern bool g_silence; 45 | #endif 46 | -------------------------------------------------------------------------------- /dex/lir/drcode.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef __DRCODE_H__ 35 | #define __DRCODE_H__ 36 | 37 | void d2rMethod( 38 | D2Dpool* pool, 39 | DexFile* pDexFile, 40 | const DexMethod* pDexMethod, 41 | const DexClassDef* classdef, 42 | RegionMgr* rumgr, 43 | List * rulist); 44 | void d2rCopyData(D2Dpool* pool, BYTE* endAddr); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /dex/dex2dex/d2d_dexlib.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef _D2D_DEXLIB_H 35 | #define _D2D_DEXLIB_H 36 | 37 | #define MIN_INT ((Int32)1<<(sizeof(Int32)*8 - 1)) 38 | 39 | #include "std/cstd.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | int signedLeb128Size(Int32 value); 45 | void writeSignedLeb128(Int8* ptr, Int32 value); 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /dex/dex_pass_mgr.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_PASS_MGR_H_ 35 | #define _DEX_PASS_MGR_H_ 36 | 37 | class DexPassMgr : public PassMgr { 38 | public: 39 | DexPassMgr(Region * ru) : PassMgr(ru) {} 40 | virtual ~DexPassMgr() {} 41 | 42 | virtual Pass * allocCFG(); 43 | virtual Pass * allocDCE(); 44 | virtual Pass * allocCopyProp(); 45 | virtual Pass * allocRP(); 46 | 47 | virtual void performScalarOpt(OptCtx & oc); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /dex/dex2dex/d2d_comm.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef _D2D_COMM_H_ 35 | #define _D2D_COMM_H_ 36 | 37 | //avoid confict instruction: kSparseSwitchSignature 0x0200 and lc_nop 0x0200 38 | #define KVM_kPackedSwitchSignature 0x10FF 39 | #define KVM_kSparseSwitchSignature 0x20FF 40 | #define KVM_kArrayDataSignature 0x30FF 41 | 42 | #define L2D_kPackedSwitchSignature 0x0100 43 | #define L2D_kSparseSwitchSignature 0x0200 44 | #define L2D_kArrayDataSignature 0x0300 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /opt/targ_const_info.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __TARG_CONST_INFO_H__ 35 | #define __TARG_CONST_INFO_H__ 36 | 37 | #if defined(FOR_X86) 38 | #include "../x86/x86_const_info.h" 39 | 40 | #elif defined(FOR_ARM) 41 | #include "../arm/arm_const_info.h" 42 | 43 | #elif defined(FOR_PAC) 44 | #include "../pac/pac_const_info.h" 45 | 46 | #elif defined(FOR_DEX) 47 | #include "../dex/dex_const_info.h" 48 | 49 | #elif defined(FOR_JS) 50 | #include "../js/js_const_info.h" 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/windows/mem/cmemport.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmemport.c 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #include "mem/cmemport.h" 12 | #include "errno/cerrno.h" 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | bool cMemInitPort() { 20 | return true; 21 | } 22 | 23 | void cMemFinalPort() { 24 | } 25 | 26 | void* cMallocPort(UInt32 size) { 27 | void* ret = NULL; 28 | #ifdef WIN32 29 | printf("");//yangyang added not to crash in windows 30 | #endif 31 | ret = malloc(size); 32 | if(ret == NULL) { 33 | _cerrno = ERROR_MEM_ALLOC; 34 | return NULL; 35 | } 36 | 37 | return ret; 38 | } 39 | 40 | void cFreePort(void* p) { 41 | if(p == NULL) 42 | return; 43 | 44 | free(p); 45 | } 46 | 47 | UInt32 cMemTotalSizePort(void) { 48 | return 64*1024*1024; 49 | } 50 | 51 | UInt32 cMemUsedSizePort(void) { 52 | return 1*1024*1024; 53 | } 54 | 55 | void *cMmapPort(Int32 fd, Int32 alignment, Int32 size, Int32 mode) 56 | { 57 | HANDLE mmaping; 58 | void *result; 59 | Int32 prot; 60 | Int32 mapmode; 61 | 62 | switch (mode) { 63 | case 1: 64 | prot = PAGE_READONLY; 65 | mapmode = FILE_MAP_READ; 66 | break; 67 | case 2: 68 | prot = PAGE_READWRITE; 69 | mapmode = FILE_MAP_WRITE; 70 | break; 71 | case 4: 72 | prot = PAGE_WRITECOPY; 73 | mapmode = FILE_MAP_COPY; 74 | break; 75 | default: 76 | return ((void *) -1); 77 | } 78 | 79 | mmaping = CreateFileMapping((HANDLE) fd, NULL, prot, 0, 0, NULL); 80 | 81 | if (mmaping == NULL) 82 | return ((void *) -1); 83 | 84 | result = MapViewOfFile(mmaping, mapmode, (DWORD) ((alignment >> 0x20) & 0x7fffffff), (DWORD) (alignment & 0xffffffff), (SIZE_T) (size & 0xffffffff)); 85 | CloseHandle(mmaping); 86 | 87 | return result; 88 | } 89 | 90 | void cMunmapPort(void *address, Int32 length) 91 | { 92 | UnmapViewOfFile((HANDLE) address); 93 | } 94 | 95 | -------------------------------------------------------------------------------- /dex/dex_driver.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_DRIVER_H_ 35 | #define _DEX_DRIVER_H_ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | //Export Functions. 42 | bool compileFunc( 43 | RegionMgr * rumgr, 44 | D2Dpool * pool, 45 | LIRCode * fu, 46 | DexFile * df, 47 | DexMethod const* dm, 48 | DexCode const* dexcode, 49 | DexClassDef const* dexclassdef, 50 | OffsetVec const& offsetvec, 51 | List * rulist); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /dex/dex_cp.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_CP_H_ 35 | #define _DEX_CP_H_ 36 | 37 | class DEX_CP : public IR_CP { 38 | public: 39 | DEX_CP(Region * ru) : IR_CP(ru) {} 40 | virtual ~DEX_CP() {} 41 | 42 | //Check if ir is appropriate for propagation. 43 | virtual bool canBeCandidate(IR const* ir) const 44 | { 45 | //Prop const imm may generate code which is not legal dex format. 46 | //TODO: Perform more code normalization before ir2dex. 47 | //return ir->is_const() || ir->is_pr(); 48 | 49 | return ir->is_pr(); 50 | } 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/io/cioport.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cioport.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/22/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_IO_PORT_H 12 | #define CLIBS_IO_PORT_H 13 | 14 | 15 | #include "io/cio.h" 16 | 17 | //file only operations 18 | 19 | EXTERN_C Int32 cIOOpenPort(const char* fname, UInt32 flags); 20 | 21 | EXTERN_C void cIOClosePort(Int32 fd); 22 | 23 | EXTERN_C Int32 cIOReadPort(Int32 fd, void* buf, UInt32 bufSize); 24 | 25 | EXTERN_C Int32 cIOWritePort(Int32 fd, const void* buf, UInt32 bufSize); 26 | 27 | EXTERN_C Int32 cIOSeekPort(Int32 fd, Int32 offset, UInt8 flags); 28 | 29 | EXTERN_C Int32 cIOPositionPort(Int32 fd); 30 | 31 | EXTERN_C bool cIORemovePort(const char* fname); 32 | 33 | EXTERN_C bool cIOGetFileInfoPort(const char* fname, FileInfoT* info); 34 | 35 | EXTERN_C bool cIOGetFDInfoPort(Int32 fd, FileInfoT* info); 36 | 37 | EXTERN_C bool cIOSetFileAttributesPort(const char* fname, UInt32 attrs); 38 | 39 | EXTERN_C Int32 cIOSizePort(Int32 fd); 40 | 41 | EXTERN_C bool cIOTruncatePort(Int32 fd, UInt32 size); 42 | 43 | //dir only operations 44 | 45 | /** 46 | * @param matchPattern NULL for default, that means match *.* 47 | * @return 0 if failed 48 | */ 49 | EXTERN_C DirHandleT cIOOpenDirPort(const char* path, const char* matchPattern); 50 | 51 | EXTERN_C bool cIOReadDirPort(DirHandleT dir, DirentT* info); 52 | 53 | EXTERN_C bool cIORemoveDirPort(const char *pathName); 54 | 55 | EXTERN_C void cIORewindDirPort(DirHandleT dir); 56 | 57 | EXTERN_C void cIOCloseDirPort(DirHandleT dir); 58 | 59 | EXTERN_C bool cIOMakeDirPort(const char* path); 60 | 61 | EXTERN_C bool cIORemoveDirPort(const char* path); 62 | 63 | //folder and file operations 64 | EXTERN_C bool cIOExistsPort(const char* fname); 65 | 66 | EXTERN_C bool cIORenamePort(const char*oldName,const char* newName); 67 | 68 | //** added by raymond 69 | Int32 cIOFsyncPort(Int32 fd); 70 | Int32 cIOGetGranularityPort(); 71 | Int32 cIOIsCaseSensitivePort(); 72 | void cIOGetCanonPort(char *path); 73 | bool cIOSyncPort(Int32 fd); 74 | //** end 75 | 76 | EXTERN_C bool cIOSetLastModifiedPort(const char *filePath,UInt64 time); 77 | 78 | EXTERN_C char cIOSeparatorCharPort(); 79 | 80 | EXTERN_C char cIOPathSeparatorCharPort(); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /opt/cdg.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _CDG_H_ 35 | #define _CDG_H_ 36 | 37 | namespace xoc { 38 | 39 | class Region; 40 | 41 | //Control Dependence Graph 42 | class CDG : public Graph { 43 | Region * m_ru; 44 | public: 45 | CDG(Region * ru) { m_ru = ru; } 46 | void get_cd_preds(UINT id, OUT List & lst); 47 | void get_cd_succs(UINT id, OUT List & lst); 48 | bool is_only_cd_self(UINT id); 49 | bool is_cd(UINT a, UINT b); 50 | void dump(); 51 | void build(IN OUT OptCtx & oc, DGraph & cfg); 52 | void rebuild(IN OUT OptCtx & oc, DGraph & cfg); 53 | }; 54 | 55 | } //namespace xoc 56 | #endif 57 | -------------------------------------------------------------------------------- /dex/dex2dex/d2d_main.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef _D2D_MAIN_H 35 | #define _D2D_MAIN_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | int d2dEntry(int dexfd, 41 | int outputfd, 42 | long* filelen, 43 | bool ifopt, 44 | char const* dexfilename); 45 | bool d2dEntryBuf(unsigned char ** dxbuf, 46 | unsigned int* dxbuflen, 47 | unsigned int* cbsHandler, 48 | char const* dexfilename); 49 | void d2dEntryBufFree(unsigned int cbsHandler); 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /dex/trycatch_info.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __TRY_CATCH_INFO_H__ 35 | #define __TRY_CATCH_INFO_H__ 36 | 37 | //Map from LIR to LABEL. 38 | typedef TMap*> LIR2LabelInfo; 39 | 40 | class CatchInfo { 41 | public: 42 | CatchInfo * prev; 43 | CatchInfo * next; 44 | LabelInfo * catch_start; 45 | UINT kind; //record exception type. 46 | CHAR const* kindname; //record exception type name. 47 | }; 48 | 49 | 50 | class TryInfo { 51 | public: 52 | TryInfo * prev; 53 | TryInfo * next; 54 | LabelInfo * try_start; 55 | LabelInfo * try_end; 56 | UINT try_start_pos; 57 | UINT try_end_pos; 58 | CatchInfo * catch_list; 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /opt/comopt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | //Optimizations 35 | #include "prssainfo.h" 36 | #include "prdf.h" 37 | #include "ir_ssa.h" 38 | //#include "ir_mdssa.h" 39 | #include "cfs_mgr.h" 40 | #include "cfs_opt.h" 41 | #include "goto_opt.h" 42 | #include "if_opt.h" 43 | #include "ir_gvn.h" 44 | #include "ir_lcse.h" 45 | #include "ir_gcse.h" 46 | #include "ir_dce.h" 47 | #include "ir_rce.h" 48 | //#include "ir_dse.h" 49 | //#include "ir_vrp.h" 50 | #include "ir_cp.h" 51 | //#include "ir_ccp.h" 52 | //#include "ir_pre.h" 53 | #include "ir_rp.h" 54 | //#include "ir_poly.h" 55 | #include "ir_licm.h" 56 | #include "ir_ivr.h" 57 | #include "ir_loop_cvt.h" 58 | #include "callg.h" 59 | #include "ipa.h" 60 | #include "inliner.h" 61 | -------------------------------------------------------------------------------- /dex/config.mk: -------------------------------------------------------------------------------- 1 | #The following code is written by Alibaba Group: 2 | 3 | #some global macros 4 | 5 | ifeq ($(PLATFORM_SDK_VERSION), 8) 6 | ANDROID_MAJOR_VERSION_NUM := 22 7 | endif 8 | ifeq ($(PLATFORM_SDK_VERSION), 9) 9 | ANDROID_MAJOR_VERSION_NUM := 22 10 | endif 11 | ifeq ($(PLATFORM_SDK_VERSION), 10) 12 | ANDROID_MAJOR_VERSION_NUM := 23 13 | endif 14 | ifeq ($(PLATFORM_SDK_VERSION), 14) 15 | ANDROID_MAJOR_VERSION_NUM := 40 16 | endif 17 | ifeq ($(PLATFORM_SDK_VERSION), 15) 18 | ANDROID_MAJOR_VERSION_NUM := 40 19 | endif 20 | ifeq ($(PLATFORM_SDK_VERSION), 16) 21 | ANDROID_MAJOR_VERSION_NUM := 41 22 | endif 23 | ifeq ($(PLATFORM_SDK_VERSION), 17) 24 | ANDROID_MAJOR_VERSION_NUM := 42 25 | endif 26 | ifeq ($(PLATFORM_SDK_VERSION), 18) 27 | ANDROID_MAJOR_VERSION_NUM := 43 28 | endif 29 | ifeq ($(PLATFORM_SDK_VERSION), 19) 30 | ANDROID_MAJOR_VERSION_NUM := 44 31 | endif 32 | ifeq ($(PLATFORM_SDK_VERSION), 21) 33 | ANDROID_MAJOR_VERSION_NUM := 50 34 | endif 35 | 36 | ifeq ($(ANDROID_MAJOR_VERSION_NUM),) 37 | COMPARE_RESULT := $(shell echo ${PLATFORM_SDK_VERSION} \>= 15 | bc) 38 | ifeq ($(COMPARE_RESULT), 1) 39 | ANDROID_MAJOR_VERSION_NUM := 40 40 | endif 41 | endif 42 | 43 | ifeq ($(ANDROID_MAJOR_VERSION_NUM),) 44 | $(error ANDROID_MAJOR_VERSION_NUM does not get a value for sdk version $(PLATFORM_SDK_VERSION)) 45 | endif 46 | 47 | TARGET_lemur_CFLAGS := 48 | TARGET_lemur_CFLAGS += -mpoke-function-name 49 | TARGET_lemur_CFLAGS += -fomit-frame-pointer 50 | TARGET_lemur_CFLAGS += -fno-strict-aliasing 51 | TARGET_lemur_CFLAGS += -funswitch-loops 52 | TARGET_lemur_CFLAGS += -finline-limit=1200 53 | TARGET_lemur_CFLAGS += -finline-functions 54 | 55 | LOCAL_CFLAGS := \ 56 | -DANDROID_MAJOR_VERSION=$(ANDROID_MAJOR_VERSION_NUM) \ 57 | -DARCH=\"$(TARGET_ARCH)\" 58 | 59 | ## release variant has a higher priviledge than building variant 60 | ## TVM_RELEASE seemed as debug's trigger, later may be more complicated 61 | building_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT)) 62 | ifneq ($(building_variant),) 63 | TVM_RELEASE := true 64 | else 65 | TVM_RELEASE := false 66 | endif 67 | 68 | release_variant := $(filter on off,$(VM_DEBUG)) 69 | ifeq (off,$(release_variant)) 70 | TVM_RELEASE := true 71 | $(info "setting lemur in release mode with VM_DEBUG"); 72 | else 73 | ifeq (on,$(release_variant)) 74 | TVM_RELEASE := false 75 | $(info "setting lemur in debug mode with VM_DEBUG"); 76 | endif 77 | endif 78 | -------------------------------------------------------------------------------- /opt/commoninc.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __COMMONINC_H__ 35 | #define __COMMONINC_H__ 36 | 37 | //Common included files 38 | #include "stdlib.h" 39 | #include "stdarg.h" 40 | #include "stdio.h" 41 | #include "string.h" 42 | #include "ltype.h" 43 | #include "math.h" 44 | 45 | //libxcom 46 | #include "comf.h" 47 | #include "strbuf.h" 48 | #include "smempool.h" 49 | #include "sstl.h" 50 | #include "matt.h" 51 | #include "bs.h" 52 | #include "sbs.h" 53 | #include "sbs_hash.h" 54 | #include "sgraph.h" 55 | #include "rational.h" 56 | #include "flty.h" 57 | #include "xmat.h" 58 | 59 | using namespace xcom; 60 | 61 | #include "option.h" 62 | #include "targ_const_info.h" 63 | #include "util.h" 64 | #include "symtab.h" 65 | #include "label.h" 66 | #include "cdg.h" 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /dex/linealloc/drAlloc.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #include "cominc.h" 35 | #include "drAlloc.h" 36 | 37 | #define PIG_SIZE (4096) 38 | #define DEFAULT_ALLOC_SIZE (PIG_SIZE*32) 39 | 40 | static SMemPool * g_d2d_used_pool = NULL; 41 | 42 | bool drLinearInit(void){ 43 | if (g_d2d_used_pool == NULL) { 44 | g_d2d_used_pool = smpoolCreate(DEFAULT_ALLOC_SIZE, MEM_COMM); 45 | } 46 | return true; 47 | } 48 | 49 | void* drLinearAlloc(size_t size) 50 | { 51 | ASSERT0(g_d2d_used_pool); 52 | return smpoolMalloc(size, g_d2d_used_pool); 53 | } 54 | 55 | void drLinearFree(void) 56 | { 57 | ASSERT0(g_d2d_used_pool); 58 | smpoolDelete(g_d2d_used_pool); 59 | g_d2d_used_pool = NULL; 60 | return; 61 | } 62 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | COM_OBJS +=\ 2 | com/ltype.o \ 3 | com/comf.o \ 4 | com/smempool.o \ 5 | com/agraph.o \ 6 | com/sgraph.o \ 7 | com/rational.o \ 8 | com/linsys.o \ 9 | com/xmat.o \ 10 | com/strbuf.o \ 11 | com/testbs.o \ 12 | com/flty.o \ 13 | com/bs.o 14 | 15 | OPT_OBJS +=\ 16 | opt/cfs_opt.o\ 17 | opt/dbg.o\ 18 | opt/goto_opt.o\ 19 | opt/if_opt.o \ 20 | opt/ir.o\ 21 | opt/ir_bb.o\ 22 | opt/ir_du.o\ 23 | opt/du.o\ 24 | opt/ir_cfg.o\ 25 | opt/ir_simp.o\ 26 | opt/ir_gvn.o\ 27 | opt/ir_rce.o\ 28 | opt/ir_dce.o\ 29 | opt/ir_cp.o\ 30 | opt/ir_lcse.o\ 31 | opt/ir_gcse.o\ 32 | opt/ir_licm.o\ 33 | opt/ir_ivr.o\ 34 | opt/ir_middle_opt.o\ 35 | opt/ir_high_opt.o\ 36 | opt/ir_expr_tab.o\ 37 | opt/cdg.o\ 38 | opt/ir_refine.o\ 39 | opt/ir_rp.o\ 40 | opt/ir_aa.o\ 41 | opt/ir_ssa.o\ 42 | opt/label.o\ 43 | opt/data_type.o \ 44 | opt/option.o\ 45 | opt/region.o\ 46 | opt/region_mgr.o\ 47 | opt/util.o\ 48 | opt/var.o\ 49 | opt/md.o\ 50 | opt/cfs_mgr.o\ 51 | opt/pass_mgr.o\ 52 | opt/inliner.o\ 53 | opt/ipa.o\ 54 | opt/callg.o\ 55 | opt/loop.o\ 56 | opt/ir_loop_cvt.o\ 57 | opt/prdf.o 58 | 59 | CFLAGS = -DFOR_DEX -D_DEBUG_ -O0 -g2 -Wno-write-strings -Wsign-promo \ 60 | -Wsign-compare -Wpointer-arith -Wno-multichar -Winit-self \ 61 | -Wstrict-aliasing=3 -finline-limit=10000000 -Wswitch #-Wall 62 | #-Werror=overloaded-virtual \ 63 | 64 | all: com_objs opt_objs 65 | ar rcs libxoc.a $(COM_OBJS) $(OPT_OBJS) 66 | @echo "success!!" 67 | 68 | INC=-I opt -I com -I dex -I . 69 | %.o:%.cpp 70 | @echo "build $<" 71 | gcc $(CFLAGS) $(INC) -c $< -o $@ 72 | 73 | com_objs: $(COM_OBJS) 74 | opt_objs: $(OPT_OBJS) 75 | 76 | clean: 77 | @find -name "*.o" | xargs rm -f 78 | @find -name "*.a" | xargs rm -f 79 | @find -name "*.dot" | xargs rm -f 80 | @find -name "*.exe" | xargs rm -f 81 | @find -name "*.elf" | xargs rm -f 82 | @find -name "*.out" | xargs rm -f 83 | @find -name "*.tmp" | xargs rm -f 84 | @find -name "*.vcg" | xargs rm -f 85 | @find -name "*.cxx" | xargs rm -f 86 | @find -name "*.asm" | xargs rm -f 87 | @find -name "*.swp" | xargs rm -f 88 | @find -name "*.swo" | xargs rm -f 89 | @find -name "*.LOGLOG" | xargs rm -f 90 | @find -name "LOGLOG" | xargs rm -f 91 | 92 | -------------------------------------------------------------------------------- /opt/cominc.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __COMINC_H__ 35 | #define __COMINC_H__ 36 | 37 | #include "commoninc.h" 38 | #include "data_type.h" 39 | #include "dbg.h" 40 | #include "loop.h" 41 | #include "cfg.h" 42 | 43 | //Middle level included files 44 | #include "var.h" 45 | #include "md.h" 46 | #include "pass.h" 47 | #include "ai.h" 48 | #include "du.h" 49 | #include "ir.h" 50 | #include "ir_bb.h" 51 | #include "ir_refine.h" 52 | #include "ir_simp.h" 53 | #include "pass_mgr.h" 54 | #include "ir_cfg.h" 55 | #include "ir_high_opt.h" 56 | #include "ir_middle_opt.h" 57 | #include "targ_info.h" 58 | #include "region_mgr.h" 59 | #include "region.h" 60 | #include "ir_du.h" 61 | #include "ir_aa.h" 62 | #include "ir_expr_tab.h" 63 | 64 | using namespace xoc; 65 | #endif 66 | -------------------------------------------------------------------------------- /com/ltype.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "ltype.h" 35 | 36 | INT m518087(CHAR const* info, ...) 37 | { 38 | //CHAR * ptr = (CHAR*)&info; 39 | //ptr += sizeof(CHAR*); //being sizeof(info) 40 | va_list ptr; 41 | va_start(ptr, info); 42 | 43 | //PROTOTYPE: int __cdecl vprintf(char const*, char *) 44 | //vprintf(info, ptr); 45 | 46 | //PROTOTYPE: int vfprintf (FILE * stream, const char * format, va_list ap) 47 | vfprintf(stdout, info, ptr); 48 | fflush(stdout); 49 | 50 | //abort() has type 'void' and is not a throw-expression. 51 | //And it is unable to be used in clause : a ? 1 : abort(). 52 | va_end(ptr); 53 | abort(); 54 | return 0; 55 | } 56 | 57 | 58 | INT m022138(CHAR const* filename, INT line) 59 | { 60 | printf("\nASSERTION in %s(%d): ", filename, line); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /dex/aoc_dx_mgr.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _AOC_DX_MGR_ 35 | #define _AOC_DX_MGR_ 36 | 37 | class AocDxMgr : public DxMgr { 38 | DexFile const* m_df; 39 | public: 40 | AocDxMgr(DexFile const* df) { m_df = df; } 41 | virtual ~AocDxMgr() {} 42 | virtual CHAR const* get_string(UINT str_idx); 43 | virtual CHAR const* get_type_name(UINT idx); 44 | virtual CHAR const* get_field_name(UINT field_idx); 45 | virtual CHAR const* get_method_name(UINT method_idx); 46 | virtual CHAR const* get_class_name(UINT class_type_idx); 47 | virtual CHAR const* get_class_name_by_method_id(UINT method_idx); 48 | virtual CHAR const* get_class_name_by_field_id(UINT field_idx); 49 | virtual CHAR const* get_class_name_by_declaration_id(UINT cls_def_idx); 50 | }; 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/str/cstr.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include "str/cstr.h" 3 | #include 4 | 5 | void cStrcrep(char* str, char pat, char rep) { 6 | if(str == NULL) 7 | return; 8 | while(*str) { 9 | if(*str == pat) 10 | *str = rep; 11 | ++str; 12 | } 13 | } 14 | 15 | Int32 cStrLastIndexOf(const char* str, char c) { 16 | Int32 i; 17 | Int32 last = -1; 18 | 19 | i = 0; 20 | while(str[i]) { 21 | if(str[i] == c) 22 | last = i; 23 | ++i; 24 | } 25 | return last; 26 | } 27 | 28 | #ifdef WIN32 29 | #define HAVE_NO_STRTOK_R 30 | #endif 31 | 32 | #ifdef HAVE_NO_STRTOK_R 33 | 34 | /* Reentrant string tokenizer. Generic version. 35 | Copyright (C) 1991,1996-1999,2001,2004 Free Software Foundation, Inc. 36 | This file is part of the GNU C Library. 37 | 38 | The GNU C Library is free software; you can redistribute it and/or 39 | modify it under the terms of the GNU Lesser General Public 40 | License as published by the Free Software Foundation; either 41 | version 2.1 of the License, or (at your option) any later version. 42 | 43 | The GNU C Library is distributed in the hope that it will be useful, 44 | but WITHOUT ANY WARRANTY; without even the implied warranty of 45 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 46 | Lesser General Public License for more details. 47 | 48 | You should have received a copy of the GNU Lesser General Public 49 | License along with the GNU C Library; if not, write to the Free 50 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 51 | 02111-1307 USA. */ 52 | 53 | # define __strtok_r strtok_r 54 | # define __rawmemchr strchr 55 | 56 | char * 57 | __strtok_r (char *s, const char *delim, char **save_ptr) 58 | { 59 | char *token; 60 | 61 | if (s == NULL) 62 | s = *save_ptr; 63 | 64 | /* Scan leading delimiters. */ 65 | s += strspn (s, delim); 66 | if (*s == '\0') 67 | { 68 | *save_ptr = s; 69 | return NULL; 70 | } 71 | 72 | /* Find the end of the token. */ 73 | token = s; 74 | s = strpbrk (token, delim); 75 | if (s == NULL) 76 | /* This token finishes the string. */ 77 | *save_ptr = __rawmemchr (token, '\0'); 78 | else 79 | { 80 | /* Terminate the token and make *SAVE_PTR point past it. */ 81 | *s = '\0'; 82 | *save_ptr = s + 1; 83 | } 84 | return token; 85 | } 86 | #endif /* HAVE_NO_STRTOK_R */ 87 | -------------------------------------------------------------------------------- /com/example/use_slist.cpp: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "ltype.h" 3 | #include "comf.h" 4 | #include "smempool.h" 5 | #include "sstl.h" 6 | using namespace xcom; 7 | void use_slist_core() 8 | { 9 | //Single List Core need user declared a mempool. 10 | SMemPool * pool = smpoolCreate(sizeof(SC), MEM_CONST_SIZE); 11 | 12 | //Define a free list 13 | SC * free_list = NULL; 14 | 15 | //Of course you can use "new" to allocate. 16 | SListCore * l = (SListCore*)malloc(sizeof(SListCore)); 17 | 18 | //You need to invoke the init() to do initialization. 19 | l->init(); 20 | 21 | SC * ct = l->append_head(4, &free_list, pool); //append a new element at the beginning. 22 | 23 | //Insert "5" after position of first element 24 | //place before second element. 25 | ct = l->insert_after(5, ct, &free_list, pool); 26 | 27 | //Insert "6" after "5". 28 | l->insert_after(6, ct, &free_list, pool); 29 | 30 | printf("Iter list element by user declared iter:\n"); 31 | for (SC * iter = l->get_head(); 32 | iter != l->end(); iter = l->get_next(iter)) { 33 | printf("%d\n", iter->val()); 34 | } 35 | 36 | //You can not access the last element unless using the SListEx. 37 | 38 | printf("%d\n", l->get_elem_count()); 39 | 40 | l->clean(&free_list); 41 | free(l); 42 | smpoolDelete(pool); 43 | } 44 | 45 | 46 | void use_slist() 47 | { 48 | //Single List need user declared a mempool. 49 | SMemPool * pool = smpoolCreate(sizeof(SC), MEM_CONST_SIZE); 50 | SList l(pool); 51 | 52 | //Or you can initialize pool via l.set_pool(pool) as well. 53 | 54 | SC * ct = l.append_head(1); //append a new element at the beginning. 55 | 56 | //Insert "2" after position of first element 57 | //place before second element. 58 | ct = l.insert_after(2, ct); 59 | 60 | //Insert "3" after "2". 61 | l.insert_after(3, ct); 62 | 63 | printf("Iter list element by user declared iter:\n"); 64 | for (SC * iter = l.get_head(); 65 | iter != l.end(); iter = l.get_next(iter)) { 66 | printf("%d\n", iter->val()); 67 | } 68 | 69 | //You can not access the last element unless using the SListEx. 70 | 71 | printf("%d\n", l.get_elem_count()); 72 | 73 | smpoolDelete(pool); 74 | } 75 | 76 | 77 | int main() 78 | { 79 | use_slist(); 80 | use_slist_core(); 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /opt/du.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "cominc.h" 35 | 36 | namespace xoc { 37 | 38 | //Add define stmt with check if the stmt is unique in list. 39 | void DUSet::add_use(IR const* exp, DefMiscBitSetMgr & m) 40 | { 41 | ASSERT0(exp && exp->is_exp()); 42 | bunion(IR_id(exp), m); 43 | } 44 | 45 | 46 | //Add define stmt with check if the stmt is unique in list. 47 | void DUSet::add_def(IR const* stmt, DefMiscBitSetMgr & m) 48 | { 49 | ASSERT0(stmt && stmt->is_stmt()); 50 | bunion(IR_id(stmt), m); 51 | } 52 | 53 | 54 | void DUSet::remove_use(IR const* exp, DefMiscBitSetMgr & m) 55 | { 56 | ASSERT0(exp && exp->is_exp()); 57 | diff(IR_id(exp), m); 58 | } 59 | 60 | 61 | void DUSet::removeDef(IR const* stmt, DefMiscBitSetMgr & m) 62 | { 63 | ASSERT0(stmt && stmt->is_stmt()); 64 | diff(IR_id(stmt), m); 65 | } 66 | 67 | } //namespace xoc 68 | -------------------------------------------------------------------------------- /com/strbuf.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | Copyright (c) 2013-2014, Su Zhenyu steven.known@gmail.com 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the Su Zhenyu nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 26 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | @*/ 28 | #ifndef _STRBUF_H_ 29 | #define _STRBUF_H_ 30 | 31 | namespace xcom { 32 | 33 | class StrBuf { 34 | public: 35 | CHAR * buf; 36 | UINT buflen; 37 | 38 | public: 39 | StrBuf(UINT initsize) 40 | { 41 | ASSERT0(initsize > 0); 42 | buflen = initsize; 43 | buf = (CHAR*)malloc(initsize); 44 | buf[0] = 0; 45 | } 46 | COPY_CONSTRUCTOR(StrBuf); 47 | ~StrBuf() { if (buf != NULL) { delete buf; } } 48 | 49 | void clean() 50 | { 51 | ASSERT0(buf); 52 | buf[0] = 0; 53 | } 54 | void sprint(CHAR const* format, ...); 55 | void vsprint(CHAR const* format, va_list args); 56 | void strcat(CHAR const* format, ...); 57 | void strcat(UINT l, CHAR const* format, va_list args); 58 | UINT strlen() const { return ::strlen(buf); } 59 | void nstrcat(UINT size, CHAR const* format, ...); 60 | void vstrcat(CHAR const* format, va_list args); 61 | }; 62 | 63 | } //namespace xcom 64 | #endif 65 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/math/cfdlibm.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cmath.h 4 | * madagascar 5 | * 6 | * Created by Alba.Xu on 4/16/09. 7 | * Copyright 2009 vmkid. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_MATH_H 12 | #define CLIBS_MATH_H 13 | 14 | #include "std/cstd.h" 15 | 16 | extern double __ieee754_sqrt (double); 17 | extern double __ieee754_sin (double); 18 | extern double __ieee754_cos (double); 19 | extern double __ieee754_tan (double); 20 | extern double __ieee754_tanh (double); 21 | extern double __ieee754_acos (double); 22 | extern double __ieee754_acosh (double); 23 | extern double __ieee754_log (double); 24 | extern double __ieee754_atanh (double); 25 | extern double __ieee754_asin (double); 26 | extern double __ieee754_atan(double x); 27 | extern double __ieee754_atan2 (double,double); 28 | extern double __ieee754_cbrt(double); 29 | extern double __ieee754_ceil(double); 30 | extern double __ieee754_exp (double); 31 | extern double __ieee754_expm1 (double); 32 | extern double __ieee754_cosh (double); 33 | extern double __ieee754_floor (double); 34 | extern double __ieee754_fmod (double,double); 35 | extern double __ieee754_nextafter (double,double); 36 | extern float __ieee754_nextafterf (float,float); 37 | extern double __ieee754_pow (double,double); 38 | extern double __ieee754_lgamma_r (double,int *); 39 | extern double __ieee754_gamma_r (double,int *); 40 | extern double __ieee754_lgamma (double); 41 | extern double __ieee754_gamma (double); 42 | extern double __ieee754_log10 (double); 43 | extern double __ieee754_log1p (double); 44 | extern double __ieee754_rint (double); 45 | extern double __ieee754_sinh (double); 46 | extern double __ieee754_hypot (double,double); 47 | extern double __ieee754_j0 (double); 48 | extern double __ieee754_j1 (double); 49 | extern double __ieee754_y0 (double); 50 | extern double __ieee754_y1 (double); 51 | extern double __ieee754_jn (int,double); 52 | extern double __ieee754_yn (int,double); 53 | extern double __ieee754_remainder (double,double); 54 | extern int __ieee754_rem_pio2 (double,double*); 55 | #ifdef _SCALB_INT 56 | extern double __ieee754_scalb (double,int); 57 | #else 58 | extern double __ieee754_scalb (double,double); 59 | #endif 60 | 61 | /* fdlibm kernel function */ 62 | extern double __kernel_standard (double,double,int); 63 | extern double __kernel_sin (double,double,int); 64 | extern double __kernel_cos (double,double); 65 | extern double __kernel_tan (double,double,int); 66 | extern int __kernel_rem_pio2 (double*,double*,int,int,int,const int*); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /dex/dex_call_graph.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_CALL_GRAPH_H_ 35 | #define _DEX_CALL_GRAPH_H_ 36 | 37 | class DexCallGraph : public CallGraph { 38 | protected: 39 | //Record very unimportant functions that do not 40 | //need to add an edge on call graph. 41 | TTab m_unimportant_symtab; 42 | 43 | public: 44 | DexCallGraph(UINT edge_hash, UINT vex_hash, RegionMgr * rumgr); 45 | virtual ~DexCallGraph() {} 46 | 47 | bool is_unimportant(SYM const* sym) const; 48 | 49 | virtual bool shouldAddEdge(IR const* ir) const 50 | { 51 | ASSERT0(ir->is_calls_stmt()); 52 | SYM const* name = VAR_name(CALL_idinfo(ir)); 53 | if (is_unimportant(name)) { return false; } 54 | 55 | CHAR const* q = "Ljava/lang/"; 56 | CHAR const* p = SYM_name(name); 57 | while ((*p++ == *q++) && *q != 0); 58 | return *q != 0; 59 | } 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /opt/pass.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __IR_OPT_H__ 35 | #define __IR_OPT_H__ 36 | 37 | namespace xoc { 38 | 39 | class SimpCtx; 40 | 41 | //Basis Class of pass. 42 | class Pass { 43 | protected: 44 | SimpCtx * m_simp; 45 | public: 46 | Pass() { m_simp = NULL; } 47 | virtual ~Pass() {} 48 | COPY_CONSTRUCTOR(Pass); 49 | 50 | virtual CHAR const* get_pass_name() const 51 | { 52 | ASSERT(0, ("Optimization Dependent Code")); 53 | return NULL; 54 | } 55 | 56 | virtual PASS_TYPE get_pass_type() const 57 | { 58 | ASSERT(0, ("Optimization Dependent Code")); 59 | return PASS_UNDEF; 60 | } 61 | 62 | void set_simp_cont(SimpCtx * simp) { m_simp = simp; } 63 | 64 | virtual bool perform(OptCtx &) 65 | { 66 | ASSERT(0, ("Optimization Dependent Code")); 67 | return false; 68 | } 69 | }; 70 | 71 | } //namespace xoc 72 | #endif 73 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/std/cstd.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cstd.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_STD_H 12 | #define CLIBS_STD_H 13 | 14 | #include "clibconfig.h" 15 | 16 | /** define C_BYTE_ORDER in clibconfig_xxx.h */ 17 | #define C_LITTLE_ENDIAN 1234 18 | #define C_BIG_ENDIAN 4321 19 | #define C_IS_LITTLE_ENDIAN (C_BYTE_ORDER == C_LITTLE_ENDIAN) 20 | #define C_IS_BIG_ENDIAN (C_BYTE_ORDER == C_BIG_ENDIAN) 21 | 22 | 23 | /* Define NULL pointer value */ 24 | 25 | #ifndef NULL 26 | #ifdef __cplusplus 27 | #define NULL 0 28 | #else 29 | #define NULL ((void *)0) 30 | #endif 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | #define EXTERN_C extern "C" 35 | #else 36 | #define EXTERN_C extern 37 | #endif 38 | 39 | # include /* C99 */ 40 | 41 | #if 0 42 | #ifndef __cplusplus 43 | /**define bool for C*/ 44 | #undef bool 45 | #undef true 46 | #undef false 47 | #define bool char 48 | #define true (!0) 49 | #define false 0 50 | #endif 51 | #endif 52 | 53 | typedef signed int Int32; 54 | #ifdef __IPHONEOS__ 55 | #include 56 | #else 57 | typedef unsigned int UInt32; 58 | typedef unsigned long ULong; 59 | typedef signed long Long; 60 | #endif 61 | typedef signed short Int16; 62 | typedef unsigned short UInt16; 63 | typedef signed char Int8; 64 | typedef unsigned char UInt8; 65 | typedef unsigned char BYTE; 66 | typedef float Float32; 67 | typedef double Float64; 68 | #ifdef _MSC_VER 69 | //for VC6, it's a must 70 | typedef __int64 Int64; 71 | typedef unsigned __int64 UInt64; 72 | #define LLValue(v) v##L 73 | #elif defined(__SYMBIAN32__) 74 | #ifdef __WINSCW__ 75 | typedef long long Int64; 76 | #endif 77 | typedef unsigned long long UInt64; 78 | #define LLValue(v) v##LL 79 | #else 80 | typedef long long Int64; 81 | typedef unsigned long long UInt64; 82 | #define LLValue(v) v##LL 83 | #endif 84 | 85 | typedef void* HandleT; 86 | 87 | #define FIXED_FRACTION_BITS 16 88 | typedef Int32 SFixed32; 89 | #define Int32ToSFixed32(_SINT_X) ((_SINT_X)<>FIXED_FRACTION_BITS) 91 | 92 | #ifndef ABS 93 | #define ABS(x) ((x)<0?-(x):(x)) 94 | #endif 95 | #if 0 96 | #ifndef MIN 97 | #define MIN(x, y) ((x)<(y) ? (x):(y)) 98 | #endif 99 | 100 | #ifndef MAX 101 | #define MAX(x, y) ((x)>(y) ? (x):(y)) 102 | #endif 103 | #endif 104 | //carefully use it! wrong when x==y 105 | #ifndef SWAP 106 | #define SWAP(x,y) {(x)^=(y);(y)^=(x);(x)^=(y);} 107 | #endif 108 | 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/config/clibplatform.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /** 3 | * clibplatform.h 4 | * 5 | * Created on: 2009-7-24 6 | * Author: aaron 7 | */ 8 | #ifndef CLIBS_PLATFORM_H 9 | #define CLIBS_PLATFORM_H 10 | 11 | #if defined(_AIX) 12 | # undef __AIX__ 13 | # define __AIX__ 1 14 | #endif 15 | 16 | #if defined(__BEOS__) 17 | # undef __BEOS__ 18 | # define __BEOS__ 1 19 | #endif 20 | 21 | #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__) 22 | #undef __BSDI__ 23 | #define __BSDI__ 1 24 | #endif 25 | 26 | #if defined(_arch_dreamcast) 27 | #undef __DREAMCAST__ 28 | #define __DREAMCAST__ 1 29 | #endif 30 | 31 | #if defined(__FreeBSD__) || defined(__DragonFly__) 32 | #undef __FREEBSD__ 33 | #define __FREEBSD__ 1 34 | #define __UNIX_LIKE__ 1 35 | #endif 36 | 37 | #if defined(hpux) || defined(__hpux) || defined(__hpux__) 38 | #undef __HPUX__ 39 | #define __HPUX__ 1 40 | #define __UNIX_LIKE__ 1 41 | #endif 42 | 43 | #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE) 44 | #undef __IRIX__ 45 | #define __IRIX__ 1 46 | #endif 47 | 48 | #if defined(linux) || defined(__linux) || defined(__linux__) 49 | #undef __LINUX__ 50 | #define __LINUX__ 1 51 | #define __UNIX_LIKE__ 1 52 | #endif 53 | 54 | #if defined(__APPLE__) 55 | #undef __MACOSX__ 56 | #define __MACOSX__ 1 57 | #define __IPHONE__ 1 58 | #elif defined(macintosh) 59 | #undef __MACOS__ 60 | #define __MACOS__ 1 61 | #define __IPHONE__ 1 62 | #endif 63 | 64 | #if defined(__NetBSD__) 65 | #undef __NETBSD__ 66 | #define __NETBSD__ 1 67 | #define __UNIX_LIKE__ 1 68 | #endif 69 | 70 | #if defined(__OpenBSD__) 71 | #undef __OPENBSD__ 72 | #define __OPENBSD__ 1 73 | #define __UNIX_LIKE__ 1 74 | #endif 75 | 76 | #if defined(__OS2__) 77 | #undef __OS2__ 78 | #define __OS2__ 1 79 | #endif 80 | 81 | #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE) 82 | #undef __OSF__ 83 | #define __OSF__ 1 84 | #endif 85 | 86 | #if defined(__QNXNTO__) 87 | #undef __QNXNTO__ 88 | #define __QNXNTO__ 1 89 | #endif 90 | 91 | #if defined(riscos) || defined(__riscos) || defined(__riscos__) 92 | #undef __RISCOS__ 93 | #define __RISCOS__ 1 94 | #endif 95 | #if defined(__SVR4) 96 | #undef __SOLARIS__ 97 | #define __SOLARIS__ 1 98 | #endif 99 | 100 | #if defined(MTK_KAL) || defined(__MTK_TARGET__) 101 | #undef __MTK__ 102 | #define __MTK__ 1 103 | #endif 104 | 105 | #if defined(WINCE) 106 | 107 | #endif 108 | 109 | #if defined(WIN32) || defined(_WIN32) 110 | #undef __WIN32__ 111 | #define __WIN32__ 1 112 | #endif 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /opt/dbg.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DBG_H_ 35 | #define _DBG_H_ 36 | 37 | namespace xoc { 38 | 39 | class Region; 40 | 41 | //Describe debug information. 42 | //Note line number can not be 0. 43 | #define DBX_lineno(d) ((d)->lineno) 44 | class Dbx { 45 | public: 46 | UINT lineno; //Note line number can not be 0. 47 | 48 | public: 49 | void clean() { lineno = 0; } 50 | void copy(Dbx const& dbx) { lineno = dbx.lineno; } 51 | }; 52 | 53 | 54 | class DbxMgr { 55 | public: 56 | virtual ~DbxMgr() {} 57 | 58 | //Do some prepare work before print source file. 59 | virtual void doPrepareWorkBeforePrint() {} 60 | 61 | virtual void printSrcLine(IR const*); 62 | virtual void printSrcLine(Dbx const&) {} //Taget Dependent Code 63 | }; 64 | 65 | 66 | //User need to initialize DbxMgr before compilation. 67 | extern DbxMgr * g_dbx_mgr; 68 | 69 | //Copy Dbx from src. 70 | void copyDbx(IR * tgt, IR const* src, Region * ru); 71 | void set_lineno(IR * ir, UINT lineno, Region * ru); 72 | UINT get_lineno(IR const* ir); 73 | UINT get_lineno(Dbx const& dbx); 74 | Dbx * get_dbx(IR const* ir); 75 | 76 | } //namespace xoc 77 | #endif 78 | -------------------------------------------------------------------------------- /opt/cfs_opt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __CFS_OPT_H__ 35 | #define __CFS_OPT_H__ 36 | 37 | namespace xoc { 38 | 39 | class IR_CFS_OPT : public Pass { 40 | protected: 41 | Region * m_ru; 42 | TypeMgr * m_tm; 43 | bool transformToDoWhile(IR ** head, IR * ir); 44 | bool transformIf1(IR ** head, IR * ir); 45 | bool transformIf2(IR ** head, IR * ir); 46 | bool transformIf3(IR ** head, IR * ir); 47 | bool transformIf4(IR ** head, IR * ir); 48 | bool transformIf5(IR ** head, IR * ir); 49 | bool hoistLoop(IR ** head, IR * ir); 50 | bool hoistIf(IR ** head, IR * ir); 51 | public: 52 | IR_CFS_OPT(Region * ru) { m_ru = ru; m_tm = ru->get_type_mgr(); } 53 | ~IR_CFS_OPT() {} 54 | 55 | void dump(); 56 | 57 | virtual CHAR const* get_pass_name() const { return "IR_CFS_OPT"; } 58 | 59 | bool perform_cfs_optimization(IN OUT IR ** ir_list, SimpCtx const& sc); 60 | virtual bool perform(OptCtx &) 61 | { 62 | UNREACH(); 63 | return false; 64 | } 65 | virtual bool perform(SimpCtx const& simp); 66 | }; 67 | 68 | } //namespace xoc 69 | #endif 70 | -------------------------------------------------------------------------------- /dex/dex_cfg.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_CFG_H_ 35 | #define _DEX_CFG_H_ 36 | 37 | class DEX_CFG : public IR_CFG { 38 | protected: 39 | void dump_node(FILE * h, bool detail, BitSet const& tryblock); 40 | void dump_node2( 41 | FILE * h, 42 | bool detail, 43 | BitSet const& trybbs, 44 | BitSet const& catchbbs); 45 | void dump_bb( 46 | FILE * h, 47 | bool detail, 48 | UINT id, 49 | UINT rpo, 50 | CHAR const* shape, 51 | CHAR const* color, 52 | CHAR const* font, 53 | UINT scale, 54 | OUT UINT & vertical_order); 55 | public: 56 | DEX_CFG(CFG_SHAPE cs, 57 | BBList * bbl, 58 | Region * ru, 59 | UINT edge_hash_size = 16, 60 | UINT vertex_hash_size = 16) : 61 | IR_CFG(cs, bbl, ru, edge_hash_size, vertex_hash_size) {} 62 | virtual ~DEX_CFG() {} 63 | 64 | void dump_vcg_ex(BitSet const& markbbs); 65 | void dump_vcg_ex2(BitSet const& trybbs, BitSet const& catchbbs); 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /dex/dex_call_graph.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "libdex/DexFile.h" 35 | #include "libdex/DexClass.h" 36 | #include "libdex/DexProto.h" 37 | #include "liropcode.h" 38 | #include "lir.h" 39 | #include "cominc.h" 40 | #include "comopt.h" 41 | #include "drAlloc.h" 42 | #include "d2d_comm.h" 43 | #include "dex.h" 44 | #include "gra.h" 45 | #include "dex_hook.h" 46 | #include "dex_util.h" 47 | 48 | static CHAR const* g_unimportant_func[] = { 49 | "Ljava/lang/StringBuilder;:()V:", 50 | }; 51 | static UINT g_unimportant_func_num = 52 | sizeof(g_unimportant_func) / sizeof(g_unimportant_func[0]); 53 | 54 | 55 | DexCallGraph::DexCallGraph(UINT edge_hash, UINT vex_hash, RegionMgr * rumgr) : 56 | CallGraph(edge_hash, vex_hash, rumgr) 57 | { 58 | ASSERT0(rumgr); 59 | SymTab * symtab = rumgr->get_sym_tab(); 60 | for (UINT i = 0; i < g_unimportant_func_num; i++) { 61 | SYM const* sym = symtab->add(g_unimportant_func[i]); 62 | m_unimportant_symtab.append(sym); 63 | } 64 | } 65 | 66 | 67 | bool DexCallGraph::is_unimportant(SYM const* sym) const 68 | { 69 | return m_unimportant_symtab.find(sym); 70 | } 71 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/zip/czip.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_ZIP_H 3 | #define CLIBS_ZIP_H 4 | 5 | #include "std/cstd.h" 6 | 7 | typedef unsigned long ZipHandle; 8 | typedef unsigned long ZipFile; 9 | 10 | typedef bool (*ZipTraversalFunc)(ZipHandle zip, ZipFile zfile, void* args); 11 | 12 | /** create a zip struct. 13 | * @param bufSize: size of compress data buffer. 14 | */ 15 | EXTERN_C ZipHandle cZipCreate(UInt32 bufSize); 16 | 17 | /** open a zip file, create zip struct from file data */ 18 | EXTERN_C ZipHandle cZipOpen(const char* fname, UInt32 bufSize); 19 | 20 | #define Zip_Comp_None 0 21 | #define Zip_Comp_Deflated 8 22 | /** for a zip, only one alive added file allow at same time, next call of 'cZipAddFile', previous added ZipFile will be close. */ 23 | EXTERN_C bool cZipAddFile(ZipHandle zip, const char* name, UInt16 nameLen, UInt16 compMode); 24 | 25 | EXTERN_C bool cZipAddFileData(ZipHandle zip, BYTE* data, UInt32 size); 26 | 27 | EXTERN_C void cZipAddFileEnd(ZipHandle zip); 28 | 29 | EXTERN_C bool cZipAddDirectory(ZipHandle zip, const char* path, UInt16 pathLen); 30 | 31 | /** remove a file or directory from zip. 32 | * if 'pathName' is '/' terminate, means remove directory. '/' can't be begin of pathname. 33 | */ 34 | EXTERN_C bool cZipRemove(ZipHandle zip, const char* pathName, UInt16 nameLen); 35 | 36 | /** write data to zip file */ 37 | EXTERN_C bool cZipWrite(ZipHandle zip, const char* name); 38 | 39 | EXTERN_C ZipFile cZipGetFile(ZipHandle zip, const char* name, UInt16 nameLen); 40 | 41 | EXTERN_C UInt32 cZipGetFileSize(ZipHandle zip, ZipFile file); 42 | 43 | EXTERN_C const char* cZipGetFileName(ZipHandle zip, ZipFile zfile, UInt16* nameLen); 44 | 45 | /** @return: actual bytes number got by this function call. 46 | * @param 'totalOutSize': total bytes number of this file be got. 47 | */ 48 | EXTERN_C UInt32 cZipGetFileData(ZipHandle zip, ZipFile file, BYTE* buf, UInt32 bufSize, UInt32* totalOutSize); 49 | 50 | EXTERN_C bool cZipHave(ZipHandle zip, const char* name, UInt16 nameLen); 51 | 52 | EXTERN_C void cZipDestroy(ZipHandle zip); 53 | 54 | EXTERN_C ZipFile cZipGetRoot(ZipHandle zip); 55 | 56 | EXTERN_C ZipFile cZipGetChild(ZipHandle zip, ZipFile zfile); 57 | 58 | EXTERN_C ZipFile cZipGetNext(ZipHandle zip, ZipFile zfile); 59 | 60 | EXTERN_C ZipFile cZipGetParent(ZipHandle zip, ZipFile zfile); 61 | 62 | EXTERN_C bool cZipIsDirectory(ZipHandle zip, ZipFile zfile); 63 | 64 | EXTERN_C bool cZipTraversal(ZipHandle zip, ZipTraversalFunc func, void* args); 65 | 66 | EXTERN_C UInt32 cZipFileNumber(ZipHandle zip); 67 | 68 | EXTERN_C UInt32 cZipDirNumber(ZipHandle zip); 69 | 70 | EXTERN_C bool cZipWriteByfd(ZipHandle zip, Int32 fd); 71 | 72 | EXTERN_C ZipHandle cZipCreateByMemory(UInt32 bufSize,void* bufferAddr); 73 | 74 | EXTERN_C void cZipDestroyByMemory(ZipHandle zip); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /dex/dex_region_mgr.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "libdex/DexFile.h" 35 | #include "libdex/DexClass.h" 36 | #include "libdex/DexProto.h" 37 | #include "liropcode.h" 38 | #include "lir.h" 39 | #include "d2d_comm.h" 40 | #include "drAlloc.h" 41 | #include "cominc.h" 42 | #include "comopt.h" 43 | #include "dex.h" 44 | #include "gra.h" 45 | #include "dex_hook.h" 46 | #include "dex_util.h" 47 | 48 | //Add a variable of CLASS. 49 | VAR * DexRegionMgr::addVarForBuiltin(CHAR const* name) 50 | { 51 | SYM * sym = addToSymbolTab(name); 52 | UINT flag = 0; 53 | SET_FLAG(flag, VAR_GLOBAL); 54 | return get_var_mgr()->registerVar(sym, get_type_mgr()->getVoid(), 0, flag); 55 | } 56 | 57 | 58 | void DexRegionMgr::initBuiltin() 59 | { 60 | for (UINT i = BLTIN_UNDEF + 1; i < BLTIN_LAST; i++) { 61 | VAR * v = addVarForBuiltin(BLTIN_name((BLTIN_TYPE)i)); 62 | m_var2blt.set(v, i); 63 | m_blt2var.set(i, v); 64 | } 65 | } 66 | 67 | 68 | bool DexRegionMgr::processProgramRegion(Region * program) 69 | { 70 | ASSERT0(program && program->is_program()); 71 | 72 | //Function region has been handled. And call list should be available. 73 | OptCtx oc; 74 | buildCallGraph(oc, false, false); 75 | ASSERT0(OC_is_callg_valid(oc)); 76 | 77 | 78 | return true; 79 | } 80 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/errno/cerrno.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | /* 3 | * cerrno.h 4 | * madagascar 5 | * 6 | * Created by Misa.Z on 2/19/09. 7 | * Copyright 2009 Virtualnology. All rights reserved. 8 | * 9 | */ 10 | 11 | #ifndef CLIBS_ERRNO_H 12 | #define CLIBS_ERRNO_H 13 | 14 | #include "std/cstd.h" 15 | 16 | #define ERROR_NOTHING 0 17 | 18 | #define ERROR_MEM_ALLOC -1 19 | #define ERROR_MEM_FREE -2 20 | #define ERROR_MEM_NULL_OBJ -3 21 | 22 | #define ERROR_ILLEGAL_ARGUMENT -10 23 | 24 | #define ERROR_GUI_VIDEO_MODE -100 25 | #define ERROR_GUI_VIDEO_ROTATE -101 26 | #define ERROR_GUI_CANVAS_MODE -102 27 | #define ERROR_GUI_BPP_NOT_SUPPORT -103 28 | 29 | #define ERROR_IO_ID -200 30 | #define ERROR_IO_MAX -201 31 | #define ERROR_IO_EAGAIN -202 32 | 33 | #define ERROR_DEV_NONE -300 34 | #define ERROR_DEV_DISABLED -301 35 | #define ERROR_DEV_COMMAND -302 36 | #define ERROR_DEV_BUSY -303 37 | #define ERROR_DEV_ASYNC_NOTIFY -304 38 | #define ERROR_DEV_CMD_NOT_SUPPORT -320 39 | #define ERROR_DEV_GENERNAL_ERROR -321 40 | 41 | #define ERROR_EV_OVERFLOW -400 42 | 43 | #define ERROR_SOCKET_GENERAL_ERROR -500 44 | #define ERROR_SOCKET_NO_SERVICE -501 45 | #define ERROR_SOCKET_CREATE_FAILED -502 46 | #define ERROR_SOCKET_SET_OPTION -503 47 | #define ERROR_SOCKET_INVALID_SOCKET -504 48 | #define ERROR_SOCKET_INVALID_ADDR -505 49 | #define ERROR_SOCKET_GET_HOST_BY_NAME -506 50 | #define ERROR_SOCKET_MSG_TOO_LONG -507 51 | #define ERROR_SOCKET_NOT_CONNECT -508 52 | #define ERROR_SOCKET_NOT_BINDED -509//listen without bind first 53 | #define ERROR_SOCKET_NOT_LISTENED -510//accept without listen first 54 | #define ERROR_SOCKET_BROKEN -520 55 | 56 | #define ERROR_MEDIA_OPEN -600 57 | 58 | 59 | #define ERROR_SMS_GENERAL_ERROR -700 60 | #define ERROR_SMS_BAD_FORMAT -701 61 | #define ERROR_SMS_TOO_LARGE -702 62 | #define ERROR_SMS_INVALID_HOST -703 63 | 64 | 65 | #define ERROR_PIM_GENERAL_ERROR -800 66 | #define ERROR_PIM_INVALID_INDEX -801 67 | 68 | 69 | #define ERROR_HTTPS_NOT_SUPPORT -900 70 | 71 | #define ERROR_ICONV_INSUFFICIENT_BUFFER -1000 72 | //ERROR_NO_UNICODE_TRANSLATION is returned if the input string is a UTF-8 string that contains invalid characters and the MB_ERR_INVALID_CHARS flag is set. 73 | #define ERROR_ICONV_NO_UNICODE_TRANSLATION -1001 74 | 75 | EXTERN_C Int32 _cerrno; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /dex/dex2dex/d2d_d2l.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef _D2D_D2L_H 35 | #define _D2D_D2L_H 36 | 37 | #define asUInt32(addr) (*((UInt32*)addr)) 38 | #define GET_NEWOFFSET(offset)\ 39 | do\ 40 | {\ 41 | offset = getNewOffset(pool, (Int32)(offset));\ 42 | ASSERT0(-1 != (Int32)(offset));\ 43 | }while(0) 44 | 45 | #define GET_NEWOFFSET_CHECK(offset)\ 46 | do\ 47 | {\ 48 | Int32 nAddr;\ 49 | nAddr = getNewOffset(pool, (Int32)(offset));\ 50 | ASSERT0(nAddr == (Int32)(offset));\ 51 | }while(0) 52 | 53 | #define GET_NEWADDR_CHECK(addr)\ 54 | do\ 55 | {\ 56 | BYTE* nAddr;\ 57 | nAddr = getNewAddr(pool, (BYTE*)(addr));\ 58 | ASSERT0(nAddr == (BYTE*)(addr));\ 59 | }while(0) 60 | 61 | #define GET_NEWADDR(addr)\ 62 | do\ 63 | {\ 64 | addr = getNewAddr(pool, (BYTE*)addr);\ 65 | }while(0) 66 | 67 | #ifdef __cplusplus 68 | extern "C" { 69 | #endif 70 | Int32 doDex2Dex( 71 | DexFile* pDexFile, 72 | int outFd, 73 | long* fileLen, 74 | bool ifOpt, 75 | char const* dexfilename); 76 | Int32 doDex2Dex2( 77 | DexFile* pDexFile, 78 | unsigned char ** dxbuf, 79 | unsigned int* dxbuflen, 80 | unsigned int* cbsHandler, 81 | char const* dexfilename); 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /dex/dex.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include "../opt/cominc.h" 35 | #include "dex.h" 36 | 37 | BuiltInInfo g_builtin_info[] = { 38 | {BLTIN_UNDEF, "" }, 39 | {BLTIN_NEW, "#new" }, 40 | {BLTIN_NEW_ARRAY, "#new_array" }, 41 | {BLTIN_MOVE_EXP, "#move_exception" }, 42 | {BLTIN_MOVE_RES, "#move_result" }, 43 | {BLTIN_THROW, "#throw" }, 44 | {BLTIN_CHECK_CAST, "#check_cast" }, 45 | {BLTIN_FILLED_NEW_ARRAY, "#filled_new_array" }, 46 | {BLTIN_FILL_ARRAY_DATA, "#fill_array_data" }, 47 | {BLTIN_CONST_CLASS, "#const_class" }, 48 | {BLTIN_ARRAY_LENGTH, "#array_length" }, 49 | {BLTIN_MONITOR_ENTER, "#monitor_enter" }, 50 | {BLTIN_MONITOR_EXIT, "#monitor_exit" }, 51 | {BLTIN_INSTANCE_OF, "#instance_of" }, 52 | {BLTIN_CMP_BIAS, "#cmp_bias" }, 53 | {BLTIN_LAST, "" }, 54 | }; 55 | UINT g_builtin_num = sizeof(g_builtin_info) / sizeof(g_builtin_info[0]); 56 | 57 | 58 | //Perform Dex register allocation. 59 | bool g_do_dex_ra = false; 60 | 61 | //Set true to collect debug info. 62 | bool g_collect_debuginfo = false; 63 | bool g_dump_ir2dex = false; 64 | bool g_dump_dex2ir = false; 65 | bool g_dump_classdefs = false; 66 | bool g_dump_lirs = false; 67 | bool g_is_pretty_print_method_name = true; 68 | bool g_dump_dex_file_path = false; 69 | bool g_record_region_for_classs = false; 70 | -------------------------------------------------------------------------------- /opt/ir_rce.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _IR_RCE_H_ 35 | #define _IR_RCE_H_ 36 | 37 | namespace xoc { 38 | 39 | //Perform Redundant Code Elimination. 40 | class IR_RCE : public Pass { 41 | protected: 42 | Region * m_ru; 43 | IR_CFG * m_cfg; 44 | IR_GVN * m_gvn; 45 | IR_DU_MGR * m_du; 46 | 47 | //Use GVN info to determine if code is redundant. 48 | //Note that compute GVN is expensive. 49 | bool m_use_gvn; 50 | public: 51 | IR_RCE(Region * ru, IR_GVN * gvn) 52 | { 53 | ASSERT0(ru != NULL); 54 | m_ru = ru; 55 | m_gvn = gvn; 56 | m_cfg = ru->get_cfg(); 57 | m_du = m_ru->get_du_mgr(); 58 | ASSERT0(m_cfg && m_du); 59 | m_use_gvn = false; 60 | } 61 | COPY_CONSTRUCTOR(IR_RCE); 62 | virtual ~IR_RCE() {} 63 | 64 | IR * calcCondMustVal( 65 | IN IR * ir, 66 | OUT bool & must_true, 67 | OUT bool & must_false, 68 | bool & changed); 69 | 70 | void dump(); 71 | virtual CHAR const* get_pass_name() const 72 | { return "Redundant Code Elimination"; } 73 | 74 | PASS_TYPE get_pass_type() const { return PASS_RCE; } 75 | 76 | bool is_use_gvn() const { return m_use_gvn; } 77 | 78 | void set_use_gvn(bool use_gvn) { m_use_gvn = use_gvn; } 79 | 80 | IR * processStore(IR * ir); 81 | IR * processStorePR(IR * ir); 82 | IR * processBranch(IR * ir, IN OUT bool & cfg_mod); 83 | bool performSimplyRCE(IN OUT bool & cfg_mod); 84 | virtual bool perform(OptCtx & oc); 85 | }; 86 | 87 | } //namespace xoc 88 | #endif 89 | -------------------------------------------------------------------------------- /dex/dex2dex/main.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "trace/ctrace.h" 43 | #include "d2d_main.h" 44 | 45 | #include "cominc.h" 46 | #include "cmdline.h" 47 | #include "dex.h" 48 | 49 | //#define DEBUG_D2D 50 | #ifdef DEBUG_D2D 51 | int main(int argcc, char * argvc[]) 52 | { 53 | UNUSED(argcc); 54 | UNUSED(argvc); 55 | 56 | CHAR * argv[] = { 57 | "d2d.exe", 58 | //"test.apk", 59 | "-o", "output.dex", 60 | }; 61 | int argc = sizeof(argv)/sizeof(argv[0]); 62 | #else 63 | int main(int argc, char const* argv[]) 64 | { 65 | #endif 66 | int locerrno = 0; //0 indicates no error. 67 | long filelen; 68 | if (!processCommandLine(argc, argv)) { 69 | locerrno = -1; 70 | goto FIN; 71 | } 72 | 73 | if (g_tfile != NULL && g_dump_dex_file_path) { 74 | fprintf(g_tfile, "\n==---- %s ----==\n", g_dex_file_path); 75 | } 76 | 77 | if (d2dEntry(g_source_file_handler, g_output_file_handler, 78 | &filelen, false, g_dex_file_path) != 0) { 79 | locerrno = errno; 80 | LOGE("error: perform dexpro failed.\n"); 81 | } 82 | 83 | FIN: 84 | if (g_source_file_handler >= 0) { 85 | close(g_source_file_handler); 86 | } 87 | 88 | if (g_output_file_handler >= 0) { 89 | close(g_output_file_handler); 90 | } 91 | 92 | xoc::finidump(); 93 | 94 | return locerrno; //success. 95 | } 96 | 97 | -------------------------------------------------------------------------------- /opt/targ_info.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | Copyright (c) 2013-2014, Su Zhenyu steven.known@gmail.com 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of the Su Zhenyu nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | @*/ 29 | #ifndef __TARG_INFO_H__ 30 | #define __TARG_INFO_H__ 31 | 32 | //This class represents interfaces to target machine/platform. 33 | //Passes use these interfaces to perform transformations. 34 | 35 | namespace xoc { 36 | 37 | class TargInfo { 38 | public: 39 | TargInfo() {} 40 | COPY_CONSTRUCTOR(TargInfo); 41 | virtual ~TargInfo() {} 42 | 43 | virtual UINT getNumOfAllocableIntegerRegister() 44 | { 45 | ASSERT(0, ("Target Dependent Code")); 46 | return 0; 47 | } 48 | 49 | virtual UINT getNumOfAllocableFloatRegister() 50 | { 51 | ASSERT(0, ("Target Dependent Code")); 52 | return 0; 53 | } 54 | 55 | //Return byte size of data cache. 56 | virtual UINT getDCacheSize() 57 | { 58 | ASSERT(0, ("Target Dependent Code")); 59 | return 0; 60 | } 61 | 62 | //Return byte size of instruction cache. 63 | virtual UINT getICacheSize() 64 | { 65 | ASSERT(0, ("Target Dependent Code")); 66 | return 0; 67 | } 68 | 69 | //Return byte size of cache line. 70 | virtual UINT getCacheLineSize() 71 | { 72 | ASSERT(0, ("Target Dependent Code")); 73 | return 0; 74 | } 75 | 76 | //Return byte size of TLB if any. 77 | virtual UINT getTLBSize() 78 | { 79 | ASSERT(0, ("Target Dependent Code")); 80 | return 0; 81 | } 82 | 83 | //Approximate the cycles to execute ir operation. 84 | virtual UINT estimateNumOfCycles(IR const* ir) 85 | { 86 | ASSERT(0, ("Target Dependent Code")); 87 | UNUSED(ir); 88 | return 0; 89 | } 90 | }; 91 | 92 | } //namespace xoc 93 | #endif 94 | -------------------------------------------------------------------------------- /dex/clibs/basic/arch/common/utils/cbuf.c: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #include 3 | #include "std/cstd.h" 4 | #include "str/cstrport.h" 5 | #include "utils/cbuf.h" 6 | #include "mem/cmem.h" 7 | 8 | #define EXPAND_MEM_BLOCK_SIZE 128 9 | 10 | int cBufFormatString(CBufferT *mem, const char* format, ...) { 11 | va_list arg; 12 | Int32 count; 13 | 14 | if(!mem || !format) 15 | return -1; 16 | va_start(arg, format); 17 | if(mem->size == 0) 18 | if(!cBufExpand(mem, EXPAND_MEM_BLOCK_SIZE)) { 19 | va_end(arg); 20 | return -1; 21 | } 22 | count = cVsnprintf(mem->buffer, mem->size, format, arg); 23 | if((int)mem->size > count) { 24 | mem->usedLen = count; 25 | va_end(arg); 26 | return count; 27 | } 28 | if(!cBufExpand(mem, count+1)) { 29 | va_end(arg); 30 | return -1; 31 | } 32 | #ifdef __MTK_TARGET__//for mtk platform only 33 | va_end(arg); 34 | va_start(arg, format); 35 | #endif 36 | count = cVsnprintf(mem->buffer, mem->size, format, arg); 37 | va_end(arg); 38 | mem->usedLen = count; 39 | return count; 40 | } 41 | 42 | bool cBufAppend(CBufferT *mem, const void *data, UInt32 len) { 43 | if(!mem || !data) 44 | return false; 45 | if(len == 0) 46 | return true; 47 | if(mem->usedLen + len > mem->size) 48 | if(!cBufExpand(mem, mem->usedLen + len + EXPAND_MEM_BLOCK_SIZE)) 49 | return false; 50 | cMemcpy(mem->buffer + mem->usedLen, data, len); 51 | mem->usedLen += len; 52 | return true; 53 | } 54 | 55 | bool cBufAppendString(CBufferT *mem, const char* str) { 56 | UInt32 len; 57 | bool ret; 58 | 59 | if(!mem || !str) 60 | return false; 61 | len = cStrlen(str); 62 | ret = cBufAppend(mem, str, len + 1); 63 | 64 | //ignore string null terminate for next append call 65 | if(ret) 66 | --mem->usedLen; 67 | return ret; 68 | } 69 | 70 | bool cBufSetValue(CBufferT *mem, const void *data, UInt32 size) { 71 | if(!mem || !data) 72 | return false; 73 | if(mem->size < size) 74 | if(!cBufExpand(mem, size + EXPAND_MEM_BLOCK_SIZE)) 75 | return false; 76 | cMemcpy(mem->buffer, data, size); 77 | mem->usedLen = size; 78 | return true; 79 | } 80 | 81 | bool cBufExpand(CBufferT *mem, int size) { 82 | char* tmp; 83 | 84 | if(!mem) 85 | return false; 86 | if((int)mem->size >= size) 87 | return true; 88 | tmp = mem->buffer; 89 | mem->buffer = (char*)cMalloc(size); 90 | if(!mem->buffer) { 91 | mem->buffer = tmp; 92 | return false; 93 | } 94 | cMemset(mem->buffer, 0, size); 95 | if(tmp != NULL) { 96 | cMemcpy(mem->buffer, tmp, mem->size); 97 | cFree(tmp); 98 | } 99 | mem->size = size; 100 | return true; 101 | } 102 | 103 | void cBufClear(CBufferT *mem) { 104 | if(mem == NULL) 105 | return; 106 | mem->usedLen = 0; 107 | } 108 | 109 | void cBufFree(CBufferT *mem) { 110 | if(!mem) 111 | return; 112 | if(mem->buffer) { 113 | cFree(mem->buffer); 114 | mem->buffer = NULL; 115 | } 116 | mem->size = 0; 117 | mem->usedLen = 0; 118 | } 119 | -------------------------------------------------------------------------------- /opt/du.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef __DU_H__ 35 | #define __DU_H__ 36 | 37 | namespace xoc { 38 | 39 | class IR_DU_MGR; 40 | 41 | typedef SEGIter * DUIter; 42 | 43 | class DUSet : public DefSBitSetCore { 44 | protected: 45 | friend class IR_DU_MGR; 46 | public: 47 | DUSet() {} 48 | ~DUSet() 49 | { 50 | //Do not free ref here. They are allocated in mempool, 51 | //and the memory is freed when the pool destructed. 52 | } 53 | 54 | void add(UINT irid, DefMiscBitSetMgr & m) { bunion(irid, m); } 55 | void add_def(IR const* stmt, DefMiscBitSetMgr & m); 56 | void add_use(IR const* exp, DefMiscBitSetMgr & m); 57 | 58 | void remove(UINT irid, DefMiscBitSetMgr & m) { diff(irid, m); } 59 | void remove_use(IR const* exp, DefMiscBitSetMgr & m); 60 | void removeDef(IR const* stmt, DefMiscBitSetMgr & m); 61 | 62 | void union_set(DUSet const* set, DefMiscBitSetMgr & m) 63 | { 64 | if (set == NULL) { return; } 65 | bunion(*set, m); 66 | } 67 | }; 68 | 69 | 70 | #define DU_md(du) ((du)->md) 71 | #define DU_mds(du) ((du)->mds) 72 | #define DU_duset(du) ((du)->duset) 73 | class DU { 74 | public: 75 | MD const* md; //indicate the Must MD reference. 76 | MDSet const* mds; //indicate May MDSet reference. 77 | DUSet * duset; //indicate Def/Use of stmt/expr set. 78 | 79 | void clean() 80 | { 81 | md = NULL; 82 | mds = NULL; 83 | duset = NULL; 84 | } 85 | 86 | bool has_clean() const 87 | { return md == NULL && mds == NULL && duset == NULL; } 88 | }; 89 | 90 | } //namespace xoc 91 | #endif 92 | -------------------------------------------------------------------------------- /opt/ir_loop_cvt.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _IR_LOOP_CVT_H_ 35 | #define _IR_LOOP_CVT_H_ 36 | 37 | namespace xoc { 38 | 39 | /* Perform Loop Convertion. 40 | Transform while-do loop to do-while loop. 41 | 42 | e.g: Given loop I, the loop induction variable is i, loop upper bound is N. 43 | 44 | while do loop is: 45 | bb1: 46 | if i > N, branch bb3; 47 | bb2: 48 | loop body; 49 | goto bb1; 50 | bb3: 51 | ... 52 | 53 | after convertion: 54 | 55 | bb1: 56 | if i > N, branch bb3; 57 | bb2: 58 | loop body; 59 | if i <= N, branch bb2; 60 | bb3: 61 | ... 62 | */ 63 | class IR_LOOP_CVT : public Pass { 64 | protected: 65 | Region * m_ru; 66 | IR_CFG * m_cfg; 67 | IR_DU_MGR * m_du; 68 | IRIter m_ii; 69 | 70 | bool is_while_do(LI const* li, IRBB ** gobackbb, 71 | UINT * succ1, UINT * succ2); 72 | bool try_convert(LI * li, IRBB * gobackbb, 73 | UINT succ1, UINT succ2); 74 | bool find_and_convert(List*> & worklst); 75 | public: 76 | explicit IR_LOOP_CVT(Region * ru) 77 | { 78 | ASSERT0(ru != NULL); 79 | m_ru = ru; 80 | m_du = ru->get_du_mgr(); 81 | m_cfg = m_ru->get_cfg(); 82 | ASSERT0(m_cfg && m_du); 83 | } 84 | COPY_CONSTRUCTOR(IR_LOOP_CVT); 85 | virtual ~IR_LOOP_CVT() {} 86 | 87 | virtual CHAR const* get_pass_name() const { return "Loop Convertion"; } 88 | PASS_TYPE get_pass_type() const { return PASS_LOOP_CVT; } 89 | 90 | virtual bool perform(OptCtx & oc); 91 | }; 92 | 93 | } //namespace xoc 94 | #endif 95 | -------------------------------------------------------------------------------- /dex/dex_region_mgr.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _DEX_REGION_MGR_H_ 35 | #define _DEX_REGION_MGR_H_ 36 | 37 | class DexRegionMgr : public RegionMgr { 38 | protected: 39 | SMemPool * m_pool; 40 | Var2UINT m_var2blt; 41 | UINT2Var m_blt2var; 42 | 43 | protected: 44 | VAR * addVarForBuiltin(CHAR const* name); 45 | void initBuiltin(); 46 | 47 | public: 48 | DexRegionMgr() 49 | { m_pool = smpoolCreate(128, MEM_COMM); } 50 | 51 | COPY_CONSTRUCTOR(DexRegionMgr); 52 | virtual ~DexRegionMgr() { smpoolDelete(m_pool); } 53 | 54 | virtual Region * allocRegion(REGION_TYPE rt) 55 | { return new DexRegion(rt, this); } 56 | 57 | virtual CallGraph * allocCallGraph(UINT edgenum, UINT vexnum) 58 | { return new DexCallGraph(edgenum, vexnum, this); } 59 | 60 | Region * getProgramRegion() 61 | { 62 | //The first region should be program-region. 63 | return get_region(1); 64 | } 65 | SMemPool * get_pool() { return m_pool; } 66 | Var2UINT & getVar2Builtin() { return m_var2blt; } 67 | UINT2Var & getBuiltin2Var() { return m_blt2var; } 68 | Var2UINT const& getVar2BuiltinC() const { return m_var2blt; } 69 | UINT2Var const& getBuiltin2VarC() const { return m_blt2var; } 70 | 71 | //Do some initialization. 72 | void init() { initBuiltin(); } 73 | 74 | DexRegionMgr * self() { return this; } 75 | 76 | void * xmalloc(UINT size) 77 | { 78 | void * p = smpoolMalloc(size, m_pool); 79 | ASSERT0(p); 80 | memset(p, 0, size); 81 | return p; 82 | } 83 | 84 | virtual bool processProgramRegion(Region * program); 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /opt/loop.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _LOOP_H_ 35 | #define _LOOP_H_ 36 | 37 | namespace xoc { 38 | 39 | //This file represent loop structure and relate algorithms. 40 | 41 | //CFG Loop Info. 42 | #define LI_id(li) ((li)->id) 43 | #define LI_next(li) ((li)->next) 44 | #define LI_prev(li) ((li)->prev) 45 | #define LI_has_early_exit(li) ((li)->has_early_exit) 46 | #define LI_has_call(li) ((li)->has_call) 47 | #define LI_inner_list(li) ((li)->inner_list) 48 | #define LI_outer(li) ((li)->outer) 49 | #define LI_bb_set(li) ((li)->bb_set) 50 | #define LI_loop_head(li) ((li)->loop_head) 51 | template class LI { 52 | public: 53 | UINT id; 54 | LI * next; 55 | LI * prev; 56 | LI * inner_list; //inner loop list 57 | LI * outer; //outer loop 58 | UCHAR has_early_exit:1; 59 | UCHAR has_call:1; 60 | BB * loop_head; //loop head node, the only one header 61 | //indicates a natural loop. 62 | BitSet * bb_set; //loop body elements 63 | 64 | bool is_loop_reduction() 65 | { return !has_early_exit; } 66 | 67 | //Return true if bb is belong to current loop. 68 | //'bbid': id of BB. 69 | bool is_inside_loop(UINT bbid) const 70 | { return LI_bb_set(this)->is_contain(bbid); } 71 | }; 72 | 73 | 74 | class IRBB; 75 | class Region; 76 | class IR_CFG; 77 | 78 | IRBB * findAndInsertPreheader( 79 | LI const* li, Region * ru, 80 | OUT bool & insert_bb, bool force); 81 | IRBB * findSingleBackedgeStartBB(LI const* li, IR_CFG * cfg); 82 | bool findTwoSuccessorBBOfLoopHeader( 83 | LI const* li, IR_CFG * cfg, 84 | UINT * succ1, UINT * succ2); 85 | 86 | } //namespace xoc 87 | #endif 88 | -------------------------------------------------------------------------------- /dex/lir/lir.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: GongKai, JinYue 33 | @*/ 34 | #ifndef __LIR_H__ 35 | #define __LIR_H__ 36 | 37 | #define LIRMALLOC drLinearAlloc 38 | #define LIRFREEALL drLinearFree 39 | 40 | #define LIRC_num_of_op(l) ((l)->instrCount) 41 | #define LIRC_op(l, i) ((l)->lirList[i]) 42 | 43 | #define LIR_opcode(ir) ((ir)->opcode) 44 | #define LIR_name(ir) (gLIROpcodeInfo.opNames[LIR_opcode(ir)]) 45 | #define LIR_dt(ir) ((ir)->flags) 46 | 47 | //For CONST 48 | #define LIR_int_imm(ir) (((LIRConstOp*)ir)->vB) 49 | 50 | //For SPUT 51 | #define LIR_sym_ptr(ir) (((LIRABOp*)ir)->ptr) 52 | #define LIR_val(ir) (((LIRABOp*)ir)->vA) //store value 53 | 54 | //For ADD,SUB,MUL,DIV,REM,AND,OR,SHL,SHR,USHR, 55 | //XOR,CONST,NEW_INSTANCE. 56 | #define LIR_res(ir) (((LIRABCOp*)ir)->vA) 57 | 58 | //For ADD,SUB,MUL,DIV,REM,AND,OR,SHL,SHR,USHR, 59 | //XOR,NEW_INSTANCE. 60 | #define LIR_op0(ir) (((LIRABCOp*)ir)->vB) 61 | 62 | //For ADD,SUB,MUL,DIV,REM,AND,OR,SHL,SHR,USHR,XOR 63 | #define LIR_op1(ir) (((LIRABCOp*)ir)->vC) 64 | 65 | #define LIR_fill_array_data_mark(ir) \ 66 | (((USHORT*)(((LIRSwitchOp*)ir)->data))[0]) 67 | #define LIR_switch_kind(ir) \ 68 | (((USHORT*)(((LIRSwitchOp*)ir)->data))[0]) 69 | #define LIR_case_num(ir) \ 70 | (((USHORT*)(((LIRSwitchOp*)ir)->data))[1]) 71 | #define LIR_packed_switch_base_value(ir) \ 72 | (*((INT*)(&(((LIRSwitchOp*)ir)->data[2])))) 73 | #define LIR_packed_switch_case_entry(ir) \ 74 | ((UINT*)(((USHORT*)((LIRSwitchOp*)ir)->data) + 4)) 75 | #define LIR_sparse_switch_case_value(ir) \ 76 | ((UINT*)(((USHORT*)(((LIRSwitchOp*)ir)->data)) + 2)) 77 | #define LIR_sparse_switch_case_entry(ir) \ 78 | (UINT*)&(((BYTE*)(((LIRSwitchOp*)ir)->data))[4 + LIR_case_num(ir) * 4]) 79 | 80 | typedef LIRBaseOp LIR; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /opt/ipa.h: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #ifndef _IPA_H_ 35 | #define _IPA_H_ 36 | 37 | namespace xoc { 38 | 39 | class IPA : public Pass { 40 | protected: 41 | RegionMgr * m_rumgr; 42 | Region * m_program; 43 | SMemPool * m_pool; 44 | MDSystem * m_mdsys; 45 | bool m_is_keep_dumgr; //true to keep AA and DU mgr if computed. 46 | bool m_is_keep_reachdef; //true to keep Reachdef. 47 | bool m_is_recompute_du_ref; //true to recompute DU reference. 48 | 49 | protected: 50 | void * xmalloc(UINT size) 51 | { 52 | void * p = smpoolMalloc(size, m_pool); 53 | ASSERT0(p); 54 | memset(p, 0, size); 55 | return p; 56 | } 57 | 58 | void createCallDummyuse(IR * call, Region * callru); 59 | void createCallDummyuse(Region * ru); 60 | void createCallDummyuse(OptCtx & oc); 61 | 62 | void recomputeDUChain(Region * ru, OptCtx & oc); 63 | 64 | Region * findRegion(IR * call, Region * callru); 65 | public: 66 | IPA(Region * program) 67 | { 68 | ASSERT0(program && program->is_program()); 69 | m_rumgr = program->get_region_mgr(); 70 | ASSERT0(m_rumgr); 71 | m_program = program; 72 | m_mdsys = m_rumgr->get_md_sys(); 73 | m_pool = smpoolCreate(16, MEM_COMM); 74 | m_is_keep_dumgr = false; 75 | m_is_keep_reachdef = false; 76 | m_is_recompute_du_ref = true; 77 | } 78 | virtual ~IPA() { smpoolDelete(m_pool); } 79 | 80 | void setKeepDUMgr(bool keep) { m_is_keep_dumgr = keep; } 81 | void setKeepReachdef(bool keep) { m_is_keep_reachdef = keep; } 82 | void setRecomputeDURef(bool doit) { m_is_recompute_du_ref = doit; } 83 | virtual CHAR const* get_pass_name() const { return "IPA"; } 84 | virtual PASS_TYPE get_pass_type() const { return PASS_IPA; } 85 | virtual bool perform(OptCtx & oc); 86 | }; 87 | 88 | } //namespace xoc 89 | #endif 90 | -------------------------------------------------------------------------------- /win/misc.cpp: -------------------------------------------------------------------------------- 1 | /*@ 2 | XOC Release License 3 | 4 | Copyright (c) 2013-2014, Alibaba Group, All rights reserved. 5 | 6 | compiler@aliexpress.com 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the Su Zhenyu nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 24 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | author: Su Zhenyu 33 | @*/ 34 | #include 35 | #include 36 | #include 37 | 38 | static LARGE_INTEGER li = {0}, li2 = {0}; 39 | 40 | void tstart() 41 | { 42 | QueryPerformanceFrequency(&li); 43 | __int64 freq = li.QuadPart; 44 | QueryPerformanceCounter(&li); 45 | } 46 | 47 | 48 | char * format_elapsed(double d) 49 | { 50 | char buf[256] = {0}; 51 | 52 | if( d < 0.00000001 ) 53 | { 54 | // show in ps with 4 digits 55 | sprintf(buf, "%0.4f ps", d * 1000000000000.0); 56 | } 57 | else if( d < 0.00001 ) 58 | { 59 | // show in ns 60 | sprintf(buf, "%0.0f ns", d * 1000000000.0); 61 | } 62 | else if( d < 0.001 ) 63 | { 64 | // show in us 65 | sprintf(buf, "%0.0f us", d * 1000000.0); 66 | } 67 | else if( d < 0.1 ) 68 | { 69 | // show in ms 70 | sprintf(buf, "%0.0f ms", d * 1000.0); 71 | } 72 | else if( d <= 60.0 ) 73 | { 74 | // show in seconds 75 | sprintf(buf, "%0.2f s", d); 76 | } 77 | else if( d < 3600.0 ) 78 | { 79 | // show in min:sec 80 | sprintf(buf, "%01.0f:%02.2f", floor(d/60.0), fmod(d,60.0)); 81 | } 82 | // show in h:min:sec 83 | else 84 | sprintf(buf, "%01.0f:%02.0f:%02.2f", floor(d/3600.0), floor(fmod(d,3600.0)/60.0), fmod(d,60.0)); 85 | return buf; 86 | } 87 | 88 | 89 | 90 | #include 91 | //Return time, in ps, ns, ms, or h:min:sec. 92 | char * tend() 93 | { 94 | clock_t start = clock(); 95 | /*Do something*/ 96 | clock_t end = clock(); 97 | float seconds = (float)(end - start) / CLOCKS_PER_SEC; 98 | 99 | long long freq = 4294967296; 100 | QueryPerformanceCounter(&li2); 101 | __int64 ticks = li2.QuadPart-li.QuadPart; 102 | char * s = format_elapsed((double)ticks/(double)freq); 103 | return s; 104 | } 105 | -------------------------------------------------------------------------------- /dex/clibs/basic/include/time/ctime.h: -------------------------------------------------------------------------------- 1 | /*Copyright 2011 Alibaba Group*/ 2 | #ifndef CLIBS_TIME_H 3 | #define CLIBS_TIME_H 4 | 5 | #include "std/cstd.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef struct STDate { 12 | Float32 zone; /* time zone, -12 - +12 */ 13 | UInt16 ms; /* milliseconds, 0 - 999 */ 14 | UInt8 sec; /* seconds, 0 - 59 */ 15 | UInt8 min; /* minutes, 0 - 59 */ 16 | UInt8 hour; /* hours, 0 - 23 */ 17 | UInt8 mday; /* day of the month, 1 - 31(28,29,30) */ 18 | UInt8 mon; /* month, 1 - 12 */ 19 | UInt16 year; /* full year as "2007" */ 20 | UInt8 wday; /* day of week, 1 - 7 mon - sun */ 21 | UInt16 yday; /* day of year, 1 - 365(366) */ 22 | UInt8 isdst; /* is daylight saving time */ 23 | } CDateT; 24 | 25 | //typedef struct STTime { 26 | // UInt32 sec; /* seconds since GMT 1970-01-01 00:00:00 */ 27 | // UInt16 ms; /* milliseconds, 0 - 999*/ 28 | //} CTimeT; 29 | 30 | typedef UInt64 CTimeT; 31 | 32 | #define CTIME_SECOND(t) ((t)/1000) 33 | #define CTIME_MS(t) ((t)%1000) 34 | 35 | /** max number of ticks in milliseconds */ 36 | #define maxTicksNum ((UInt32)-1) 37 | 38 | /***************************************************/ 39 | //cTimeset time api 40 | 41 | /** 42 | * set the local timezone, this will affect cTimeGetLocalDate() and mcTime2LocalDate() 43 | * @param z: timezone, values of [-12 to +12] 44 | */ 45 | void cTimeSetTimeZone(Float32 z); 46 | 47 | /** 48 | * get the local timezone 49 | */ 50 | Float32 cTimeGetTimeZone(void); 51 | 52 | /** 53 | * get date of the specified timezone, if need GMT date, set param z to 0 54 | */ 55 | void cTimeGetDate(CDateT* d, Float32 z); 56 | 57 | /** 58 | * get local date 59 | */ 60 | void cTimeGetLocalDate(CDateT* d); 61 | 62 | /** 63 | * get the time in millseconds, since GMT 1970-01-01 00:00:00 000 64 | */ 65 | CTimeT cTimeGetTime(void); 66 | 67 | CTimeT cTimeGetNanoTime(void); 68 | /** 69 | * get ticks in milliseconds from system start up 70 | */ 71 | UInt32 cTimeTicks(void); 72 | 73 | /** 74 | * convert one date to another date of a specified timezone 75 | * @param d1: source date 76 | * @param d2: dist date 77 | * @param z: dist timezone 78 | */ 79 | void cTimeDateConvert(CDateT* d1, CDateT* d2, Float32 z); 80 | 81 | /** 82 | * convert time to date of specified timezone, if need GMT date, set param z to 0 83 | */ 84 | void cTimeTime2Date(CTimeT t, CDateT* d, Float32 z); 85 | 86 | /** 87 | * convert time to local date 88 | */ 89 | void cTimeTime2LocalDate(CTimeT t, CDateT* d); 90 | 91 | /** 92 | * convert date to time 93 | */ 94 | CTimeT cTimeDate2Time(CDateT* d); 95 | 96 | 97 | /******************************************/ 98 | //util time api 99 | /** 100 | * is the year leap year 101 | */ 102 | bool cTimeIsLeapYear(UInt16 year); 103 | /** 104 | * is the date valid 105 | */ 106 | bool cTimeIsDateValid(UInt16 year, UInt8 month, UInt8 mday); 107 | /** 108 | * get days since 1970-1-1, begin from 0 109 | * for example: 110 | * cTimeGetDays(1970,1,2) returns 1 111 | */ 112 | UInt32 cTimeGetDays(UInt16 year, UInt8 month, UInt8 mday); 113 | /** 114 | * get the day of the year 115 | * for example: 116 | * cTimeGetYearDay(1970,1,1) returns 1 117 | */ 118 | UInt16 cTimeGetYearDay(UInt16 year, UInt8 month, UInt8 mday); 119 | /** 120 | * get the week day 121 | * 122 | */ 123 | UInt8 cTimeGetWeekDay(UInt16 year, UInt8 month, UInt8 mday); 124 | /** 125 | * get month and day of month, return value combines the month and mday, 126 | * month in the high byte while mday in the low byte 127 | */ 128 | UInt16 cTimeGetMonthAndDay(UInt16 year, UInt16 yday); 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | #endif 134 | 135 | --------------------------------------------------------------------------------