summaryrefslogtreecommitdiff
path: root/compiler_and_linker/unsorted/CMachine.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-11 22:29:53 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-11 22:29:53 +0000
commit0bec4f557a96e1a40437cf5af20cc78a5eec8a63 (patch)
treec1e05ec804c43aa5a8f5f21b0ed02d0587d29563 /compiler_and_linker/unsorted/CMachine.c
parentaec1b8dddc68ecb8288ec6132932e4c7b4bca09f (diff)
downloadMWCC-0bec4f557a96e1a40437cf5af20cc78a5eec8a63.tar.gz
MWCC-0bec4f557a96e1a40437cf5af20cc78a5eec8a63.zip
getting closer
Diffstat (limited to 'compiler_and_linker/unsorted/CMachine.c')
-rw-r--r--compiler_and_linker/unsorted/CMachine.c172
1 files changed, 85 insertions, 87 deletions
diff --git a/compiler_and_linker/unsorted/CMachine.c b/compiler_and_linker/unsorted/CMachine.c
index 2b1440f..4bde879 100644
--- a/compiler_and_linker/unsorted/CMachine.c
+++ b/compiler_and_linker/unsorted/CMachine.c
@@ -6,6 +6,7 @@
#include "compiler/CPrep.h"
#include "compiler/CPrepTokenizer.h"
#include "compiler/CompilerTools.h"
+#include "compiler/ScanFloat.h"
#include "compiler/objects.h"
#include "compiler/types.h"
@@ -126,7 +127,7 @@ static short cmach_packsize[] = {
static SInt16 CMach_GetQualifiedTypeAlign(Type *type, Boolean flag);
static SInt16 CMach_GetMemberAlignment(Type *type, SInt32 align, Boolean flag);
-void CMach_Configure() {
+void CMach_Configure(void) {
}
SInt32 CMach_GetQUALalign(UInt32 qual) {
@@ -170,8 +171,7 @@ SInt32 CMach_GetQUALalign(UInt32 qual) {
}
SInt32 CMach_ArgumentAlignment(Type *type) {
- // does not match - registers
- UInt8 save_align_mode;
+ char save_align_mode;
UInt8 save_oldalignment;
SInt32 align;
@@ -252,13 +252,13 @@ CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right) {
break;
case '/':
if (CInt64_IsZero(&right))
- CError_Warning(139);
+ CError_Warning(CErrorStr139);
else
left = CInt64_DivU(left, right);
break;
case '%':
if (CInt64_IsZero(&right))
- CError_Warning(139);
+ CError_Warning(CErrorStr139);
else
left = CInt64_ModU(left, right);
break;
@@ -302,13 +302,13 @@ CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right) {
left = CInt64_Or(left, right);
break;
case TK_LOGICAL_AND:
- CInt64_SetLong(&left, (CInt64_IsZero(&left) == 0 && CInt64_IsZero(&right) == 0));
+ CInt64_SetLong(&left, (!CInt64_IsZero(&left) && !CInt64_IsZero(&right)));
break;
case TK_LOGICAL_OR:
- CInt64_SetLong(&left, (CInt64_IsZero(&left) == 0 || CInt64_IsZero(&right) == 0));
+ CInt64_SetLong(&left, (!CInt64_IsZero(&left) || !CInt64_IsZero(&right)));
break;
default:
- CError_Error(120);
+ CError_Error(CErrorStr120);
}
switch (type->size) {
@@ -350,13 +350,13 @@ CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right) {
break;
case '/':
if (CInt64_IsZero(&right))
- CError_Warning(139);
+ CError_Warning(CErrorStr139);
else
left = CInt64_Div(left, right);
break;
case '%':
if (CInt64_IsZero(&right))
- CError_Warning(139);
+ CError_Warning(CErrorStr139);
else
left = CInt64_Mod(left, right);
break;
@@ -400,13 +400,13 @@ CInt64 CMach_CalcIntDiadic(Type *type, CInt64 left, short op, CInt64 right) {
left = CInt64_Or(left, right);
break;
case TK_LOGICAL_AND:
- CInt64_SetLong(&left, (CInt64_IsZero(&left) == 0 && CInt64_IsZero(&right) == 0));
+ CInt64_SetLong(&left, (!CInt64_IsZero(&left) && !CInt64_IsZero(&right)));
break;
case TK_LOGICAL_OR:
- CInt64_SetLong(&left, (CInt64_IsZero(&left) == 0 || CInt64_IsZero(&right) == 0));
+ CInt64_SetLong(&left, (!CInt64_IsZero(&left) || !CInt64_IsZero(&right)));
break;
default:
- CError_Error(120);
+ CError_Error(CErrorStr120);
}
switch (type->size) {
@@ -456,7 +456,7 @@ CInt64 CMach_CalcIntMonadic(Type *type, short op, CInt64 val) {
val = CInt64_Not(val);
break;
default:
- CError_Error(120);
+ CError_Error(CErrorStr120);
}
switch (type->size) {
@@ -500,7 +500,7 @@ CInt64 CMach_CalcIntMonadic(Type *type, short op, CInt64 val) {
val = CInt64_Not(val);
break;
default:
- CError_Error(120);
+ CError_Error(CErrorStr120);
}
switch (type->size) {
@@ -683,7 +683,7 @@ char *CMach_FloatScan(char *input, Float *result, Boolean *fail) {
char *outpos;
if (!(outpos = ScanFloat(input, &resultval, fail)))
- CError_ErrorTerm(154);
+ CError_ErrorTerm(CErrorStr154);
if (*fail)
result->value = 0.0;
@@ -768,9 +768,9 @@ void CMach_PrintFloat(char *buf, Float val) {
sprintf(buf, "%g", f);
}
-void CMach_PragmaParams() {
+void CMach_PragmaParams(void) {
if (copts.warn_illpragma)
- CError_Warning(186, 0);
+ CError_Warning(CErrorStr186, 0);
while (notendofline())
lex();
@@ -835,37 +835,49 @@ static SInt32 CMach_GetPPCTypeAlign(Type *type, Boolean flag1, Boolean flag2) {
return align;
}
-static SInt16 CMach_GetQualifiedStructAlign(TypeStruct *tstruct, Boolean flag) {
+static SInt16 CMach_GetQualifiedStructAlign(const TypeStruct *tstruct, Boolean flag) {
StructMember *member;
SInt32 best;
SInt32 align;
Boolean isFirst;
- // very close to matching but tstruct->stype gets cached when it should not be
- if (tstruct->stype >= STRUCT_TYPE_4 && tstruct->stype <= STRUCT_TYPE_E) {
+ if (tstruct->stype >= STRUCT_TYPE_4 && tstruct->stype <= STRUCT_TYPE_E)
return 16;
- } else {
-
- switch (copts.align_mode) {
- case AlignMode3_1Byte:
- case AlignMode8_Packed:
- return 1;
- case AlignMode0_Mac68k:
- return 2;
- case AlignMode1_Mac68k4byte:
- return (tstruct->size <= 2) ? 2 : 4;
- }
- if (tstruct->size <= 1)
+ switch (copts.align_mode) {
+ case AlignMode3_1Byte:
+ case AlignMode8_Packed:
return 1;
- best = 1;
- switch (copts.align_mode) {
- default:
- CError_FATAL(1026);
- case AlignMode4_2Byte:
- case AlignMode5_4Byte:
- case AlignMode6_8Byte:
- case AlignMode7_16Byte:
+ case AlignMode0_Mac68k:
+ return 2;
+ case AlignMode1_Mac68k4byte:
+ return (tstruct->size <= 2) ? 2 : 4;
+ }
+
+ if (tstruct->size <= 1)
+ return 1;
+
+ best = 1;
+ switch (copts.align_mode) {
+ default:
+ CError_FATAL(1026);
+ case AlignMode4_2Byte:
+ case AlignMode5_4Byte:
+ case AlignMode6_8Byte:
+ case AlignMode7_16Byte:
+ for (member = tstruct->members; member; member = member->next) {
+ align = CMach_GetQualifiedTypeAlign(member->type, flag);
+ if (align > best)
+ best = align;
+ if (flag) {
+ align = CMach_GetQUALalign(member->qual);
+ if (align > best)
+ best = align;
+ }
+ }
+ return best;
+ case AlignMode2_PPC:
+ if (copts.oldalignment) {
for (member = tstruct->members; member; member = member->next) {
align = CMach_GetQualifiedTypeAlign(member->type, flag);
if (align > best)
@@ -876,46 +888,32 @@ static SInt16 CMach_GetQualifiedStructAlign(TypeStruct *tstruct, Boolean flag) {
best = align;
}
}
- return best;
- case AlignMode2_PPC:
- if (copts.oldalignment) {
- for (member = tstruct->members; member; member = member->next) {
- align = CMach_GetQualifiedTypeAlign(member->type, flag);
- if (align > best)
- best = align;
- if (flag) {
- align = CMach_GetQUALalign(member->qual);
- if (align > best)
- best = align;
- }
- }
- } else if (tstruct->stype == STRUCT_TYPE_UNION) {
- for (member = tstruct->members; member; member = member->next) {
- align = CMach_GetPPCTypeAlign(member->type, 1, flag);
+ } else if (TYPE_STRUCT(tstruct)->stype == STRUCT_TYPE_UNION) {
+ for (member = tstruct->members; member; member = member->next) {
+ align = CMach_GetPPCTypeAlign(member->type, 1, flag);
+ if (align > best)
+ best = align;
+ if (flag) {
+ align = CMach_GetQUALalign(member->qual);
if (align > best)
best = align;
- if (flag) {
- align = CMach_GetQUALalign(member->qual);
- if (align > best)
- best = align;
- }
}
- } else {
- isFirst = 1;
- for (member = tstruct->members; member; member = member->next) {
- align = CMach_GetPPCTypeAlign(member->type, isFirst || (best >= 8), flag);
+ }
+ } else {
+ isFirst = 1;
+ for (member = tstruct->members; member; member = member->next) {
+ align = CMach_GetPPCTypeAlign(member->type, isFirst || (best >= 8), flag);
+ if (align > best)
+ best = align;
+ if (flag) {
+ align = CMach_GetQUALalign(member->qual);
if (align > best)
best = align;
- if (flag) {
- align = CMach_GetQUALalign(member->qual);
- if (align > best)
- best = align;
- }
- isFirst = 0;
}
+ isFirst = 0;
}
- return best;
- }
+ }
+ return best;
}
}
@@ -1029,7 +1027,7 @@ static SInt16 CMach_GetWinMinimizeAlign(SInt16 align) {
}
static SInt16 CMach_GetQualifiedTypeAlign(Type *type, Boolean flag) {
- Boolean r31;
+ Boolean isWin;
SInt16 align;
if (type->type == TYPESTRUCT && TYPE_STRUCT(type)->stype >= STRUCT_TYPE_4 && TYPE_STRUCT(type)->stype <= STRUCT_TYPE_E)
@@ -1043,10 +1041,10 @@ static SInt16 CMach_GetQualifiedTypeAlign(Type *type, Boolean flag) {
case AlignMode5_4Byte:
case AlignMode6_8Byte:
case AlignMode7_16Byte:
- r31 = 1;
+ isWin = 1;
break;
default:
- r31 = 0;
+ isWin = 0;
break;
}
@@ -1059,7 +1057,7 @@ restart:
case TYPEENUM:
type = TYPE_ENUM(type)->enumtype;
case TYPEINT:
- if (r31)
+ if (isWin)
return CMach_GetWinTypeAlign(type);
if (type->size == 1)
return 1;
@@ -1069,7 +1067,7 @@ restart:
return 4;
return 2;
case TYPEFLOAT:
- if (r31)
+ if (isWin)
return CMach_GetWinTypeAlign(type);
switch (copts.align_mode) {
case AlignMode0_Mac68k:
@@ -1085,7 +1083,7 @@ restart:
}
case TYPEMEMBERPOINTER:
case TYPEPOINTER:
- if (r31)
+ if (isWin)
return CMach_GetWinTypeAlign(type);
if (copts.align_mode == AlignMode0_Mac68k)
return 2;
@@ -1093,7 +1091,7 @@ restart:
return 4;
case TYPEARRAY:
if (copts.align_array_members) {
- if (r31)
+ if (isWin)
return CMach_GetWinTypeAlign(type);
if (type->size == 1)
return 1;
@@ -1115,7 +1113,7 @@ restart:
align = TYPE_STRUCT(type)->align;
else
align = CMach_GetQualifiedStructAlign(TYPE_STRUCT(type), flag);
- if (r31)
+ if (isWin)
return CMach_GetWinMinimizeAlign(align);
else
return align;
@@ -1124,7 +1122,7 @@ restart:
align = TYPE_CLASS(type)->align;
else
align = CMach_GetQualifiedClassAlign(TYPE_CLASS(type), flag);
- if (r31)
+ if (isWin)
return CMach_GetWinMinimizeAlign(align);
else
return align;
@@ -1150,7 +1148,7 @@ static SInt16 CMach_GetMemberAlignment(Type *type, SInt32 var, Boolean flag) {
if (align < 1)
align = 1;
- if (type->type == TYPESTRUCT && TYPE_STRUCT(type)->stype >= STRUCT_TYPE_4 && TYPE_STRUCT(type)->stype <= STRUCT_TYPE_E && align < 16)
+ if (IS_TYPE_VECTOR(type) && align < 16)
align = 16;
switch (copts.align_mode) {
@@ -1197,7 +1195,7 @@ void CMach_StructLayoutInitOffset(SInt32 offset) {
cmach_curbfsize = 0;
}
-SInt32 CMach_StructLayoutGetCurSize() {
+SInt32 CMach_StructLayoutGetCurSize(void) {
return cmach_structoffset;
}
@@ -1323,7 +1321,7 @@ Boolean CMach_PassResultInHiddenArg(Type *type) {
}
}
-char *CMach_GetCPU() {
+char *CMach_GetCPU(void) {
switch (copts.cpu) {
case CPU_PPC401: return "__PPC401__";
case CPU_PPC403: return "__PPC403__";
@@ -1379,7 +1377,7 @@ SInt32 CMach_RoundedSizeOf(Object *object) {
return (size + align) & ~align;
}
-void CMach_ReInitRuntimeObjects() {
+void CMach_ReInitRuntimeObjects(void) {
HashNameNode *e0 = GetHashNameNodeExport("[0]");
HashNameNode *e1 = GetHashNameNodeExport("[1]");
HashNameNode *e2 = GetHashNameNodeExport("[2]");