Add support for Emscripten to the compiler.
This commit is contained in:
parent
17683249fd
commit
46123d359f
|
@ -28,40 +28,50 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PRINTF pc_printf = NULL;
|
|
||||||
|
|
||||||
void ReadFileIntoPl(abl *pl, FILE *fp);
|
void ReadFileIntoPl(abl *pl, FILE *fp);
|
||||||
bool CompressPl(abl *pl);
|
bool CompressPl(abl *pl);
|
||||||
void Pl2Bh(abl *pl, BinPlugin *bh);
|
void Pl2Bh(abl *pl, BinPlugin *bh);
|
||||||
void WriteBh(BinaryWriter *bw, BinPlugin *bh);
|
void WriteBh(BinaryWriter *bw, BinPlugin *bh);
|
||||||
|
|
||||||
|
#if defined(EMSCRIPTEN)
|
||||||
|
extern "C" void Compile32(int argc, char **argv);
|
||||||
|
extern "C" int pc_printf(const char *message,...);
|
||||||
|
#else
|
||||||
|
static PRINTF pc_printf = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct abl pl32;
|
struct abl pl32;
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(EMSCRIPTEN)
|
||||||
|
COMPILER sc32 = (COMPILER)Compile32;
|
||||||
|
//pc_printf = (PRINTF)pc_printf;
|
||||||
|
#else
|
||||||
|
# if defined(__linux__)
|
||||||
HINSTANCE lib = NULL;
|
HINSTANCE lib = NULL;
|
||||||
if (FileExists("./amxxpc32.so"))
|
if (FileExists("./amxxpc32.so"))
|
||||||
lib = dlmount("./amxxpc32.so");
|
lib = dlmount("./amxxpc32.so");
|
||||||
else
|
else
|
||||||
lib = dlmount("amxxpc32.so");
|
lib = dlmount("amxxpc32.so");
|
||||||
#elif defined(__APPLE__)
|
# elif defined(__APPLE__)
|
||||||
HINSTANCE lib = dlmount("amxxpc32.dylib");
|
HINSTANCE lib = dlmount("amxxpc32.dylib");
|
||||||
#else
|
# else
|
||||||
HINSTANCE lib = dlmount("amxxpc32.dll");
|
HINSTANCE lib = dlmount("amxxpc32.dll");
|
||||||
#endif
|
# endif
|
||||||
if (!lib)
|
if (!lib)
|
||||||
{
|
{
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
# if defined(__linux__) || defined(__APPLE__)
|
||||||
printf("compiler failed to instantiate: %s\n", dlerror());
|
printf("compiler failed to instantiate: %s\n", dlerror());
|
||||||
#else
|
# else
|
||||||
printf("compiler failed to instantiate: %d\n", GetLastError());
|
printf("compiler failed to instantiate: %d\n", GetLastError());
|
||||||
#endif
|
# endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPILER sc32 = (COMPILER)dlsym(lib, "Compile32");
|
COMPILER sc32 = (COMPILER)dlsym(lib, "Compile32");
|
||||||
pc_printf = (PRINTF)dlsym(lib, "pc_printf");
|
pc_printf = (PRINTF)dlsym(lib, "pc_printf");
|
||||||
|
#endif //EMSCRIPTEN
|
||||||
|
|
||||||
if (!sc32 || !pc_printf)
|
if (!sc32 || !pc_printf)
|
||||||
{
|
{
|
||||||
|
@ -73,8 +83,9 @@ int main(int argc, char **argv)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_printf("Welcome to the AMX Mod X %s Compiler.\n", SVN_VERSION);
|
pc_printf("AMX Mod X Compiler %s\n", SVN_VERSION);
|
||||||
pc_printf("Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team\n\n");
|
pc_printf("Copyright (c) 1997-2006 ITB CompuPhase\n");
|
||||||
|
pc_printf("Copyright (c) 2004-2013 AMX Mod X Team\n\n");
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
|
@ -166,7 +177,9 @@ int main(int argc, char **argv)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
unlink(file);
|
unlink(file);
|
||||||
pc_printf("Error, failed to write binary\n");
|
pc_printf("Error, failed to write binary\n");
|
||||||
|
#if !defined EMSCRIPTEN
|
||||||
dlclose(lib);
|
dlclose(lib);
|
||||||
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +189,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
pc_printf("Done.\n");
|
pc_printf("Done.\n");
|
||||||
|
|
||||||
|
#if !defined EMSCRIPTEN
|
||||||
dlclose(lib);
|
dlclose(lib);
|
||||||
|
#endif
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,10 @@
|
||||||
#ifndef _AMXXSC_INCLUDE_H
|
#ifndef _AMXXSC_INCLUDE_H
|
||||||
#define _AMXXSC_INCLUDE_H
|
#define _AMXXSC_INCLUDE_H
|
||||||
|
|
||||||
|
#ifndef SVN_VERSION
|
||||||
#include <amxmodx_version.h>
|
#include <amxmodx_version.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAGIC_HEADER2 0x414D5858
|
#define MAGIC_HEADER2 0x414D5858
|
||||||
#define MAGIC_VERSION 0x0300
|
#define MAGIC_VERSION 0x0300
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,11 @@
|
||||||
* For Linux, we must overrule these settings with those defined in glibc.
|
* For Linux, we must overrule these settings with those defined in glibc.
|
||||||
*/
|
*/
|
||||||
#if !defined __BYTE_ORDER
|
#if !defined __BYTE_ORDER
|
||||||
# include <stdlib.h>
|
# if defined EMSCRIPTEN
|
||||||
|
# include <endian.h>
|
||||||
|
# else
|
||||||
|
# include <stdlib.h>
|
||||||
|
# endif
|
||||||
# if defined __APPLE__
|
# if defined __APPLE__
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# define __BYTE_ORDER BYTE_ORDER
|
# define __BYTE_ORDER BYTE_ORDER
|
||||||
|
|
|
@ -683,11 +683,13 @@ cleanup:
|
||||||
pc_printf("Header size: %8ld bytes\n", (long)hdrsize);
|
pc_printf("Header size: %8ld bytes\n", (long)hdrsize);
|
||||||
pc_printf("Code size: %8ld bytes\n", (long)code_idx);
|
pc_printf("Code size: %8ld bytes\n", (long)code_idx);
|
||||||
pc_printf("Data size: %8ld bytes\n", (long)glb_declared*sizeof(cell));
|
pc_printf("Data size: %8ld bytes\n", (long)glb_declared*sizeof(cell));
|
||||||
pc_printf("Stack/heap size: %8ld bytes; ", (long)sc_stksize*sizeof(cell));
|
pc_printf("Stack/heap size: %8ld bytes\n", (long)sc_stksize*sizeof(cell));
|
||||||
|
#if 0
|
||||||
if (stacksize<0)
|
if (stacksize<0)
|
||||||
pc_printf("max. usage is unknown, due to recursion\n");
|
pc_printf("max. usage is unknown, due to recursion\n");
|
||||||
else if (stacksize>0)
|
else if (stacksize>0)
|
||||||
pc_printf("estimated max. usage=%ld cells (%ld bytes)\n",stacksize,stacksize*sizeof(cell));
|
pc_printf("estimated max. usage=%ld cells (%ld bytes)\n",stacksize,stacksize*sizeof(cell));
|
||||||
|
#endif
|
||||||
pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)sc_stksize*sizeof(cell));
|
pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)sc_stksize*sizeof(cell));
|
||||||
} /* if */
|
} /* if */
|
||||||
if (flag_exceed)
|
if (flag_exceed)
|
||||||
|
@ -1253,7 +1255,7 @@ static void setconfig(char *root)
|
||||||
/* add the default "include" directory */
|
/* add the default "include" directory */
|
||||||
#if defined __WIN32__ || defined _WIN32
|
#if defined __WIN32__ || defined _WIN32
|
||||||
GetModuleFileName(NULL,path,_MAX_PATH);
|
GetModuleFileName(NULL,path,_MAX_PATH);
|
||||||
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
|
#elif defined ENABLE_BINRELOC && (defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__)
|
||||||
/* see www.autopackage.org for the BinReloc module */
|
/* see www.autopackage.org for the BinReloc module */
|
||||||
ptr = (char *)SELFPATH;
|
ptr = (char *)SELFPATH;
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
|
|
|
@ -586,7 +586,7 @@ static int htoi(cell *val,const unsigned char *curptr)
|
||||||
return (int)(ptr-curptr);
|
return (int)(ptr-curptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined __GNUC__
|
#if defined __APPLE__
|
||||||
static double pow10(double d)
|
static double pow10(double d)
|
||||||
{
|
{
|
||||||
return pow(10, d);
|
return pow(10, d);
|
||||||
|
|
|
@ -31,7 +31,11 @@
|
||||||
* For Linux, we must overrule these settings with those defined in glibc.
|
* For Linux, we must overrule these settings with those defined in glibc.
|
||||||
*/
|
*/
|
||||||
#if !defined __BYTE_ORDER
|
#if !defined __BYTE_ORDER
|
||||||
# include <stdlib.h>
|
# if defined EMSCRIPTEN
|
||||||
|
# include <endian.h>
|
||||||
|
# else
|
||||||
|
# include <stdlib.h>
|
||||||
|
# endif
|
||||||
# if defined __APPLE__
|
# if defined __APPLE__
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# define __BYTE_ORDER BYTE_ORDER
|
# define __BYTE_ORDER BYTE_ORDER
|
||||||
|
|
Loading…
Reference in New Issue
Block a user