From c1228e4ae028c6ed6d0bb98d97af2059b9c01f14 Mon Sep 17 00:00:00 2001 From: David Brown Date: Sat, 20 Aug 2016 23:41:49 +0100 Subject: [PATCH] Replace alignment constants with calcualted alignment. --- bootstrap/unix-44/OPB.c | 107 +++++++++++++++---------------------- bootstrap/unix-44/OPC.c | 94 +++++++++++--------------------- bootstrap/unix-44/OPC.h | 3 +- bootstrap/unix-44/OPM.c | 88 +++++++----------------------- bootstrap/unix-44/OPM.h | 7 +-- bootstrap/unix-44/OPV.c | 14 ++--- bootstrap/unix-48/OPB.c | 107 +++++++++++++++---------------------- bootstrap/unix-48/OPC.c | 94 +++++++++++--------------------- bootstrap/unix-48/OPC.h | 3 +- bootstrap/unix-48/OPM.c | 88 +++++++----------------------- bootstrap/unix-48/OPM.h | 7 +-- bootstrap/unix-48/OPV.c | 14 ++--- bootstrap/unix-88/OPB.c | 107 +++++++++++++++---------------------- bootstrap/unix-88/OPC.c | 94 +++++++++++--------------------- bootstrap/unix-88/OPC.h | 3 +- bootstrap/unix-88/OPM.c | 88 +++++++----------------------- bootstrap/unix-88/OPM.h | 7 +-- bootstrap/unix-88/OPV.c | 14 ++--- bootstrap/windows-48/OPB.c | 107 +++++++++++++++---------------------- bootstrap/windows-48/OPC.c | 94 +++++++++++--------------------- bootstrap/windows-48/OPC.h | 3 +- bootstrap/windows-48/OPM.c | 88 +++++++----------------------- bootstrap/windows-48/OPM.h | 7 +-- bootstrap/windows-48/OPV.c | 14 ++--- bootstrap/windows-88/OPB.c | 107 +++++++++++++++---------------------- bootstrap/windows-88/OPC.c | 94 +++++++++++--------------------- bootstrap/windows-88/OPC.h | 3 +- bootstrap/windows-88/OPM.c | 88 +++++++----------------------- bootstrap/windows-88/OPM.h | 7 +-- bootstrap/windows-88/OPV.c | 14 ++--- src/compiler/OPB.Mod | 16 +----- src/compiler/OPC.Mod | 44 ++++++++------- src/compiler/OPM.cmdln.Mod | 67 ++++++++++++++++------- src/compiler/OPV.Mod | 10 ++-- 34 files changed, 618 insertions(+), 1084 deletions(-) diff --git a/bootstrap/unix-44/OPB.c b/bootstrap/unix-44/OPB.c index dcf7d09d..6567ca50 100644 --- a/bootstrap/unix-44/OPB.c +++ b/bootstrap/unix-44/OPB.c @@ -55,8 +55,6 @@ static void OPB_SetIntType (OPT_Node node); export void OPB_SetRange (OPT_Node *x, OPT_Node y); static LONGINT OPB_ShorterSize (LONGINT i); static INTEGER OPB_SignedByteSize (LONGINT n); -static LONGINT OPB_SignedMaximum (LONGINT bytecount); -static LONGINT OPB_SignedMinimum (LONGINT bytecount); export void OPB_StFct (OPT_Node *par0, SHORTINT fctno, INTEGER parno); export void OPB_StPar0 (OPT_Node *par0, INTEGER fctno); export void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno); @@ -226,23 +224,6 @@ OPT_Node OPB_EmptySet (void) return _o_result; } -static LONGINT OPB_SignedMaximum (LONGINT bytecount) -{ - LONGINT _o_result; - LONGINT result; - result = 1; - result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); - _o_result = result - 1; - return _o_result; -} - -static LONGINT OPB_SignedMinimum (LONGINT bytecount) -{ - LONGINT _o_result; - _o_result = -OPB_SignedMaximum(bytecount) - 1; - return _o_result; -} - static INTEGER OPB_SignedByteSize (LONGINT n) { INTEGER _o_result; @@ -448,16 +429,16 @@ void OPB_Field (OPT_Node *x, OPT_Object y) } } -static struct TypTest__63 { +static struct TypTest__61 { OPT_Node *x; OPT_Object *obj; BOOLEAN *guard; - struct TypTest__63 *lnk; -} *TypTest__63_s; + struct TypTest__61 *lnk; +} *TypTest__61_s; -static void GTT__64 (OPT_Struct t0, OPT_Struct t1); +static void GTT__62 (OPT_Struct t0, OPT_Struct t1); -static void GTT__64 (OPT_Struct t0, OPT_Struct t1) +static void GTT__62 (OPT_Struct t0, OPT_Struct t1) { OPT_Node node = NIL; OPT_Struct t = NIL; @@ -470,54 +451,54 @@ static void GTT__64 (OPT_Struct t0, OPT_Struct t1) t1 = t1->BaseTyp; } if (t1 == t0 || t0->form == 0) { - if (*TypTest__63_s->guard) { - OPB_BindNodes(5, NIL, &*TypTest__63_s->x, NIL); - (*TypTest__63_s->x)->readonly = (*TypTest__63_s->x)->left->readonly; + if (*TypTest__61_s->guard) { + OPB_BindNodes(5, NIL, &*TypTest__61_s->x, NIL); + (*TypTest__61_s->x)->readonly = (*TypTest__61_s->x)->left->readonly; } else { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } } else { OPB_err(85); } } else if (t0 != t1) { OPB_err(85); - } else if (!*TypTest__63_s->guard) { - if ((*TypTest__63_s->x)->class == 5) { + } else if (!*TypTest__61_s->guard) { + if ((*TypTest__61_s->x)->class == 5) { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } else { - *TypTest__63_s->x = OPB_NewBoolConst(1); + *TypTest__61_s->x = OPB_NewBoolConst(1); } } } void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) { - struct TypTest__63 _s; + struct TypTest__61 _s; _s.x = x; _s.obj = &obj; _s.guard = &guard; - _s.lnk = TypTest__63_s; - TypTest__63_s = &_s; + _s.lnk = TypTest__61_s; + TypTest__61_s = &_s; if (OPB_NotVar(*x)) { OPB_err(112); } else if ((*x)->typ->form == 13) { if (((*x)->typ->BaseTyp->comp != 4 && (*x)->typ != OPT_sysptrtyp)) { OPB_err(85); } else if (obj->typ->form == 13) { - GTT__64((*x)->typ->BaseTyp, obj->typ->BaseTyp); + GTT__62((*x)->typ->BaseTyp, obj->typ->BaseTyp); } else { OPB_err(86); } } else if (((((*x)->typ->comp == 4 && (*x)->class == 1)) && obj->typ->comp == 4)) { - GTT__64((*x)->typ, obj->typ); + GTT__62((*x)->typ, obj->typ); } else { OPB_err(87); } @@ -526,7 +507,7 @@ void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) } else { (*x)->typ = OPT_booltyp; } - TypTest__63_s = _s.lnk; + TypTest__61_s = _s.lnk; } void OPB_In (OPT_Node *x, OPT_Node y) @@ -1849,7 +1830,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMinimum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMinimum(x->typ->size)); break; case 9: x = OPB_NewIntConst(((LONGINT)(0))); @@ -1880,7 +1861,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMaximum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMaximum(x->typ->size)); break; case 9: x = OPB_NewIntConst(OPM_MaxSet); @@ -2062,13 +2043,13 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) *par0 = x; } -static struct StPar1__58 { - struct StPar1__58 *lnk; -} *StPar1__58_s; +static struct StPar1__56 { + struct StPar1__56 *lnk; +} *StPar1__56_s; -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) { OPT_Node _o_result; OPT_Node node = NIL; @@ -2085,9 +2066,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) INTEGER f, L; OPT_Struct typ = NIL; OPT_Node p = NIL, t = NIL; - struct StPar1__58 _s; - _s.lnk = StPar1__58_s; - StPar1__58_s = &_s; + struct StPar1__56 _s; + _s.lnk = StPar1__56_s; + StPar1__56_s = &_s; p = *par0; f = x->typ->form; switch (fctno) { @@ -2103,7 +2084,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); p->typ = OPT_notyp; } break; @@ -2114,7 +2095,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if ((x->class == 7 && (0 > x->conval->intval || x->conval->intval > (LONGINT)OPM_MaxSet))) { OPB_err(202); } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2139,7 +2120,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) p = p->left; x->conval->intval += 1; } - p = NewOp__59(12, 19, p, x); + p = NewOp__57(12, 19, p, x); p->typ = OPT_linttyp; } else { p = x; @@ -2161,7 +2142,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) t = x; x = p; p = t; - p = NewOp__59(19, 18, p, x); + p = NewOp__57(19, 18, p, x); } else { OPB_err(111); } @@ -2187,7 +2168,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) } p->obj = NIL; } else { - p = NewOp__59(12, 17, p, x); + p = NewOp__57(12, 17, p, x); p->typ = OPT_linttyp; } } else { @@ -2218,9 +2199,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } else { if (fctno == 22) { - p = NewOp__59(12, 27, p, x); + p = NewOp__57(12, 27, p, x); } else { - p = NewOp__59(12, 28, p, x); + p = NewOp__57(12, 28, p, x); } p->typ = p->left->typ; } @@ -2237,7 +2218,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) x = p; p = t; } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2247,7 +2228,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(12, 26, p, x); + p = NewOp__57(12, 26, p, x); } else { OPB_err(111); } @@ -2271,7 +2252,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(19, 30, p, x); + p = NewOp__57(19, 30, p, x); } else { OPB_err(111); } @@ -2317,7 +2298,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) break; } *par0 = p; - StPar1__58_s = _s.lnk; + StPar1__56_s = _s.lnk; } void OPB_StParN (OPT_Node *par0, OPT_Node x, INTEGER fctno, INTEGER n) diff --git a/bootstrap/unix-44/OPC.c b/bootstrap/unix-44/OPC.c index 2efc2010..7ce3cbe5 100644 --- a/bootstrap/unix-44/OPC.c +++ b/bootstrap/unix-44/OPC.c @@ -16,7 +16,7 @@ static CHAR OPC_BodyNameExt[13]; export void OPC_Align (LONGINT *adr, LONGINT base); export void OPC_Andent (OPT_Struct typ); static void OPC_AnsiParamList (OPT_Object obj, BOOLEAN showParamNames); -export LONGINT OPC_Base (OPT_Struct typ); +export LONGINT OPC_BaseAlignment (OPT_Struct typ); export OPT_Object OPC_BaseTProc (OPT_Object obj); export void OPC_BegBlk (void); export void OPC_BegStat (void); @@ -74,6 +74,7 @@ static void OPC_PutBase (OPT_Struct typ); static void OPC_PutPtrOffsets (OPT_Struct typ, LONGINT adr, LONGINT *cnt); static void OPC_RegCmds (OPT_Object obj); export void OPC_SetInclude (BOOLEAN exclude); +export LONGINT OPC_SizeAlignment (LONGINT size); static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause); static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x); static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l); @@ -867,70 +868,37 @@ void OPC_Align (LONGINT *adr, LONGINT base) } } -LONGINT OPC_Base (OPT_Struct typ) +LONGINT OPC_SizeAlignment (LONGINT size) { LONGINT _o_result; - switch (typ->form) { - case 1: - _o_result = 1; - return _o_result; - break; - case 3: - _o_result = OPM_CharAlign; - return _o_result; - break; - case 2: - _o_result = OPM_BoolAlign; - return _o_result; - break; - case 4: - _o_result = OPM_SIntAlign; - return _o_result; - break; - case 5: - _o_result = OPM_IntAlign; - return _o_result; - break; - case 6: - _o_result = OPM_LIntAlign; - return _o_result; - break; - case 7: - _o_result = OPM_RealAlign; - return _o_result; - break; - case 8: - _o_result = OPM_LRealAlign; - return _o_result; - break; - case 9: - _o_result = OPM_SetAlign; - return _o_result; - break; - case 13: - _o_result = OPM_PointerAlign; - return _o_result; - break; - case 14: - _o_result = OPM_ProcAlign; - return _o_result; - break; - case 15: - if (typ->comp == 4) { - _o_result = __MASK(typ->align, -65536); - return _o_result; - } else { - _o_result = OPC_Base(typ->BaseTyp); - return _o_result; - } - break; - default: - OPM_LogWStr((CHAR*)"unhandled case in OPC.Base, typ^form = ", (LONGINT)40); - OPM_LogWNum(typ->form, ((LONGINT)(0))); - OPM_LogWLn(); - break; + LONGINT alignment; + if (size < (LONGINT)OPM_Alignment) { + alignment = 1; + while (alignment < size) { + alignment = __ASHL(alignment, 1); + } + } else { + alignment = OPM_Alignment; } - __RETCHK; + _o_result = alignment; + return _o_result; +} + +LONGINT OPC_BaseAlignment (OPT_Struct typ) +{ + LONGINT _o_result; + LONGINT alignment; + if (typ->form == 15) { + if (typ->comp == 4) { + alignment = __MASK(typ->align, -65536); + } else { + alignment = OPC_BaseAlignment(typ->BaseTyp); + } + } else { + alignment = OPC_SizeAlignment(typ->size); + } + _o_result = alignment; + return _o_result; } static void OPC_FillGap (LONGINT gap, LONGINT off, LONGINT align, LONGINT *n, LONGINT *curAlign) @@ -984,7 +952,7 @@ static void OPC_FieldList (OPT_Struct typ, BOOLEAN last, LONGINT *off, LONGINT * } } else { adr = *off; - fldAlign = OPC_Base(fld->typ); + fldAlign = OPC_BaseAlignment(fld->typ); OPC_Align(&adr, fldAlign); gap = fld->adr - adr; if (fldAlign > *curAlign) { diff --git a/bootstrap/unix-44/OPC.h b/bootstrap/unix-44/OPC.h index ac61a9a4..8786c7c6 100644 --- a/bootstrap/unix-44/OPC.h +++ b/bootstrap/unix-44/OPC.h @@ -11,7 +11,7 @@ import void OPC_Align (LONGINT *adr, LONGINT base); import void OPC_Andent (OPT_Struct typ); -import LONGINT OPC_Base (OPT_Struct typ); +import LONGINT OPC_BaseAlignment (OPT_Struct typ); import OPT_Object OPC_BaseTProc (OPT_Object obj); import void OPC_BegBlk (void); import void OPC_BegStat (void); @@ -40,6 +40,7 @@ import void OPC_InitTDesc (OPT_Struct typ); import void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim); import LONGINT OPC_NofPtrs (OPT_Struct typ); import void OPC_SetInclude (BOOLEAN exclude); +import LONGINT OPC_SizeAlignment (LONGINT size); import void OPC_TDescDecl (OPT_Struct typ); import void OPC_TypeDefs (OPT_Object obj, INTEGER vis); import void OPC_TypeOf (OPT_Object ap); diff --git a/bootstrap/unix-44/OPM.c b/bootstrap/unix-44/OPM.c index fc316318..4bdc065f 100644 --- a/bootstrap/unix-44/OPM.c +++ b/bootstrap/unix-44/OPM.c @@ -14,8 +14,8 @@ typedef static CHAR OPM_SourceFileName[256]; -export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -export LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +export LONGINT OPM_MaxIndex; export LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; export BOOLEAN OPM_noerr; export LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -36,7 +36,6 @@ static CHAR OPM_OBERON[1024]; static CHAR OPM_MODULES[1024]; -export INTEGER OPM_AlignSize (LONGINT size); static void OPM_Append (Files_Rider *R, LONGINT *R__typ, Files_File F); export void OPM_CloseFiles (void); export void OPM_CloseOldSym (void); @@ -65,6 +64,8 @@ export BOOLEAN OPM_OpenPar (void); export void OPM_RegisterNewSym (void); static void OPM_ScanOptions (CHAR *s, LONGINT s__len, SET *opt); static void OPM_ShowLine (LONGINT pos); +export LONGINT OPM_SignedMaximum (LONGINT bytecount); +export LONGINT OPM_SignedMinimum (LONGINT bytecount); export void OPM_SymRCh (CHAR *ch); export LONGINT OPM_SymRInt (void); export void OPM_SymRLReal (LONGREAL *lr); @@ -607,111 +608,62 @@ static void OPM_VerboseListSizes (void) OPM_LogWLn(); OPM_LogWStr((CHAR*)"CHAR ", (LONGINT)14); OPM_LogWNum(OPM_CharSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_CharAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"BOOLEAN ", (LONGINT)14); OPM_LogWNum(OPM_BoolSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_BoolAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SHORTINT ", (LONGINT)14); OPM_LogWNum(OPM_SIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"INTEGER ", (LONGINT)14); OPM_LogWNum(OPM_IntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_IntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGINT ", (LONGINT)14); OPM_LogWNum(OPM_LIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SET ", (LONGINT)14); OPM_LogWNum(OPM_SetSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SetAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"REAL ", (LONGINT)14); OPM_LogWNum(OPM_RealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGREAL ", (LONGINT)14); OPM_LogWNum(OPM_LRealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LRealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PTR ", (LONGINT)14); OPM_LogWNum(OPM_PointerSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_PointerAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PROC ", (LONGINT)14); OPM_LogWNum(OPM_ProcSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_ProcAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"RECORD ", (LONGINT)14); OPM_LogWNum(OPM_RecSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RecAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MinSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MaxSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min integer ", (LONGINT)14); - OPM_LogWNum(OPM_MinInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max integer ", (LONGINT)14); - OPM_LogWNum(OPM_MaxInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min longint ", (LONGINT)14); - OPM_LogWNum(OPM_MinLInt, ((LONGINT)(4))); - OPM_LogWLn(); } -INTEGER OPM_AlignSize (LONGINT size) +LONGINT OPM_SignedMaximum (LONGINT bytecount) { - INTEGER _o_result; - INTEGER align; - if (size < (LONGINT)OPM_Alignment) { - if (size > 8) { - align = 16; - } else if (size > 4) { - align = 8; - } else if (size > 2) { - align = 4; - } else { - align = (int)size; - } - } else { - align = OPM_Alignment; - } - _o_result = align; + LONGINT _o_result; + LONGINT result; + result = 1; + result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); + _o_result = result - 1; + return _o_result; +} + +LONGINT OPM_SignedMinimum (LONGINT bytecount) +{ + LONGINT _o_result; + _o_result = -OPM_SignedMaximum(bytecount) - 1; return _o_result; } static void OPM_GetProperties (void) { - LONGINT base; OPM_ProcSize = OPM_PointerSize; OPM_LIntSize = __ASHL(OPM_IntSize, 1); OPM_SetSize = OPM_LIntSize; - OPM_CharAlign = OPM_AlignSize(OPM_CharSize); - OPM_BoolAlign = OPM_AlignSize(OPM_BoolSize); - OPM_SIntAlign = OPM_AlignSize(OPM_SIntSize); - OPM_RecAlign = OPM_AlignSize(OPM_RecSize); - OPM_RealAlign = OPM_AlignSize(OPM_RealSize); - OPM_LRealAlign = OPM_AlignSize(OPM_LRealSize); - OPM_PointerAlign = OPM_AlignSize(OPM_PointerSize); - OPM_ProcAlign = OPM_AlignSize(OPM_ProcSize); - OPM_IntAlign = OPM_AlignSize(OPM_IntSize); - OPM_LIntAlign = OPM_AlignSize(OPM_LIntSize); - OPM_SetAlign = OPM_AlignSize(OPM_SetSize); - base = -2; - OPM_MinSInt = __ASH(base, __ASHL(OPM_SIntSize, 3) - 2); - OPM_MaxSInt = OPM_minusop(OPM_MinSInt + 1); - OPM_MinInt = __ASH(base, __ASHL(OPM_IntSize, 3) - 2); - OPM_MaxInt = OPM_minusop(OPM_MinInt + 1); - OPM_MinLInt = __ASH(base, __ASHL(OPM_LIntSize, 3) - 2); - OPM_MaxLInt = OPM_minusop(OPM_MinLInt + 1); if (OPM_RealSize == 4) { OPM_MaxReal = 3.40282346000000e+038; } else if (OPM_RealSize == 8) { @@ -725,7 +677,7 @@ static void OPM_GetProperties (void) OPM_MinReal = -OPM_MaxReal; OPM_MinLReal = -OPM_MaxLReal; OPM_MaxSet = __ASHL(OPM_SetSize, 3) - 1; - OPM_MaxIndex = OPM_MaxLInt; + OPM_MaxIndex = OPM_SignedMaximum(OPM_PointerSize); if (OPM_Verbose) { OPM_VerboseListSizes(); } @@ -887,7 +839,7 @@ void OPM_WriteInt (LONGINT i) { CHAR s[20]; LONGINT i1, k; - if (i == OPM_MinInt || i == OPM_MinLInt) { + if (i == OPM_SignedMinimum(OPM_IntSize) || i == OPM_SignedMinimum(OPM_LIntSize)) { OPM_Write('('); OPM_WriteInt(i + 1); OPM_WriteString((CHAR*)"-1)", (LONGINT)4); @@ -920,7 +872,7 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_MaxLInt && r > OPM_MinLInt)) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { diff --git a/bootstrap/unix-44/OPM.h b/bootstrap/unix-44/OPM.h index ec53cacf..5f8cc38c 100644 --- a/bootstrap/unix-44/OPM.h +++ b/bootstrap/unix-44/OPM.h @@ -6,8 +6,8 @@ #include "SYSTEM.h" -import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -import LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +import LONGINT OPM_MaxIndex; import LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; import BOOLEAN OPM_noerr; import LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -18,7 +18,6 @@ import SET OPM_opt, OPM_glbopt; import BOOLEAN OPM_dontAsm, OPM_dontLink, OPM_mainProg, OPM_mainLinkStat, OPM_notColorOutput, OPM_forceNewSym, OPM_Verbose; -import INTEGER OPM_AlignSize (LONGINT size); import void OPM_CloseFiles (void); import void OPM_CloseOldSym (void); import void OPM_DeleteNewSym (void); @@ -39,6 +38,8 @@ import void OPM_OldSym (CHAR *modName, LONGINT modName__len, BOOLEAN *done); import void OPM_OpenFiles (CHAR *moduleName, LONGINT moduleName__len); import BOOLEAN OPM_OpenPar (void); import void OPM_RegisterNewSym (void); +import LONGINT OPM_SignedMaximum (LONGINT bytecount); +import LONGINT OPM_SignedMinimum (LONGINT bytecount); import void OPM_SymRCh (CHAR *ch); import LONGINT OPM_SymRInt (void); import void OPM_SymRLReal (LONGREAL *lr); diff --git a/bootstrap/unix-44/OPV.c b/bootstrap/unix-44/OPV.c index 961c5e11..50f58fae 100644 --- a/bootstrap/unix-44/OPV.c +++ b/bootstrap/unix-44/OPV.c @@ -82,7 +82,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = typ->BaseTyp; if (btyp == NIL) { offset = 0; - base = OPM_RecAlign; + base = OPC_SizeAlignment(OPM_RecSize); } else { OPV_TypSize(btyp); offset = btyp->size - (LONGINT)__ASHR(btyp->sysflag, 8); @@ -93,7 +93,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = fld->typ; OPV_TypSize(btyp); size = btyp->size; - fbase = OPC_Base(btyp); + fbase = OPC_BaseAlignment(btyp); OPC_Align(&offset, fbase); fld->adr = offset; offset += size; @@ -107,7 +107,7 @@ void OPV_TypSize (OPT_Struct typ) offset = 1; } if (OPM_RecSize == 0) { - base = OPV_NaturalAlignment(offset, OPM_RecAlign); + base = OPV_NaturalAlignment(offset, OPC_SizeAlignment(OPM_RecSize)); } OPC_Align(&offset, base); if ((typ->strobj == NIL && __MASK(typ->align, -65536) == 0)) { @@ -491,7 +491,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -507,7 +507,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxSInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -795,7 +795,7 @@ static void OPV_ActualPar (OPT_Node n, OPT_Object fp) } if ((((mode == 2 && n->class == 11)) && n->subcl == 29)) { OPV_expr(n->left, prec); - } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_MaxInt)) && n->conval->intval >= OPM_MinInt)) { + } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_SignedMaximum(OPM_IntSize))) && n->conval->intval >= OPM_SignedMinimum(OPM_IntSize))) { OPM_WriteString((CHAR*)"((LONGINT)(", (LONGINT)12); OPV_expr(n, prec); OPM_WriteString((CHAR*)"))", (LONGINT)3); @@ -1322,7 +1322,7 @@ static void OPV_NewArr (OPT_Node d, OPT_Node x) OPM_WriteInt(base->size); OPM_WriteString((CHAR*)"))", (LONGINT)3); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPC_Base(base)); + OPM_WriteInt(OPC_BaseAlignment(base)); OPM_WriteString((CHAR*)", ", (LONGINT)3); OPM_WriteInt(nofdim); OPM_WriteString((CHAR*)", ", (LONGINT)3); diff --git a/bootstrap/unix-48/OPB.c b/bootstrap/unix-48/OPB.c index dcf7d09d..6567ca50 100644 --- a/bootstrap/unix-48/OPB.c +++ b/bootstrap/unix-48/OPB.c @@ -55,8 +55,6 @@ static void OPB_SetIntType (OPT_Node node); export void OPB_SetRange (OPT_Node *x, OPT_Node y); static LONGINT OPB_ShorterSize (LONGINT i); static INTEGER OPB_SignedByteSize (LONGINT n); -static LONGINT OPB_SignedMaximum (LONGINT bytecount); -static LONGINT OPB_SignedMinimum (LONGINT bytecount); export void OPB_StFct (OPT_Node *par0, SHORTINT fctno, INTEGER parno); export void OPB_StPar0 (OPT_Node *par0, INTEGER fctno); export void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno); @@ -226,23 +224,6 @@ OPT_Node OPB_EmptySet (void) return _o_result; } -static LONGINT OPB_SignedMaximum (LONGINT bytecount) -{ - LONGINT _o_result; - LONGINT result; - result = 1; - result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); - _o_result = result - 1; - return _o_result; -} - -static LONGINT OPB_SignedMinimum (LONGINT bytecount) -{ - LONGINT _o_result; - _o_result = -OPB_SignedMaximum(bytecount) - 1; - return _o_result; -} - static INTEGER OPB_SignedByteSize (LONGINT n) { INTEGER _o_result; @@ -448,16 +429,16 @@ void OPB_Field (OPT_Node *x, OPT_Object y) } } -static struct TypTest__63 { +static struct TypTest__61 { OPT_Node *x; OPT_Object *obj; BOOLEAN *guard; - struct TypTest__63 *lnk; -} *TypTest__63_s; + struct TypTest__61 *lnk; +} *TypTest__61_s; -static void GTT__64 (OPT_Struct t0, OPT_Struct t1); +static void GTT__62 (OPT_Struct t0, OPT_Struct t1); -static void GTT__64 (OPT_Struct t0, OPT_Struct t1) +static void GTT__62 (OPT_Struct t0, OPT_Struct t1) { OPT_Node node = NIL; OPT_Struct t = NIL; @@ -470,54 +451,54 @@ static void GTT__64 (OPT_Struct t0, OPT_Struct t1) t1 = t1->BaseTyp; } if (t1 == t0 || t0->form == 0) { - if (*TypTest__63_s->guard) { - OPB_BindNodes(5, NIL, &*TypTest__63_s->x, NIL); - (*TypTest__63_s->x)->readonly = (*TypTest__63_s->x)->left->readonly; + if (*TypTest__61_s->guard) { + OPB_BindNodes(5, NIL, &*TypTest__61_s->x, NIL); + (*TypTest__61_s->x)->readonly = (*TypTest__61_s->x)->left->readonly; } else { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } } else { OPB_err(85); } } else if (t0 != t1) { OPB_err(85); - } else if (!*TypTest__63_s->guard) { - if ((*TypTest__63_s->x)->class == 5) { + } else if (!*TypTest__61_s->guard) { + if ((*TypTest__61_s->x)->class == 5) { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } else { - *TypTest__63_s->x = OPB_NewBoolConst(1); + *TypTest__61_s->x = OPB_NewBoolConst(1); } } } void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) { - struct TypTest__63 _s; + struct TypTest__61 _s; _s.x = x; _s.obj = &obj; _s.guard = &guard; - _s.lnk = TypTest__63_s; - TypTest__63_s = &_s; + _s.lnk = TypTest__61_s; + TypTest__61_s = &_s; if (OPB_NotVar(*x)) { OPB_err(112); } else if ((*x)->typ->form == 13) { if (((*x)->typ->BaseTyp->comp != 4 && (*x)->typ != OPT_sysptrtyp)) { OPB_err(85); } else if (obj->typ->form == 13) { - GTT__64((*x)->typ->BaseTyp, obj->typ->BaseTyp); + GTT__62((*x)->typ->BaseTyp, obj->typ->BaseTyp); } else { OPB_err(86); } } else if (((((*x)->typ->comp == 4 && (*x)->class == 1)) && obj->typ->comp == 4)) { - GTT__64((*x)->typ, obj->typ); + GTT__62((*x)->typ, obj->typ); } else { OPB_err(87); } @@ -526,7 +507,7 @@ void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) } else { (*x)->typ = OPT_booltyp; } - TypTest__63_s = _s.lnk; + TypTest__61_s = _s.lnk; } void OPB_In (OPT_Node *x, OPT_Node y) @@ -1849,7 +1830,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMinimum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMinimum(x->typ->size)); break; case 9: x = OPB_NewIntConst(((LONGINT)(0))); @@ -1880,7 +1861,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMaximum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMaximum(x->typ->size)); break; case 9: x = OPB_NewIntConst(OPM_MaxSet); @@ -2062,13 +2043,13 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) *par0 = x; } -static struct StPar1__58 { - struct StPar1__58 *lnk; -} *StPar1__58_s; +static struct StPar1__56 { + struct StPar1__56 *lnk; +} *StPar1__56_s; -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) { OPT_Node _o_result; OPT_Node node = NIL; @@ -2085,9 +2066,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) INTEGER f, L; OPT_Struct typ = NIL; OPT_Node p = NIL, t = NIL; - struct StPar1__58 _s; - _s.lnk = StPar1__58_s; - StPar1__58_s = &_s; + struct StPar1__56 _s; + _s.lnk = StPar1__56_s; + StPar1__56_s = &_s; p = *par0; f = x->typ->form; switch (fctno) { @@ -2103,7 +2084,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); p->typ = OPT_notyp; } break; @@ -2114,7 +2095,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if ((x->class == 7 && (0 > x->conval->intval || x->conval->intval > (LONGINT)OPM_MaxSet))) { OPB_err(202); } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2139,7 +2120,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) p = p->left; x->conval->intval += 1; } - p = NewOp__59(12, 19, p, x); + p = NewOp__57(12, 19, p, x); p->typ = OPT_linttyp; } else { p = x; @@ -2161,7 +2142,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) t = x; x = p; p = t; - p = NewOp__59(19, 18, p, x); + p = NewOp__57(19, 18, p, x); } else { OPB_err(111); } @@ -2187,7 +2168,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) } p->obj = NIL; } else { - p = NewOp__59(12, 17, p, x); + p = NewOp__57(12, 17, p, x); p->typ = OPT_linttyp; } } else { @@ -2218,9 +2199,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } else { if (fctno == 22) { - p = NewOp__59(12, 27, p, x); + p = NewOp__57(12, 27, p, x); } else { - p = NewOp__59(12, 28, p, x); + p = NewOp__57(12, 28, p, x); } p->typ = p->left->typ; } @@ -2237,7 +2218,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) x = p; p = t; } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2247,7 +2228,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(12, 26, p, x); + p = NewOp__57(12, 26, p, x); } else { OPB_err(111); } @@ -2271,7 +2252,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(19, 30, p, x); + p = NewOp__57(19, 30, p, x); } else { OPB_err(111); } @@ -2317,7 +2298,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) break; } *par0 = p; - StPar1__58_s = _s.lnk; + StPar1__56_s = _s.lnk; } void OPB_StParN (OPT_Node *par0, OPT_Node x, INTEGER fctno, INTEGER n) diff --git a/bootstrap/unix-48/OPC.c b/bootstrap/unix-48/OPC.c index 2efc2010..7ce3cbe5 100644 --- a/bootstrap/unix-48/OPC.c +++ b/bootstrap/unix-48/OPC.c @@ -16,7 +16,7 @@ static CHAR OPC_BodyNameExt[13]; export void OPC_Align (LONGINT *adr, LONGINT base); export void OPC_Andent (OPT_Struct typ); static void OPC_AnsiParamList (OPT_Object obj, BOOLEAN showParamNames); -export LONGINT OPC_Base (OPT_Struct typ); +export LONGINT OPC_BaseAlignment (OPT_Struct typ); export OPT_Object OPC_BaseTProc (OPT_Object obj); export void OPC_BegBlk (void); export void OPC_BegStat (void); @@ -74,6 +74,7 @@ static void OPC_PutBase (OPT_Struct typ); static void OPC_PutPtrOffsets (OPT_Struct typ, LONGINT adr, LONGINT *cnt); static void OPC_RegCmds (OPT_Object obj); export void OPC_SetInclude (BOOLEAN exclude); +export LONGINT OPC_SizeAlignment (LONGINT size); static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause); static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x); static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l); @@ -867,70 +868,37 @@ void OPC_Align (LONGINT *adr, LONGINT base) } } -LONGINT OPC_Base (OPT_Struct typ) +LONGINT OPC_SizeAlignment (LONGINT size) { LONGINT _o_result; - switch (typ->form) { - case 1: - _o_result = 1; - return _o_result; - break; - case 3: - _o_result = OPM_CharAlign; - return _o_result; - break; - case 2: - _o_result = OPM_BoolAlign; - return _o_result; - break; - case 4: - _o_result = OPM_SIntAlign; - return _o_result; - break; - case 5: - _o_result = OPM_IntAlign; - return _o_result; - break; - case 6: - _o_result = OPM_LIntAlign; - return _o_result; - break; - case 7: - _o_result = OPM_RealAlign; - return _o_result; - break; - case 8: - _o_result = OPM_LRealAlign; - return _o_result; - break; - case 9: - _o_result = OPM_SetAlign; - return _o_result; - break; - case 13: - _o_result = OPM_PointerAlign; - return _o_result; - break; - case 14: - _o_result = OPM_ProcAlign; - return _o_result; - break; - case 15: - if (typ->comp == 4) { - _o_result = __MASK(typ->align, -65536); - return _o_result; - } else { - _o_result = OPC_Base(typ->BaseTyp); - return _o_result; - } - break; - default: - OPM_LogWStr((CHAR*)"unhandled case in OPC.Base, typ^form = ", (LONGINT)40); - OPM_LogWNum(typ->form, ((LONGINT)(0))); - OPM_LogWLn(); - break; + LONGINT alignment; + if (size < (LONGINT)OPM_Alignment) { + alignment = 1; + while (alignment < size) { + alignment = __ASHL(alignment, 1); + } + } else { + alignment = OPM_Alignment; } - __RETCHK; + _o_result = alignment; + return _o_result; +} + +LONGINT OPC_BaseAlignment (OPT_Struct typ) +{ + LONGINT _o_result; + LONGINT alignment; + if (typ->form == 15) { + if (typ->comp == 4) { + alignment = __MASK(typ->align, -65536); + } else { + alignment = OPC_BaseAlignment(typ->BaseTyp); + } + } else { + alignment = OPC_SizeAlignment(typ->size); + } + _o_result = alignment; + return _o_result; } static void OPC_FillGap (LONGINT gap, LONGINT off, LONGINT align, LONGINT *n, LONGINT *curAlign) @@ -984,7 +952,7 @@ static void OPC_FieldList (OPT_Struct typ, BOOLEAN last, LONGINT *off, LONGINT * } } else { adr = *off; - fldAlign = OPC_Base(fld->typ); + fldAlign = OPC_BaseAlignment(fld->typ); OPC_Align(&adr, fldAlign); gap = fld->adr - adr; if (fldAlign > *curAlign) { diff --git a/bootstrap/unix-48/OPC.h b/bootstrap/unix-48/OPC.h index ac61a9a4..8786c7c6 100644 --- a/bootstrap/unix-48/OPC.h +++ b/bootstrap/unix-48/OPC.h @@ -11,7 +11,7 @@ import void OPC_Align (LONGINT *adr, LONGINT base); import void OPC_Andent (OPT_Struct typ); -import LONGINT OPC_Base (OPT_Struct typ); +import LONGINT OPC_BaseAlignment (OPT_Struct typ); import OPT_Object OPC_BaseTProc (OPT_Object obj); import void OPC_BegBlk (void); import void OPC_BegStat (void); @@ -40,6 +40,7 @@ import void OPC_InitTDesc (OPT_Struct typ); import void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim); import LONGINT OPC_NofPtrs (OPT_Struct typ); import void OPC_SetInclude (BOOLEAN exclude); +import LONGINT OPC_SizeAlignment (LONGINT size); import void OPC_TDescDecl (OPT_Struct typ); import void OPC_TypeDefs (OPT_Object obj, INTEGER vis); import void OPC_TypeOf (OPT_Object ap); diff --git a/bootstrap/unix-48/OPM.c b/bootstrap/unix-48/OPM.c index fc316318..4bdc065f 100644 --- a/bootstrap/unix-48/OPM.c +++ b/bootstrap/unix-48/OPM.c @@ -14,8 +14,8 @@ typedef static CHAR OPM_SourceFileName[256]; -export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -export LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +export LONGINT OPM_MaxIndex; export LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; export BOOLEAN OPM_noerr; export LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -36,7 +36,6 @@ static CHAR OPM_OBERON[1024]; static CHAR OPM_MODULES[1024]; -export INTEGER OPM_AlignSize (LONGINT size); static void OPM_Append (Files_Rider *R, LONGINT *R__typ, Files_File F); export void OPM_CloseFiles (void); export void OPM_CloseOldSym (void); @@ -65,6 +64,8 @@ export BOOLEAN OPM_OpenPar (void); export void OPM_RegisterNewSym (void); static void OPM_ScanOptions (CHAR *s, LONGINT s__len, SET *opt); static void OPM_ShowLine (LONGINT pos); +export LONGINT OPM_SignedMaximum (LONGINT bytecount); +export LONGINT OPM_SignedMinimum (LONGINT bytecount); export void OPM_SymRCh (CHAR *ch); export LONGINT OPM_SymRInt (void); export void OPM_SymRLReal (LONGREAL *lr); @@ -607,111 +608,62 @@ static void OPM_VerboseListSizes (void) OPM_LogWLn(); OPM_LogWStr((CHAR*)"CHAR ", (LONGINT)14); OPM_LogWNum(OPM_CharSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_CharAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"BOOLEAN ", (LONGINT)14); OPM_LogWNum(OPM_BoolSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_BoolAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SHORTINT ", (LONGINT)14); OPM_LogWNum(OPM_SIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"INTEGER ", (LONGINT)14); OPM_LogWNum(OPM_IntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_IntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGINT ", (LONGINT)14); OPM_LogWNum(OPM_LIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SET ", (LONGINT)14); OPM_LogWNum(OPM_SetSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SetAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"REAL ", (LONGINT)14); OPM_LogWNum(OPM_RealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGREAL ", (LONGINT)14); OPM_LogWNum(OPM_LRealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LRealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PTR ", (LONGINT)14); OPM_LogWNum(OPM_PointerSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_PointerAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PROC ", (LONGINT)14); OPM_LogWNum(OPM_ProcSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_ProcAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"RECORD ", (LONGINT)14); OPM_LogWNum(OPM_RecSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RecAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MinSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MaxSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min integer ", (LONGINT)14); - OPM_LogWNum(OPM_MinInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max integer ", (LONGINT)14); - OPM_LogWNum(OPM_MaxInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min longint ", (LONGINT)14); - OPM_LogWNum(OPM_MinLInt, ((LONGINT)(4))); - OPM_LogWLn(); } -INTEGER OPM_AlignSize (LONGINT size) +LONGINT OPM_SignedMaximum (LONGINT bytecount) { - INTEGER _o_result; - INTEGER align; - if (size < (LONGINT)OPM_Alignment) { - if (size > 8) { - align = 16; - } else if (size > 4) { - align = 8; - } else if (size > 2) { - align = 4; - } else { - align = (int)size; - } - } else { - align = OPM_Alignment; - } - _o_result = align; + LONGINT _o_result; + LONGINT result; + result = 1; + result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); + _o_result = result - 1; + return _o_result; +} + +LONGINT OPM_SignedMinimum (LONGINT bytecount) +{ + LONGINT _o_result; + _o_result = -OPM_SignedMaximum(bytecount) - 1; return _o_result; } static void OPM_GetProperties (void) { - LONGINT base; OPM_ProcSize = OPM_PointerSize; OPM_LIntSize = __ASHL(OPM_IntSize, 1); OPM_SetSize = OPM_LIntSize; - OPM_CharAlign = OPM_AlignSize(OPM_CharSize); - OPM_BoolAlign = OPM_AlignSize(OPM_BoolSize); - OPM_SIntAlign = OPM_AlignSize(OPM_SIntSize); - OPM_RecAlign = OPM_AlignSize(OPM_RecSize); - OPM_RealAlign = OPM_AlignSize(OPM_RealSize); - OPM_LRealAlign = OPM_AlignSize(OPM_LRealSize); - OPM_PointerAlign = OPM_AlignSize(OPM_PointerSize); - OPM_ProcAlign = OPM_AlignSize(OPM_ProcSize); - OPM_IntAlign = OPM_AlignSize(OPM_IntSize); - OPM_LIntAlign = OPM_AlignSize(OPM_LIntSize); - OPM_SetAlign = OPM_AlignSize(OPM_SetSize); - base = -2; - OPM_MinSInt = __ASH(base, __ASHL(OPM_SIntSize, 3) - 2); - OPM_MaxSInt = OPM_minusop(OPM_MinSInt + 1); - OPM_MinInt = __ASH(base, __ASHL(OPM_IntSize, 3) - 2); - OPM_MaxInt = OPM_minusop(OPM_MinInt + 1); - OPM_MinLInt = __ASH(base, __ASHL(OPM_LIntSize, 3) - 2); - OPM_MaxLInt = OPM_minusop(OPM_MinLInt + 1); if (OPM_RealSize == 4) { OPM_MaxReal = 3.40282346000000e+038; } else if (OPM_RealSize == 8) { @@ -725,7 +677,7 @@ static void OPM_GetProperties (void) OPM_MinReal = -OPM_MaxReal; OPM_MinLReal = -OPM_MaxLReal; OPM_MaxSet = __ASHL(OPM_SetSize, 3) - 1; - OPM_MaxIndex = OPM_MaxLInt; + OPM_MaxIndex = OPM_SignedMaximum(OPM_PointerSize); if (OPM_Verbose) { OPM_VerboseListSizes(); } @@ -887,7 +839,7 @@ void OPM_WriteInt (LONGINT i) { CHAR s[20]; LONGINT i1, k; - if (i == OPM_MinInt || i == OPM_MinLInt) { + if (i == OPM_SignedMinimum(OPM_IntSize) || i == OPM_SignedMinimum(OPM_LIntSize)) { OPM_Write('('); OPM_WriteInt(i + 1); OPM_WriteString((CHAR*)"-1)", (LONGINT)4); @@ -920,7 +872,7 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_MaxLInt && r > OPM_MinLInt)) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { diff --git a/bootstrap/unix-48/OPM.h b/bootstrap/unix-48/OPM.h index ec53cacf..5f8cc38c 100644 --- a/bootstrap/unix-48/OPM.h +++ b/bootstrap/unix-48/OPM.h @@ -6,8 +6,8 @@ #include "SYSTEM.h" -import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -import LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +import LONGINT OPM_MaxIndex; import LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; import BOOLEAN OPM_noerr; import LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -18,7 +18,6 @@ import SET OPM_opt, OPM_glbopt; import BOOLEAN OPM_dontAsm, OPM_dontLink, OPM_mainProg, OPM_mainLinkStat, OPM_notColorOutput, OPM_forceNewSym, OPM_Verbose; -import INTEGER OPM_AlignSize (LONGINT size); import void OPM_CloseFiles (void); import void OPM_CloseOldSym (void); import void OPM_DeleteNewSym (void); @@ -39,6 +38,8 @@ import void OPM_OldSym (CHAR *modName, LONGINT modName__len, BOOLEAN *done); import void OPM_OpenFiles (CHAR *moduleName, LONGINT moduleName__len); import BOOLEAN OPM_OpenPar (void); import void OPM_RegisterNewSym (void); +import LONGINT OPM_SignedMaximum (LONGINT bytecount); +import LONGINT OPM_SignedMinimum (LONGINT bytecount); import void OPM_SymRCh (CHAR *ch); import LONGINT OPM_SymRInt (void); import void OPM_SymRLReal (LONGREAL *lr); diff --git a/bootstrap/unix-48/OPV.c b/bootstrap/unix-48/OPV.c index 961c5e11..50f58fae 100644 --- a/bootstrap/unix-48/OPV.c +++ b/bootstrap/unix-48/OPV.c @@ -82,7 +82,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = typ->BaseTyp; if (btyp == NIL) { offset = 0; - base = OPM_RecAlign; + base = OPC_SizeAlignment(OPM_RecSize); } else { OPV_TypSize(btyp); offset = btyp->size - (LONGINT)__ASHR(btyp->sysflag, 8); @@ -93,7 +93,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = fld->typ; OPV_TypSize(btyp); size = btyp->size; - fbase = OPC_Base(btyp); + fbase = OPC_BaseAlignment(btyp); OPC_Align(&offset, fbase); fld->adr = offset; offset += size; @@ -107,7 +107,7 @@ void OPV_TypSize (OPT_Struct typ) offset = 1; } if (OPM_RecSize == 0) { - base = OPV_NaturalAlignment(offset, OPM_RecAlign); + base = OPV_NaturalAlignment(offset, OPC_SizeAlignment(OPM_RecSize)); } OPC_Align(&offset, base); if ((typ->strobj == NIL && __MASK(typ->align, -65536) == 0)) { @@ -491,7 +491,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -507,7 +507,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxSInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -795,7 +795,7 @@ static void OPV_ActualPar (OPT_Node n, OPT_Object fp) } if ((((mode == 2 && n->class == 11)) && n->subcl == 29)) { OPV_expr(n->left, prec); - } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_MaxInt)) && n->conval->intval >= OPM_MinInt)) { + } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_SignedMaximum(OPM_IntSize))) && n->conval->intval >= OPM_SignedMinimum(OPM_IntSize))) { OPM_WriteString((CHAR*)"((LONGINT)(", (LONGINT)12); OPV_expr(n, prec); OPM_WriteString((CHAR*)"))", (LONGINT)3); @@ -1322,7 +1322,7 @@ static void OPV_NewArr (OPT_Node d, OPT_Node x) OPM_WriteInt(base->size); OPM_WriteString((CHAR*)"))", (LONGINT)3); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPC_Base(base)); + OPM_WriteInt(OPC_BaseAlignment(base)); OPM_WriteString((CHAR*)", ", (LONGINT)3); OPM_WriteInt(nofdim); OPM_WriteString((CHAR*)", ", (LONGINT)3); diff --git a/bootstrap/unix-88/OPB.c b/bootstrap/unix-88/OPB.c index 514304bd..73daf26e 100644 --- a/bootstrap/unix-88/OPB.c +++ b/bootstrap/unix-88/OPB.c @@ -56,8 +56,6 @@ static void OPB_SetIntType (OPT_Node node); export void OPB_SetRange (OPT_Node *x, OPT_Node y); static LONGINT OPB_ShorterSize (LONGINT i); static INTEGER OPB_SignedByteSize (LONGINT n); -static LONGINT OPB_SignedMaximum (LONGINT bytecount); -static LONGINT OPB_SignedMinimum (LONGINT bytecount); export void OPB_StFct (OPT_Node *par0, SHORTINT fctno, INTEGER parno); export void OPB_StPar0 (OPT_Node *par0, INTEGER fctno); export void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno); @@ -227,23 +225,6 @@ OPT_Node OPB_EmptySet (void) return _o_result; } -static LONGINT OPB_SignedMaximum (LONGINT bytecount) -{ - LONGINT _o_result; - LONGINT result; - result = 1; - result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); - _o_result = result - 1; - return _o_result; -} - -static LONGINT OPB_SignedMinimum (LONGINT bytecount) -{ - LONGINT _o_result; - _o_result = -OPB_SignedMaximum(bytecount) - 1; - return _o_result; -} - static INTEGER OPB_SignedByteSize (LONGINT n) { INTEGER _o_result; @@ -449,16 +430,16 @@ void OPB_Field (OPT_Node *x, OPT_Object y) } } -static struct TypTest__63 { +static struct TypTest__61 { OPT_Node *x; OPT_Object *obj; BOOLEAN *guard; - struct TypTest__63 *lnk; -} *TypTest__63_s; + struct TypTest__61 *lnk; +} *TypTest__61_s; -static void GTT__64 (OPT_Struct t0, OPT_Struct t1); +static void GTT__62 (OPT_Struct t0, OPT_Struct t1); -static void GTT__64 (OPT_Struct t0, OPT_Struct t1) +static void GTT__62 (OPT_Struct t0, OPT_Struct t1) { OPT_Node node = NIL; OPT_Struct t = NIL; @@ -471,54 +452,54 @@ static void GTT__64 (OPT_Struct t0, OPT_Struct t1) t1 = t1->BaseTyp; } if (t1 == t0 || t0->form == 0) { - if (*TypTest__63_s->guard) { - OPB_BindNodes(5, NIL, &*TypTest__63_s->x, NIL); - (*TypTest__63_s->x)->readonly = (*TypTest__63_s->x)->left->readonly; + if (*TypTest__61_s->guard) { + OPB_BindNodes(5, NIL, &*TypTest__61_s->x, NIL); + (*TypTest__61_s->x)->readonly = (*TypTest__61_s->x)->left->readonly; } else { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } } else { OPB_err(85); } } else if (t0 != t1) { OPB_err(85); - } else if (!*TypTest__63_s->guard) { - if ((*TypTest__63_s->x)->class == 5) { + } else if (!*TypTest__61_s->guard) { + if ((*TypTest__61_s->x)->class == 5) { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } else { - *TypTest__63_s->x = OPB_NewBoolConst(1); + *TypTest__61_s->x = OPB_NewBoolConst(1); } } } void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) { - struct TypTest__63 _s; + struct TypTest__61 _s; _s.x = x; _s.obj = &obj; _s.guard = &guard; - _s.lnk = TypTest__63_s; - TypTest__63_s = &_s; + _s.lnk = TypTest__61_s; + TypTest__61_s = &_s; if (OPB_NotVar(*x)) { OPB_err(112); } else if ((*x)->typ->form == 13) { if (((*x)->typ->BaseTyp->comp != 4 && (*x)->typ != OPT_sysptrtyp)) { OPB_err(85); } else if (obj->typ->form == 13) { - GTT__64((*x)->typ->BaseTyp, obj->typ->BaseTyp); + GTT__62((*x)->typ->BaseTyp, obj->typ->BaseTyp); } else { OPB_err(86); } } else if (((((*x)->typ->comp == 4 && (*x)->class == 1)) && obj->typ->comp == 4)) { - GTT__64((*x)->typ, obj->typ); + GTT__62((*x)->typ, obj->typ); } else { OPB_err(87); } @@ -527,7 +508,7 @@ void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) } else { (*x)->typ = OPT_booltyp; } - TypTest__63_s = _s.lnk; + TypTest__61_s = _s.lnk; } void OPB_In (OPT_Node *x, OPT_Node y) @@ -1850,7 +1831,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMinimum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMinimum(x->typ->size)); break; case 9: x = OPB_NewIntConst(((LONGINT)(0))); @@ -1881,7 +1862,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMaximum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMaximum(x->typ->size)); break; case 9: x = OPB_NewIntConst(OPM_MaxSet); @@ -2063,13 +2044,13 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) *par0 = x; } -static struct StPar1__58 { - struct StPar1__58 *lnk; -} *StPar1__58_s; +static struct StPar1__56 { + struct StPar1__56 *lnk; +} *StPar1__56_s; -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) { OPT_Node _o_result; OPT_Node node = NIL; @@ -2086,9 +2067,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) INTEGER f, L; OPT_Struct typ = NIL; OPT_Node p = NIL, t = NIL; - struct StPar1__58 _s; - _s.lnk = StPar1__58_s; - StPar1__58_s = &_s; + struct StPar1__56 _s; + _s.lnk = StPar1__56_s; + StPar1__56_s = &_s; p = *par0; f = x->typ->form; switch (fctno) { @@ -2104,7 +2085,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); p->typ = OPT_notyp; } break; @@ -2115,7 +2096,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if ((x->class == 7 && (0 > x->conval->intval || x->conval->intval > (LONGINT)OPM_MaxSet))) { OPB_err(202); } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2140,7 +2121,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) p = p->left; x->conval->intval += 1; } - p = NewOp__59(12, 19, p, x); + p = NewOp__57(12, 19, p, x); p->typ = OPT_linttyp; } else { p = x; @@ -2162,7 +2143,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) t = x; x = p; p = t; - p = NewOp__59(19, 18, p, x); + p = NewOp__57(19, 18, p, x); } else { OPB_err(111); } @@ -2188,7 +2169,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) } p->obj = NIL; } else { - p = NewOp__59(12, 17, p, x); + p = NewOp__57(12, 17, p, x); p->typ = OPT_linttyp; } } else { @@ -2219,9 +2200,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } else { if (fctno == 22) { - p = NewOp__59(12, 27, p, x); + p = NewOp__57(12, 27, p, x); } else { - p = NewOp__59(12, 28, p, x); + p = NewOp__57(12, 28, p, x); } p->typ = p->left->typ; } @@ -2238,7 +2219,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) x = p; p = t; } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2248,7 +2229,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(12, 26, p, x); + p = NewOp__57(12, 26, p, x); } else { OPB_err(111); } @@ -2272,7 +2253,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(19, 30, p, x); + p = NewOp__57(19, 30, p, x); } else { OPB_err(111); } @@ -2318,7 +2299,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) break; } *par0 = p; - StPar1__58_s = _s.lnk; + StPar1__56_s = _s.lnk; } void OPB_StParN (OPT_Node *par0, OPT_Node x, INTEGER fctno, INTEGER n) diff --git a/bootstrap/unix-88/OPC.c b/bootstrap/unix-88/OPC.c index b286807f..b74145a7 100644 --- a/bootstrap/unix-88/OPC.c +++ b/bootstrap/unix-88/OPC.c @@ -17,7 +17,7 @@ static CHAR OPC_BodyNameExt[13]; export void OPC_Align (LONGINT *adr, LONGINT base); export void OPC_Andent (OPT_Struct typ); static void OPC_AnsiParamList (OPT_Object obj, BOOLEAN showParamNames); -export LONGINT OPC_Base (OPT_Struct typ); +export LONGINT OPC_BaseAlignment (OPT_Struct typ); export OPT_Object OPC_BaseTProc (OPT_Object obj); export void OPC_BegBlk (void); export void OPC_BegStat (void); @@ -75,6 +75,7 @@ static void OPC_PutBase (OPT_Struct typ); static void OPC_PutPtrOffsets (OPT_Struct typ, LONGINT adr, LONGINT *cnt); static void OPC_RegCmds (OPT_Object obj); export void OPC_SetInclude (BOOLEAN exclude); +export LONGINT OPC_SizeAlignment (LONGINT size); static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause); static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x); static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l); @@ -868,70 +869,37 @@ void OPC_Align (LONGINT *adr, LONGINT base) } } -LONGINT OPC_Base (OPT_Struct typ) +LONGINT OPC_SizeAlignment (LONGINT size) { LONGINT _o_result; - switch (typ->form) { - case 1: - _o_result = 1; - return _o_result; - break; - case 3: - _o_result = OPM_CharAlign; - return _o_result; - break; - case 2: - _o_result = OPM_BoolAlign; - return _o_result; - break; - case 4: - _o_result = OPM_SIntAlign; - return _o_result; - break; - case 5: - _o_result = OPM_IntAlign; - return _o_result; - break; - case 6: - _o_result = OPM_LIntAlign; - return _o_result; - break; - case 7: - _o_result = OPM_RealAlign; - return _o_result; - break; - case 8: - _o_result = OPM_LRealAlign; - return _o_result; - break; - case 9: - _o_result = OPM_SetAlign; - return _o_result; - break; - case 13: - _o_result = OPM_PointerAlign; - return _o_result; - break; - case 14: - _o_result = OPM_ProcAlign; - return _o_result; - break; - case 15: - if (typ->comp == 4) { - _o_result = __MASK(typ->align, -65536); - return _o_result; - } else { - _o_result = OPC_Base(typ->BaseTyp); - return _o_result; - } - break; - default: - OPM_LogWStr((CHAR*)"unhandled case in OPC.Base, typ^form = ", (LONGINT)40); - OPM_LogWNum(typ->form, ((LONGINT)(0))); - OPM_LogWLn(); - break; + LONGINT alignment; + if (size < (LONGINT)OPM_Alignment) { + alignment = 1; + while (alignment < size) { + alignment = __ASHL(alignment, 1); + } + } else { + alignment = OPM_Alignment; } - __RETCHK; + _o_result = alignment; + return _o_result; +} + +LONGINT OPC_BaseAlignment (OPT_Struct typ) +{ + LONGINT _o_result; + LONGINT alignment; + if (typ->form == 15) { + if (typ->comp == 4) { + alignment = __MASK(typ->align, -65536); + } else { + alignment = OPC_BaseAlignment(typ->BaseTyp); + } + } else { + alignment = OPC_SizeAlignment(typ->size); + } + _o_result = alignment; + return _o_result; } static void OPC_FillGap (LONGINT gap, LONGINT off, LONGINT align, LONGINT *n, LONGINT *curAlign) @@ -985,7 +953,7 @@ static void OPC_FieldList (OPT_Struct typ, BOOLEAN last, LONGINT *off, LONGINT * } } else { adr = *off; - fldAlign = OPC_Base(fld->typ); + fldAlign = OPC_BaseAlignment(fld->typ); OPC_Align(&adr, fldAlign); gap = fld->adr - adr; if (fldAlign > *curAlign) { diff --git a/bootstrap/unix-88/OPC.h b/bootstrap/unix-88/OPC.h index 1b09dedc..525240c8 100644 --- a/bootstrap/unix-88/OPC.h +++ b/bootstrap/unix-88/OPC.h @@ -12,7 +12,7 @@ import void OPC_Align (LONGINT *adr, LONGINT base); import void OPC_Andent (OPT_Struct typ); -import LONGINT OPC_Base (OPT_Struct typ); +import LONGINT OPC_BaseAlignment (OPT_Struct typ); import OPT_Object OPC_BaseTProc (OPT_Object obj); import void OPC_BegBlk (void); import void OPC_BegStat (void); @@ -41,6 +41,7 @@ import void OPC_InitTDesc (OPT_Struct typ); import void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim); import LONGINT OPC_NofPtrs (OPT_Struct typ); import void OPC_SetInclude (BOOLEAN exclude); +import LONGINT OPC_SizeAlignment (LONGINT size); import void OPC_TDescDecl (OPT_Struct typ); import void OPC_TypeDefs (OPT_Object obj, INTEGER vis); import void OPC_TypeOf (OPT_Object ap); diff --git a/bootstrap/unix-88/OPM.c b/bootstrap/unix-88/OPM.c index 27de68da..1517e019 100644 --- a/bootstrap/unix-88/OPM.c +++ b/bootstrap/unix-88/OPM.c @@ -15,8 +15,8 @@ typedef static CHAR OPM_SourceFileName[256]; -export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -export LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +export LONGINT OPM_MaxIndex; export LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; export BOOLEAN OPM_noerr; export LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -37,7 +37,6 @@ static CHAR OPM_OBERON[1024]; static CHAR OPM_MODULES[1024]; -export INTEGER OPM_AlignSize (LONGINT size); static void OPM_Append (Files_Rider *R, LONGINT *R__typ, Files_File F); export void OPM_CloseFiles (void); export void OPM_CloseOldSym (void); @@ -66,6 +65,8 @@ export BOOLEAN OPM_OpenPar (void); export void OPM_RegisterNewSym (void); static void OPM_ScanOptions (CHAR *s, LONGINT s__len, SET *opt); static void OPM_ShowLine (LONGINT pos); +export LONGINT OPM_SignedMaximum (LONGINT bytecount); +export LONGINT OPM_SignedMinimum (LONGINT bytecount); export void OPM_SymRCh (CHAR *ch); export LONGINT OPM_SymRInt (void); export void OPM_SymRLReal (LONGREAL *lr); @@ -606,111 +607,62 @@ static void OPM_VerboseListSizes (void) OPM_LogWLn(); OPM_LogWStr((CHAR*)"CHAR ", (LONGINT)14); OPM_LogWNum(OPM_CharSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_CharAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"BOOLEAN ", (LONGINT)14); OPM_LogWNum(OPM_BoolSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_BoolAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SHORTINT ", (LONGINT)14); OPM_LogWNum(OPM_SIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"INTEGER ", (LONGINT)14); OPM_LogWNum(OPM_IntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_IntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGINT ", (LONGINT)14); OPM_LogWNum(OPM_LIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SET ", (LONGINT)14); OPM_LogWNum(OPM_SetSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SetAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"REAL ", (LONGINT)14); OPM_LogWNum(OPM_RealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGREAL ", (LONGINT)14); OPM_LogWNum(OPM_LRealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LRealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PTR ", (LONGINT)14); OPM_LogWNum(OPM_PointerSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_PointerAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PROC ", (LONGINT)14); OPM_LogWNum(OPM_ProcSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_ProcAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"RECORD ", (LONGINT)14); OPM_LogWNum(OPM_RecSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RecAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MinSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MaxSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min integer ", (LONGINT)14); - OPM_LogWNum(OPM_MinInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max integer ", (LONGINT)14); - OPM_LogWNum(OPM_MaxInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min longint ", (LONGINT)14); - OPM_LogWNum(OPM_MinLInt, ((LONGINT)(4))); - OPM_LogWLn(); } -INTEGER OPM_AlignSize (LONGINT size) +LONGINT OPM_SignedMaximum (LONGINT bytecount) { - INTEGER _o_result; - INTEGER align; - if (size < (LONGINT)OPM_Alignment) { - if (size > 8) { - align = 16; - } else if (size > 4) { - align = 8; - } else if (size > 2) { - align = 4; - } else { - align = (int)size; - } - } else { - align = OPM_Alignment; - } - _o_result = align; + LONGINT _o_result; + LONGINT result; + result = 1; + result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); + _o_result = result - 1; + return _o_result; +} + +LONGINT OPM_SignedMinimum (LONGINT bytecount) +{ + LONGINT _o_result; + _o_result = -OPM_SignedMaximum(bytecount) - 1; return _o_result; } static void OPM_GetProperties (void) { - LONGINT base; OPM_ProcSize = OPM_PointerSize; OPM_LIntSize = __ASHL(OPM_IntSize, 1); OPM_SetSize = OPM_LIntSize; - OPM_CharAlign = OPM_AlignSize(OPM_CharSize); - OPM_BoolAlign = OPM_AlignSize(OPM_BoolSize); - OPM_SIntAlign = OPM_AlignSize(OPM_SIntSize); - OPM_RecAlign = OPM_AlignSize(OPM_RecSize); - OPM_RealAlign = OPM_AlignSize(OPM_RealSize); - OPM_LRealAlign = OPM_AlignSize(OPM_LRealSize); - OPM_PointerAlign = OPM_AlignSize(OPM_PointerSize); - OPM_ProcAlign = OPM_AlignSize(OPM_ProcSize); - OPM_IntAlign = OPM_AlignSize(OPM_IntSize); - OPM_LIntAlign = OPM_AlignSize(OPM_LIntSize); - OPM_SetAlign = OPM_AlignSize(OPM_SetSize); - base = -2; - OPM_MinSInt = __ASH(base, __ASHL(OPM_SIntSize, 3) - 2); - OPM_MaxSInt = OPM_minusop(OPM_MinSInt + 1); - OPM_MinInt = __ASH(base, __ASHL(OPM_IntSize, 3) - 2); - OPM_MaxInt = OPM_minusop(OPM_MinInt + 1); - OPM_MinLInt = __ASH(base, __ASHL(OPM_LIntSize, 3) - 2); - OPM_MaxLInt = OPM_minusop(OPM_MinLInt + 1); if (OPM_RealSize == 4) { OPM_MaxReal = 3.40282346000000e+038; } else if (OPM_RealSize == 8) { @@ -724,7 +676,7 @@ static void OPM_GetProperties (void) OPM_MinReal = -OPM_MaxReal; OPM_MinLReal = -OPM_MaxLReal; OPM_MaxSet = __ASHL(OPM_SetSize, 3) - 1; - OPM_MaxIndex = OPM_MaxLInt; + OPM_MaxIndex = OPM_SignedMaximum(OPM_PointerSize); if (OPM_Verbose) { OPM_VerboseListSizes(); } @@ -886,7 +838,7 @@ void OPM_WriteInt (LONGINT i) { CHAR s[20]; LONGINT i1, k; - if (i == OPM_MinInt || i == OPM_MinLInt) { + if (i == OPM_SignedMinimum(OPM_IntSize) || i == OPM_SignedMinimum(OPM_LIntSize)) { OPM_Write('('); OPM_WriteInt(i + 1); OPM_WriteString((CHAR*)"-1)", (LONGINT)4); @@ -919,7 +871,7 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_MaxLInt && r > OPM_MinLInt)) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { diff --git a/bootstrap/unix-88/OPM.h b/bootstrap/unix-88/OPM.h index 78d88d0b..db45a834 100644 --- a/bootstrap/unix-88/OPM.h +++ b/bootstrap/unix-88/OPM.h @@ -7,8 +7,8 @@ #include "SYSTEM.h" -import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -import LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +import LONGINT OPM_MaxIndex; import LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; import BOOLEAN OPM_noerr; import LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -19,7 +19,6 @@ import SET OPM_opt, OPM_glbopt; import BOOLEAN OPM_dontAsm, OPM_dontLink, OPM_mainProg, OPM_mainLinkStat, OPM_notColorOutput, OPM_forceNewSym, OPM_Verbose; -import INTEGER OPM_AlignSize (LONGINT size); import void OPM_CloseFiles (void); import void OPM_CloseOldSym (void); import void OPM_DeleteNewSym (void); @@ -40,6 +39,8 @@ import void OPM_OldSym (CHAR *modName, LONGINT modName__len, BOOLEAN *done); import void OPM_OpenFiles (CHAR *moduleName, LONGINT moduleName__len); import BOOLEAN OPM_OpenPar (void); import void OPM_RegisterNewSym (void); +import LONGINT OPM_SignedMaximum (LONGINT bytecount); +import LONGINT OPM_SignedMinimum (LONGINT bytecount); import void OPM_SymRCh (CHAR *ch); import LONGINT OPM_SymRInt (void); import void OPM_SymRLReal (LONGREAL *lr); diff --git a/bootstrap/unix-88/OPV.c b/bootstrap/unix-88/OPV.c index 5c482eb4..2632d95e 100644 --- a/bootstrap/unix-88/OPV.c +++ b/bootstrap/unix-88/OPV.c @@ -83,7 +83,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = typ->BaseTyp; if (btyp == NIL) { offset = 0; - base = OPM_RecAlign; + base = OPC_SizeAlignment(OPM_RecSize); } else { OPV_TypSize(btyp); offset = btyp->size - (LONGINT)__ASHR(btyp->sysflag, 8); @@ -94,7 +94,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = fld->typ; OPV_TypSize(btyp); size = btyp->size; - fbase = OPC_Base(btyp); + fbase = OPC_BaseAlignment(btyp); OPC_Align(&offset, fbase); fld->adr = offset; offset += size; @@ -108,7 +108,7 @@ void OPV_TypSize (OPT_Struct typ) offset = 1; } if (OPM_RecSize == 0) { - base = OPV_NaturalAlignment(offset, OPM_RecAlign); + base = OPV_NaturalAlignment(offset, OPC_SizeAlignment(OPM_RecSize)); } OPC_Align(&offset, base); if ((typ->strobj == NIL && __MASK(typ->align, -65536) == 0)) { @@ -492,7 +492,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -508,7 +508,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxSInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -796,7 +796,7 @@ static void OPV_ActualPar (OPT_Node n, OPT_Object fp) } if ((((mode == 2 && n->class == 11)) && n->subcl == 29)) { OPV_expr(n->left, prec); - } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_MaxInt)) && n->conval->intval >= OPM_MinInt)) { + } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_SignedMaximum(OPM_IntSize))) && n->conval->intval >= OPM_SignedMinimum(OPM_IntSize))) { OPM_WriteString((CHAR*)"((LONGINT)(", (LONGINT)12); OPV_expr(n, prec); OPM_WriteString((CHAR*)"))", (LONGINT)3); @@ -1323,7 +1323,7 @@ static void OPV_NewArr (OPT_Node d, OPT_Node x) OPM_WriteInt(base->size); OPM_WriteString((CHAR*)"))", (LONGINT)3); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPC_Base(base)); + OPM_WriteInt(OPC_BaseAlignment(base)); OPM_WriteString((CHAR*)", ", (LONGINT)3); OPM_WriteInt(nofdim); OPM_WriteString((CHAR*)", ", (LONGINT)3); diff --git a/bootstrap/windows-48/OPB.c b/bootstrap/windows-48/OPB.c index dcf7d09d..6567ca50 100644 --- a/bootstrap/windows-48/OPB.c +++ b/bootstrap/windows-48/OPB.c @@ -55,8 +55,6 @@ static void OPB_SetIntType (OPT_Node node); export void OPB_SetRange (OPT_Node *x, OPT_Node y); static LONGINT OPB_ShorterSize (LONGINT i); static INTEGER OPB_SignedByteSize (LONGINT n); -static LONGINT OPB_SignedMaximum (LONGINT bytecount); -static LONGINT OPB_SignedMinimum (LONGINT bytecount); export void OPB_StFct (OPT_Node *par0, SHORTINT fctno, INTEGER parno); export void OPB_StPar0 (OPT_Node *par0, INTEGER fctno); export void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno); @@ -226,23 +224,6 @@ OPT_Node OPB_EmptySet (void) return _o_result; } -static LONGINT OPB_SignedMaximum (LONGINT bytecount) -{ - LONGINT _o_result; - LONGINT result; - result = 1; - result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); - _o_result = result - 1; - return _o_result; -} - -static LONGINT OPB_SignedMinimum (LONGINT bytecount) -{ - LONGINT _o_result; - _o_result = -OPB_SignedMaximum(bytecount) - 1; - return _o_result; -} - static INTEGER OPB_SignedByteSize (LONGINT n) { INTEGER _o_result; @@ -448,16 +429,16 @@ void OPB_Field (OPT_Node *x, OPT_Object y) } } -static struct TypTest__63 { +static struct TypTest__61 { OPT_Node *x; OPT_Object *obj; BOOLEAN *guard; - struct TypTest__63 *lnk; -} *TypTest__63_s; + struct TypTest__61 *lnk; +} *TypTest__61_s; -static void GTT__64 (OPT_Struct t0, OPT_Struct t1); +static void GTT__62 (OPT_Struct t0, OPT_Struct t1); -static void GTT__64 (OPT_Struct t0, OPT_Struct t1) +static void GTT__62 (OPT_Struct t0, OPT_Struct t1) { OPT_Node node = NIL; OPT_Struct t = NIL; @@ -470,54 +451,54 @@ static void GTT__64 (OPT_Struct t0, OPT_Struct t1) t1 = t1->BaseTyp; } if (t1 == t0 || t0->form == 0) { - if (*TypTest__63_s->guard) { - OPB_BindNodes(5, NIL, &*TypTest__63_s->x, NIL); - (*TypTest__63_s->x)->readonly = (*TypTest__63_s->x)->left->readonly; + if (*TypTest__61_s->guard) { + OPB_BindNodes(5, NIL, &*TypTest__61_s->x, NIL); + (*TypTest__61_s->x)->readonly = (*TypTest__61_s->x)->left->readonly; } else { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } } else { OPB_err(85); } } else if (t0 != t1) { OPB_err(85); - } else if (!*TypTest__63_s->guard) { - if ((*TypTest__63_s->x)->class == 5) { + } else if (!*TypTest__61_s->guard) { + if ((*TypTest__61_s->x)->class == 5) { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } else { - *TypTest__63_s->x = OPB_NewBoolConst(1); + *TypTest__61_s->x = OPB_NewBoolConst(1); } } } void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) { - struct TypTest__63 _s; + struct TypTest__61 _s; _s.x = x; _s.obj = &obj; _s.guard = &guard; - _s.lnk = TypTest__63_s; - TypTest__63_s = &_s; + _s.lnk = TypTest__61_s; + TypTest__61_s = &_s; if (OPB_NotVar(*x)) { OPB_err(112); } else if ((*x)->typ->form == 13) { if (((*x)->typ->BaseTyp->comp != 4 && (*x)->typ != OPT_sysptrtyp)) { OPB_err(85); } else if (obj->typ->form == 13) { - GTT__64((*x)->typ->BaseTyp, obj->typ->BaseTyp); + GTT__62((*x)->typ->BaseTyp, obj->typ->BaseTyp); } else { OPB_err(86); } } else if (((((*x)->typ->comp == 4 && (*x)->class == 1)) && obj->typ->comp == 4)) { - GTT__64((*x)->typ, obj->typ); + GTT__62((*x)->typ, obj->typ); } else { OPB_err(87); } @@ -526,7 +507,7 @@ void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) } else { (*x)->typ = OPT_booltyp; } - TypTest__63_s = _s.lnk; + TypTest__61_s = _s.lnk; } void OPB_In (OPT_Node *x, OPT_Node y) @@ -1849,7 +1830,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMinimum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMinimum(x->typ->size)); break; case 9: x = OPB_NewIntConst(((LONGINT)(0))); @@ -1880,7 +1861,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMaximum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMaximum(x->typ->size)); break; case 9: x = OPB_NewIntConst(OPM_MaxSet); @@ -2062,13 +2043,13 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) *par0 = x; } -static struct StPar1__58 { - struct StPar1__58 *lnk; -} *StPar1__58_s; +static struct StPar1__56 { + struct StPar1__56 *lnk; +} *StPar1__56_s; -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) { OPT_Node _o_result; OPT_Node node = NIL; @@ -2085,9 +2066,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) INTEGER f, L; OPT_Struct typ = NIL; OPT_Node p = NIL, t = NIL; - struct StPar1__58 _s; - _s.lnk = StPar1__58_s; - StPar1__58_s = &_s; + struct StPar1__56 _s; + _s.lnk = StPar1__56_s; + StPar1__56_s = &_s; p = *par0; f = x->typ->form; switch (fctno) { @@ -2103,7 +2084,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); p->typ = OPT_notyp; } break; @@ -2114,7 +2095,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if ((x->class == 7 && (0 > x->conval->intval || x->conval->intval > (LONGINT)OPM_MaxSet))) { OPB_err(202); } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2139,7 +2120,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) p = p->left; x->conval->intval += 1; } - p = NewOp__59(12, 19, p, x); + p = NewOp__57(12, 19, p, x); p->typ = OPT_linttyp; } else { p = x; @@ -2161,7 +2142,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) t = x; x = p; p = t; - p = NewOp__59(19, 18, p, x); + p = NewOp__57(19, 18, p, x); } else { OPB_err(111); } @@ -2187,7 +2168,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) } p->obj = NIL; } else { - p = NewOp__59(12, 17, p, x); + p = NewOp__57(12, 17, p, x); p->typ = OPT_linttyp; } } else { @@ -2218,9 +2199,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } else { if (fctno == 22) { - p = NewOp__59(12, 27, p, x); + p = NewOp__57(12, 27, p, x); } else { - p = NewOp__59(12, 28, p, x); + p = NewOp__57(12, 28, p, x); } p->typ = p->left->typ; } @@ -2237,7 +2218,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) x = p; p = t; } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2247,7 +2228,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(12, 26, p, x); + p = NewOp__57(12, 26, p, x); } else { OPB_err(111); } @@ -2271,7 +2252,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(19, 30, p, x); + p = NewOp__57(19, 30, p, x); } else { OPB_err(111); } @@ -2317,7 +2298,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) break; } *par0 = p; - StPar1__58_s = _s.lnk; + StPar1__56_s = _s.lnk; } void OPB_StParN (OPT_Node *par0, OPT_Node x, INTEGER fctno, INTEGER n) diff --git a/bootstrap/windows-48/OPC.c b/bootstrap/windows-48/OPC.c index 2efc2010..7ce3cbe5 100644 --- a/bootstrap/windows-48/OPC.c +++ b/bootstrap/windows-48/OPC.c @@ -16,7 +16,7 @@ static CHAR OPC_BodyNameExt[13]; export void OPC_Align (LONGINT *adr, LONGINT base); export void OPC_Andent (OPT_Struct typ); static void OPC_AnsiParamList (OPT_Object obj, BOOLEAN showParamNames); -export LONGINT OPC_Base (OPT_Struct typ); +export LONGINT OPC_BaseAlignment (OPT_Struct typ); export OPT_Object OPC_BaseTProc (OPT_Object obj); export void OPC_BegBlk (void); export void OPC_BegStat (void); @@ -74,6 +74,7 @@ static void OPC_PutBase (OPT_Struct typ); static void OPC_PutPtrOffsets (OPT_Struct typ, LONGINT adr, LONGINT *cnt); static void OPC_RegCmds (OPT_Object obj); export void OPC_SetInclude (BOOLEAN exclude); +export LONGINT OPC_SizeAlignment (LONGINT size); static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause); static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x); static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l); @@ -867,70 +868,37 @@ void OPC_Align (LONGINT *adr, LONGINT base) } } -LONGINT OPC_Base (OPT_Struct typ) +LONGINT OPC_SizeAlignment (LONGINT size) { LONGINT _o_result; - switch (typ->form) { - case 1: - _o_result = 1; - return _o_result; - break; - case 3: - _o_result = OPM_CharAlign; - return _o_result; - break; - case 2: - _o_result = OPM_BoolAlign; - return _o_result; - break; - case 4: - _o_result = OPM_SIntAlign; - return _o_result; - break; - case 5: - _o_result = OPM_IntAlign; - return _o_result; - break; - case 6: - _o_result = OPM_LIntAlign; - return _o_result; - break; - case 7: - _o_result = OPM_RealAlign; - return _o_result; - break; - case 8: - _o_result = OPM_LRealAlign; - return _o_result; - break; - case 9: - _o_result = OPM_SetAlign; - return _o_result; - break; - case 13: - _o_result = OPM_PointerAlign; - return _o_result; - break; - case 14: - _o_result = OPM_ProcAlign; - return _o_result; - break; - case 15: - if (typ->comp == 4) { - _o_result = __MASK(typ->align, -65536); - return _o_result; - } else { - _o_result = OPC_Base(typ->BaseTyp); - return _o_result; - } - break; - default: - OPM_LogWStr((CHAR*)"unhandled case in OPC.Base, typ^form = ", (LONGINT)40); - OPM_LogWNum(typ->form, ((LONGINT)(0))); - OPM_LogWLn(); - break; + LONGINT alignment; + if (size < (LONGINT)OPM_Alignment) { + alignment = 1; + while (alignment < size) { + alignment = __ASHL(alignment, 1); + } + } else { + alignment = OPM_Alignment; } - __RETCHK; + _o_result = alignment; + return _o_result; +} + +LONGINT OPC_BaseAlignment (OPT_Struct typ) +{ + LONGINT _o_result; + LONGINT alignment; + if (typ->form == 15) { + if (typ->comp == 4) { + alignment = __MASK(typ->align, -65536); + } else { + alignment = OPC_BaseAlignment(typ->BaseTyp); + } + } else { + alignment = OPC_SizeAlignment(typ->size); + } + _o_result = alignment; + return _o_result; } static void OPC_FillGap (LONGINT gap, LONGINT off, LONGINT align, LONGINT *n, LONGINT *curAlign) @@ -984,7 +952,7 @@ static void OPC_FieldList (OPT_Struct typ, BOOLEAN last, LONGINT *off, LONGINT * } } else { adr = *off; - fldAlign = OPC_Base(fld->typ); + fldAlign = OPC_BaseAlignment(fld->typ); OPC_Align(&adr, fldAlign); gap = fld->adr - adr; if (fldAlign > *curAlign) { diff --git a/bootstrap/windows-48/OPC.h b/bootstrap/windows-48/OPC.h index ac61a9a4..8786c7c6 100644 --- a/bootstrap/windows-48/OPC.h +++ b/bootstrap/windows-48/OPC.h @@ -11,7 +11,7 @@ import void OPC_Align (LONGINT *adr, LONGINT base); import void OPC_Andent (OPT_Struct typ); -import LONGINT OPC_Base (OPT_Struct typ); +import LONGINT OPC_BaseAlignment (OPT_Struct typ); import OPT_Object OPC_BaseTProc (OPT_Object obj); import void OPC_BegBlk (void); import void OPC_BegStat (void); @@ -40,6 +40,7 @@ import void OPC_InitTDesc (OPT_Struct typ); import void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim); import LONGINT OPC_NofPtrs (OPT_Struct typ); import void OPC_SetInclude (BOOLEAN exclude); +import LONGINT OPC_SizeAlignment (LONGINT size); import void OPC_TDescDecl (OPT_Struct typ); import void OPC_TypeDefs (OPT_Object obj, INTEGER vis); import void OPC_TypeOf (OPT_Object ap); diff --git a/bootstrap/windows-48/OPM.c b/bootstrap/windows-48/OPM.c index fc316318..4bdc065f 100644 --- a/bootstrap/windows-48/OPM.c +++ b/bootstrap/windows-48/OPM.c @@ -14,8 +14,8 @@ typedef static CHAR OPM_SourceFileName[256]; -export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -export LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +export LONGINT OPM_MaxIndex; export LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; export BOOLEAN OPM_noerr; export LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -36,7 +36,6 @@ static CHAR OPM_OBERON[1024]; static CHAR OPM_MODULES[1024]; -export INTEGER OPM_AlignSize (LONGINT size); static void OPM_Append (Files_Rider *R, LONGINT *R__typ, Files_File F); export void OPM_CloseFiles (void); export void OPM_CloseOldSym (void); @@ -65,6 +64,8 @@ export BOOLEAN OPM_OpenPar (void); export void OPM_RegisterNewSym (void); static void OPM_ScanOptions (CHAR *s, LONGINT s__len, SET *opt); static void OPM_ShowLine (LONGINT pos); +export LONGINT OPM_SignedMaximum (LONGINT bytecount); +export LONGINT OPM_SignedMinimum (LONGINT bytecount); export void OPM_SymRCh (CHAR *ch); export LONGINT OPM_SymRInt (void); export void OPM_SymRLReal (LONGREAL *lr); @@ -607,111 +608,62 @@ static void OPM_VerboseListSizes (void) OPM_LogWLn(); OPM_LogWStr((CHAR*)"CHAR ", (LONGINT)14); OPM_LogWNum(OPM_CharSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_CharAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"BOOLEAN ", (LONGINT)14); OPM_LogWNum(OPM_BoolSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_BoolAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SHORTINT ", (LONGINT)14); OPM_LogWNum(OPM_SIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"INTEGER ", (LONGINT)14); OPM_LogWNum(OPM_IntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_IntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGINT ", (LONGINT)14); OPM_LogWNum(OPM_LIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SET ", (LONGINT)14); OPM_LogWNum(OPM_SetSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SetAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"REAL ", (LONGINT)14); OPM_LogWNum(OPM_RealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGREAL ", (LONGINT)14); OPM_LogWNum(OPM_LRealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LRealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PTR ", (LONGINT)14); OPM_LogWNum(OPM_PointerSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_PointerAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PROC ", (LONGINT)14); OPM_LogWNum(OPM_ProcSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_ProcAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"RECORD ", (LONGINT)14); OPM_LogWNum(OPM_RecSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RecAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MinSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MaxSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min integer ", (LONGINT)14); - OPM_LogWNum(OPM_MinInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max integer ", (LONGINT)14); - OPM_LogWNum(OPM_MaxInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min longint ", (LONGINT)14); - OPM_LogWNum(OPM_MinLInt, ((LONGINT)(4))); - OPM_LogWLn(); } -INTEGER OPM_AlignSize (LONGINT size) +LONGINT OPM_SignedMaximum (LONGINT bytecount) { - INTEGER _o_result; - INTEGER align; - if (size < (LONGINT)OPM_Alignment) { - if (size > 8) { - align = 16; - } else if (size > 4) { - align = 8; - } else if (size > 2) { - align = 4; - } else { - align = (int)size; - } - } else { - align = OPM_Alignment; - } - _o_result = align; + LONGINT _o_result; + LONGINT result; + result = 1; + result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); + _o_result = result - 1; + return _o_result; +} + +LONGINT OPM_SignedMinimum (LONGINT bytecount) +{ + LONGINT _o_result; + _o_result = -OPM_SignedMaximum(bytecount) - 1; return _o_result; } static void OPM_GetProperties (void) { - LONGINT base; OPM_ProcSize = OPM_PointerSize; OPM_LIntSize = __ASHL(OPM_IntSize, 1); OPM_SetSize = OPM_LIntSize; - OPM_CharAlign = OPM_AlignSize(OPM_CharSize); - OPM_BoolAlign = OPM_AlignSize(OPM_BoolSize); - OPM_SIntAlign = OPM_AlignSize(OPM_SIntSize); - OPM_RecAlign = OPM_AlignSize(OPM_RecSize); - OPM_RealAlign = OPM_AlignSize(OPM_RealSize); - OPM_LRealAlign = OPM_AlignSize(OPM_LRealSize); - OPM_PointerAlign = OPM_AlignSize(OPM_PointerSize); - OPM_ProcAlign = OPM_AlignSize(OPM_ProcSize); - OPM_IntAlign = OPM_AlignSize(OPM_IntSize); - OPM_LIntAlign = OPM_AlignSize(OPM_LIntSize); - OPM_SetAlign = OPM_AlignSize(OPM_SetSize); - base = -2; - OPM_MinSInt = __ASH(base, __ASHL(OPM_SIntSize, 3) - 2); - OPM_MaxSInt = OPM_minusop(OPM_MinSInt + 1); - OPM_MinInt = __ASH(base, __ASHL(OPM_IntSize, 3) - 2); - OPM_MaxInt = OPM_minusop(OPM_MinInt + 1); - OPM_MinLInt = __ASH(base, __ASHL(OPM_LIntSize, 3) - 2); - OPM_MaxLInt = OPM_minusop(OPM_MinLInt + 1); if (OPM_RealSize == 4) { OPM_MaxReal = 3.40282346000000e+038; } else if (OPM_RealSize == 8) { @@ -725,7 +677,7 @@ static void OPM_GetProperties (void) OPM_MinReal = -OPM_MaxReal; OPM_MinLReal = -OPM_MaxLReal; OPM_MaxSet = __ASHL(OPM_SetSize, 3) - 1; - OPM_MaxIndex = OPM_MaxLInt; + OPM_MaxIndex = OPM_SignedMaximum(OPM_PointerSize); if (OPM_Verbose) { OPM_VerboseListSizes(); } @@ -887,7 +839,7 @@ void OPM_WriteInt (LONGINT i) { CHAR s[20]; LONGINT i1, k; - if (i == OPM_MinInt || i == OPM_MinLInt) { + if (i == OPM_SignedMinimum(OPM_IntSize) || i == OPM_SignedMinimum(OPM_LIntSize)) { OPM_Write('('); OPM_WriteInt(i + 1); OPM_WriteString((CHAR*)"-1)", (LONGINT)4); @@ -920,7 +872,7 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_MaxLInt && r > OPM_MinLInt)) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { diff --git a/bootstrap/windows-48/OPM.h b/bootstrap/windows-48/OPM.h index ec53cacf..5f8cc38c 100644 --- a/bootstrap/windows-48/OPM.h +++ b/bootstrap/windows-48/OPM.h @@ -6,8 +6,8 @@ #include "SYSTEM.h" -import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -import LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +import LONGINT OPM_MaxIndex; import LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; import BOOLEAN OPM_noerr; import LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -18,7 +18,6 @@ import SET OPM_opt, OPM_glbopt; import BOOLEAN OPM_dontAsm, OPM_dontLink, OPM_mainProg, OPM_mainLinkStat, OPM_notColorOutput, OPM_forceNewSym, OPM_Verbose; -import INTEGER OPM_AlignSize (LONGINT size); import void OPM_CloseFiles (void); import void OPM_CloseOldSym (void); import void OPM_DeleteNewSym (void); @@ -39,6 +38,8 @@ import void OPM_OldSym (CHAR *modName, LONGINT modName__len, BOOLEAN *done); import void OPM_OpenFiles (CHAR *moduleName, LONGINT moduleName__len); import BOOLEAN OPM_OpenPar (void); import void OPM_RegisterNewSym (void); +import LONGINT OPM_SignedMaximum (LONGINT bytecount); +import LONGINT OPM_SignedMinimum (LONGINT bytecount); import void OPM_SymRCh (CHAR *ch); import LONGINT OPM_SymRInt (void); import void OPM_SymRLReal (LONGREAL *lr); diff --git a/bootstrap/windows-48/OPV.c b/bootstrap/windows-48/OPV.c index 961c5e11..50f58fae 100644 --- a/bootstrap/windows-48/OPV.c +++ b/bootstrap/windows-48/OPV.c @@ -82,7 +82,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = typ->BaseTyp; if (btyp == NIL) { offset = 0; - base = OPM_RecAlign; + base = OPC_SizeAlignment(OPM_RecSize); } else { OPV_TypSize(btyp); offset = btyp->size - (LONGINT)__ASHR(btyp->sysflag, 8); @@ -93,7 +93,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = fld->typ; OPV_TypSize(btyp); size = btyp->size; - fbase = OPC_Base(btyp); + fbase = OPC_BaseAlignment(btyp); OPC_Align(&offset, fbase); fld->adr = offset; offset += size; @@ -107,7 +107,7 @@ void OPV_TypSize (OPT_Struct typ) offset = 1; } if (OPM_RecSize == 0) { - base = OPV_NaturalAlignment(offset, OPM_RecAlign); + base = OPV_NaturalAlignment(offset, OPC_SizeAlignment(OPM_RecSize)); } OPC_Align(&offset, base); if ((typ->strobj == NIL && __MASK(typ->align, -65536) == 0)) { @@ -491,7 +491,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -507,7 +507,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxSInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -795,7 +795,7 @@ static void OPV_ActualPar (OPT_Node n, OPT_Object fp) } if ((((mode == 2 && n->class == 11)) && n->subcl == 29)) { OPV_expr(n->left, prec); - } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_MaxInt)) && n->conval->intval >= OPM_MinInt)) { + } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_SignedMaximum(OPM_IntSize))) && n->conval->intval >= OPM_SignedMinimum(OPM_IntSize))) { OPM_WriteString((CHAR*)"((LONGINT)(", (LONGINT)12); OPV_expr(n, prec); OPM_WriteString((CHAR*)"))", (LONGINT)3); @@ -1322,7 +1322,7 @@ static void OPV_NewArr (OPT_Node d, OPT_Node x) OPM_WriteInt(base->size); OPM_WriteString((CHAR*)"))", (LONGINT)3); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPC_Base(base)); + OPM_WriteInt(OPC_BaseAlignment(base)); OPM_WriteString((CHAR*)", ", (LONGINT)3); OPM_WriteInt(nofdim); OPM_WriteString((CHAR*)", ", (LONGINT)3); diff --git a/bootstrap/windows-88/OPB.c b/bootstrap/windows-88/OPB.c index 514304bd..73daf26e 100644 --- a/bootstrap/windows-88/OPB.c +++ b/bootstrap/windows-88/OPB.c @@ -56,8 +56,6 @@ static void OPB_SetIntType (OPT_Node node); export void OPB_SetRange (OPT_Node *x, OPT_Node y); static LONGINT OPB_ShorterSize (LONGINT i); static INTEGER OPB_SignedByteSize (LONGINT n); -static LONGINT OPB_SignedMaximum (LONGINT bytecount); -static LONGINT OPB_SignedMinimum (LONGINT bytecount); export void OPB_StFct (OPT_Node *par0, SHORTINT fctno, INTEGER parno); export void OPB_StPar0 (OPT_Node *par0, INTEGER fctno); export void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno); @@ -227,23 +225,6 @@ OPT_Node OPB_EmptySet (void) return _o_result; } -static LONGINT OPB_SignedMaximum (LONGINT bytecount) -{ - LONGINT _o_result; - LONGINT result; - result = 1; - result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); - _o_result = result - 1; - return _o_result; -} - -static LONGINT OPB_SignedMinimum (LONGINT bytecount) -{ - LONGINT _o_result; - _o_result = -OPB_SignedMaximum(bytecount) - 1; - return _o_result; -} - static INTEGER OPB_SignedByteSize (LONGINT n) { INTEGER _o_result; @@ -449,16 +430,16 @@ void OPB_Field (OPT_Node *x, OPT_Object y) } } -static struct TypTest__63 { +static struct TypTest__61 { OPT_Node *x; OPT_Object *obj; BOOLEAN *guard; - struct TypTest__63 *lnk; -} *TypTest__63_s; + struct TypTest__61 *lnk; +} *TypTest__61_s; -static void GTT__64 (OPT_Struct t0, OPT_Struct t1); +static void GTT__62 (OPT_Struct t0, OPT_Struct t1); -static void GTT__64 (OPT_Struct t0, OPT_Struct t1) +static void GTT__62 (OPT_Struct t0, OPT_Struct t1) { OPT_Node node = NIL; OPT_Struct t = NIL; @@ -471,54 +452,54 @@ static void GTT__64 (OPT_Struct t0, OPT_Struct t1) t1 = t1->BaseTyp; } if (t1 == t0 || t0->form == 0) { - if (*TypTest__63_s->guard) { - OPB_BindNodes(5, NIL, &*TypTest__63_s->x, NIL); - (*TypTest__63_s->x)->readonly = (*TypTest__63_s->x)->left->readonly; + if (*TypTest__61_s->guard) { + OPB_BindNodes(5, NIL, &*TypTest__61_s->x, NIL); + (*TypTest__61_s->x)->readonly = (*TypTest__61_s->x)->left->readonly; } else { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } } else { OPB_err(85); } } else if (t0 != t1) { OPB_err(85); - } else if (!*TypTest__63_s->guard) { - if ((*TypTest__63_s->x)->class == 5) { + } else if (!*TypTest__61_s->guard) { + if ((*TypTest__61_s->x)->class == 5) { node = OPT_NewNode(11); node->subcl = 16; - node->left = *TypTest__63_s->x; - node->obj = *TypTest__63_s->obj; - *TypTest__63_s->x = node; + node->left = *TypTest__61_s->x; + node->obj = *TypTest__61_s->obj; + *TypTest__61_s->x = node; } else { - *TypTest__63_s->x = OPB_NewBoolConst(1); + *TypTest__61_s->x = OPB_NewBoolConst(1); } } } void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) { - struct TypTest__63 _s; + struct TypTest__61 _s; _s.x = x; _s.obj = &obj; _s.guard = &guard; - _s.lnk = TypTest__63_s; - TypTest__63_s = &_s; + _s.lnk = TypTest__61_s; + TypTest__61_s = &_s; if (OPB_NotVar(*x)) { OPB_err(112); } else if ((*x)->typ->form == 13) { if (((*x)->typ->BaseTyp->comp != 4 && (*x)->typ != OPT_sysptrtyp)) { OPB_err(85); } else if (obj->typ->form == 13) { - GTT__64((*x)->typ->BaseTyp, obj->typ->BaseTyp); + GTT__62((*x)->typ->BaseTyp, obj->typ->BaseTyp); } else { OPB_err(86); } } else if (((((*x)->typ->comp == 4 && (*x)->class == 1)) && obj->typ->comp == 4)) { - GTT__64((*x)->typ, obj->typ); + GTT__62((*x)->typ, obj->typ); } else { OPB_err(87); } @@ -527,7 +508,7 @@ void OPB_TypTest (OPT_Node *x, OPT_Object obj, BOOLEAN guard) } else { (*x)->typ = OPT_booltyp; } - TypTest__63_s = _s.lnk; + TypTest__61_s = _s.lnk; } void OPB_In (OPT_Node *x, OPT_Node y) @@ -1850,7 +1831,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMinimum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMinimum(x->typ->size)); break; case 9: x = OPB_NewIntConst(((LONGINT)(0))); @@ -1881,7 +1862,7 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) x->typ = OPT_chartyp; break; case 4: case 5: case 6: - x = OPB_NewIntConst(OPB_SignedMaximum(x->typ->size)); + x = OPB_NewIntConst(OPM_SignedMaximum(x->typ->size)); break; case 9: x = OPB_NewIntConst(OPM_MaxSet); @@ -2063,13 +2044,13 @@ void OPB_StPar0 (OPT_Node *par0, INTEGER fctno) *par0 = x; } -static struct StPar1__58 { - struct StPar1__58 *lnk; -} *StPar1__58_s; +static struct StPar1__56 { + struct StPar1__56 *lnk; +} *StPar1__56_s; -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right); -static OPT_Node NewOp__59 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) +static OPT_Node NewOp__57 (SHORTINT class, SHORTINT subcl, OPT_Node left, OPT_Node right) { OPT_Node _o_result; OPT_Node node = NIL; @@ -2086,9 +2067,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) INTEGER f, L; OPT_Struct typ = NIL; OPT_Node p = NIL, t = NIL; - struct StPar1__58 _s; - _s.lnk = StPar1__58_s; - StPar1__58_s = &_s; + struct StPar1__56 _s; + _s.lnk = StPar1__56_s; + StPar1__56_s = &_s; p = *par0; f = x->typ->form; switch (fctno) { @@ -2104,7 +2085,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); p->typ = OPT_notyp; } break; @@ -2115,7 +2096,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if ((x->class == 7 && (0 > x->conval->intval || x->conval->intval > (LONGINT)OPM_MaxSet))) { OPB_err(202); } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2140,7 +2121,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) p = p->left; x->conval->intval += 1; } - p = NewOp__59(12, 19, p, x); + p = NewOp__57(12, 19, p, x); p->typ = OPT_linttyp; } else { p = x; @@ -2162,7 +2143,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) t = x; x = p; p = t; - p = NewOp__59(19, 18, p, x); + p = NewOp__57(19, 18, p, x); } else { OPB_err(111); } @@ -2188,7 +2169,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) } p->obj = NIL; } else { - p = NewOp__59(12, 17, p, x); + p = NewOp__57(12, 17, p, x); p->typ = OPT_linttyp; } } else { @@ -2219,9 +2200,9 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) OPB_err(111); } else { if (fctno == 22) { - p = NewOp__59(12, 27, p, x); + p = NewOp__57(12, 27, p, x); } else { - p = NewOp__59(12, 28, p, x); + p = NewOp__57(12, 28, p, x); } p->typ = p->left->typ; } @@ -2238,7 +2219,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) x = p; p = t; } - p = NewOp__59(19, fctno, p, x); + p = NewOp__57(19, fctno, p, x); } else { OPB_err(111); } @@ -2248,7 +2229,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(12, 26, p, x); + p = NewOp__57(12, 26, p, x); } else { OPB_err(111); } @@ -2272,7 +2253,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) if (x->class == 8 || x->class == 9) { OPB_err(126); } else if (__IN(f, 0x70)) { - p = NewOp__59(19, 30, p, x); + p = NewOp__57(19, 30, p, x); } else { OPB_err(111); } @@ -2318,7 +2299,7 @@ void OPB_StPar1 (OPT_Node *par0, OPT_Node x, SHORTINT fctno) break; } *par0 = p; - StPar1__58_s = _s.lnk; + StPar1__56_s = _s.lnk; } void OPB_StParN (OPT_Node *par0, OPT_Node x, INTEGER fctno, INTEGER n) diff --git a/bootstrap/windows-88/OPC.c b/bootstrap/windows-88/OPC.c index b286807f..b74145a7 100644 --- a/bootstrap/windows-88/OPC.c +++ b/bootstrap/windows-88/OPC.c @@ -17,7 +17,7 @@ static CHAR OPC_BodyNameExt[13]; export void OPC_Align (LONGINT *adr, LONGINT base); export void OPC_Andent (OPT_Struct typ); static void OPC_AnsiParamList (OPT_Object obj, BOOLEAN showParamNames); -export LONGINT OPC_Base (OPT_Struct typ); +export LONGINT OPC_BaseAlignment (OPT_Struct typ); export OPT_Object OPC_BaseTProc (OPT_Object obj); export void OPC_BegBlk (void); export void OPC_BegStat (void); @@ -75,6 +75,7 @@ static void OPC_PutBase (OPT_Struct typ); static void OPC_PutPtrOffsets (OPT_Struct typ, LONGINT adr, LONGINT *cnt); static void OPC_RegCmds (OPT_Object obj); export void OPC_SetInclude (BOOLEAN exclude); +export LONGINT OPC_SizeAlignment (LONGINT size); static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause); static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x); static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l); @@ -868,70 +869,37 @@ void OPC_Align (LONGINT *adr, LONGINT base) } } -LONGINT OPC_Base (OPT_Struct typ) +LONGINT OPC_SizeAlignment (LONGINT size) { LONGINT _o_result; - switch (typ->form) { - case 1: - _o_result = 1; - return _o_result; - break; - case 3: - _o_result = OPM_CharAlign; - return _o_result; - break; - case 2: - _o_result = OPM_BoolAlign; - return _o_result; - break; - case 4: - _o_result = OPM_SIntAlign; - return _o_result; - break; - case 5: - _o_result = OPM_IntAlign; - return _o_result; - break; - case 6: - _o_result = OPM_LIntAlign; - return _o_result; - break; - case 7: - _o_result = OPM_RealAlign; - return _o_result; - break; - case 8: - _o_result = OPM_LRealAlign; - return _o_result; - break; - case 9: - _o_result = OPM_SetAlign; - return _o_result; - break; - case 13: - _o_result = OPM_PointerAlign; - return _o_result; - break; - case 14: - _o_result = OPM_ProcAlign; - return _o_result; - break; - case 15: - if (typ->comp == 4) { - _o_result = __MASK(typ->align, -65536); - return _o_result; - } else { - _o_result = OPC_Base(typ->BaseTyp); - return _o_result; - } - break; - default: - OPM_LogWStr((CHAR*)"unhandled case in OPC.Base, typ^form = ", (LONGINT)40); - OPM_LogWNum(typ->form, ((LONGINT)(0))); - OPM_LogWLn(); - break; + LONGINT alignment; + if (size < (LONGINT)OPM_Alignment) { + alignment = 1; + while (alignment < size) { + alignment = __ASHL(alignment, 1); + } + } else { + alignment = OPM_Alignment; } - __RETCHK; + _o_result = alignment; + return _o_result; +} + +LONGINT OPC_BaseAlignment (OPT_Struct typ) +{ + LONGINT _o_result; + LONGINT alignment; + if (typ->form == 15) { + if (typ->comp == 4) { + alignment = __MASK(typ->align, -65536); + } else { + alignment = OPC_BaseAlignment(typ->BaseTyp); + } + } else { + alignment = OPC_SizeAlignment(typ->size); + } + _o_result = alignment; + return _o_result; } static void OPC_FillGap (LONGINT gap, LONGINT off, LONGINT align, LONGINT *n, LONGINT *curAlign) @@ -985,7 +953,7 @@ static void OPC_FieldList (OPT_Struct typ, BOOLEAN last, LONGINT *off, LONGINT * } } else { adr = *off; - fldAlign = OPC_Base(fld->typ); + fldAlign = OPC_BaseAlignment(fld->typ); OPC_Align(&adr, fldAlign); gap = fld->adr - adr; if (fldAlign > *curAlign) { diff --git a/bootstrap/windows-88/OPC.h b/bootstrap/windows-88/OPC.h index 1b09dedc..525240c8 100644 --- a/bootstrap/windows-88/OPC.h +++ b/bootstrap/windows-88/OPC.h @@ -12,7 +12,7 @@ import void OPC_Align (LONGINT *adr, LONGINT base); import void OPC_Andent (OPT_Struct typ); -import LONGINT OPC_Base (OPT_Struct typ); +import LONGINT OPC_BaseAlignment (OPT_Struct typ); import OPT_Object OPC_BaseTProc (OPT_Object obj); import void OPC_BegBlk (void); import void OPC_BegStat (void); @@ -41,6 +41,7 @@ import void OPC_InitTDesc (OPT_Struct typ); import void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim); import LONGINT OPC_NofPtrs (OPT_Struct typ); import void OPC_SetInclude (BOOLEAN exclude); +import LONGINT OPC_SizeAlignment (LONGINT size); import void OPC_TDescDecl (OPT_Struct typ); import void OPC_TypeDefs (OPT_Object obj, INTEGER vis); import void OPC_TypeOf (OPT_Object ap); diff --git a/bootstrap/windows-88/OPM.c b/bootstrap/windows-88/OPM.c index 27de68da..1517e019 100644 --- a/bootstrap/windows-88/OPM.c +++ b/bootstrap/windows-88/OPM.c @@ -15,8 +15,8 @@ typedef static CHAR OPM_SourceFileName[256]; -export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -export LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +export INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +export LONGINT OPM_MaxIndex; export LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; export BOOLEAN OPM_noerr; export LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -37,7 +37,6 @@ static CHAR OPM_OBERON[1024]; static CHAR OPM_MODULES[1024]; -export INTEGER OPM_AlignSize (LONGINT size); static void OPM_Append (Files_Rider *R, LONGINT *R__typ, Files_File F); export void OPM_CloseFiles (void); export void OPM_CloseOldSym (void); @@ -66,6 +65,8 @@ export BOOLEAN OPM_OpenPar (void); export void OPM_RegisterNewSym (void); static void OPM_ScanOptions (CHAR *s, LONGINT s__len, SET *opt); static void OPM_ShowLine (LONGINT pos); +export LONGINT OPM_SignedMaximum (LONGINT bytecount); +export LONGINT OPM_SignedMinimum (LONGINT bytecount); export void OPM_SymRCh (CHAR *ch); export LONGINT OPM_SymRInt (void); export void OPM_SymRLReal (LONGREAL *lr); @@ -606,111 +607,62 @@ static void OPM_VerboseListSizes (void) OPM_LogWLn(); OPM_LogWStr((CHAR*)"CHAR ", (LONGINT)14); OPM_LogWNum(OPM_CharSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_CharAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"BOOLEAN ", (LONGINT)14); OPM_LogWNum(OPM_BoolSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_BoolAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SHORTINT ", (LONGINT)14); OPM_LogWNum(OPM_SIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"INTEGER ", (LONGINT)14); OPM_LogWNum(OPM_IntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_IntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGINT ", (LONGINT)14); OPM_LogWNum(OPM_LIntSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LIntAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"SET ", (LONGINT)14); OPM_LogWNum(OPM_SetSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_SetAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"REAL ", (LONGINT)14); OPM_LogWNum(OPM_RealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"LONGREAL ", (LONGINT)14); OPM_LogWNum(OPM_LRealSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_LRealAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PTR ", (LONGINT)14); OPM_LogWNum(OPM_PointerSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_PointerAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"PROC ", (LONGINT)14); OPM_LogWNum(OPM_ProcSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_ProcAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWStr((CHAR*)"RECORD ", (LONGINT)14); OPM_LogWNum(OPM_RecSize, ((LONGINT)(4))); - OPM_LogWNum(OPM_RecAlign, ((LONGINT)(5))); OPM_LogWLn(); OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MinSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max shortint ", (LONGINT)14); - OPM_LogWNum(OPM_MaxSInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min integer ", (LONGINT)14); - OPM_LogWNum(OPM_MinInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Max integer ", (LONGINT)14); - OPM_LogWNum(OPM_MaxInt, ((LONGINT)(4))); - OPM_LogWLn(); - OPM_LogWStr((CHAR*)"Min longint ", (LONGINT)14); - OPM_LogWNum(OPM_MinLInt, ((LONGINT)(4))); - OPM_LogWLn(); } -INTEGER OPM_AlignSize (LONGINT size) +LONGINT OPM_SignedMaximum (LONGINT bytecount) { - INTEGER _o_result; - INTEGER align; - if (size < (LONGINT)OPM_Alignment) { - if (size > 8) { - align = 16; - } else if (size > 4) { - align = 8; - } else if (size > 2) { - align = 4; - } else { - align = (int)size; - } - } else { - align = OPM_Alignment; - } - _o_result = align; + LONGINT _o_result; + LONGINT result; + result = 1; + result = __LSH(result, __ASHL(bytecount, 3) - 1, LONGINT); + _o_result = result - 1; + return _o_result; +} + +LONGINT OPM_SignedMinimum (LONGINT bytecount) +{ + LONGINT _o_result; + _o_result = -OPM_SignedMaximum(bytecount) - 1; return _o_result; } static void OPM_GetProperties (void) { - LONGINT base; OPM_ProcSize = OPM_PointerSize; OPM_LIntSize = __ASHL(OPM_IntSize, 1); OPM_SetSize = OPM_LIntSize; - OPM_CharAlign = OPM_AlignSize(OPM_CharSize); - OPM_BoolAlign = OPM_AlignSize(OPM_BoolSize); - OPM_SIntAlign = OPM_AlignSize(OPM_SIntSize); - OPM_RecAlign = OPM_AlignSize(OPM_RecSize); - OPM_RealAlign = OPM_AlignSize(OPM_RealSize); - OPM_LRealAlign = OPM_AlignSize(OPM_LRealSize); - OPM_PointerAlign = OPM_AlignSize(OPM_PointerSize); - OPM_ProcAlign = OPM_AlignSize(OPM_ProcSize); - OPM_IntAlign = OPM_AlignSize(OPM_IntSize); - OPM_LIntAlign = OPM_AlignSize(OPM_LIntSize); - OPM_SetAlign = OPM_AlignSize(OPM_SetSize); - base = -2; - OPM_MinSInt = __ASH(base, __ASHL(OPM_SIntSize, 3) - 2); - OPM_MaxSInt = OPM_minusop(OPM_MinSInt + 1); - OPM_MinInt = __ASH(base, __ASHL(OPM_IntSize, 3) - 2); - OPM_MaxInt = OPM_minusop(OPM_MinInt + 1); - OPM_MinLInt = __ASH(base, __ASHL(OPM_LIntSize, 3) - 2); - OPM_MaxLInt = OPM_minusop(OPM_MinLInt + 1); if (OPM_RealSize == 4) { OPM_MaxReal = 3.40282346000000e+038; } else if (OPM_RealSize == 8) { @@ -724,7 +676,7 @@ static void OPM_GetProperties (void) OPM_MinReal = -OPM_MaxReal; OPM_MinLReal = -OPM_MaxLReal; OPM_MaxSet = __ASHL(OPM_SetSize, 3) - 1; - OPM_MaxIndex = OPM_MaxLInt; + OPM_MaxIndex = OPM_SignedMaximum(OPM_PointerSize); if (OPM_Verbose) { OPM_VerboseListSizes(); } @@ -886,7 +838,7 @@ void OPM_WriteInt (LONGINT i) { CHAR s[20]; LONGINT i1, k; - if (i == OPM_MinInt || i == OPM_MinLInt) { + if (i == OPM_SignedMinimum(OPM_IntSize) || i == OPM_SignedMinimum(OPM_LIntSize)) { OPM_Write('('); OPM_WriteInt(i + 1); OPM_WriteString((CHAR*)"-1)", (LONGINT)4); @@ -919,7 +871,7 @@ void OPM_WriteReal (LONGREAL r, CHAR suffx) CHAR s[32]; CHAR ch; INTEGER i; - if ((((r < OPM_MaxLInt && r > OPM_MinLInt)) && r == (__ENTIER(r)))) { + if ((((r < OPM_SignedMaximum(OPM_LIntSize) && r > OPM_SignedMinimum(OPM_LIntSize))) && r == (__ENTIER(r)))) { if (suffx == 'f') { OPM_WriteString((CHAR*)"(REAL)", (LONGINT)7); } else { diff --git a/bootstrap/windows-88/OPM.h b/bootstrap/windows-88/OPM.h index 78d88d0b..db45a834 100644 --- a/bootstrap/windows-88/OPM.h +++ b/bootstrap/windows-88/OPM.h @@ -7,8 +7,8 @@ #include "SYSTEM.h" -import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_CharAlign, OPM_BoolAlign, OPM_SIntAlign, OPM_IntAlign, OPM_LIntAlign, OPM_SetAlign, OPM_RealAlign, OPM_LRealAlign, OPM_PointerAlign, OPM_ProcAlign, OPM_RecAlign, OPM_MaxSet; -import LONGINT OPM_MinSInt, OPM_MinInt, OPM_MinLInt, OPM_MaxSInt, OPM_MaxInt, OPM_MaxLInt, OPM_MaxIndex; +import INTEGER OPM_Alignment, OPM_ByteSize, OPM_CharSize, OPM_BoolSize, OPM_SIntSize, OPM_IntSize, OPM_LIntSize, OPM_SetSize, OPM_RealSize, OPM_LRealSize, OPM_PointerSize, OPM_ProcSize, OPM_RecSize, OPM_MaxSet; +import LONGINT OPM_MaxIndex; import LONGREAL OPM_MinReal, OPM_MaxReal, OPM_MinLReal, OPM_MaxLReal; import BOOLEAN OPM_noerr; import LONGINT OPM_curpos, OPM_errpos, OPM_breakpc; @@ -19,7 +19,6 @@ import SET OPM_opt, OPM_glbopt; import BOOLEAN OPM_dontAsm, OPM_dontLink, OPM_mainProg, OPM_mainLinkStat, OPM_notColorOutput, OPM_forceNewSym, OPM_Verbose; -import INTEGER OPM_AlignSize (LONGINT size); import void OPM_CloseFiles (void); import void OPM_CloseOldSym (void); import void OPM_DeleteNewSym (void); @@ -40,6 +39,8 @@ import void OPM_OldSym (CHAR *modName, LONGINT modName__len, BOOLEAN *done); import void OPM_OpenFiles (CHAR *moduleName, LONGINT moduleName__len); import BOOLEAN OPM_OpenPar (void); import void OPM_RegisterNewSym (void); +import LONGINT OPM_SignedMaximum (LONGINT bytecount); +import LONGINT OPM_SignedMinimum (LONGINT bytecount); import void OPM_SymRCh (CHAR *ch); import LONGINT OPM_SymRInt (void); import void OPM_SymRLReal (LONGREAL *lr); diff --git a/bootstrap/windows-88/OPV.c b/bootstrap/windows-88/OPV.c index 5c482eb4..2632d95e 100644 --- a/bootstrap/windows-88/OPV.c +++ b/bootstrap/windows-88/OPV.c @@ -83,7 +83,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = typ->BaseTyp; if (btyp == NIL) { offset = 0; - base = OPM_RecAlign; + base = OPC_SizeAlignment(OPM_RecSize); } else { OPV_TypSize(btyp); offset = btyp->size - (LONGINT)__ASHR(btyp->sysflag, 8); @@ -94,7 +94,7 @@ void OPV_TypSize (OPT_Struct typ) btyp = fld->typ; OPV_TypSize(btyp); size = btyp->size; - fbase = OPC_Base(btyp); + fbase = OPC_BaseAlignment(btyp); OPC_Align(&offset, fbase); fld->adr = offset; offset += size; @@ -108,7 +108,7 @@ void OPV_TypSize (OPT_Struct typ) offset = 1; } if (OPM_RecSize == 0) { - base = OPV_NaturalAlignment(offset, OPM_RecAlign); + base = OPV_NaturalAlignment(offset, OPC_SizeAlignment(OPM_RecSize)); } OPC_Align(&offset, base); if ((typ->strobj == NIL && __MASK(typ->align, -65536) == 0)) { @@ -492,7 +492,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_IntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -508,7 +508,7 @@ static void OPV_Convert (OPT_Node n, INTEGER form, INTEGER prec) OPM_Write('('); OPV_Entier(n, -1); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPM_MaxSInt + 1); + OPM_WriteInt(OPM_SignedMaximum(OPM_SIntSize) + 1); OPM_Write(')'); } else { OPM_WriteString((CHAR*)"(int)", (LONGINT)6); @@ -796,7 +796,7 @@ static void OPV_ActualPar (OPT_Node n, OPT_Object fp) } if ((((mode == 2 && n->class == 11)) && n->subcl == 29)) { OPV_expr(n->left, prec); - } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_MaxInt)) && n->conval->intval >= OPM_MinInt)) { + } else if ((((((form == 6 && n->class == 7)) && n->conval->intval <= OPM_SignedMaximum(OPM_IntSize))) && n->conval->intval >= OPM_SignedMinimum(OPM_IntSize))) { OPM_WriteString((CHAR*)"((LONGINT)(", (LONGINT)12); OPV_expr(n, prec); OPM_WriteString((CHAR*)"))", (LONGINT)3); @@ -1323,7 +1323,7 @@ static void OPV_NewArr (OPT_Node d, OPT_Node x) OPM_WriteInt(base->size); OPM_WriteString((CHAR*)"))", (LONGINT)3); OPM_WriteString((CHAR*)", ", (LONGINT)3); - OPM_WriteInt(OPC_Base(base)); + OPM_WriteInt(OPC_BaseAlignment(base)); OPM_WriteString((CHAR*)", ", (LONGINT)3); OPM_WriteInt(nofdim); OPM_WriteString((CHAR*)", ", (LONGINT)3); diff --git a/src/compiler/OPB.Mod b/src/compiler/OPB.Mod index 2f6d8b84..5f5f2c5e 100644 --- a/src/compiler/OPB.Mod +++ b/src/compiler/OPB.Mod @@ -108,18 +108,6 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) (* Integer size support *) - PROCEDURE SignedMaximum(bytecount: LONGINT): LONGINT; - VAR result: LONGINT; - BEGIN - result := 1; - result := SYSTEM.LSH(result, bytecount*8-1); - RETURN result - 1; - END SignedMaximum; - - PROCEDURE SignedMinimum(bytecount: LONGINT): LONGINT; - BEGIN RETURN -SignedMaximum(bytecount) - 1 - END SignedMinimum; - PROCEDURE SignedByteSize(n: LONGINT): INTEGER; (* Returns number of bytes required to represent signed value n *) VAR b: INTEGER; @@ -1016,7 +1004,7 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) | OPM.Char: x := NewIntConst(0); x^.typ := OPT.chartyp | OPM.SInt, OPM.Int, - OPM.LInt: x := NewIntConst(SignedMinimum(x.typ.size)) + OPM.LInt: x := NewIntConst(OPM.SignedMinimum(x.typ.size)) | OPM.Set: x := NewIntConst(0); x^.typ := OPT.inttyp | OPM.Real: x := NewRealConst(OPM.MinReal, OPT.realtyp) | OPM.LReal: x := NewRealConst(OPM.MinLReal, OPT.lrltyp) @@ -1031,7 +1019,7 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) | OPM.Char: x := NewIntConst(0FFH); x^.typ := OPT.chartyp | OPM.SInt, OPM.Int, - OPM.LInt: x := NewIntConst(SignedMaximum(x.typ.size)) + OPM.LInt: x := NewIntConst(OPM.SignedMaximum(x.typ.size)) | OPM.Set: x := NewIntConst(OPM.MaxSet); x^.typ := OPT.inttyp | OPM.Real: x := NewRealConst(OPM.MaxReal, OPT.realtyp) | OPM.LReal: x := NewRealConst(OPM.MaxLReal, OPT.lrltyp) diff --git a/src/compiler/OPC.Mod b/src/compiler/OPC.Mod index 83468209..6fa42a48 100644 --- a/src/compiler/OPC.Mod +++ b/src/compiler/OPC.Mod @@ -574,6 +574,7 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *) END END Align; + (* PROCEDURE Base0(typ: OPT.Struct): LONGINT; BEGIN CASE typ^.form OF @@ -594,39 +595,42 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *) ELSE OPM.LogWStr("unhandled case in OPC.BaseAlignment, typ^form = "); OPM.LogWNum(typ^.form, 0); OPM.LogWLn; END END Base0; + *) + + PROCEDURE SizeAlignment*(size: LONGINT): LONGINT; + VAR alignment: LONGINT; + BEGIN + IF size < OPM.Alignment THEN + (* Round up to next power of 2 *) + alignment := 1; WHILE alignment < size DO alignment := alignment * 2 END; + ELSE + alignment := OPM.Alignment + END; + RETURN alignment + END SizeAlignment; PROCEDURE BaseAlignment*(typ: OPT.Struct): LONGINT; - VAR align, result: LONGINT; + VAR alignment: LONGINT; BEGIN IF typ.form = OPM.Comp THEN IF typ.comp = OPM.Record THEN - result := typ.align MOD 10000H + alignment := typ.align MOD 10000H ELSE - result := BaseAlignment(typ.BaseTyp) + alignment := BaseAlignment(typ.BaseTyp) END ELSE - (* Not a compound type *) - result := Base0(typ); - - (* Now determine alignment from size *) - IF typ.size < OPM.Alignment THEN - (* Round up to next power of 2 *) - align := 1; WHILE align < typ.size DO align := align * 2 END; - ELSE - align := OPM.Alignment - END; - - IF align # result THEN + (* Not a compound type, determine alignment from size *) + alignment := SizeAlignment(typ.size) + (* + IF alignment # Base0(typ) THEN OPM.LogWStr("BaseAlignment. typ.form "); OPM.LogWNum(typ.form,1); OPM.LogWStr(", typ.size "); OPM.LogWNum(typ.size,1); - OPM.LogWStr(", old alignment "); OPM.LogWNum(result,1); + OPM.LogWStr(", old alignment "); OPM.LogWNum(alignment,1); OPM.LogWStr(", alignment based on size "); OPM.LogWNum(align,1); OPM.LogWLn END; - ASSERT(align = result) + *) END; - - - RETURN result + RETURN alignment END BaseAlignment; diff --git a/src/compiler/OPM.cmdln.Mod b/src/compiler/OPM.cmdln.Mod index 96aa25d8..f7b31286 100644 --- a/src/compiler/OPM.cmdln.Mod +++ b/src/compiler/OPM.cmdln.Mod @@ -210,11 +210,16 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) ByteSize*, CharSize*, BoolSize*, SIntSize*, IntSize*, LIntSize*, SetSize*, RealSize*, LRealSize*, PointerSize*, ProcSize*, RecSize*, + (* CharAlign*, BoolAlign*, SIntAlign*, IntAlign*, LIntAlign*, SetAlign*, RealAlign*, LRealAlign*, PointerAlign*, ProcAlign*, RecAlign*, + *) MaxSet*: INTEGER; - MinSInt*, MinInt*, MinLInt*, MaxSInt*, MaxInt*, MaxLInt*, MaxIndex*: LONGINT; + (* + MinSInt*, MinInt*, MinLInt*, MaxSInt*, MaxInt*, MaxLInt*, + *) + MaxIndex*: LONGINT; MinReal*, MaxReal*, MinLReal*, MaxLReal*: LONGREAL; @@ -645,27 +650,30 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) BEGIN LogWLn; LogWStr("Type Size Alignement"); LogWLn; - LogWStr("CHAR "); LogWNum(CharSize, 4); LogWNum(CharAlign, 5); LogWLn; - LogWStr("BOOLEAN "); LogWNum(BoolSize, 4); LogWNum(BoolAlign, 5); LogWLn; - LogWStr("SHORTINT "); LogWNum(SIntSize, 4); LogWNum(SIntAlign, 5); LogWLn; - LogWStr("INTEGER "); LogWNum(IntSize, 4); LogWNum(IntAlign, 5); LogWLn; - LogWStr("LONGINT "); LogWNum(LIntSize, 4); LogWNum(LIntAlign, 5); LogWLn; - LogWStr("SET "); LogWNum(SetSize, 4); LogWNum(SetAlign, 5); LogWLn; - LogWStr("REAL "); LogWNum(RealSize, 4); LogWNum(RealAlign, 5); LogWLn; - LogWStr("LONGREAL "); LogWNum(LRealSize, 4); LogWNum(LRealAlign, 5); LogWLn; - LogWStr("PTR "); LogWNum(PointerSize, 4); LogWNum(PointerAlign, 5); LogWLn; - LogWStr("PROC "); LogWNum(ProcSize, 4); LogWNum(ProcAlign, 5); LogWLn; - LogWStr("RECORD "); LogWNum(RecSize, 4); LogWNum(RecAlign, 5); LogWLn; + LogWStr("CHAR "); LogWNum(CharSize, 4); (* LogWNum(CharAlign, 5); *) LogWLn; + LogWStr("BOOLEAN "); LogWNum(BoolSize, 4); (* LogWNum(BoolAlign, 5); *) LogWLn; + LogWStr("SHORTINT "); LogWNum(SIntSize, 4); (* LogWNum(SIntAlign, 5); *) LogWLn; + LogWStr("INTEGER "); LogWNum(IntSize, 4); (* LogWNum(IntAlign, 5); *) LogWLn; + LogWStr("LONGINT "); LogWNum(LIntSize, 4); (* LogWNum(LIntAlign, 5); *) LogWLn; + LogWStr("SET "); LogWNum(SetSize, 4); (* LogWNum(SetAlign, 5); *) LogWLn; + LogWStr("REAL "); LogWNum(RealSize, 4); (* LogWNum(RealAlign, 5); *) LogWLn; + LogWStr("LONGREAL "); LogWNum(LRealSize, 4); (* LogWNum(LRealAlign, 5); *) LogWLn; + LogWStr("PTR "); LogWNum(PointerSize, 4); (* LogWNum(PointerAlign, 5); *) LogWLn; + LogWStr("PROC "); LogWNum(ProcSize, 4); (* LogWNum(ProcAlign, 5); *) LogWLn; + LogWStr("RECORD "); LogWNum(RecSize, 4); (* LogWNum(RecAlign, 5); *) LogWLn; (*LogWStr("ENDIAN "); LogWNum(ByteOrder, 4); LogWNum(BitOrder, 5); LogWLn;*) LogWLn; + (* LogWStr("Min shortint "); LogWNum(MinSInt, 4); LogWLn; LogWStr("Max shortint "); LogWNum(MaxSInt, 4); LogWLn; LogWStr("Min integer "); LogWNum(MinInt, 4); LogWLn; LogWStr("Max integer "); LogWNum(MaxInt, 4); LogWLn; LogWStr("Min longint "); LogWNum(MinLInt, 4); LogWLn; + *) END VerboseListSizes; + (* PROCEDURE AlignSize*(size: LONGINT): INTEGER; VAR align: INTEGER; BEGIN @@ -680,10 +688,25 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) END; RETURN align END AlignSize; + *) + + PROCEDURE SignedMaximum*(bytecount: LONGINT): LONGINT; + VAR result: LONGINT; + BEGIN + result := 1; + result := SYSTEM.LSH(result, bytecount*8-1); + RETURN result - 1; + END SignedMaximum; + + PROCEDURE SignedMinimum*(bytecount: LONGINT): LONGINT; + BEGIN RETURN -SignedMaximum(bytecount) - 1 + END SignedMinimum; + + + PROCEDURE GetProperties(); - VAR - base: LONGINT; + (* VAR base: LONGINT; *) BEGIN (* Fixed and Configuration.Mod based sizes have been initialised in the module startup code, and maybe overridden by the -Bnnn bootstrap @@ -695,6 +718,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) SetSize := LIntSize; (* Calculate all type alignments *) + (* CharAlign := AlignSize(CharSize); BoolAlign := AlignSize(BoolSize); SIntAlign := AlignSize(SIntSize); @@ -706,8 +730,9 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) IntAlign := AlignSize(IntSize); LIntAlign := AlignSize(LIntSize); SetAlign := AlignSize(SetSize); + *) - (* and I'd like to calculate it, not hardcode constants *) + (* base := -2; MinSInt := ASH(base, SIntSize*8-2); MaxSInt := minusop(MinSInt + 1); @@ -717,6 +742,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) MinLInt := ASH(base, LIntSize*8-2); MaxLInt := minusop(MinLInt +1); + *) IF RealSize = 4 THEN MaxReal := 3.40282346D38 ELSIF RealSize = 8 THEN MaxReal := 1.7976931348623157D307 * 9.999999 @@ -732,16 +758,17 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) MinLReal := -MaxLReal; MaxSet := SetSize * 8 - 1; + (* MaxIndex := MaxLInt; (* shouldn't it be like max(int)? so that for loop will be safe, noch *) + *) + MaxIndex := SignedMaximum(PointerSize); IF Verbose THEN VerboseListSizes END; END GetProperties; - - - (* ------------------------- Read Symbol File ------------------------- *) + PROCEDURE SymRCh*(VAR ch: CHAR); BEGIN Files.Read(oldSF, ch) END SymRCh; @@ -863,7 +890,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) PROCEDURE WriteInt* (i: LONGINT); VAR s: ARRAY 20 OF CHAR; i1, k: LONGINT; BEGIN - IF (i = MinInt) OR (i = MinLInt) THEN + IF (i = SignedMinimum(IntSize)) OR (i = SignedMinimum(LIntSize)) THEN (* abs(minint) is one more than maxint, causing problems representing the value as a minus sign followed by absoute value. Therefore represent as -maxint - 1. For INTEGER this avoids a compiler warning 'this decimal constant is unsigned only in ISO C90', for LONGINT it is the @@ -881,7 +908,7 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) VAR W: Texts.Writer; T: Texts.Text; R: Texts.Reader; s: ARRAY 32 OF CHAR; ch: CHAR; i: INTEGER; BEGIN (*should be improved *) - IF (r < MaxLInt) & (r > MinLInt) & (r = ENTIER(r)) THEN + IF (r < SignedMaximum(LIntSize)) & (r > SignedMinimum(LIntSize)) & (r = ENTIER(r)) THEN IF suffx = "f" THEN WriteString("(REAL)") ELSE WriteString("(LONGREAL)") END ; WriteInt(ENTIER(r)) ELSE diff --git a/src/compiler/OPV.Mod b/src/compiler/OPV.Mod index 2493dd1a..a3e78221 100644 --- a/src/compiler/OPV.Mod +++ b/src/compiler/OPV.Mod @@ -76,7 +76,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 ELSIF typ^.size = -1 THEN f := typ^.form; c := typ^.comp; IF c = OPM.Record THEN btyp := typ^.BaseTyp; - IF btyp = NIL THEN offset := 0; base := OPM.RecAlign; + IF btyp = NIL THEN offset := 0; base := (*OPM.RecAlign*)OPC.SizeAlignment(OPM.RecSize); ELSE TypSize(btyp); offset := btyp^.size - btyp^.sysflag DIV 100H; base := btyp^.align; END; fld := typ^.link; @@ -90,7 +90,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 END ; off0 := offset; IF offset = 0 THEN offset := 1 END ; (* 1 byte filler to avoid empty struct *) - IF OPM.RecSize = 0 THEN base := NaturalAlignment(offset, OPM.RecAlign) END ; + IF OPM.RecSize = 0 THEN base := NaturalAlignment(offset, (*OPM.RecAlign*)OPC.SizeAlignment(OPM.RecSize)) END ; OPC.Align(offset, base); IF (typ^.strobj = NIL) & (typ^.align MOD 10000H = 0) THEN INC(recno); INC(base, recno * 10000H) END ; typ^.size := offset; typ^.align := base; @@ -303,7 +303,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END ; OPM.Write(OpenParen); Entier(n, MinPrec); - OPM.WriteString(Comma); OPM.WriteInt(OPM.MaxInt + 1); OPM.Write(CloseParen) + OPM.WriteString(Comma); OPM.WriteInt(OPM.SignedMaximum(OPM.IntSize) + 1); OPM.Write(CloseParen) ELSE OPM.WriteString("(int)"); Entier(n, 9) END END @@ -311,7 +311,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END ; OPM.Write(OpenParen); Entier(n, MinPrec); - OPM.WriteString(Comma); OPM.WriteInt(OPM.MaxSInt + 1); OPM.Write(CloseParen) + OPM.WriteString(Comma); OPM.WriteInt(OPM.SignedMaximum(OPM.SIntSize) + 1); OPM.Write(CloseParen) ELSE OPM.WriteString("(int)"); Entier(n, 9) END ELSIF form = OPM.Char THEN @@ -475,7 +475,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96 IF (mode = OPM.VarPar) & (n^.class = OPM.Nmop) & (n^.subcl = OPM.val) THEN expr(n^.left, prec) (* avoid cast in lvalue *) ELSIF (form = OPM.LInt) & (n^.class = OPM.Nconst) - & (n^.conval^.intval <= OPM.MaxInt) & (n^.conval^.intval >= OPM.MinInt) THEN + & (n^.conval^.intval <= OPM.SignedMaximum(OPM.IntSize)) & (n^.conval^.intval >= OPM.SignedMinimum(OPM.IntSize)) THEN OPM.WriteString("((LONGINT)("); expr(n, prec); OPM.WriteString("))"); ELSE expr(n, prec)