diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-01-19 13:00:09 +0000 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-01-19 13:00:09 +0000 |
commit | 4d670146b4054e11e90227f96a3a1c66410e8d0b (patch) | |
tree | 8dca31cf9ee497ee59e833f48dd76c81aaef3cf5 /compiler_and_linker | |
parent | 5d0bbb19cc133753cebda7099e46d4b2084336c6 (diff) | |
download | MWCC-4d670146b4054e11e90227f96a3a1c66410e8d0b.tar.gz MWCC-4d670146b4054e11e90227f96a3a1c66410e8d0b.zip |
more cross-platform work
Diffstat (limited to '')
-rw-r--r-- | compiler_and_linker/unsorted/CCompiler.c | 12 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/CMachine.c | 30 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/CParser.c | 33 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/IrOptimizer.c | 2 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/IroDump.c | 4 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/ObjGenMachO.c | 6 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/Operands.c | 8 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/PCodeAssembly.c | 4 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/PCodeListing.c | 4 | ||||
-rw-r--r-- | compiler_and_linker/unsorted/uDump.c | 4 |
10 files changed, 60 insertions, 47 deletions
diff --git a/compiler_and_linker/unsorted/CCompiler.c b/compiler_and_linker/unsorted/CCompiler.c index 06d518f..1eb6cd0 100644 --- a/compiler_and_linker/unsorted/CCompiler.c +++ b/compiler_and_linker/unsorted/CCompiler.c @@ -23,8 +23,13 @@ static void get_extension(ConstStringPtr src, char *dst) { if (ep >= 2) { int x; - for (x = 0; (x + ep) <= src[0]; x++) + for (x = 0; (x + ep) <= src[0]; x++) { +#ifdef CW_CLT dst[x] = src[x + ep]; +#else + dst[x] = tolower(src[x + ep]); +#endif + } dst[x] = 0; } } @@ -71,7 +76,7 @@ static int setup_param_block(CWPluginContext context) { cparams.targetOS = tinfo.targetOS; cparams.targetCPU = tinfo.targetCPU; cparams.idetargetname = target_name; - return CWGetTargetName(context, target_name, sizeof(target_name)) == cwNoErr; + return CWGetTargetName(context, cparams.idetargetname, sizeof(target_name)) == cwNoErr; } static short store_compile_results(void) { @@ -231,7 +236,8 @@ CWPLUGIN_ENTRY(MWC_main)(CWPluginContext context) { CodeGen_InitBackEndOptions(); CodeGen_UpdateOptimizerOptions(); CodeGen_UpdateBackEndOptions(); - if (C_Compiler(&cparams)) + result = C_Compiler(&cparams); + if (result != noErr) result = store_compile_results(); else result = cwErrRequestFailed; diff --git a/compiler_and_linker/unsorted/CMachine.c b/compiler_and_linker/unsorted/CMachine.c index c62faf5..eff2243 100644 --- a/compiler_and_linker/unsorted/CMachine.c +++ b/compiler_and_linker/unsorted/CMachine.c @@ -132,7 +132,7 @@ void CMach_Configure(void) { SInt32 CMach_GetQUALalign(UInt32 qual) { SInt32 result = 0; - SInt32 chk; + UInt32 chk; if ((chk = (qual & Q_ALIGNED_MASK))) { if (chk == Q_ALIGNED_1) @@ -183,10 +183,14 @@ SInt32 CMach_ArgumentAlignment(Type *type) { copts.structalignment = save_align_mode; copts.oldalignment = save_oldalignment; - if (type->type == TYPESTRUCT && !TYPE_STRUCT(type)->members && TYPE_STRUCT(type)->align > align) - align = TYPE_STRUCT(type)->align; - - return align; + if (type->type == TYPESTRUCT && !TYPE_STRUCT(type)->members) { + if (TYPE_STRUCT(type)->align > align) + return TYPE_STRUCT(type)->align; + else + return align; + } else { + return align; + } } // TODO: investigate if this returns SInt16 actually @@ -540,23 +544,23 @@ CInt64 CMach_CalcIntConvertFromFloat(Type *type, Float fval) { } void CMach_InitIntMem(Type *type, CInt64 val, void *mem) { - UInt32 lg; - UInt16 sh; - UInt8 ch; + SInt32 lg; + SInt16 sh; + SInt8 ch; switch (type->type) { case TYPEINT: switch (type->size) { case 1: - ch = (UInt8) CInt64_GetULong(&val); + ch = CInt64_GetULong(&val); memcpy(mem, &ch, 1); break; case 2: - sh = (UInt16) CTool_EndianConvertWord16(CInt64_GetULong(&val)); + sh = CTool_EndianConvertWord16(CInt64_GetULong(&val)); memcpy(mem, &sh, 2); break; case 4: - lg = (UInt32) CTool_EndianConvertWord32(CInt64_GetULong(&val)); + lg = CTool_EndianConvertWord32(CInt64_GetULong(&val)); memcpy(mem, &lg, 4); break; case 8: @@ -1299,7 +1303,7 @@ UInt8 CMach_GetFunctionResultClass(TypeFunc *tfunc) { return 0; case TYPECLASS: case TYPEMEMBERPOINTER: - return CMach_PassResultInHiddenArg(tfunc->functype) ? 1 : 0; + return CMach_PassResultInHiddenArg(tfunc->functype) != 0; default: return 0; } @@ -1315,7 +1319,7 @@ Boolean CMach_PassResultInHiddenArg(Type *type) { case TYPECLASS: return 1; case TYPEMEMBERPOINTER: - return (type->size == 4) ? 0 : 1; + return (type->size != 4); default: return 0; } diff --git a/compiler_and_linker/unsorted/CParser.c b/compiler_and_linker/unsorted/CParser.c index 075932e..92d75c1 100644 --- a/compiler_and_linker/unsorted/CParser.c +++ b/compiler_and_linker/unsorted/CParser.c @@ -519,9 +519,8 @@ void CParser_PrintUniqueID(char *buf) { ptr = mybuf; id = CParser_GetUniqueID(); while (id) { - *ptr = '0' + (id - ((id / 10) * 10)); + *(ptr++) = '0' + (id - ((id / 10) * 10)); id = id / 10; - ptr++; } while (ptr > mybuf) @@ -541,7 +540,7 @@ HashNameNode *CParser_GetUniqueName(void) { return GetHashNameNodeExport(buf); } -HashNameNode *CParser_NameConcat(char *a, char *b) { +HashNameNode *CParser_NameConcat(const char *a, const char *b) { char mybuf[256]; char *buf; char *dst; @@ -658,18 +657,18 @@ static void CParser_SetCFMFlags(Object *object, DeclInfo *declinfo) { if (object->datatype == DDATA) { if (copts.cfm_export) - object->flags |= OBJECT_FLAGS_40; + object->flags = object->flags | OBJECT_FLAGS_40; if (copts.cfm_internal) - object->flags |= OBJECT_FLAGS_10; + object->flags = object->flags | OBJECT_FLAGS_10; } else if (copts.cfm_internal) { - object->flags |= OBJECT_FLAGS_10; + object->flags = object->flags | OBJECT_FLAGS_10; } else { if (copts.cfm_import) - object->flags |= OBJECT_FLAGS_20; + object->flags = object->flags | OBJECT_FLAGS_20; if (copts.cfm_export) - object->flags |= OBJECT_FLAGS_40; + object->flags = object->flags | OBJECT_FLAGS_40; if (copts.cfm_lib_export) - object->flags |= OBJECT_FLAGS_20 | OBJECT_FLAGS_40; + object->flags = object->flags | OBJECT_FLAGS_20 | OBJECT_FLAGS_40; } } @@ -1686,7 +1685,7 @@ Boolean CParser_IsConst(Type *type, UInt32 qual) { break; } - return qual & Q_CONST; + return (qual & Q_CONST) != 0; } Boolean CParser_IsVolatile(Type *type, UInt32 qual) { @@ -1702,7 +1701,7 @@ Boolean CParser_IsVolatile(Type *type, UInt32 qual) { break; } - return (qual & Q_VOLATILE) ? 1 : 0; + return (qual & Q_VOLATILE) != 0; } Boolean is_const_object(Object *obj) { @@ -2105,15 +2104,15 @@ void CParser_ParseDeclSpec(DeclInfo *declinfo, Boolean flag) { if (tk != TK_EXPORT) CError_Error(CErrorStr107); else - declinfo->exportflags |= EXPORT_FLAGS_EXPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_EXPORT; } else if (!strcmp("internal", tkidentifier->name)) { - declinfo->exportflags |= EXPORT_FLAGS_INTERNAL; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_INTERNAL; } else if (!strcmp("import", tkidentifier->name) || !strcmp("dllimport", tkidentifier->name)) { - declinfo->exportflags |= EXPORT_FLAGS_IMPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_IMPORT; } else if (!strcmp("export", tkidentifier->name) || !strcmp("dllexport", tkidentifier->name)) { - declinfo->exportflags |= EXPORT_FLAGS_EXPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_EXPORT; } else if (!strcmp("lib_export", tkidentifier->name)) { - declinfo->exportflags |= EXPORT_FLAGS_IMPORT | EXPORT_FLAGS_EXPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_IMPORT | EXPORT_FLAGS_EXPORT; } else if (!strcmp("weak", tkidentifier->name)) { declinfo->qual |= Q_OVERLOAD; } else { @@ -3157,7 +3156,7 @@ void CParser_NewCallBackAction(Object *obj, TypeClass *tclass) { act->obj = obj; act->tclass = tclass; callbackactions = act; - obj->flags |= OBJECT_FLAGS_8; + obj->flags = obj->flags | OBJECT_FLAGS_8; } void CParser_NewClassAction(TypeClass *tclass) { diff --git a/compiler_and_linker/unsorted/IrOptimizer.c b/compiler_and_linker/unsorted/IrOptimizer.c index 87be84c..121c65f 100644 --- a/compiler_and_linker/unsorted/IrOptimizer.c +++ b/compiler_and_linker/unsorted/IrOptimizer.c @@ -121,7 +121,7 @@ Statement *IRO_Optimizer(Object *func, Statement *statements) { CError_ASSERT(234, stIsSetup); -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_IRO_DEBUG if (copts.debuglisting) IRO_Log = 1; #endif diff --git a/compiler_and_linker/unsorted/IroDump.c b/compiler_and_linker/unsorted/IroDump.c index c59aa7b..38412ea 100644 --- a/compiler_and_linker/unsorted/IroDump.c +++ b/compiler_and_linker/unsorted/IroDump.c @@ -295,7 +295,7 @@ void IRO_DumpBits(char *name, BitVector *bv) { } void IRO_DumpAfterPhase(char *str, Boolean flag) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_IRO_DEBUG if (copts.debuglisting) flag = 1; #endif @@ -445,7 +445,7 @@ void IRO_DumpExprs(void) { } void IRO_SetupDump(void) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_IRO_DEBUG IRO_Log = 1; #endif diff --git a/compiler_and_linker/unsorted/ObjGenMachO.c b/compiler_and_linker/unsorted/ObjGenMachO.c index 10ce456..244a1bc 100644 --- a/compiler_and_linker/unsorted/ObjGenMachO.c +++ b/compiler_and_linker/unsorted/ObjGenMachO.c @@ -16,6 +16,10 @@ #include "compiler/objects.h" #include "cos.h" +#ifndef CW_TARGET_MACH +#error "Wrong configuration for ObjGenMachO" +#endif + #ifdef __MWERKS__ #pragma options align=mac68k #endif @@ -1290,7 +1294,7 @@ MachOSection *ObjGen_DeclareFunction(Object *object) { return section; } -MachOSection *ObjGen_DeclareCode(Object *object) { +MachOSection *ObjGen_DeclareCode(Object *object, SInt32 size) { MachOSection *section; section = ObjGen_DeclareFunction(object); diff --git a/compiler_and_linker/unsorted/Operands.c b/compiler_and_linker/unsorted/Operands.c index 2b717e9..e61d5b0 100644 --- a/compiler_and_linker/unsorted/Operands.c +++ b/compiler_and_linker/unsorted/Operands.c @@ -26,7 +26,7 @@ void load_immediate(short reg, SInt32 value) { if (copts.optimizationlevel > 1 && value) tmpreg = used_virtual_registers[RegClass_GPR]++; emitpcode(PC_LIS, tmpreg2 = tmpreg, 0, (short) HIGH_PART(value)); - if (value) + if (LOW_PART(value)) emitpcode(PC_ADDI, reg, tmpreg2, 0, LOW_PART(value)); } else { emitpcode(PC_LI, reg, value); @@ -263,7 +263,7 @@ void combine(Operand *opA, Operand *opB, short output_reg, Operand *opOut) { emitpcode(PC_ADDI, opOut->regOffset, opB->regOffset, 0, LOW_PART(opA->immediate)); } else { emitpcode(PC_ADDIS, opOut->regOffset, opB->regOffset, 0, (short) HIGH_PART(opA->immediate)); - if (opA->immediate != 0) + if (LOW_PART(opA->immediate)) emitpcode(PC_ADDI, opOut->regOffset, opOut->regOffset, 0, LOW_PART(opA->immediate)); } break; @@ -384,7 +384,7 @@ void Coerce_to_register(Operand *op, Type *type, short output_reg) { if (copts.optimizationlevel > 1 && offset) tmp = used_virtual_registers[RegClass_GPR]++; emitpcode(PC_LIS, tmp, 0, (short) HIGH_PART(offset)); - if (offset) + if (LOW_PART(offset)) emitpcode(PC_ADDI, reg, tmp, 0, LOW_PART(offset)); } break; @@ -533,7 +533,7 @@ void coerce_to_register_pair(Operand *op, Type *type, short output_reg, short ou if (copts.optimizationlevel > 1 && offset) tmp1 = used_virtual_registers[RegClass_GPR]++; emitpcode(PC_LIS, tmp1, 0, (short) HIGH_PART(offset)); - if (offset) + if (LOW_PART(offset)) emitpcode(PC_ADDI, reg, tmp1, 0, LOW_PART(offset)); } regHi = output_regHi ? output_regHi : used_virtual_registers[RegClass_GPR]++; diff --git a/compiler_and_linker/unsorted/PCodeAssembly.c b/compiler_and_linker/unsorted/PCodeAssembly.c index cd3f376..58a3d51 100644 --- a/compiler_and_linker/unsorted/PCodeAssembly.c +++ b/compiler_and_linker/unsorted/PCodeAssembly.c @@ -1540,7 +1540,7 @@ SInt32 assemblefunction(Object *func, EntryPoint *entrypoints) { SInt32 codesize; SInt32 tbsize; SInt32 offset; - MachOSection *section; + SectionHandle section; EntryPoint *ep; WeirdOperand wop; @@ -1567,7 +1567,7 @@ SInt32 assemblefunction(Object *func, EntryPoint *entrypoints) { func->section = SECT_TEXT; offset = tbsize; - section = ObjGen_DeclareCode(func); + section = ObjGen_DeclareCode(func, codesize + tbsize); gl = ObjGen_GetSectionGList(section); codebase = gl->size; diff --git a/compiler_and_linker/unsorted/PCodeListing.c b/compiler_and_linker/unsorted/PCodeListing.c index 485d52d..7a9fa13 100644 --- a/compiler_and_linker/unsorted/PCodeListing.c +++ b/compiler_and_linker/unsorted/PCodeListing.c @@ -150,7 +150,7 @@ void pcinitlisting() { } void pccleanuplisting(void) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_PCODE_DEBUG // this code is not based on the original as we don't have it if (pcfile) { fclose(pcfile); @@ -160,7 +160,7 @@ void pccleanuplisting(void) { } void pclistblocks(char *name1, char *name2) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_PCODE_DEBUG // this code is not based on the original as we don't have it PCodeBlock *block; if (copts.debuglisting) { diff --git a/compiler_and_linker/unsorted/uDump.c b/compiler_and_linker/unsorted/uDump.c index 58bc589..e7ed2d2 100644 --- a/compiler_and_linker/unsorted/uDump.c +++ b/compiler_and_linker/unsorted/uDump.c @@ -68,7 +68,7 @@ void SetupDumpIR(void) { } void CleanupDumpIR(void) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_PCODE_DEBUG // this code is not based on the original as we don't have it if (outfile) { fclose(outfile); @@ -78,7 +78,7 @@ void CleanupDumpIR(void) { } void DumpIR(Statement *statements, Object *func) { -#ifdef CW_PATCH_DEBUG +#ifdef CW_ENABLE_PCODE_DEBUG // this code is not based on the original as we don't have it if (copts.debuglisting) { if (!outfile) |