import "ec"
#endif
-#include <stdarg.h>
+
+//#include <stdarg.h>
static Context globalContext { };
static Module privateModule;
int c;
bool valid = true;
char defaultOutputFile[MAX_LOCATION];
+ bool buildingBootStrap = false;
Platform targetPlatform = GetRuntimePlatform();
+ int targetBits = GetHostBits();
SetSymbolsDir("");
char * arg = argv[c];
if(arg[0] == '-')
{
- if(!strcmp(arg + 1, "m32"))
+ if(!strcmp(arg + 1, "m32") || !strcmp(arg + 1, "m64"))
{
int argLen = strlen(arg);
int newLen = cppOptionsLen + 1 + argLen;
cppOptions = renew cppOptions char[newLen + 1];
cppOptions[cppOptionsLen] = ' ';
- strcpy(cppOptions + cppOptionsLen + 1, arg);
+ strcpy(cppOptions + cppOptionsLen + 1, arg);
cppOptionsLen = newLen;
+ targetBits = !strcmp(arg + 1, "m32") ? 32 : 64;
}
else if(arg[1] == 'D')
{
SetBuildingEcereCom(true);
else if(!strcmp(arg, "-DECERE_COM_MODULE"))
SetBuildingEcereComModule(true);
+ else if(!strcmp(arg, "-DECERE_BOOTSTRAP"))
+ buildingBootStrap = true;
}
else if(arg[1] == 'I')
{
SetImports(&imports);
SetInCompiler(true);
SetTargetPlatform(targetPlatform);
+ SetTargetBits(targetBits);
SetEchoOn(false);
- privateModule = (Module)__ecere_COM_Initialize(true, 1, null);
+ privateModule = (Module)__ecere_COM_Initialize(true | (targetBits == sizeof(uintptr)*8 ? 0 : targetBits == 64 ? 2 : targetBits==32 ? 4 : 0) | 8, 1, null);
SetPrivateModule(privateModule);
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
+ if(buildingBootStrap)
+ {
+ // Do not define this when we pre-include stdint.h or the eC compiler will be confused when parsing these types (External prioritization in pass15.ec will fail)
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("intptr_t"), type = ProcessTypeString("intptr", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("uintptr_t"), type = ProcessTypeString("uintptr", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("ssize_t"), type = ProcessTypeString("intsize", false) });
+ globalContext.types.Add((BTNode)Symbol { string = CopyString("size_t"), type = ProcessTypeString("uintsize", false) });
+ }
{
GlobalData data { fullName = CopyString("__thisModule"), dataTypeString = CopyString("Module"), module = privateModule };
- data.key = (uint)data.fullName;
+ data.key = (uintptr)data.fullName;
globalData.functions.Add((BTNode)data);
}
- snprintf(command, sizeof(command), "%s%s -x c -E \"%s\"", cppCommand, cppOptions ? cppOptions : "", GetSourceFile());
+ snprintf(command, sizeof(command), "%s%s -x c -E %s\"%s\"", cppCommand, cppOptions ? cppOptions : "", buildingBootStrap ? "" : "-include stdint.h -include sys/types.h ", GetSourceFile());
command[sizeof(command)-1] = 0;
if((cppOutput = DualPipeOpen({ output = true }, command)))
{
File output = FileOpen(GetOutputFile(), write);
if(output)
{
- //output.Printf("#include <ecereCOM.h>\n\n");
-
- // Temporary patch, fix with defines or something...
- /*
- if(!strstr(GetSourceFile(), "instance.ec"))
- {
- output.Printf("#if defined(__GNUC__) && defined(__WIN32__)\n");
- output.Printf("#include <x87inline.h>\n");
- output.Printf("#endif\n");
- }
- */
- /*output.Printf("#if defined(__GNUC__) \n");
- output.Printf("typedef long long int64;\n");
- output.Printf("typedef unsigned long long uint64;\n");
- output.Printf("#else\n");
- output.Printf("typedef __int64 int64;\n");
- output.Printf("typedef unsigned __int64 uint64;\n");
- output.Printf("#endif\n");*/
output.Printf("#if defined(__GNUC__)\n");
output.Printf("typedef long long int64;\n");
output.Printf("typedef unsigned long long uint64;\n");
+ output.Printf("#ifndef _WIN32\n");
+ output.Printf("#define __declspec(x)\n");
+ output.Printf("#endif\n");
output.Printf("#elif defined(__TINYC__)\n");
output.Printf("#include <stdarg.h>\n");
output.Printf("#define __builtin_va_list va_list\n");
output.Printf("#define strcasecmp stricmp\n");
output.Printf("#define strncasecmp strnicmp\n");
output.Printf("#define __declspec(x) __attribute__((x))\n");
+ output.Printf("#else\n");
+ output.Printf("#define __declspec(x)\n");
output.Printf("#endif\n");
output.Printf("typedef long long int64;\n");
output.Printf("typedef unsigned long long uint64;\n");
output.Printf("typedef __int64 int64;\n");
output.Printf("typedef unsigned __int64 uint64;\n");
output.Printf("#endif\n");
- /*output.Printf("#if defined(__GNUC__) || defined(__TINYC__)\n");
- output.Printf("typedef long long int64;\n");
- output.Printf("typedef unsigned long long uint64;\n");
- output.Printf("#elif defined(__TINYC__)\n");
- output.Printf("#else\n");
- output.Printf("typedef __int64 int64;\n");
- output.Printf("typedef unsigned __int64 uint64;\n");
- output.Printf("#endif\n");*/
output.Printf("#ifdef __BIG_ENDIAN__\n");
output.Printf("#define __ENDIAN_PAD(x) (8 - (x))\n");
output.Printf("#else\n");
output.Printf("#define __ENDIAN_PAD(x) 0\n");
output.Printf("#endif\n");
- output.Printf("#include <stdint.h>\n");
+ if(buildingBootStrap)
+ {
+ //output.Printf("#ifdef __MINGW32__\n");
+ //output.Printf("#ifdef _WIN64\n");
+ /*
+ output.Printf("#if defined(_WIN64) || WORDSIZE == 64\n");
+ output.Printf("typedef unsigned long long int uintptr_t;\n");
+ output.Printf("typedef long long int intptr_t;\n");
+ output.Printf("#else\n");
+ output.Printf("typedef unsigned int uintptr_t;\n");
+ output.Printf("typedef int intptr_t;\n");
+ output.Printf("#endif\n");
+ */
+ //output.Printf("#else\n");
+ output.Printf("#include <stdint.h>\n");
+ output.Printf("#include <sys/types.h>\n");
+ //output.Printf("#endif\n");
+ }
// NOTE: If anything is changed up there, the start outputLine must be updated in libec's output.c or Debugging lines will be wrong