Merge branch 'master' into master

This commit is contained in:
Oliver Schmidt
2021-11-23 22:56:51 +01:00
committed by GitHub
111 changed files with 3761 additions and 2043 deletions

View File

@@ -438,9 +438,7 @@ void MacDef (unsigned Style)
/* Parse the parameter list */
if (HaveParams) {
while (CurTok.Tok == TOK_IDENT) {
/* Create a struct holding the identifier */
IdDesc* I = NewIdDesc (&CurTok.SVal);
@@ -449,6 +447,7 @@ void MacDef (unsigned Style)
M->Params = I;
} else {
IdDesc* List = M->Params;
while (1) {
if (SB_Compare (&List->Id, &CurTok.SVal) == 0) {
Error ("Duplicate symbol '%m%p'", &CurTok.SVal);
@@ -490,9 +489,8 @@ void MacDef (unsigned Style)
** the .LOCAL command is detected and removed, at this time.
*/
while (1) {
/* Check for include */
if (CurTok.Tok == TOK_INCLUDE) {
if (CurTok.Tok == TOK_INCLUDE && Style == MAC_STYLE_CLASSIC) {
/* Include another file */
NextTok ();
/* Name must follow */
@@ -529,9 +527,7 @@ void MacDef (unsigned Style)
/* Check for a .LOCAL declaration */
if (CurTok.Tok == TOK_LOCAL && Style == MAC_STYLE_CLASSIC) {
while (1) {
IdDesc* I;
/* Skip .local or comma */
@@ -570,6 +566,7 @@ void MacDef (unsigned Style)
if (CurTok.Tok == TOK_IDENT) {
unsigned Count = 0;
IdDesc* I = M->Params;
while (I) {
if (SB_Compare (&I->Id, &CurTok.SVal) == 0) {
/* Local param name, replace it */

View File

@@ -42,19 +42,35 @@
#include "expr.h"
#include "loadexpr.h"
#include "scanner.h"
#include "stackptr.h"
#include "stdnames.h"
#include "typecmp.h"
#include "typeconv.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Map a generator function and its attributes to a token */
typedef struct GenDesc {
token_t Tok; /* Token to map to */
unsigned Flags; /* Flags for generator function */
void (*Func) (unsigned, unsigned long); /* Generator func */
} GenDesc;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static int CopyStruct (ExprDesc* LExpr, ExprDesc* RExpr)
static void CopyStruct (ExprDesc* LExpr, ExprDesc* RExpr)
/* Copy the struct/union represented by RExpr to the one represented by LExpr */
{
/* If the size is that of a basic type (char, int, long), we will copy
@@ -127,14 +143,440 @@ static int CopyStruct (ExprDesc* LExpr, ExprDesc* RExpr)
** to a boolean in C, but there is no harm to be future-proof.
*/
ED_MarkAsUntested (LExpr);
return 1;
}
void Assignment (ExprDesc* Expr)
/* Parse an assignment */
void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult)
/* Process inc/dec for bit-field */
{
int AddrSP;
unsigned Flags; /* Internal codegen flags */
unsigned Mask;
unsigned ChunkFlags;
const Type* ChunkType;
/* If the bit-field fits within one byte, do the following operations
** with bytes.
*/
if ((Expr->Type->A.B.Width - 1U) / CHAR_BITS ==
(Expr->Type->A.B.Offs + Expr->Type->A.B.Width - 1U) / CHAR_BITS) {
ChunkType = GetUnderlyingType (Expr->Type);
} else {
/* We use the declarartion integer type as the chunk type.
** Note: A bit-field will not occupy bits located in bytes more than
** that of its declaration type in cc65. So this is OK.
*/
ChunkType = Expr->Type + 1;
}
/* Determine code generator flags */
Flags = TypeOf (Expr->Type) | CF_FORCECHAR;
ChunkFlags = TypeOf (ChunkType);
if ((ChunkFlags & CF_TYPEMASK) == CF_CHAR) {
ChunkFlags |= CF_FORCECHAR;
}
/* Get the address on stack for the store */
PushAddr (Expr);
/* We may need the pushed address later */
AddrSP = StackPtr;
/* Get bit mask to limit the range of the value */
Mask = (0x0001U << Expr->Type->A.B.Width) - 1U;
/* Fetch the lhs into the primary register if needed */
LoadExpr (CF_NONE, Expr);
/* Handle for add and sub */
if (Val > 0) {
g_inc (Flags | CF_CONST, Val);
} else if (Val < 0) {
g_dec (Flags | CF_CONST, -Val);
}
/* Apply the mask */
g_and (Flags | CF_CONST, Mask);
/* Do integral promotion without sign-extension if needed */
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
/* Shift it into the right position */
g_asl (ChunkFlags | CF_CONST, Expr->Type->A.B.Offs);
/* Push the interim result on stack */
g_push (ChunkFlags & ~CF_FORCECHAR, 0);
/* If the original lhs was using the primary, it is now accessible only via
** the pushed address. Reload that address.
*/
if (ED_IsLocPrimaryOrExpr (Expr)) {
g_getlocal (CF_PTR, AddrSP);
}
/* Load the whole data chunk containing the bits to be changed */
LoadExpr (ChunkFlags, Expr);
if (KeepResult == OA_NEED_OLD) {
/* Save the original expression value */
g_save (ChunkFlags | CF_FORCECHAR);
}
/* Get the bits that are not to be affected */
g_and (ChunkFlags | CF_CONST, ~(Mask << Expr->Type->A.B.Offs));
/* Restore the bits that are not to be affected */
g_or (ChunkFlags & ~CF_FORCECHAR, 0);
/* Store the whole data chunk containing the changed bits back */
Store (Expr, ChunkType);
if (KeepResult == OA_NEED_OLD) {
/* Restore the original expression value */
g_restore (ChunkFlags | CF_FORCECHAR);
}
}
static void OpAssignBitField (const GenDesc* Gen, ExprDesc* Expr, const char* Op)
/* Parse an "=" (if 'Gen' is 0) or "op=" operation for bit-field lhs */
{
ExprDesc Expr2;
CodeMark PushPos;
int AddrSP;
unsigned Mask;
unsigned Flags;
unsigned ChunkFlags;
const Type* ChunkType;
ED_Init (&Expr2);
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
/* If the bit-field fits within one byte, do the following operations
** with bytes.
*/
if ((Expr->Type->A.B.Width - 1U) / CHAR_BITS ==
(Expr->Type->A.B.Offs + Expr->Type->A.B.Width - 1U) / CHAR_BITS) {
ChunkType = GetUnderlyingType (Expr->Type);
} else {
/* We use the declarartion integer type as the chunk type.
** Note: A bit-field will not occupy bits located in bytes more than
** that of its declaration type in cc65. So this is OK.
*/
ChunkType = Expr->Type + 1;
}
/* Determine code generator flags */
Flags = TypeOf (Expr->Type) | CF_FORCECHAR;
ChunkFlags = TypeOf (ChunkType);
if ((ChunkFlags & CF_TYPEMASK) == CF_CHAR) {
ChunkFlags |= CF_FORCECHAR;
}
/* Get the address on stack for the store */
PushAddr (Expr);
/* We may need the pushed address later */
AddrSP = StackPtr;
/* Get bit mask to limit the range of the value */
Mask = (0x0001U << Expr->Type->A.B.Width) - 1U;
if (Gen != 0) {
/* Fetch the lhs into the primary register if needed */
LoadExpr (CF_NONE, Expr);
/* Backup them on stack */
GetCodePos (&PushPos);
g_push (Flags & ~CF_FORCECHAR, 0);
}
/* Read the expression on the right side of the '=' or 'op=' */
MarkedExprWithCheck (hie1, &Expr2);
/* The rhs must be an integer (or a float, but we don't support that yet */
if (!IsClassInt (Expr2.Type)) {
Error ("Invalid right operand for binary operator '%s'", Op);
/* Continue. Wrong code will be generated, but the compiler won't
** break, so this is the best error recovery.
*/
}
/* Special treatment if the value is constant.
** Beware: Expr2 may contain side effects, so there must not be
** code generated for Expr2.
*/
if (ED_IsConstAbsInt (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) {
if (Gen == 0) {
/* Get the value and apply the mask */
unsigned Val = (unsigned)(Expr2.IVal & Mask);
/* Load the whole data chunk containing the bits to be changed */
LoadExpr (ChunkFlags, Expr);
/* If the value is equal to the mask now, all bits are one, and we
** can skip the mask operation.
*/
if (Val != Mask) {
/* Get the bits that are not to be affected */
g_and (ChunkFlags | CF_CONST, ~(Mask << Expr->Type->A.B.Offs));
}
/* Restore the bits that are not to be affected */
g_or (ChunkFlags | CF_CONST, Val << Expr->Type->A.B.Offs);
/* Store the whole data chunk containing the changed bits back */
Store (Expr, ChunkType);
/* Done */
goto Done;
} else {
/* Since we will operate with a constant, we can remove the push if
** the generator has the NOPUSH flag set.
*/
if (Gen->Flags & GEN_NOPUSH) {
RemoveCode (&PushPos);
}
/* Special handling for add and sub - some sort of a hack, but short code */
if (Gen->Func == g_add) {
g_inc (Flags | CF_CONST, Expr2.IVal);
} else if (Gen->Func == g_sub) {
g_dec (Flags | CF_CONST, Expr2.IVal);
} else {
if (Expr2.IVal == 0) {
/* Check for div by zero/mod by zero */
if (Gen->Func == g_div) {
Error ("Division by zero");
} else if (Gen->Func == g_mod) {
Error ("Modulo operation with zero");
}
}
/* Adjust the types of the operands if needed */
if (Gen->Func == g_div || Gen->Func == g_mod) {
unsigned AdjustedFlags = Flags;
if (Expr->Type->A.B.Width < INT_BITS || IsSignSigned (Expr->Type)) {
AdjustedFlags = (Flags & ~CF_UNSIGNED) | CF_CONST;
AdjustedFlags = g_typeadjust (AdjustedFlags, TypeOf (Expr2.Type) | CF_CONST);
}
Gen->Func (g_typeadjust (Flags, AdjustedFlags) | CF_CONST, Expr2.IVal);
} else {
Gen->Func ((Flags & ~CF_FORCECHAR) | CF_CONST, Expr2.IVal);
}
}
}
} else {
/* Do 'op' if provided */
if (Gen != 0) {
/* Load rhs into the primary */
LoadExpr (CF_NONE, &Expr2);
/* Adjust the types of the operands if needed */
if (Gen->Func == g_div || Gen->Func == g_mod) {
unsigned AdjustedFlags = Flags;
if (Expr->Type->A.B.Width < INT_BITS || IsSignSigned (Expr->Type)) {
AdjustedFlags = (Flags & ~CF_UNSIGNED) | CF_CONST;
AdjustedFlags = g_typeadjust (AdjustedFlags, TypeOf (Expr2.Type) | CF_CONST);
}
Gen->Func (g_typeadjust (Flags, AdjustedFlags), 0);
} else {
Gen->Func (g_typeadjust (Flags, TypeOf (Expr2.Type)), 0);
}
} else {
/* Do type conversion if necessary */
TypeConversion (&Expr2, Expr->Type);
/* If necessary, load rhs into the primary register */
LoadExpr (CF_NONE, &Expr2);
}
}
/* Apply the mask */
g_and (Flags | CF_CONST, Mask);
/* Do integral promotion without sign-extension if needed */
g_typecast (ChunkFlags | CF_UNSIGNED, Flags);
/* Shift it into the right position */
g_asl (ChunkFlags | CF_CONST, Expr->Type->A.B.Offs);
/* Push the interim result on stack */
g_push (ChunkFlags & ~CF_FORCECHAR, 0);
/* If the original lhs was using the primary, it is now accessible only via
** the pushed address. Reload that address.
*/
if (ED_IsLocPrimaryOrExpr (Expr)) {
g_getlocal (CF_PTR, AddrSP);
}
/* Load the whole data chunk containing the bits to be changed */
LoadExpr (ChunkFlags, Expr);
/* Get the bits that are not to be affected */
g_and (ChunkFlags | CF_CONST, ~(Mask << Expr->Type->A.B.Offs));
/* Restore the bits that are not to be affected */
g_or (ChunkFlags & ~CF_FORCECHAR, 0);
/* Store the whole data chunk containing the changed bits back */
Store (Expr, ChunkType);
Done:
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
}
static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char* Op)
/* Parse an "=" (if 'Gen' is 0) or "op=" operation for arithmetic lhs */
{
ExprDesc Expr2;
CodeMark PushPos;
unsigned Flags;
int MustScale;
ED_Init (&Expr2);
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
/* Determine code generator flags */
Flags = TypeOf (Expr->Type);
/* Determine the type of the lhs */
MustScale = Gen != 0 && (Gen->Func == g_add || Gen->Func == g_sub) &&
IsTypePtr (Expr->Type);
/* Get the address on stack for the store */
PushAddr (Expr);
if (Gen == 0) {
/* Read the expression on the right side of the '=' */
MarkedExprWithCheck (hie1, &Expr2);
/* Do type conversion if necessary. Beware: Do not use char type
** here!
*/
TypeConversion (&Expr2, Expr->Type);
/* If necessary, load the value into the primary register */
LoadExpr (CF_NONE, &Expr2);
} else {
/* Load the original value if necessary */
LoadExpr (CF_NONE, Expr);
/* Push lhs on stack */
GetCodePos (&PushPos);
g_push (Flags, 0);
/* Read the expression on the right side of the '=' or 'op=' */
MarkedExprWithCheck (hie1, &Expr2);
/* The rhs must be an integer (or a float, but we don't support that yet */
if (!IsClassInt (Expr2.Type)) {
Error ("Invalid right operand for binary operator '%s'", Op);
/* Continue. Wrong code will be generated, but the compiler won't
** break, so this is the best error recovery.
*/
}
/* Special treatment if the value is constant.
** Beware: Expr2 may contain side effects, so there must not be
** code generated for Expr2.
*/
if (ED_IsConstAbsInt (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) {
/* Since we will operate with a constant, we can remove the push if
** the generator has the NOPUSH flag set.
*/
if (Gen->Flags & GEN_NOPUSH) {
RemoveCode (&PushPos);
}
if (MustScale) {
/* lhs is a pointer, scale rhs */
Expr2.IVal *= CheckedSizeOf (Expr->Type+1);
}
/* If the lhs is character sized, the operation may be later done
** with characters.
*/
if (CheckedSizeOf (Expr->Type) == SIZEOF_CHAR) {
Flags |= CF_FORCECHAR;
}
/* Special handling for add and sub - some sort of a hack, but short code */
if (Gen->Func == g_add) {
g_inc (Flags | CF_CONST, Expr2.IVal);
} else if (Gen->Func == g_sub) {
g_dec (Flags | CF_CONST, Expr2.IVal);
} else {
if (Expr2.IVal == 0) {
/* Check for div by zero/mod by zero */
if (Gen->Func == g_div) {
Error ("Division by zero");
} else if (Gen->Func == g_mod) {
Error ("Modulo operation with zero");
}
}
Gen->Func (Flags | CF_CONST, Expr2.IVal);
}
} else {
/* If necessary, load the value into the primary register */
LoadExpr (CF_NONE, &Expr2);
if (MustScale) {
/* lhs is a pointer, scale rhs */
g_scale (TypeOf (Expr2.Type), CheckedSizeOf (Expr->Type+1));
}
/* If the lhs is character sized, the operation may be later done
** with characters.
*/
if (CheckedSizeOf (Expr->Type) == SIZEOF_CHAR) {
Flags |= CF_FORCECHAR;
}
/* Adjust the types of the operands if needed */
Gen->Func (g_typeadjust (Flags, TypeOf (Expr2.Type)), 0);
}
}
/* Generate a store instruction */
Store (Expr, 0);
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
}
void OpAssign (const GenDesc* Gen, ExprDesc* Expr, const char* Op)
/* Parse an "=" (if 'Gen' is 0) or "op=" operation */
{
const Type* ltype = Expr->Type;
@@ -142,28 +584,32 @@ void Assignment (ExprDesc* Expr)
ED_Init (&Expr2);
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
/* We must have an lvalue for an assignment */
if (ED_IsRVal (Expr)) {
if (IsTypeArray (Expr->Type)) {
Error ("Array type '%s' is not assignable", GetFullTypeName (Expr->Type));
} else if (IsTypeFunc (Expr->Type)) {
Error ("Function type '%s' is not assignable", GetFullTypeName (Expr->Type));
} else {
Error ("Assignment to rvalue");
/* Only "=" accept struct/union */
if (IsClassStruct (ltype) ? Gen != 0 : !IsClassScalar (ltype)) {
Error ("Invalid left operand for binary operator '%s'", Op);
/* Continue. Wrong code will be generated, but the compiler won't
** break, so this is the best error recovery.
*/
} else {
/* Check for assignment to incomplete type */
if (IsIncompleteESUType (ltype)) {
Error ("Assignment to incomplete type '%s'", GetFullTypeName (ltype));
} else if (ED_IsRVal (Expr)) {
/* Assignment can only be used with lvalues */
if (IsTypeArray (ltype)) {
Error ("Array type '%s' is not assignable", GetFullTypeName (ltype));
} else if (IsTypeFunc (ltype)) {
Error ("Function type '%s' is not assignable", GetFullTypeName (ltype));
} else {
Error ("Assignment to rvalue");
}
} else if (IsQualConst (ltype)) {
/* Check for assignment to const */
Error ("Assignment to const");
}
}
/* Check for assignment to const */
if (IsQualConst (ltype)) {
Error ("Assignment to const");
}
/* Check for assignment to incomplete type */
if (IsIncompleteESUType (ltype)) {
Error ("Assignment to incomplete type '%s'", GetFullTypeName (ltype));
}
/* Skip the '=' token */
/* Skip the '=' or 'op=' token */
NextToken ();
/* cc65 does not have full support for handling structs or unions. Since
@@ -174,114 +620,131 @@ void Assignment (ExprDesc* Expr)
if (IsClassStruct (ltype)) {
/* Copy the struct or union by value */
CopyStruct (Expr, &Expr2);
} else if (ED_IsBitField (Expr)) {
CodeMark AndPos;
CodeMark PushPos;
unsigned Mask;
unsigned Flags;
/* If the bit-field fits within one byte, do the following operations
** with bytes.
*/
if (Expr->BitOffs / CHAR_BITS == (Expr->BitOffs + Expr->BitWidth - 1) / CHAR_BITS) {
Expr->Type = type_uchar;
}
/* Determine code generator flags */
Flags = TypeOf (Expr->Type);
/* Assignment to a bit field. Get the address on stack for the store. */
PushAddr (Expr);
/* Load the value from the location */
Expr->Flags &= ~E_BITFIELD;
LoadExpr (CF_NONE, Expr);
/* Mask unwanted bits */
Mask = (0x0001U << Expr->BitWidth) - 1U;
GetCodePos (&AndPos);
g_and (Flags | CF_CONST, ~(Mask << Expr->BitOffs));
/* Push it on stack */
GetCodePos (&PushPos);
g_push (Flags, 0);
/* Read the expression on the right side of the '=' */
MarkedExprWithCheck (hie1, &Expr2);
/* Do type conversion if necessary. Beware: Do not use char type
** here!
*/
TypeConversion (&Expr2, ltype);
/* Special treatment if the value is constant. */
/* Beware: Expr2 may contain side effects, so there must not be
** code generated for Expr2.
*/
if (ED_IsConstAbsInt (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) {
/* Get the value and apply the mask */
unsigned Val = (unsigned) (Expr2.IVal & Mask);
/* Since we will do the OR with a constant, we can remove the push */
RemoveCode (&PushPos);
/* If the value is equal to the mask now, all bits are one, and we
** can remove the mask operation from above.
*/
if (Val == Mask) {
RemoveCode (&AndPos);
}
/* Generate the or operation */
g_or (Flags | CF_CONST, Val << Expr->BitOffs);
} else {
/* If necessary, load the value into the primary register */
LoadExpr (CF_NONE, &Expr2);
/* Apply the mask */
g_and (Flags | CF_CONST, Mask);
/* Shift it into the right position */
g_asl (Flags | CF_CONST, Expr->BitOffs);
/* Or both values */
g_or (Flags, 0);
}
/* Generate a store instruction */
Store (Expr, 0);
/* Restore the expression type */
Expr->Type = ltype;
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
} else if (IsTypeBitField (ltype)) {
/* Special care is needed for bit-field 'op=' */
OpAssignBitField (Gen, Expr, Op);
} else {
/* Get the address on stack if needed */
PushAddr (Expr);
/* Read the expression on the right side of the '=' */
hie1 (&Expr2);
/* Do type conversion if necessary */
TypeConversion (&Expr2, ltype);
/* If necessary, load the value into the primary register */
LoadExpr (CF_NONE, &Expr2);
/* Generate a store instruction */
Store (Expr, 0);
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
/* Normal straight 'op=' */
OpAssignArithmetic (Gen, Expr, Op);
}
}
void OpAddSubAssign (const GenDesc* Gen, ExprDesc *Expr, const char* Op)
/* Parse a "+=" or "-=" operation */
{
ExprDesc Expr2;
unsigned lflags;
unsigned rflags;
int MustScale;
/* We currently only handle non-bit-fields in some addressing modes here */
if (IsTypeBitField (Expr->Type) || ED_IsLocPrimaryOrExpr (Expr)) {
/* Use generic routine instead */
OpAssign (Gen, Expr, Op);
return;
}
/* There must be an integer or pointer on the left side */
if (!IsClassInt (Expr->Type) && !IsTypePtr (Expr->Type)) {
Error ("Invalid left operand for binary operator '%s'", Op);
/* Continue. Wrong code will be generated, but the compiler won't
** break, so this is the best error recovery.
*/
} else {
/* We must have an lvalue */
if (ED_IsRVal (Expr)) {
Error ("Invalid lvalue in assignment");
} else if (IsQualConst (Expr->Type)) {
/* The left side must not be const qualified */
Error ("Assignment to const");
}
}
/* Skip the operator */
NextToken ();
/* Check if we have a pointer expression and must scale rhs */
MustScale = IsTypePtr (Expr->Type);
/* Initialize the code generator flags */
lflags = 0;
rflags = 0;
ED_Init (&Expr2);
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
/* Evaluate the rhs. We expect an integer here, since float is not
** supported
*/
hie1 (&Expr2);
if (!IsClassInt (Expr2.Type)) {
Error ("Invalid right operand for binary operator '%s'", Op);
/* Continue. Wrong code will be generated, but the compiler won't
** break, so this is the best error recovery.
*/
}
/* Setup the code generator flags */
lflags |= TypeOf (Expr->Type) | GlobalModeFlags (Expr) | CF_FORCECHAR;
rflags |= TypeOf (Expr2.Type) | CF_FORCECHAR;
if (ED_IsConstAbs (&Expr2)) {
/* The resulting value is a constant */
rflags |= CF_CONST;
lflags |= CF_CONST;
/* Scale it */
if (MustScale) {
Expr2.IVal *= CheckedSizeOf (Indirect (Expr->Type));
}
} else {
/* Not constant, load into the primary */
LoadExpr (CF_NONE, &Expr2);
/* Convert the type of the rhs to that of the lhs */
g_typecast (lflags, rflags & ~CF_FORCECHAR);
if (MustScale) {
/* lhs is a pointer, scale rhs */
g_scale (TypeOf (Expr2.Type), CheckedSizeOf (Indirect (Expr->Type)));
}
}
/* Output apropriate code depending on the location */
switch (ED_GetLoc (Expr)) {
case E_LOC_ABS:
case E_LOC_GLOBAL:
case E_LOC_STATIC:
case E_LOC_REGISTER:
case E_LOC_LITERAL:
case E_LOC_CODE:
/* Absolute numeric addressed variable, global variable, local
** static variable, register variable, pooled literal or code
** label location.
*/
if (Gen->Tok == TOK_PLUS_ASSIGN) {
g_addeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
} else {
g_subeqstatic (lflags, Expr->Name, Expr->IVal, Expr2.IVal);
}
break;
case E_LOC_STACK:
/* Value on the stack */
if (Gen->Tok == TOK_PLUS_ASSIGN) {
g_addeqlocal (lflags, Expr->IVal, Expr2.IVal);
} else {
g_subeqlocal (lflags, Expr->IVal, Expr2.IVal);
}
break;
default:
Internal ("Invalid location in Store(): 0x%04X", ED_GetLoc (Expr));
}
/* Expression is an rvalue in the primary now */
ED_FinalizeRValLoad (Expr);
}

View File

@@ -43,14 +43,38 @@
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Whether to save/restore the original lhs or result value */
enum {
OA_NEED_NONE,
OA_NEED_OLD,
OA_NEED_NEW,
};
/* Forward */
struct GenDesc;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void Assignment (ExprDesc* lval);
/* Parse an assignment */
void DoIncDecBitField (ExprDesc* Expr, long Val, unsigned KeepResult);
/* Process inc/dec for bit-field */
void OpAssign (const struct GenDesc* Gen, ExprDesc* lval, const char* Op);
/* Parse an "=" (if 'Gen' is 0) or "op=" operation */
void OpAddSubAssign (const struct GenDesc* Gen, ExprDesc *Expr, const char* Op);
/* Parse a "+=" or "-=" operation */

View File

@@ -172,6 +172,10 @@ static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
if (Info && Info->ByteUse != REG_NONE) {
/* These addressing modes will never change the zp loc */
E->Use |= Info->WordUse;
if ((E->Use & REG_SP) != 0) {
E->Use |= SLV_IND;
}
}
break;
@@ -1777,6 +1781,13 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
if (RegValIsKnown (In->RegX)) {
Out->RegX = (In->RegX ^ 0xFF);
}
} else if (strncmp (E->Arg, "asrax", 5) == 0 ||
strncmp (E->Arg, "shrax", 5) == 0) {
if (RegValIsKnown (In->RegX)) {
if (In->RegX == 0x00 || In->RegX == 0xFF) {
Out->RegX = In->RegX;
}
}
} else if (strcmp (E->Arg, "tosandax") == 0) {
if (RegValIsKnown (In->RegA) && In->RegA == 0) {
Out->RegA = 0;

View File

@@ -1166,7 +1166,9 @@ void g_putind (unsigned Flags, unsigned Offs)
/* Overflow - we need to add the low byte also */
AddCodeLine ("ldy #$00");
AddCodeLine ("clc");
AddCodeLine ("pha");
if ((Flags & CF_NOKEEP) == 0) {
AddCodeLine ("pha");
}
AddCodeLine ("lda #$%02X", Offs & 0xFF);
AddCodeLine ("adc (sp),y");
AddCodeLine ("sta (sp),y");
@@ -1174,7 +1176,9 @@ void g_putind (unsigned Flags, unsigned Offs)
AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF);
AddCodeLine ("adc (sp),y");
AddCodeLine ("sta (sp),y");
AddCodeLine ("pla");
if ((Flags & CF_NOKEEP) == 0) {
AddCodeLine ("pla");
}
/* Complete address is on stack, new offset is zero */
Offs = 0;
@@ -1184,12 +1188,15 @@ void g_putind (unsigned Flags, unsigned Offs)
/* We can just add the high byte */
AddCodeLine ("ldy #$01");
AddCodeLine ("clc");
AddCodeLine ("pha");
if ((Flags & CF_NOKEEP) == 0) {
AddCodeLine ("pha");
}
AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF);
AddCodeLine ("adc (sp),y");
AddCodeLine ("sta (sp),y");
AddCodeLine ("pla");
if ((Flags & CF_NOKEEP) == 0) {
AddCodeLine ("pla");
}
/* Offset is now just the low byte */
Offs &= 0x00FF;
}
@@ -1696,7 +1703,9 @@ void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
if (flags & CF_CONST) {
if (val == 1) {
AddCodeLine ("inc %s", lbuf);
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("lda %s", lbuf);
}
} else {
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
AddCodeLine ("clc");
@@ -1726,8 +1735,10 @@ void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("inc %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("lda %s", lbuf); /* Hmmm... */
AddCodeLine ("ldx %s+1", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("lda %s", lbuf); /* Hmmm... */
AddCodeLine ("ldx %s+1", lbuf);
}
} else {
AddCodeLine ("lda #$%02X", (int)(val & 0xFF));
AddCodeLine ("clc");
@@ -1738,13 +1749,17 @@ void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("bcc %s", LocalLabelName (L));
AddCodeLine ("inc %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("ldx %s+1", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("ldx %s+1", lbuf);
}
} else {
AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8));
AddCodeLine ("adc %s+1", lbuf);
AddCodeLine ("sta %s+1", lbuf);
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
}
}
}
} else {
@@ -1754,8 +1769,10 @@ void g_addeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("txa");
AddCodeLine ("adc %s+1", lbuf);
AddCodeLine ("sta %s+1", lbuf);
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
}
}
break;
@@ -1837,9 +1854,11 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val)
AddCodeLine ("lda #$%02X", (int) ((val >> 8) & 0xFF));
AddCodeLine ("adc (sp),y");
AddCodeLine ("sta (sp),y");
AddCodeLine ("tax");
AddCodeLine ("dey");
AddCodeLine ("lda (sp),y");
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("tax");
AddCodeLine ("dey");
AddCodeLine ("lda (sp),y");
}
} else {
g_getimmed (flags, val, 0);
AddCodeLine ("jsr addeqysp");
@@ -1919,7 +1938,9 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
if (flags & CF_CONST) {
if (val == 1) {
AddCodeLine ("dec %s", lbuf);
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("lda %s", lbuf);
}
} else {
AddCodeLine ("lda %s", lbuf);
AddCodeLine ("sec");
@@ -1953,13 +1974,17 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("bcs %s", LocalLabelName (L));
AddCodeLine ("dec %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("ldx %s+1", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("ldx %s+1", lbuf);
}
} else {
AddCodeLine ("lda %s+1", lbuf);
AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8));
AddCodeLine ("sta %s+1", lbuf);
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
}
}
} else {
AddCodeLine ("eor #$FF");
@@ -1970,8 +1995,10 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("eor #$FF");
AddCodeLine ("adc %s+1", lbuf);
AddCodeLine ("sta %s+1", lbuf);
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
if ((flags & CF_NOKEEP) == 0) {
AddCodeLine ("tax");
AddCodeLine ("lda %s", lbuf);
}
}
break;

View File

@@ -82,269 +82,296 @@ struct FuncInfo {
unsigned Chg; /* Changed/destroyed registers */
};
/* Note for the shift functions: Shifts are done modulo 32, so all shift
/* Functions that change the SP are regarded as using the SP as well.
** The callax/jmpvec functions may call a function that uses/changes more
** registers, so we should further check the info of the called function
** or just play it safe.
** Note for the shift functions: Shifts are done modulo 32, so all shift
** routines are marked to use only the A register. The remainder is ignored
** anyway.
*/
static const FuncInfo FuncInfoTable[] = {
{ "addeq0sp", REG_AX, PSTATE_ALL | REG_AXY },
{ "addeqysp", REG_AXY, PSTATE_ALL | REG_AXY },
{ "addysp", REG_Y, PSTATE_ALL | REG_NONE },
{ "aslax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "asleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "asrax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "asreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "bcasta", REG_A, PSTATE_ALL | REG_AX },
{ "bcastax", REG_AX, PSTATE_ALL | REG_AX },
{ "bcasteax", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "bnega", REG_A, PSTATE_ALL | REG_AX },
{ "bnegax", REG_AX, PSTATE_ALL | REG_AX },
{ "bnegeax", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "booleq", PSTATE_Z, PSTATE_ALL | REG_AX },
{ "boolge", PSTATE_N, PSTATE_ALL | REG_AX },
{ "boolgt", PSTATE_ZN, PSTATE_ALL | REG_AX },
{ "boolle", PSTATE_ZN, PSTATE_ALL | REG_AX },
{ "boollt", PSTATE_N, PSTATE_ALL | REG_AX },
{ "boolne", PSTATE_Z, PSTATE_ALL | REG_AX },
{ "booluge", PSTATE_C, PSTATE_ALL | REG_AX },
{ "boolugt", PSTATE_CZ, PSTATE_ALL | REG_AX },
{ "boolule", PSTATE_CZ, PSTATE_ALL | REG_AX },
{ "boolult", PSTATE_C, PSTATE_ALL | REG_AX },
{ "callax", REG_AX, PSTATE_ALL | REG_ALL },
{ "complax", REG_AX, PSTATE_ALL | REG_AX },
{ "decax1", REG_AX, PSTATE_ALL | REG_AX },
{ "decax2", REG_AX, PSTATE_ALL | REG_AX },
{ "decax3", REG_AX, PSTATE_ALL | REG_AX },
{ "decax4", REG_AX, PSTATE_ALL | REG_AX },
{ "decax5", REG_AX, PSTATE_ALL | REG_AX },
{ "decax6", REG_AX, PSTATE_ALL | REG_AX },
{ "decax7", REG_AX, PSTATE_ALL | REG_AX },
{ "decax8", REG_AX, PSTATE_ALL | REG_AX },
{ "decaxy", REG_AXY, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "deceaxy", REG_EAXY, PSTATE_ALL | REG_EAX },
{ "decsp1", REG_NONE, PSTATE_ALL | REG_Y },
{ "decsp2", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp3", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp4", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp5", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp6", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp7", REG_NONE, PSTATE_ALL | REG_A },
{ "decsp8", REG_NONE, PSTATE_ALL | REG_A },
{ "incax1", REG_AX, PSTATE_ALL | REG_AX },
{ "incax2", REG_AX, PSTATE_ALL | REG_AX },
{ "incax3", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax4", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax5", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax6", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax7", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax8", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incsp1", REG_NONE, PSTATE_ALL | REG_NONE },
{ "incsp2", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp3", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp4", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp5", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp6", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp7", REG_NONE, PSTATE_ALL | REG_Y },
{ "incsp8", REG_NONE, PSTATE_ALL | REG_Y },
{ "laddeq", REG_EAXY|REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeq0sp", REG_EAX, PSTATE_ALL | REG_EAXY },
{ "laddeq1", REG_Y | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeqa", REG_AY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeqysp", REG_EAXY, PSTATE_ALL | REG_EAXY },
{ "ldaidx", REG_AXY, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "ldauidx", REG_AXY, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "ldax0sp", REG_NONE, PSTATE_ALL | REG_AXY },
{ "ldaxi", REG_AX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "ldaxidx", REG_AXY, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "ldaxysp", REG_Y, PSTATE_ALL | REG_AXY },
{ "ldeax0sp", REG_NONE, PSTATE_ALL | REG_EAXY },
{ "ldeaxi", REG_AX, PSTATE_ALL | REG_EAXY | REG_PTR1 },
{ "ldeaxidx", REG_AXY, PSTATE_ALL | REG_EAXY | REG_PTR1 },
{ "ldeaxysp", REG_Y, PSTATE_ALL | REG_EAXY },
{ "leaa0sp", REG_A, PSTATE_ALL | REG_AX },
{ "leaaxsp", REG_AX, PSTATE_ALL | REG_AX },
{ "lsubeq", REG_EAXY|REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeq0sp", REG_EAX, PSTATE_ALL | REG_EAXY },
{ "lsubeq1", REG_Y | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeqa", REG_AY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeqysp", REG_EAXY, PSTATE_ALL | REG_EAXY },
{ "mulax10", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax3", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax5", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax6", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax7", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax9", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "negax", REG_AX, PSTATE_ALL | REG_AX },
{ "push0", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push0ax", REG_AX, PSTATE_ALL | REG_Y | REG_SREG },
{ "push1", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push2", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push3", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push4", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push5", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push6", REG_NONE, PSTATE_ALL | REG_AXY },
{ "push7", REG_NONE, PSTATE_ALL | REG_AXY },
{ "pusha", REG_A, PSTATE_ALL | REG_Y },
{ "pusha0", REG_A, PSTATE_ALL | REG_XY },
{ "pusha0sp", REG_NONE, PSTATE_ALL | REG_AY },
{ "pushaFF", REG_A, PSTATE_ALL | REG_Y },
{ "pushax", REG_AX, PSTATE_ALL | REG_Y },
{ "pushaysp", REG_Y, PSTATE_ALL | REG_AY },
{ "pushc0", REG_NONE, PSTATE_ALL | REG_A | REG_Y },
{ "pushc1", REG_NONE, PSTATE_ALL | REG_A | REG_Y },
{ "pushc2", REG_NONE, PSTATE_ALL | REG_A | REG_Y },
{ "pusheax", REG_EAX, PSTATE_ALL | REG_Y },
{ "pushl0", REG_NONE, PSTATE_ALL | REG_AXY },
{ "pushw", REG_AX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "pushw0sp", REG_NONE, PSTATE_ALL | REG_AXY },
{ "pushwidx", REG_AXY, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "pushwysp", REG_Y, PSTATE_ALL | REG_AXY },
{ "regswap", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "regswap1", REG_XY, PSTATE_ALL | REG_A },
{ "regswap2", REG_XY, PSTATE_ALL | REG_A | REG_Y },
{ "return0", REG_NONE, PSTATE_ALL | REG_AX },
{ "return1", REG_NONE, PSTATE_ALL | REG_AX },
{ "shlax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "shleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "shrax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "shreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "staspidx", REG_A | REG_Y, PSTATE_ALL | REG_Y | REG_TMP1 | REG_PTR1 },
{ "stax0sp", REG_AX, PSTATE_ALL | REG_Y },
{ "staxspidx", REG_AXY, PSTATE_ALL | REG_TMP1 | REG_PTR1 },
{ "staxysp", REG_AXY, PSTATE_ALL | REG_Y },
{ "steax0sp", REG_EAX, PSTATE_ALL | REG_Y },
{ "steaxysp", REG_EAXY, PSTATE_ALL | REG_Y },
{ "subeq0sp", REG_AX, PSTATE_ALL | REG_AXY },
{ "subeqysp", REG_AXY, PSTATE_ALL | REG_AXY },
{ "subysp", REG_Y, PSTATE_ALL | REG_AY },
{ "tosadd0ax", REG_AX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosadda0", REG_A, PSTATE_ALL | REG_AXY },
{ "tosaddax", REG_AX, PSTATE_ALL | REG_AXY },
{ "tosaddeax", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosand0ax", REG_AX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosanda0", REG_A, PSTATE_ALL | REG_AXY },
{ "tosandax", REG_AX, PSTATE_ALL | REG_AXY },
{ "tosandeax", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosaslax", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosasleax", REG_A, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosasrax", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosasreax", REG_A, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosdiv0ax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosdiva0", REG_A, PSTATE_ALL | REG_ALL },
{ "tosdivax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosdiveax", REG_EAX, PSTATE_ALL | REG_ALL },
{ "toseq00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toseqa0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toseqax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toseqeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosge00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgea0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgeax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgeeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosgt00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgta0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgtax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosgteax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosicmp", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosicmp0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toslcmp", REG_EAX, PSTATE_ALL | REG_A | REG_Y | REG_PTR1 },
{ "tosle00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toslea0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosleax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosleeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "toslt00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toslta0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosltax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "toslteax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosmod0ax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmodeax", REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosmul0ax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmula0", REG_A, PSTATE_ALL | REG_ALL },
{ "tosmulax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmuleax", REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosne00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosnea0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosneax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosneeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosor0ax", REG_AX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosora0", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosorax", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosoreax", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosrsub0ax", REG_AX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosrsuba0", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosrsubax", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosrsubeax", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosshlax", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosshleax", REG_A, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosshrax", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosshreax", REG_A, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tossub0ax", REG_AX, PSTATE_ALL | REG_EAXY },
{ "tossuba0", REG_A, PSTATE_ALL | REG_AXY },
{ "tossubax", REG_AX, PSTATE_ALL | REG_AXY },
{ "tossubeax", REG_EAX, PSTATE_ALL | REG_EAXY },
{ "tosudiv0ax", REG_AX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosudiva0", REG_A, PSTATE_ALL | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosudivax", REG_AX, PSTATE_ALL | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosudiveax", REG_EAX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosuge00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugea0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugeax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugeeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosugt00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugta0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugtax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosugteax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosule00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosulea0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosuleax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosuleeax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosult00", REG_NONE, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosulta0", REG_A, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosultax", REG_AX, PSTATE_ALL | REG_AXY | REG_SREG },
{ "tosulteax", REG_EAX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "tosumod0ax", REG_AX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosumoda0", REG_A, PSTATE_ALL | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosumodax", REG_AX, PSTATE_ALL | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosumodeax", REG_EAX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosumul0ax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosumula0", REG_A, PSTATE_ALL | REG_ALL },
{ "tosumulax", REG_AX, PSTATE_ALL | REG_ALL },
{ "tosumuleax", REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosxor0ax", REG_AX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tosxora0", REG_A, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosxorax", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "tosxoreax", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "tsteax", REG_EAX, PSTATE_ALL | REG_Y },
{ "utsteax", REG_EAX, PSTATE_ALL | REG_Y },
{ "addeq0sp", SLV_TOP | REG_AX, PSTATE_ALL | REG_AXY },
{ "addeqysp", SLV_IND | REG_AXY, PSTATE_ALL | REG_AXY },
{ "addysp", REG_SP | REG_Y, PSTATE_ALL | REG_SP },
{ "along", REG_A, PSTATE_ALL | REG_X | REG_SREG },
{ "aslax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "aslaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "asleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asleax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "asrax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "asraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "asreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "asreax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "aulong", REG_NONE, PSTATE_ALL | REG_X | REG_SREG },
{ "axlong", REG_X, PSTATE_ALL | REG_Y | REG_SREG },
{ "axulong", REG_NONE, PSTATE_ALL | REG_Y | REG_SREG },
{ "bcasta", REG_A, PSTATE_ALL | REG_AX },
{ "bcastax", REG_AX, PSTATE_ALL | REG_AX },
{ "bcasteax", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "bnega", REG_A, PSTATE_ALL | REG_AX },
{ "bnegax", REG_AX, PSTATE_ALL | REG_AX },
{ "bnegeax", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "booleq", PSTATE_Z, PSTATE_ALL | REG_AX },
{ "boolge", PSTATE_N, PSTATE_ALL | REG_AX },
{ "boolgt", PSTATE_ZN, PSTATE_ALL | REG_AX },
{ "boolle", PSTATE_ZN, PSTATE_ALL | REG_AX },
{ "boollt", PSTATE_N, PSTATE_ALL | REG_AX },
{ "boolne", PSTATE_Z, PSTATE_ALL | REG_AX },
{ "booluge", PSTATE_C, PSTATE_ALL | REG_AX },
{ "boolugt", PSTATE_CZ, PSTATE_ALL | REG_AX },
{ "boolule", PSTATE_CZ, PSTATE_ALL | REG_AX },
{ "boolult", PSTATE_C, PSTATE_ALL | REG_AX },
{ "callax", REG_AX, PSTATE_ALL | REG_ALL }, /* PSTATE_ZN | REG_PTR1 */
{ "complax", REG_AX, PSTATE_ALL | REG_AX },
{ "decax1", REG_AX, PSTATE_ALL | REG_AX },
{ "decax2", REG_AX, PSTATE_ALL | REG_AX },
{ "decax3", REG_AX, PSTATE_ALL | REG_AX },
{ "decax4", REG_AX, PSTATE_ALL | REG_AX },
{ "decax5", REG_AX, PSTATE_ALL | REG_AX },
{ "decax6", REG_AX, PSTATE_ALL | REG_AX },
{ "decax7", REG_AX, PSTATE_ALL | REG_AX },
{ "decax8", REG_AX, PSTATE_ALL | REG_AX },
{ "decaxy", REG_AXY, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "deceaxy", REG_EAXY, PSTATE_ALL | REG_EAX },
{ "decsp1", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "decsp2", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp3", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp4", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp5", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp6", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp7", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "decsp8", REG_SP, PSTATE_ALL | REG_SP | REG_A },
{ "enter", REG_SP | REG_Y, PSTATE_ALL | REG_SP | REG_AY },
{ "incax1", REG_AX, PSTATE_ALL | REG_AX },
{ "incax2", REG_AX, PSTATE_ALL | REG_AX },
{ "incax3", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax4", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax5", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax6", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax7", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incax8", REG_AX, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "incsp1", REG_SP, PSTATE_ALL | REG_SP },
{ "incsp2", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp3", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp4", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp5", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp6", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp7", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "incsp8", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "jmpvec", REG_EVERYTHING, PSTATE_ALL | REG_ALL }, /* NONE */
{ "laddeq", REG_EAXY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeq0sp", SLV_TOP | REG_EAX, PSTATE_ALL | REG_EAXY },
{ "laddeq1", REG_Y | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeqa", REG_AY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "laddeqysp", SLV_IND | REG_EAXY, PSTATE_ALL | REG_EAXY },
{ "ldaidx", REG_AXY, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "ldauidx", REG_AXY, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "ldax0sp", SLV_TOP, PSTATE_ALL | REG_AXY },
{ "ldaxi", REG_AX, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "ldaxidx", REG_AXY, PSTATE_ALL | REG_AXY | REG_PTR1 },
{ "ldaxysp", SLV_IND | REG_Y, PSTATE_ALL | REG_AXY },
{ "ldeax0sp", SLV_TOP, PSTATE_ALL | REG_EAXY },
{ "ldeaxi", REG_AX, PSTATE_ALL | REG_EAXY | REG_PTR1 },
{ "ldeaxidx", REG_AXY, PSTATE_ALL | REG_EAXY | REG_PTR1 },
{ "ldeaxysp", SLV_IND | REG_Y, PSTATE_ALL | REG_EAXY },
{ "leaa0sp", REG_SP | REG_A, PSTATE_ALL | REG_AX },
{ "leaaxsp", REG_SP | REG_AX, PSTATE_ALL | REG_AX },
{ "leave00", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "leave0", REG_SP, PSTATE_ALL | REG_SP | REG_XY },
{ "leave", REG_SP, PSTATE_ALL | REG_SP | REG_Y },
{ "leavey00", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "leavey0", REG_SP, PSTATE_ALL | REG_SP | REG_XY },
{ "leavey", REG_SP | REG_Y, PSTATE_ALL | REG_SP | REG_Y },
{ "lsubeq", REG_EAXY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeq0sp", SLV_TOP | REG_EAX, PSTATE_ALL | REG_EAXY },
{ "lsubeq1", REG_Y | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeqa", REG_AY | REG_PTR1_LO, PSTATE_ALL | REG_EAXY | REG_PTR1_HI },
{ "lsubeqysp", SLV_IND | REG_EAXY, PSTATE_ALL | REG_EAXY },
{ "mulax10", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax3", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax5", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax6", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax7", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "mulax9", REG_AX, PSTATE_ALL | REG_AX | REG_PTR1 },
{ "negax", REG_AX, PSTATE_ALL | REG_AX },
{ "negeax", REG_EAX, PSTATE_ALL | REG_EAX },
{ "popa", SLV_TOP, PSTATE_ALL | REG_SP | REG_AY },
{ "popax", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY },
{ "popeax", SLV_TOP, PSTATE_ALL | REG_SP | REG_EAXY },
{ "push0", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push0ax", REG_SP | REG_AX, PSTATE_ALL | REG_SP | REG_Y | REG_SREG },
{ "push1", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push2", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push3", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push4", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push5", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push6", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "push7", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "pusha", REG_SP | REG_A, PSTATE_ALL | REG_SP | REG_Y },
{ "pusha0", REG_SP | REG_A, PSTATE_ALL | REG_SP | REG_XY },
{ "pusha0sp", SLV_TOP, PSTATE_ALL | REG_SP | REG_AY },
{ "pushaFF", REG_SP | REG_A, PSTATE_ALL | REG_SP | REG_Y },
{ "pushax", REG_SP | REG_AX, PSTATE_ALL | REG_SP | REG_Y },
{ "pushaysp", SLV_IND | REG_Y, PSTATE_ALL | REG_SP | REG_AY },
{ "pushc0", REG_SP, PSTATE_ALL | REG_SP | REG_A | REG_Y },
{ "pushc1", REG_SP, PSTATE_ALL | REG_SP | REG_A | REG_Y },
{ "pushc2", REG_SP, PSTATE_ALL | REG_SP | REG_A | REG_Y },
{ "pusheax", REG_SP | REG_EAX, PSTATE_ALL | REG_SP | REG_Y },
{ "pushl0", REG_SP, PSTATE_ALL | REG_SP | REG_AXY },
{ "pushw", REG_SP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "pushw0sp", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY },
{ "pushwidx", REG_SP | REG_AXY, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "pushwysp", SLV_IND | REG_Y, PSTATE_ALL | REG_SP | REG_AXY },
{ "regswap", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "regswap1", REG_XY, PSTATE_ALL | REG_A },
{ "regswap2", REG_XY, PSTATE_ALL | REG_A | REG_Y },
{ "resteax", REG_SAVE, PSTATE_ZN | REG_EAX }, /* also uses regsave+2/+3 */
{ "return0", REG_NONE, PSTATE_ALL | REG_AX },
{ "return1", REG_NONE, PSTATE_ALL | REG_AX },
{ "saveeax", REG_EAX, PSTATE_ZN | REG_Y | REG_SAVE }, /* also regsave+2/+3 */
{ "shlax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shlaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "shleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shleax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "shrax1", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
{ "shraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
{ "shreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax3", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
{ "shreax4", REG_EAX, PSTATE_ALL | REG_EAXY | REG_TMP1 },
{ "staspidx", SLV_TOP | REG_AY, PSTATE_ALL | REG_SP | REG_Y | REG_TMP1 | REG_PTR1 },
{ "stax0sp", REG_SP | REG_AX, PSTATE_ALL | SLV_TOP | REG_Y },
{ "staxspidx", SLV_TOP | REG_AXY, PSTATE_ALL | REG_SP | REG_TMP1 | REG_PTR1 },
{ "staxysp", REG_SP | REG_AXY, PSTATE_ALL | SLV_IND | REG_Y },
{ "steax0sp", REG_SP | REG_EAX, PSTATE_ALL | SLV_TOP | REG_Y },
{ "steaxspidx", SLV_TOP | REG_EAXY, PSTATE_ALL | REG_SP | REG_Y | REG_TMP1 | REG_PTR1 }, /* also tmp2, tmp3 */
{ "steaxysp", REG_SP | REG_EAXY, PSTATE_ALL | SLV_IND | REG_Y },
{ "subeq0sp", SLV_TOP | REG_AX, PSTATE_ALL | REG_AXY },
{ "subeqysp", SLV_IND | REG_AXY, PSTATE_ALL | REG_AXY },
{ "subysp", REG_SP | REG_Y, PSTATE_ALL | REG_SP | REG_AY },
{ "swapstk", SLV_TOP | REG_AX, PSTATE_ALL | SLV_TOP | REG_AXY }, /* also ptr4 */
{ "tosadd0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosadda0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY },
{ "tosaddax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY },
{ "tosaddeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosand0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosanda0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY },
{ "tosandax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY },
{ "tosandeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosaslax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosasleax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosasrax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosasreax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosdiv0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_ALL },
{ "tosdiva0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_ALL },
{ "tosdivax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_ALL },
{ "tosdiveax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_ALL },
{ "toseq00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toseqa0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toseqax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toseqeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosge00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgea0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgeax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgeeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosgt00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgta0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgtax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosgteax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosicmp", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosicmp0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosint", SLV_TOP, PSTATE_ALL | REG_SP | REG_Y },
{ "toslcmp", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_A | REG_Y | REG_PTR1 },
{ "tosle00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toslea0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosleax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosleeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "toslong", SLV_TOP, PSTATE_ALL | REG_SP | REG_Y },
{ "toslt00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toslta0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosltax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "toslteax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosmod0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmodeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosmul0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmula0", SLV_TOP | REG_A, PSTATE_ALL | REG_ALL },
{ "tosmulax", SLV_TOP | REG_AX, PSTATE_ALL | REG_ALL },
{ "tosmuleax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosne00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosnea0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosneax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosneeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosor0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosora0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosorax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosoreax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosrsub0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosrsuba0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosrsubax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosrsubeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosshlax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosshleax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosshrax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosshreax", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tossub0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY },
{ "tossuba0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY },
{ "tossubax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY },
{ "tossubeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY },
{ "tosudiv0ax", SLV_TOP | REG_AX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosudiva0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosudivax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosudiveax", SLV_TOP | REG_EAX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosuge00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugea0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugeax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugeeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosugt00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugta0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugtax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosugteax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosule00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosulea0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosuleax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosuleeax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosulong", SLV_TOP, PSTATE_ALL | REG_SP | REG_Y },
{ "tosult00", SLV_TOP, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosulta0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosultax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_SREG },
{ "tosulteax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_AXY | REG_PTR1 },
{ "tosumod0ax", SLV_TOP | REG_AX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosumoda0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosumodax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_PTR1 }, /* also ptr4 */
{ "tosumodeax", SLV_TOP | REG_EAX, PSTATE_ALL | (REG_ALL & ~REG_SAVE) },
{ "tosumul0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_ALL },
{ "tosumula0", SLV_TOP | REG_A, PSTATE_ALL | REG_ALL },
{ "tosumulax", SLV_TOP | REG_AX, PSTATE_ALL | REG_ALL },
{ "tosumuleax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_ALL },
{ "tosxor0ax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tosxora0", SLV_TOP | REG_A, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosxorax", SLV_TOP | REG_AX, PSTATE_ALL | REG_SP | REG_AXY | REG_TMP1 },
{ "tosxoreax", SLV_TOP | REG_EAX, PSTATE_ALL | REG_SP | REG_EAXY | REG_TMP1 },
{ "tsteax", REG_EAX, PSTATE_ALL | REG_Y },
{ "utsteax", REG_EAX, PSTATE_ALL | REG_Y },
};
#define FuncInfoCount (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
@@ -481,6 +508,7 @@ fncls_t GetFuncInfo (const char* Name, unsigned int* Use, unsigned int* Chg)
/* Did we find it in the top-level table? */
if (E && IsTypeFunc (E->Type)) {
FuncDesc* D = GetFuncDesc (E->Type);
*Use = REG_NONE;
/* A variadic function will use the Y register (the parameter list
** size is passed there). A fastcall function will use the A or A/X
@@ -488,31 +516,40 @@ fncls_t GetFuncInfo (const char* Name, unsigned int* Use, unsigned int* Chg)
** we assume that any function will destroy all registers.
*/
if ((D->Flags & FD_VARIADIC) != 0) {
*Use = REG_Y;
*Use = REG_Y | REG_SP | SLV_TOP;
} else if (D->Flags & FD_CALL_WRAPPER) {
/* Wrappers may go to any functions, so mark them as using all
** registers.
*/
*Use = REG_EAXY;
} else if ((D->ParamCount > 0 || (D->Flags & FD_EMPTY) != 0) &&
IsFastcallFunc (E->Type)) {
} else if (D->ParamCount > 0 || (D->Flags & FD_EMPTY) != 0) {
/* Will use registers depending on the last param. If the last
** param has incomplete type, or if the function has not been
** prototyped yet, just assume __EAX__.
*/
if (D->LastParam != 0) {
switch (SizeOf (D->LastParam->Type)) {
case 1u:
*Use = REG_A;
break;
case 2u:
*Use = REG_AX;
break;
default:
*Use = REG_EAX;
if (IsFastcallFunc (E->Type)) {
if (D->LastParam != 0) {
switch (SizeOf (D->LastParam->Type)) {
case 1u:
*Use = REG_A;
break;
case 2u:
*Use = REG_AX;
break;
default:
*Use = REG_EAX;
}
if (D->ParamCount > 1) {
/* Passes other params on the stack */
*Use |= REG_SP | SLV_TOP;
}
} else {
/* We'll assume all */
*Use = REG_EAX | REG_SP | SLV_TOP;
}
} else {
*Use = REG_EAX;
/* Passes all params on the stack */
*Use = REG_SP | SLV_TOP;
}
} else {
/* Will not use any registers */
@@ -551,6 +588,9 @@ fncls_t GetFuncInfo (const char* Name, unsigned int* Use, unsigned int* Chg)
/* Use the information we have */
*Use = Info->Use;
*Chg = Info->Chg;
if ((*Use & (SLV_TOP | SLV_IND)) != 0) {
*Use |= REG_SP;
}
} else {
/* It's an internal function we have no information for. If in
** debug mode, output an additional warning, so we have a chance

View File

@@ -75,6 +75,8 @@ struct RegContents;
#define REG_SP_HI 0x2000U
/* Defines for some special register usage */
#define SLV_IND 0x00010000U /* Accesses (sp),y */
#define SLV_TOP 0x00020000U /* Accesses (sp),0 */
#define SLV_SP65 0x00200000U /* Accesses 6502 stack pointer */
#define SLV_PH65 0x00400000U /* Pushes onto 6502 stack */
#define SLV_PL65 0x00800000U /* Pops from 6502 stack */
@@ -104,6 +106,7 @@ struct RegContents;
#define REG_EAXY (REG_EAX | REG_Y)
#define REG_ZP 0xFFF8U
#define REG_ALL 0xFFFFU
#define PSTATE_CZ (PSTATE_C | PSTATE_Z)
#define PSTATE_CZN (PSTATE_C | PSTATE_Z | PSTATE_N)
#define PSTATE_CZVN (PSTATE_C | PSTATE_Z | PSTATE_V | PSTATE_N)

View File

@@ -827,21 +827,28 @@ void AdjustStackOffset (StackOpData* D, unsigned Offs)
CodeEntry* E = CS_GetEntry (D->Code, I);
/* Check against some things that should not happen */
CHECK ((E->Use & SLV_TOP) != SLV_TOP);
/* Check if this entry does a stack access, and if so, if it's a plain
** load from stack, since this is needed later.
*/
int Correction = 0;
if ((E->Use & REG_SP) != 0) {
if ((E->Use & SLV_IND) == SLV_IND) {
/* Check for some things that should not happen */
CHECK (E->AM == AM65_ZP_INDY || E->RI->In.RegY >= (short) Offs);
CHECK (strcmp (E->Arg, "sp") == 0);
/* We need to correct this one */
Correction = (E->OPC == OP65_LDA)? 2 : 1;
if (E->OPC != OP65_JSR) {
/* Check against some things that should not happen */
CHECK (E->AM == AM65_ZP_INDY && E->RI->In.RegY >= (short) Offs);
CHECK (strcmp (E->Arg, "sp") == 0);
/* We need to correct this one */
Correction = 2;
} else {
/* We need to correct this one */
Correction = 1;
}
} else if (CE_IsCallTo (E, "ldaxysp")) {
/* We need to correct this one */
Correction = 1;
}
if (Correction) {
@@ -849,7 +856,7 @@ void AdjustStackOffset (StackOpData* D, unsigned Offs)
** value.
*/
CodeEntry* P = CS_GetPrevEntry (D->Code, I);
if (P && P->OPC == OP65_LDY && CE_IsConstImm (P)) {
if (P && P->OPC == OP65_LDY && CE_IsConstImm (P) && !CE_HasLabel (E)) {
/* The Y load is just before the stack access, adjust it */
CE_SetNumArg (P, P->Num - Offs);
} else {
@@ -860,39 +867,59 @@ void AdjustStackOffset (StackOpData* D, unsigned Offs)
}
/* If we need the value of Y later, be sure to reload it */
if (RegYUsed (D->Code, I+1)) {
CodeEntry* N;
unsigned R = REG_Y | (E->Chg & ~REG_A);
R = GetRegInfo (D->Code, I + 1, R) & R;
if ((R & REG_Y) != 0) {
const char* Arg = MakeHexArg (E->RI->In.RegY);
if (Correction == 2 && (N = CS_GetNextEntry(D->Code, I)) != 0 &&
((N->Info & OF_ZBRA) != 0) && N->JumpTo != 0) {
/* The Y register is used but the load instruction loads A
** and is followed by a branch that evaluates the zero flag.
** This means that we cannot just insert the load insn
** for the Y register at this place, because it would
** destroy the Z flag. Instead place load insns at the
** target of the branch and after it.
** Note: There is a chance that this code won't work. The
** jump may be a backwards jump (in which case the stack
** offset has already been adjusted) or there may be other
** instructions between the load and the conditional jump.
** Currently the compiler does not generate such code, but
** it is possible to force the optimizer into something
** invalid by use of inline assembler.
*/
if ((R & PSTATE_ZN) != 0 && (R & ~(REG_Y | PSTATE_ZN)) == 0) {
CodeEntry* N;
if ((N = CS_GetNextEntry (D->Code, I)) != 0 &&
((N->Info & OF_ZBRA) != 0) && N->JumpTo != 0) {
/* The Y register is used but the load instruction loads A
** and is followed by a branch that evaluates the zero flag.
** This means that we cannot just insert the load insn
** for the Y register at this place, because it would
** destroy the Z flag. Instead place load insns at the
** target of the branch and after it.
** Note: There is a chance that this code won't work. The
** jump may be a backwards jump (in which case the stack
** offset has already been adjusted) or there may be other
** instructions between the load and the conditional jump.
** Currently the compiler does not generate such code, but
** it is possible to force the optimizer into something
** invalid by use of inline assembler.
** Note: In reality, this route is never taken as all
** callers of this function will just give up with
** optimization whenever they detect a branch.
*/
/* Add load insn after the branch */
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
InsertEntry (D, X, I+2);
/* Add load insn after the branch */
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
InsertEntry (D, X, I+2);
/* Add load insn before branch target */
CodeEntry* Y = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
int J = CS_GetEntryIndex (D->Code, N->JumpTo->Owner);
CHECK (J > I); /* Must not happen */
InsertEntry (D, Y, J);
/* Add load insn before branch target */
CodeEntry* Y = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
int J = CS_GetEntryIndex (D->Code, N->JumpTo->Owner);
CHECK (J > I); /* Must not happen */
InsertEntry (D, Y, J);
/* Move the label to the new insn */
CodeLabel* L = CS_GenLabel (D->Code, Y);
CS_MoveLabelRef (D->Code, N, L);
/* Move the label to the new insn */
CodeLabel* L = CS_GenLabel (D->Code, Y);
CS_MoveLabelRef (D->Code, N, L);
/* Skip the next two instructions in the next round */
I += 2;
} else {
/* This could be suboptimal but it will always work (unless stack overflows) */
CodeEntry* X = NewCodeEntry (OP65_PHP, AM65_IMP, 0, 0, E->LI);
InsertEntry (D, X, I+1);
X = NewCodeEntry (OP65_LDY, AM65_IMM, 0, 0, E->LI);
InsertEntry (D, X, I+2);
X = NewCodeEntry (OP65_PLP, AM65_IMP, 0, 0, E->LI);
InsertEntry (D, X, I+3);
/* Skip the three inserted instructions in the next round */
I += 3;
}
} else {
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
InsertEntry (D, X, I+1);
@@ -1197,66 +1224,43 @@ static int CmpHarmless (const void* Key, const void* Entry)
int HarmlessCall (const char* Name)
int HarmlessCall (const CodeEntry* E, int PushedBytes)
/* Check if this is a call to a harmless subroutine that will not interrupt
** the pushax/op sequence when encountered.
*/
{
static const char* const Tab[] = {
"aslax1",
"aslax2",
"aslax3",
"aslax4",
"aslaxy",
"asrax1",
"asrax2",
"asrax3",
"asrax4",
"asraxy",
"bcastax",
"bnegax",
"complax",
"decax1",
"decax2",
"decax3",
"decax4",
"decax5",
"decax6",
"decax7",
"decax8",
"decaxy",
"incax1",
"incax2",
"incax3",
"incax4",
"incax5",
"incax6",
"incax7",
"incax8",
"incaxy",
"ldaidx",
"ldauidx",
"ldaxidx",
"ldaxysp",
"negax",
"shlax1",
"shlax2",
"shlax3",
"shlax4",
"shlaxy",
"shrax1",
"shrax2",
"shrax3",
"shrax4",
"shraxy",
};
unsigned Use = 0, Chg = 0;
if (GetFuncInfo (E->Arg, &Use, &Chg) == FNCLS_BUILTIN) {
if ((Chg & REG_SP) != 0) {
return 0;
}
if ((Use & REG_SP) != 0 &&
((Use & (SLV_IND | SLV_TOP)) != SLV_IND ||
RegValIsUnknown (E->RI->In.RegY) ||
E->RI->In.RegY < PushedBytes)) {
/* If we are using the stack, and we don't have "indirect"
** addressing mode, or the value of Y is unknown, or less
** than two, we cannot cope with this piece of code. Having
** an unknown value of Y means that we cannot correct the
** stack offset, while having an offset less than PushedBytes
** means that the code works with the value on stack which
** is to be removed.
*/
return 0;
}
return 1;
} else {
static const char* const Tab[] = {
"_abs",
};
void* R = bsearch (Name,
Tab,
sizeof (Tab) / sizeof (Tab[0]),
sizeof (Tab[0]),
CmpHarmless);
return (R != 0);
void* R = bsearch (E->Arg,
Tab,
sizeof (Tab) / sizeof (Tab[0]),
sizeof (Tab[0]),
CmpHarmless);
return (R != 0);
}
}

View File

@@ -261,7 +261,7 @@ void RemoveRegLoads (StackOpData* D, LoadInfo* LI);
void RemoveRemainders (StackOpData* D);
/* Remove the code that is unnecessary after translation of the sequence */
int HarmlessCall (const char* Name);
int HarmlessCall (const CodeEntry* E, int PushedBytes);
/* Check if this is a call to a harmless subroutine that will not interrupt
** the pushax/op sequence when encountered.
*/

View File

@@ -1113,9 +1113,9 @@ static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer)
D->IP = D->OpIndex + 1;
if (!D->RhsMultiChg &&
(D->Rhs.A.LoadEntry->Flags & CEF_DONT_REMOVE) == 0 &&
(D->Rhs.A.Flags & LI_DIRECT) != 0) {
if (!D->RhsMultiChg &&
(D->Rhs.A.Flags & LI_DIRECT) != 0 &&
(D->Rhs.A.LoadEntry->Flags & CEF_DONT_REMOVE) == 0) {
/* cmp */
AddOpLow (D, OP65_CMP, &D->Rhs);
@@ -1820,20 +1820,18 @@ unsigned OptStackOps (CodeSeg* S)
Data.OpEntry = E;
State = FoundOp;
break;
} else if (!HarmlessCall (E->Arg)) {
/* A call to an unkown subroutine: We need to start
** over after the last pushax. Note: This will also
** happen if we encounter a call to pushax!
} else if (!HarmlessCall (E, 2)) {
/* The call might use or change the content that we are
** going to access later via the stack pointer. In any
** case, we need to start over after the last pushax.
** Note: This will also happen if we encounter a call
** to pushax!
*/
I = Data.PushIndex;
State = Initialize;
break;
}
} else if ((E->Use & REG_SP) != 0 &&
(E->AM != AM65_ZP_INDY ||
RegValIsUnknown (E->RI->In.RegY) ||
E->RI->In.RegY < 2)) {
} else if (((E->Chg | E->Use) & REG_SP) != 0) {
/* If we are using the stack, and we don't have "indirect Y"
** addressing mode, or the value of Y is unknown, or less
@@ -1843,9 +1841,14 @@ unsigned OptStackOps (CodeSeg* S)
** that the code works with the value on stack which is to
** be removed.
*/
I = Data.PushIndex;
State = Initialize;
break;
if (E->AM == AM65_ZPX_IND ||
((E->Chg | E->Use) & SLV_IND) == 0 ||
(RegValIsUnknown (E->RI->In.RegY) ||
E->RI->In.RegY < 2)) {
I = Data.PushIndex;
State = Initialize;
break;
}
}

View File

@@ -207,7 +207,11 @@ static struct StrBuf* GetFullTypeNameWestEast (struct StrBuf* West, struct StrBu
}
}
SB_AppendStr (&Buf, GetSymTypeName (T));
if (!IsTypeBitField (T)) {
SB_AppendStr (&Buf, GetSymTypeName (T));
} else {
SB_AppendStr (&Buf, GetBasicTypeName (T + 1));
}
if (!SB_IsEmpty (West)) {
SB_AppendChar (&Buf, ' ');
@@ -231,6 +235,7 @@ const char* GetBasicTypeName (const Type* T)
{
switch (GetRawType (T)) {
case T_TYPE_ENUM: return "enum";
case T_TYPE_BITFIELD: return "bit-field";
case T_TYPE_FLOAT: return "float";
case T_TYPE_DOUBLE: return "double";
case T_TYPE_VOID: return "void";
@@ -546,14 +551,14 @@ unsigned long GetIntegerTypeMax (const Type* Type)
static unsigned TypeOfBySize (const Type* Type)
static unsigned TypeOfBySize (unsigned Size)
/* Get the code generator replacement type of the object by its size */
{
unsigned NewType;
/* If the size is less than or equal to that of a a long, we will copy
** the struct using the primary register, otherwise we use memcpy.
*/
switch (SizeOf (Type)) {
switch (Size) {
case 1: NewType = CF_CHAR; break;
case 2: NewType = CF_INT; break;
case 3: /* FALLTHROUGH */
@@ -566,125 +571,6 @@ static unsigned TypeOfBySize (const Type* Type)
Type* NewPointerTo (const Type* T)
/* Return a type string that is "pointer to T". The type string is allocated
** on the heap and may be freed after use.
*/
{
/* Get the size of the type string including the terminator */
unsigned Size = TypeLen (T) + 1;
/* Allocate the new type string */
Type* P = TypeAlloc (Size + 1);
/* Create the return type... */
P[0].C = T_PTR | (T[0].C & T_QUAL_ADDRSIZE);
memcpy (P+1, T, Size * sizeof (Type));
/* ...and return it */
return P;
}
void PrintType (FILE* F, const Type* T)
/* Print fulle name of the type */
{
StrBuf Buf = AUTO_STRBUF_INITIALIZER;
fprintf (F, "%s", SB_GetConstBuf (GetFullTypeNameBuf (&Buf, T)));
SB_Done (&Buf);
}
void PrintFuncSig (FILE* F, const char* Name, const Type* T)
/* Print a function signature */
{
StrBuf Buf = AUTO_STRBUF_INITIALIZER;
StrBuf ParamList = AUTO_STRBUF_INITIALIZER;
StrBuf East = AUTO_STRBUF_INITIALIZER;
StrBuf West = AUTO_STRBUF_INITIALIZER;
/* Get the function descriptor used in definition */
const FuncDesc* D = GetFuncDefinitionDesc (T);
/* Get the parameter list string. Start from the first parameter */
SymEntry* Param = D->SymTab->SymHead;
unsigned I;
for (I = 0; I < D->ParamCount; ++I) {
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
if (I > 0) {
SB_AppendStr (&ParamList, ", ");
}
if (SymIsRegVar (Param)) {
SB_AppendStr (&ParamList, "register ");
}
if (!HasAnonName (Param)) {
SB_AppendStr (&Buf, Param->Name);
}
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));
SB_Clear (&Buf);
/* Next argument */
Param = Param->NextSym;
}
if ((D->Flags & FD_VARIADIC) == 0) {
if (D->ParamCount == 0 && (D->Flags & FD_EMPTY) == 0) {
SB_AppendStr (&ParamList, "void");
}
} else {
if (D->ParamCount > 0) {
SB_AppendStr (&ParamList, ", ...");
} else {
SB_AppendStr (&ParamList, "...");
}
}
SB_Terminate (&ParamList);
/* Get the function qualifiers */
if (GetQualifierTypeCodeNameBuf (&Buf, T->C, T_QUAL_NONE) > 0) {
/* Append a space between the qualifiers and the name */
SB_AppendChar (&Buf, ' ');
}
SB_Terminate (&Buf);
/* Get the signature string without the return type */
SB_Printf (&West, "%s%s (%s)", SB_GetConstBuf (&Buf), Name, SB_GetConstBuf (&ParamList));
SB_Done (&Buf);
SB_Done (&ParamList);
/* Complete with the return type */
GetFullTypeNameWestEast (&West, &East, GetFuncReturn (T));
SB_Append (&West, &East);
SB_Terminate (&West);
/* Output */
fprintf (F, "%s", SB_GetConstBuf (&West));
SB_Done (&East);
SB_Done (&West);
}
void PrintRawType (FILE* F, const Type* T)
/* Print a type string in raw hex format (for debugging) */
{
while (T->C != T_END) {
fprintf (F, "%04lX ", T->C);
++T;
}
fprintf (F, "\n");
}
int TypeHasAttr (const Type* T)
/* Return true if the given type has attribute data */
{
return IsClassStruct (T) || IsTypeArray (T) || IsClassFunc (T);
}
const Type* GetUnderlyingType (const Type* Type)
/* Get the underlying type of an enum or other integer class type */
{
@@ -700,6 +586,18 @@ const Type* GetUnderlyingType (const Type* Type)
if (Type->A.S->V.E.Type != 0) {
return Type->A.S->V.E.Type;
}
} else if (IsTypeBitField (Type)) {
/* We consider the smallest type that can represent all values of the
** bit-field, instead of the type used in the declaration, the truly
** underlying of the bit-field.
*/
unsigned Size = (int)(Type->A.B.Width - 1) / (int)CHAR_BITS + 1;
switch (Size) {
case SIZEOF_CHAR: Type = IsSignSigned (Type) ? type_schar : type_uchar; break;
case SIZEOF_INT: Type = IsSignSigned (Type) ? type_int : type_uint; break;
case SIZEOF_LONG: Type = IsSignSigned (Type) ? type_long : type_ulong; break;
default: Type = IsSignSigned (Type) ? type_int : type_uint; break;
}
}
return Type;
@@ -713,13 +611,14 @@ TypeCode GetUnderlyingTypeCode (const Type* Type)
*/
{
TypeCode Underlying = UnqualifiedType (Type->C);
TypeCode TCode;
if (IsISOChar (Type)) {
return IS_Get (&SignedChars) ? T_SCHAR : T_UCHAR;
} else if (IsTypeEnum (Type)) {
TypeCode TCode;
/* This should not happen, but just in case */
if (Type->A.S == 0) {
Internal ("Enum tag type error in GetUnderlyingTypeCode");
@@ -742,6 +641,21 @@ TypeCode GetUnderlyingTypeCode (const Type* Type)
case T_SIZE_LONGLONG: Underlying |= T_TYPE_LONGLONG; break;
default: Underlying |= T_TYPE_INT; break;
}
} else if (IsTypeBitField (Type)) {
/* We consider the smallest type that can represent all values of the
** bit-field, instead of the type used in the declaration, the truly
** underlying of the bit-field.
*/
unsigned Size = (int)(Type->A.B.Width - 1) / (int)CHAR_BITS + 1;
switch (Size) {
case SIZEOF_CHAR: Underlying = T_CHAR; break;
case SIZEOF_INT: Underlying = T_INT; break;
case SIZEOF_LONG: Underlying = T_LONG; break;
case SIZEOF_LONGLONG: Underlying = T_LONGLONG; break;
default: Underlying = T_INT; break;
}
Underlying &= ~T_MASK_SIGN;
Underlying |= Type->C & T_MASK_SIGN;
}
return Underlying;
@@ -906,7 +820,7 @@ unsigned TypeOf (const Type* T)
case T_STRUCT:
case T_UNION:
NewType = TypeOfBySize (T);
NewType = TypeOfBySize (SizeOf (T));
if (NewType != CF_NONE) {
return NewType;
}
@@ -968,6 +882,48 @@ Type* IndirectModifiable (Type* T)
Type* NewPointerTo (const Type* T)
/* Return a type string that is "pointer to T". The type string is allocated
** on the heap and may be freed after use.
*/
{
/* Get the size of the type string including the terminator */
unsigned Size = TypeLen (T) + 1;
/* Allocate the new type string */
Type* P = TypeAlloc (Size + 1);
/* Create the return type... */
P[0].C = T_PTR | (T[0].C & T_QUAL_ADDRSIZE);
memcpy (P+1, T, Size * sizeof (Type));
/* ...and return it */
return P;
}
const Type* AddressOf (const Type* T)
/* Return a type string that is "address of T". The type string is allocated
** on the heap and may be freed after use.
*/
{
/* Get the size of the type string including the terminator */
unsigned Size = TypeLen (T) + 1;
/* Allocate the new type string */
Type* P = TypeAlloc (Size + 1);
/* Create the return type... */
P[0].C = T_PTR | (T[0].C & T_QUAL_ADDRSIZE) | T_QUAL_CONST;
memcpy (P+1, T, Size * sizeof (Type));
/* ...and return it */
return P;
}
Type* ArrayToPtr (const Type* T)
/* Convert an array to a pointer to it's first element */
{
@@ -977,6 +933,200 @@ Type* ArrayToPtr (const Type* T)
const Type* PtrConversion (const Type* T)
/* If the type is a function, convert it to pointer to function. If the
** expression is an array, convert it to pointer to first element. Otherwise
** return T.
*/
{
if (IsTypeFunc (T)) {
return AddressOf (T);
} else if (IsTypeArray (T)) {
return AddressOf (GetElementType (T));
} else {
return T;
}
}
const Type* IntPromotion (const Type* T)
/* Apply the integer promotions to T and return the result. The returned type
** string may be T if there is no need to change it.
*/
{
/* We must have an int to apply int promotions */
PRECONDITION (IsClassInt (T));
/* https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1
** A char, a short int, or an int bit-field, or their signed or unsigned varieties, or
** an object that has enumeration type, may be used in an expression wherever an int or
** unsigned int may be used. If an int can represent all values of the original type,
** the value is converted to an int; otherwise it is converted to an unsigned int.
** These are called the integral promotions.
*/
if (IsTypeBitField (T)) {
/* The standard rule is OK for now as we don't support bit-fields with widths > 16.
*/
return T->A.B.Width >= INT_BITS && IsSignUnsigned (T) ? type_uint : type_int;
} else if (IsTypeChar (T)) {
/* An integer can represent all values from either signed or unsigned char, so convert
** chars to int.
*/
return type_int;
} else if (IsTypeShort (T)) {
/* An integer cannot represent all values from unsigned short, so convert unsigned short
** to unsigned int.
*/
return IsSignUnsigned (T) ? type_uint : type_int;
} else if (!IsIncompleteESUType (T)) {
/* The type is a complete type not smaller than int, so leave it alone. */
return T;
} else {
/* Otherwise, this is an incomplete enum, and there is expceted to be an error already.
** Assume int to avoid further errors.
*/
return type_int;
}
}
const Type* ArithmeticConvert (const Type* lhst, const Type* rhst)
/* Perform the usual arithmetic conversions for binary operators. */
{
/* https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.5
** Many binary operators that expect operands of arithmetic type cause conversions and yield
** result types in a similar way. The purpose is to yield a common type, which is also the type
** of the result. This pattern is called the usual arithmetic conversions.
*/
/* There are additional rules for floating point types that we don't bother with, since
** floating point types are not (yet) supported.
** The integral promotions are performed on both operands.
*/
lhst = IntPromotion (lhst);
rhst = IntPromotion (rhst);
/* If either operand has type unsigned long int, the other operand is converted to
** unsigned long int.
*/
if ((IsTypeLong (lhst) && IsSignUnsigned (lhst)) ||
(IsTypeLong (rhst) && IsSignUnsigned (rhst))) {
return type_ulong;
}
/* Otherwise, if one operand has type long int and the other has type unsigned int,
** if a long int can represent all values of an unsigned int, the operand of type unsigned int
** is converted to long int ; if a long int cannot represent all the values of an unsigned int,
** both operands are converted to unsigned long int.
*/
if ((IsTypeLong (lhst) && IsTypeInt (rhst) && IsSignUnsigned (rhst)) ||
(IsTypeLong (rhst) && IsTypeInt (lhst) && IsSignUnsigned (lhst))) {
/* long can represent all unsigneds, so we are in the first sub-case. */
return type_long;
}
/* Otherwise, if either operand has type long int, the other operand is converted to long int.
*/
if (IsTypeLong (lhst) || IsTypeLong (rhst)) {
return type_long;
}
/* Otherwise, if either operand has type unsigned int, the other operand is converted to
** unsigned int.
*/
if ((IsTypeInt (lhst) && IsSignUnsigned (lhst)) ||
(IsTypeInt (rhst) && IsSignUnsigned (rhst))) {
return type_uint;
}
/* Otherwise, both operands have type int. */
CHECK (IsTypeInt (lhst));
CHECK (IsSignSigned (lhst));
CHECK (IsTypeInt (rhst));
CHECK (IsSignSigned (rhst));
return type_int;
}
const Type* SignedType (const Type* T)
/* Get signed counterpart of the integral type */
{
switch (GetUnderlyingTypeCode (T) & T_MASK_TYPE) {
case T_TYPE_CHAR:
return type_schar;
case T_TYPE_INT:
case T_TYPE_SHORT:
return type_int;
case T_TYPE_LONG:
return type_long;
default:
Internal ("Unknown type code: %lX", GetUnderlyingTypeCode (T));
return T;
}
}
const Type* UnsignedType (const Type* T)
/* Get unsigned counterpart of the integral type */
{
switch (GetUnderlyingTypeCode (T) & T_MASK_TYPE) {
case T_TYPE_CHAR:
return type_uchar;
case T_TYPE_INT:
case T_TYPE_SHORT:
return type_uint;
case T_TYPE_LONG:
return type_ulong;
default:
Internal ("Unknown type code: %lX", GetUnderlyingTypeCode (T));
return T;
}
}
Type* NewBitFieldType (const Type* T, unsigned BitOffs, unsigned BitWidth)
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
** string is allocated on the heap and may be freed after use.
*/
{
Type* P;
/* The type specifier must be integeral */
CHECK (IsClassInt (T));
/* Allocate the new type string */
P = TypeAlloc (3);
/* Create the return type... */
P[0].C = IsSignSigned (T) ? T_SBITFIELD : T_UBITFIELD;
P[0].C |= (T[0].C & T_QUAL_ADDRSIZE);
P[0].A.B.Offs = BitOffs;
P[0].A.B.Width = BitWidth;
/* Get the declaration type */
memcpy (&P[1], GetUnderlyingType (T), sizeof (P[1]));
/* Get done... */
P[2].C = T_END;
/* ...and return it */
return P;
}
int IsClassObject (const Type* T)
/* Return true if this is a fully described object type */
{
@@ -1266,62 +1416,6 @@ void SetESUSymEntry (Type* T, struct SymEntry* S)
const Type* IntPromotion (const Type* T)
/* Apply the integer promotions to T and return the result. The returned type
** string may be T if there is no need to change it.
*/
{
/* We must have an int to apply int promotions */
PRECONDITION (IsClassInt (T));
/* https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1
** A char, a short int, or an int bit-field, or their signed or unsigned varieties, or an
** object that has enumeration type, may be used in an expression wherever an int or
** unsigned int may be used. If an int can represent all values of the original type, the value
** is converted to an int; otherwise it is converted to an unsigned int.
** These are called the integral promotions.
*/
if (IsTypeChar (T)) {
/* An integer can represent all values from either signed or unsigned char, so convert
** chars to int.
*/
return type_int;
} else if (IsTypeShort (T)) {
/* An integer cannot represent all values from unsigned short, so convert unsigned short
** to unsigned int.
*/
return IsSignUnsigned (T) ? type_uint : type_int;
} else if (!IsIncompleteESUType (T)) {
/* The type is a complete type not smaller than int, so leave it alone. */
return T;
} else {
/* Otherwise, this is an incomplete enum, and there is expceted to be an error already.
** Assume int to avoid further errors.
*/
return type_int;
}
}
const Type* PtrConversion (const Type* T)
/* If the type is a function, convert it to pointer to function. If the
** expression is an array, convert it to pointer to first element. Otherwise
** return T.
*/
{
if (IsTypeFunc (T)) {
return NewPointerTo (T);
} else if (IsTypeArray (T)) {
return ArrayToPtr (T);
} else {
return T;
}
}
TypeCode AddrSizeQualifier (unsigned AddrSize)
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
{
@@ -1339,3 +1433,101 @@ TypeCode AddrSizeQualifier (unsigned AddrSize)
}
}
int TypeHasAttr (const Type* T)
/* Return true if the given type has attribute data */
{
return IsClassStruct (T) || IsTypeArray (T) || IsClassFunc (T);
}
void PrintType (FILE* F, const Type* T)
/* Print fulle name of the type */
{
StrBuf Buf = AUTO_STRBUF_INITIALIZER;
fprintf (F, "%s", SB_GetConstBuf (GetFullTypeNameBuf (&Buf, T)));
SB_Done (&Buf);
}
void PrintFuncSig (FILE* F, const char* Name, const Type* T)
/* Print a function signature */
{
StrBuf Buf = AUTO_STRBUF_INITIALIZER;
StrBuf ParamList = AUTO_STRBUF_INITIALIZER;
StrBuf East = AUTO_STRBUF_INITIALIZER;
StrBuf West = AUTO_STRBUF_INITIALIZER;
/* Get the function descriptor used in definition */
const FuncDesc* D = GetFuncDefinitionDesc (T);
/* Get the parameter list string. Start from the first parameter */
SymEntry* Param = D->SymTab->SymHead;
unsigned I;
for (I = 0; I < D->ParamCount; ++I) {
CHECK (Param != 0 && (Param->Flags & SC_PARAM) != 0);
if (I > 0) {
SB_AppendStr (&ParamList, ", ");
}
if (SymIsRegVar (Param)) {
SB_AppendStr (&ParamList, "register ");
}
if (!HasAnonName (Param)) {
SB_AppendStr (&Buf, Param->Name);
}
SB_AppendStr (&ParamList, SB_GetConstBuf (GetFullTypeNameBuf (&Buf, Param->Type)));
SB_Clear (&Buf);
/* Next argument */
Param = Param->NextSym;
}
if ((D->Flags & FD_VARIADIC) == 0) {
if (D->ParamCount == 0 && (D->Flags & FD_EMPTY) == 0) {
SB_AppendStr (&ParamList, "void");
}
} else {
if (D->ParamCount > 0) {
SB_AppendStr (&ParamList, ", ...");
} else {
SB_AppendStr (&ParamList, "...");
}
}
SB_Terminate (&ParamList);
/* Get the function qualifiers */
if (GetQualifierTypeCodeNameBuf (&Buf, T->C, T_QUAL_NONE) > 0) {
/* Append a space between the qualifiers and the name */
SB_AppendChar (&Buf, ' ');
}
SB_Terminate (&Buf);
/* Get the signature string without the return type */
SB_Printf (&West, "%s%s (%s)", SB_GetConstBuf (&Buf), Name, SB_GetConstBuf (&ParamList));
SB_Done (&Buf);
SB_Done (&ParamList);
/* Complete with the return type */
GetFullTypeNameWestEast (&West, &East, GetFuncReturn (T));
SB_Append (&West, &East);
SB_Terminate (&West);
/* Output */
fprintf (F, "%s", SB_GetConstBuf (&West));
SB_Done (&East);
SB_Done (&West);
}
void PrintRawType (FILE* F, const Type* T)
/* Print a type string in raw hex format (for debugging) */
{
while (T->C != T_END) {
fprintf (F, "%04lX ", T->C);
++T;
}
fprintf (F, "\n");
}

View File

@@ -78,54 +78,55 @@ enum {
T_TYPE_INT = 0x000003,
T_TYPE_LONG = 0x000004,
T_TYPE_LONGLONG = 0x000005,
T_TYPE_ENUM = 0x000006,
T_TYPE_FLOAT = 0x000007,
T_TYPE_DOUBLE = 0x000008,
T_TYPE_VOID = 0x000009,
T_TYPE_STRUCT = 0x00000A,
T_TYPE_UNION = 0x00000B,
T_TYPE_ARRAY = 0x00000C,
T_TYPE_PTR = 0x00000D,
T_TYPE_FUNC = 0x00000E,
T_MASK_TYPE = 0x00000F,
T_TYPE_ENUM = 0x000008,
T_TYPE_BITFIELD = 0x000009,
T_TYPE_FLOAT = 0x00000A,
T_TYPE_DOUBLE = 0x00000B,
T_TYPE_VOID = 0x000010,
T_TYPE_STRUCT = 0x000011,
T_TYPE_UNION = 0x000012,
T_TYPE_ARRAY = 0x000018,
T_TYPE_PTR = 0x000019,
T_TYPE_FUNC = 0x00001A,
T_MASK_TYPE = 0x00001F,
/* Type classes */
T_CLASS_NONE = 0x000000,
T_CLASS_INT = 0x000010,
T_CLASS_FLOAT = 0x000020,
T_CLASS_PTR = 0x000030,
T_CLASS_STRUCT = 0x000040,
T_CLASS_FUNC = 0x000050,
T_MASK_CLASS = 0x000070,
T_CLASS_INT = 0x000020,
T_CLASS_FLOAT = 0x000040,
T_CLASS_PTR = 0x000060,
T_CLASS_STRUCT = 0x000080,
T_CLASS_FUNC = 0x0000A0,
T_MASK_CLASS = 0x0000E0,
/* Type signedness */
T_SIGN_NONE = 0x000000,
T_SIGN_UNSIGNED = 0x000080,
T_SIGN_SIGNED = 0x000100,
T_MASK_SIGN = 0x000180,
T_SIGN_UNSIGNED = 0x000100,
T_SIGN_SIGNED = 0x000200,
T_MASK_SIGN = 0x000300,
/* Type size modifiers */
T_SIZE_NONE = 0x000000,
T_SIZE_CHAR = 0x000200,
T_SIZE_SHORT = 0x000400,
T_SIZE_INT = 0x000600,
T_SIZE_LONG = 0x000800,
T_SIZE_LONGLONG = 0x000A00,
T_MASK_SIZE = 0x000E00,
T_SIZE_CHAR = 0x001000,
T_SIZE_SHORT = 0x002000,
T_SIZE_INT = 0x003000,
T_SIZE_LONG = 0x004000,
T_SIZE_LONGLONG = 0x005000,
T_MASK_SIZE = 0x00F000,
/* Type qualifiers */
T_QUAL_NONE = 0x000000,
T_QUAL_CONST = 0x001000,
T_QUAL_VOLATILE = 0x002000,
T_QUAL_RESTRICT = 0x004000,
T_QUAL_CONST = 0x010000,
T_QUAL_VOLATILE = 0x020000,
T_QUAL_RESTRICT = 0x040000,
T_QUAL_CVR = T_QUAL_CONST | T_QUAL_VOLATILE | T_QUAL_RESTRICT,
T_QUAL_NEAR = 0x008000,
T_QUAL_FAR = 0x010000,
T_QUAL_NEAR = 0x080000,
T_QUAL_FAR = 0x100000,
T_QUAL_ADDRSIZE = T_QUAL_NEAR | T_QUAL_FAR,
T_QUAL_FASTCALL = 0x020000,
T_QUAL_CDECL = 0x040000,
T_QUAL_FASTCALL = 0x200000,
T_QUAL_CDECL = 0x400000,
T_QUAL_CCONV = T_QUAL_FASTCALL | T_QUAL_CDECL,
T_MASK_QUAL = 0x07F000,
T_MASK_QUAL = 0x7F0000,
/* Types */
T_CHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_NONE | T_SIZE_CHAR,
@@ -140,6 +141,8 @@ enum {
T_LONGLONG = T_TYPE_LONGLONG | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONGLONG,
T_ULONGLONG = T_TYPE_LONGLONG | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
T_ENUM = T_TYPE_ENUM | T_CLASS_INT | T_SIGN_NONE | T_SIZE_NONE,
T_SBITFIELD = T_TYPE_BITFIELD | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
T_UBITFIELD = T_TYPE_BITFIELD | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
T_FLOAT = T_TYPE_FLOAT | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
T_DOUBLE = T_TYPE_DOUBLE | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
T_VOID = T_TYPE_VOID | T_CLASS_NONE | T_SIGN_NONE | T_SIZE_NONE,
@@ -171,6 +174,10 @@ struct Type {
struct SymEntry* S; /* Enum/struct/union tag symbol entry pointer */
long L; /* Numeric attribute value */
unsigned long U; /* Dito, unsigned */
struct {
unsigned Offs; /* Bit offset into storage unit */
unsigned Width; /* Width in bits */
} B; /* Data for bit fields */
} A; /* Type attribute if necessary */
};
@@ -288,33 +295,6 @@ unsigned long GetIntegerTypeMax (const Type* Type);
** The type must have a known size.
*/
Type* NewPointerTo (const Type* T);
/* Return a type string that is "pointer to T". The type string is allocated
** on the heap and may be freed after use.
*/
void PrintType (FILE* F, const Type* T);
/* Print fulle name of the type */
void PrintFuncSig (FILE* F, const char* Name, const Type* T);
/* Print a function signature */
void PrintRawType (FILE* F, const Type* T);
/* Print a type string in raw hex format (for debugging) */
int TypeHasAttr (const Type* T);
/* Return true if the given type has attribute data */
#if defined(HAVE_INLINE)
INLINE void CopyTypeAttr (const Type* Src, Type* Dest)
/* Copy attribute data from Src to Dest */
{
Dest->A = Src->A;
}
#else
# define CopyTypeAttr(Src, Dest) ((Dest)->A = (Src)->A)
#endif
#if defined(HAVE_INLINE)
INLINE TypeCode UnqualifiedType (TypeCode T)
/* Return the unqalified type code */
@@ -366,9 +346,44 @@ Type* IndirectModifiable (Type* T);
** given type points to.
*/
Type* NewPointerTo (const Type* T);
/* Return a type string that is "pointer to T". The type string is allocated
** on the heap and may be freed after use.
*/
const Type* AddressOf (const Type* T);
/* Return a type string that is "address of T". The type string is allocated
** on the heap and may be freed after use.
*/
Type* ArrayToPtr (const Type* T);
/* Convert an array to a pointer to it's first element */
const Type* PtrConversion (const Type* T);
/* If the type is a function, convert it to pointer to function. If the
** expression is an array, convert it to pointer to first element. Otherwise
** return T.
*/
const Type* IntPromotion (const Type* T);
/* Apply the integer promotions to T and return the result. The returned type
** string may be T if there is no need to change it.
*/
const Type* ArithmeticConvert (const Type* lhst, const Type* rhst);
/* Perform the usual arithmetic conversions for binary operators. */
const Type* SignedType (const Type* T);
/* Get signed counterpart of the integral type */
const Type* UnsignedType (const Type* T);
/* Get unsigned counterpart of the integral type */
Type* NewBitFieldType (const Type* T, unsigned BitOffs, unsigned BitWidth);
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
** string is allocated on the heap and may be freed after use.
*/
#if defined(HAVE_INLINE)
INLINE TypeCode GetRawType (const Type* T)
/* Get the raw type */
@@ -511,6 +526,36 @@ INLINE int IsTypeEnum (const Type* T)
# define IsTypeEnum(T) (GetRawType (T) == T_TYPE_ENUM)
#endif
#if defined(HAVE_INLINE)
INLINE int IsTypeSignedBitField (const Type* T)
/* Return true if this is a signed bit-field */
{
return (UnqualifiedType (T->C) == T_SBITFIELD);
}
#else
# define IsTypeSignedBitField(T) (UnqualifiedType ((T)->C) == T_SBITFIELD)
#endif
#if defined(HAVE_INLINE)
INLINE int IsTypeUnsignedBitField (const Type* T)
/* Return true if this is an unsigned bit-field */
{
return (UnqualifiedType (T->C) == T_UBITFIELD);
}
#else
# define IsTypeUnsignedBitField(T) (UnqualifiedType ((T)->C) == T_UBITFIELD)
#endif
#if defined(HAVE_INLINE)
INLINE int IsTypeBitField (const Type* T)
/* Return true if this is a bit-field (either signed or unsigned) */
{
return IsTypeSignedBitField (T) || IsTypeUnsignedBitField (T);
}
#else
# define IsTypeBitField(T) (IsTypeSignedBitField (T) || IsTypeUnsignedBitField (T))
#endif
#if defined(HAVE_INLINE)
INLINE int IsTypeStruct (const Type* T)
/* Return true if this is a struct type */
@@ -892,17 +937,6 @@ struct SymEntry* GetESUSymEntry (const Type* T) attribute ((const));
void SetESUSymEntry (Type* T, struct SymEntry* S);
/* Set the SymEntry pointer for an enum/struct/union type */
const Type* IntPromotion (const Type* T);
/* Apply the integer promotions to T and return the result. The returned type
** string may be T if there is no need to change it.
*/
const Type* PtrConversion (const Type* T);
/* If the type is a function, convert it to pointer to function. If the
** expression is an array, convert it to pointer to first element. Otherwise
** return T.
*/
TypeCode AddrSizeQualifier (unsigned AddrSize);
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
@@ -926,6 +960,28 @@ INLINE TypeCode DataAddrSizeQualifier (void)
# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize))
#endif
int TypeHasAttr (const Type* T);
/* Return true if the given type has attribute data */
#if defined(HAVE_INLINE)
INLINE void CopyTypeAttr (const Type* Src, Type* Dest)
/* Copy attribute data from Src to Dest */
{
Dest->A = Src->A;
}
#else
# define CopyTypeAttr(Src, Dest) ((Dest)->A = (Src)->A)
#endif
void PrintType (FILE* F, const Type* T);
/* Print fulle name of the type */
void PrintFuncSig (FILE* F, const char* Name, const Type* T);
/* Print a function signature */
void PrintRawType (FILE* F, const Type* T);
/* Print a type string in raw hex format (for debugging) */
/* End of datatype.h */

View File

@@ -2243,7 +2243,7 @@ static void DefineData (ExprDesc* Expr)
static void OutputBitFieldData (StructInitData* SI)
static void DefineBitFieldData (StructInitData* SI)
/* Output bit field data */
{
/* Ignore if we have no data */
@@ -2266,7 +2266,18 @@ static void OutputBitFieldData (StructInitData* SI)
static ExprDesc ParseScalarInitInternal (Type* T)
static void DefineStrData (Literal* Lit, unsigned Count)
{
/* Translate into target charset */
TranslateLiteral (Lit);
/* Output the data */
g_defbytes (GetLiteralStr (Lit), Count);
}
static ExprDesc ParseScalarInitInternal (const Type* T)
/* Parse initializaton for scalar data types. This function will not output the
** data but return it in ED.
*/
@@ -2293,7 +2304,7 @@ static ExprDesc ParseScalarInitInternal (Type* T)
static unsigned ParseScalarInit (Type* T)
static unsigned ParseScalarInit (const Type* T)
/* Parse initializaton for scalar data types. Return the number of data bytes. */
{
/* Parse initialization */
@@ -2311,7 +2322,7 @@ static unsigned ParseScalarInit (Type* T)
static unsigned ParsePointerInit (Type* T)
static unsigned ParsePointerInit (const Type* T)
/* Parse initializaton for pointer data types. Return the number of data bytes. */
{
/* Optional opening brace */
@@ -2364,9 +2375,6 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
NextToken ();
}
/* Translate into target charset */
TranslateLiteral (CurTok.SVal);
/* If the array is one too small for the string literal, omit the
** trailing zero.
*/
@@ -2379,7 +2387,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
}
/* Output the data */
g_defbytes (GetLiteralStr (CurTok.SVal), Count);
DefineStrData (CurTok.SVal, Count);
/* Skip the string */
NextToken ();
@@ -2453,7 +2461,7 @@ static unsigned ParseArrayInit (Type* T, int* Braces, int AllowFlexibleMembers)
static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
/* Parse initialization of a struct or union. Return the number of data bytes. */
{
SymEntry* Entry;
SymEntry* Sym;
SymTable* Tab;
StructInitData SI;
int HasCurly = 0;
@@ -2468,15 +2476,15 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
}
/* Get a pointer to the struct entry from the type */
Entry = GetESUSymEntry (T);
Sym = GetESUSymEntry (T);
/* Get the size of the struct from the symbol table entry */
SI.Size = Entry->V.S.Size;
SI.Size = Sym->V.S.Size;
/* Check if this struct definition has a field table. If it doesn't, it
** is an incomplete definition.
*/
Tab = Entry->V.S.SymTab;
Tab = Sym->V.S.SymTab;
if (Tab == 0) {
Error ("Cannot initialize variables with incomplete type");
/* Try error recovery */
@@ -2486,7 +2494,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
}
/* Get a pointer to the list of symbols */
Entry = Tab->SymHead;
Sym = Tab->SymHead;
/* Initialize fields */
SI.Offs = 0;
@@ -2495,7 +2503,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
while (CurTok.Tok != TOK_RCURLY) {
/* Check for excess elements */
if (Entry == 0) {
if (Sym == 0) {
/* Is there just one trailing comma before a closing curly? */
if (NextTok.Tok == TOK_RCURLY && CurTok.Tok == TOK_COMMA) {
/* Skip comma and exit scope */
@@ -2511,7 +2519,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
}
/* Check for special members that don't consume the initializer */
if ((Entry->Flags & SC_ALIAS) == SC_ALIAS) {
if ((Sym->Flags & SC_ALIAS) == SC_ALIAS) {
/* Just skip */
goto NextMember;
}
@@ -2519,17 +2527,17 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
/* This may be an anonymous bit-field, in which case it doesn't
** have an initializer.
*/
if (SymIsBitField (Entry) && (IsAnonName (Entry->Name))) {
if (SymIsBitField (Sym) && (IsAnonName (Sym->Name))) {
/* Account for the data and output it if we have at least a full
** word. We may have more if there was storage unit overlap, for
** example two consecutive 10 bit fields. These will be packed
** into 3 bytes.
*/
SI.ValBits += Entry->V.B.BitWidth;
SI.ValBits += Sym->Type->A.B.Width;
/* TODO: Generalize this so any type can be used. */
CHECK (SI.ValBits <= CHAR_BITS + INT_BITS - 2);
while (SI.ValBits >= CHAR_BITS) {
OutputBitFieldData (&SI);
DefineBitFieldData (&SI);
}
/* Avoid consuming the comma if any */
goto NextMember;
@@ -2541,7 +2549,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
SkipComma = 0;
}
if (SymIsBitField (Entry)) {
if (SymIsBitField (Sym)) {
/* Parse initialization of one field. Bit-fields need a special
** handling.
@@ -2552,14 +2560,14 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
unsigned Shift;
/* Calculate the bitmask from the bit-field data */
unsigned Mask = (1U << Entry->V.B.BitWidth) - 1U;
unsigned Mask = (1U << Sym->Type->A.B.Width) - 1U;
/* Safety ... */
CHECK (Entry->V.B.Offs * CHAR_BITS + Entry->V.B.BitOffs ==
SI.Offs * CHAR_BITS + SI.ValBits);
CHECK (Sym->V.Offs * CHAR_BITS + Sym->Type->A.B.Offs ==
SI.Offs * CHAR_BITS + SI.ValBits);
/* Read the data, check for a constant integer, do a range check */
ED = ParseScalarInitInternal (Entry->Type);
ED = ParseScalarInitInternal (IntPromotion (Sym->Type));
if (!ED_IsConstAbsInt (&ED)) {
Error ("Constant initializer expected");
ED_MakeConstAbsInt (&ED, 1);
@@ -2569,31 +2577,31 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
** any useful bits.
*/
Val = (unsigned) ED.IVal & Mask;
if (IsSignUnsigned (Entry->Type)) {
if (IsSignUnsigned (Sym->Type)) {
if (ED.IVal < 0 || (unsigned long) ED.IVal != Val) {
Warning ("Implicit truncation from '%s' to '%s : %u' in bit-field initializer"
" changes value from %ld to %u",
GetFullTypeName (ED.Type), GetFullTypeName (Entry->Type),
Entry->V.B.BitWidth, ED.IVal, Val);
GetFullTypeName (ED.Type), GetFullTypeName (Sym->Type),
Sym->Type->A.B.Width, ED.IVal, Val);
}
} else {
/* Sign extend back to full width of host long. */
unsigned ShiftBits = sizeof (long) * CHAR_BIT - Entry->V.B.BitWidth;
unsigned ShiftBits = sizeof (long) * CHAR_BIT - Sym->Type->A.B.Width;
long RestoredVal = asr_l(asl_l (Val, ShiftBits), ShiftBits);
if (ED.IVal != RestoredVal) {
Warning ("Implicit truncation from '%s' to '%s : %u' in bit-field initializer "
"changes value from %ld to %ld",
GetFullTypeName (ED.Type), GetFullTypeName (Entry->Type),
Entry->V.B.BitWidth, ED.IVal, RestoredVal);
GetFullTypeName (ED.Type), GetFullTypeName (Sym->Type),
Sym->Type->A.B.Width, ED.IVal, RestoredVal);
}
}
/* Add the value to the currently stored bit-field value */
Shift = (Entry->V.B.Offs - SI.Offs) * CHAR_BITS + Entry->V.B.BitOffs;
Shift = (Sym->V.Offs - SI.Offs) * CHAR_BITS + Sym->Type->A.B.Offs;
SI.BitVal |= (Val << Shift);
/* Account for the data and output any full bytes we have. */
SI.ValBits += Entry->V.B.BitWidth;
SI.ValBits += Sym->Type->A.B.Width;
/* Make sure unsigned is big enough to hold the value, 22 bits.
** This is 22 bits because the most we can have is 7 bits left
** over from the previous OutputBitField call, plus 15 bits
@@ -2604,7 +2612,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
/* TODO: Generalize this so any type can be used. */
CHECK (SI.ValBits <= CHAR_BITS + INT_BITS - 2);
while (SI.ValBits >= CHAR_BITS) {
OutputBitFieldData (&SI);
DefineBitFieldData (&SI);
}
} else {
@@ -2618,7 +2626,7 @@ static unsigned ParseStructInit (Type* T, int* Braces, int AllowFlexibleMembers)
/* Flexible array members may only be initialized if they are
** the last field (or part of the last struct field).
*/
SI.Offs += ParseInitInternal (Entry->Type, Braces, AllowFlexibleMembers && Entry->NextSym == 0);
SI.Offs += ParseInitInternal (Sym->Type, Braces, AllowFlexibleMembers && Sym->NextSym == 0);
}
/* More initializers? */
@@ -2633,10 +2641,10 @@ NextMember:
/* Next member. For unions, only the first one can be initialized */
if (IsTypeUnion (T)) {
/* Union */
Entry = 0;
Sym = 0;
} else {
/* Struct */
Entry = Entry->NextSym;
Sym = Sym->NextSym;
}
}
@@ -2647,7 +2655,7 @@ NextMember:
/* If we have data from a bit-field left, output it now */
CHECK (SI.ValBits < CHAR_BITS);
OutputBitFieldData (&SI);
DefineBitFieldData (&SI);
/* If there are struct fields left, reserve additional storage */
if (SI.Offs < SI.Size) {

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,11 @@
#define SQP_KEEP_EAX 0x02U
#define SQP_KEEP_EXPR 0x03U /* SQP_KEEP_TEST | SQP_KEEP_EAX */
/* Generator attributes */
#define GEN_NOPUSH 0x01 /* Don't push lhs */
#define GEN_COMM 0x02 /* Operator is commutative */
#define GEN_NOFUNC 0x04 /* Not allowed for function pointers */
/*****************************************************************************/
@@ -36,6 +41,9 @@
unsigned GlobalModeFlags (const ExprDesc* Expr);
/* Return the addressing mode flags for the given expression */
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr);
/* Call an expression function with checks. */
@@ -44,6 +52,9 @@ void MarkedExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr);
** generated code.
*/
void LimitExprValue (ExprDesc* Expr);
/* Limit the constant value of the expression to the range of its type */
void PushAddr (const ExprDesc* Expr);
/* If the expression contains an address that was somehow evaluated,
** push this address on the stack. This is a helper function for all

View File

@@ -56,30 +56,17 @@
ExprDesc* ED_Init (ExprDesc* Expr)
/* Initialize an ExprDesc */
{
Expr->Sym = 0;
Expr->Type = 0;
Expr->Flags = E_NEED_EAX;
Expr->Name = 0;
Expr->Sym = 0;
Expr->IVal = 0;
Expr->FVal = FP_D_Make (0.0);
Expr->LVal = 0;
Expr->BitOffs = 0;
Expr->BitWidth = 0;
memset (&Expr->V, 0, sizeof (Expr->V));
return Expr;
}
void ED_MakeBitField (ExprDesc* Expr, unsigned BitOffs, unsigned BitWidth)
/* Make this expression a bit field expression */
{
Expr->Flags |= E_BITFIELD;
Expr->BitOffs = BitOffs;
Expr->BitWidth = BitWidth;
}
#if !defined(HAVE_INLINE)
int ED_IsLocQuasiConst (const ExprDesc* Expr)
/* Return true if the expression is a constant location of some sort or on the
@@ -231,12 +218,12 @@ int ED_GetStackOffs (const ExprDesc* Expr, int Offs)
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, const Type* Type)
/* Replace Expr with an absolute const with the given value and type */
{
Expr->Sym = 0;
Expr->Type = Type;
Expr->Flags = E_LOC_NONE | E_RTYPE_RVAL | (Expr->Flags & E_MASK_KEEP_MAKE);
Expr->Name = 0;
Expr->Sym = 0;
Expr->IVal = Value;
Expr->FVal = FP_D_Make (0.0);
memset (&Expr->V, 0, sizeof (Expr->V));
return Expr;
}
@@ -245,12 +232,12 @@ ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, const Type* Type)
ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value)
/* Replace Expr with a constant integer expression with the given value */
{
Expr->Sym = 0;
Expr->Type = type_int;
Expr->Flags = E_LOC_NONE | E_RTYPE_RVAL | (Expr->Flags & E_MASK_KEEP_MAKE);
Expr->Name = 0;
Expr->Sym = 0;
Expr->IVal = Value;
Expr->FVal = FP_D_Make (0.0);
memset (&Expr->V, 0, sizeof (Expr->V));
return Expr;
}
@@ -264,7 +251,7 @@ ExprDesc* ED_MakeConstBool (ExprDesc* Expr, long Value)
Expr->Flags = E_LOC_NONE | E_RTYPE_RVAL | (Expr->Flags & E_MASK_KEEP_MAKE);
Expr->Name = 0;
Expr->IVal = Value;
Expr->FVal = FP_D_Make (0.0);
memset (&Expr->V, 0, sizeof (Expr->V));
return Expr;
}
@@ -273,13 +260,13 @@ ExprDesc* ED_MakeConstBool (ExprDesc* Expr, long Value)
ExprDesc* ED_FinalizeRValLoad (ExprDesc* Expr)
/* Finalize the result of LoadExpr to be an rvalue in the primary register */
{
Expr->Sym = 0;
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_BITFIELD | E_ADDRESS_OF);
Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_ADDRESS_OF);
Expr->Flags &= ~E_CC_SET;
Expr->Flags |= (E_LOC_PRIMARY | E_RTYPE_RVAL);
Expr->Sym = 0;
Expr->Name = 0;
Expr->IVal = 0; /* No offset */
Expr->FVal = FP_D_Make (0.0);
memset (&Expr->V, 0, sizeof (Expr->V));
return Expr;
}
@@ -464,8 +451,8 @@ int ED_IsQuasiConstAddr (const ExprDesc* Expr)
int ED_IsNullPtr (const ExprDesc* Expr)
/* Return true if the given expression is a NULL pointer constant */
{
return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE|E_BITFIELD)) ==
(E_LOC_NONE|E_RTYPE_RVAL) &&
return (Expr->Flags & (E_MASK_LOC|E_MASK_RTYPE)) ==
(E_LOC_NONE|E_RTYPE_RVAL) &&
Expr->IVal == 0 &&
IsClassInt (Expr->Type);
}
@@ -503,7 +490,7 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
"Raw type: (unknown)\n");
}
fprintf (F, "IVal: 0x%08lX\n", E->IVal);
fprintf (F, "FVal: %f\n", FP_D_ToFloat (E->FVal));
fprintf (F, "FVal: %f\n", FP_D_ToFloat (E->V.FVal));
Flags = E->Flags;
Sep = '(';
@@ -558,11 +545,6 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
Flags &= ~E_LOC_CODE;
Sep = ',';
}
if (Flags & E_BITFIELD) {
fprintf (F, "%cE_BITFIELD", Sep);
Flags &= ~E_BITFIELD;
Sep = ',';
}
if (Flags & E_NEED_TEST) {
fprintf (F, "%cE_NEED_TEST", Sep);
Flags &= ~E_NEED_TEST;

View File

@@ -114,7 +114,6 @@ enum {
E_LOC_QUASICONST = E_LOC_CONST | E_LOC_STACK,
/* Expression type modifiers */
E_BITFIELD = 0x0200, /* Expression is a bit-field */
E_ADDRESS_OF = 0x0400, /* Expression is the address of the lvalue */
/* lvalue/rvalue in C language's sense */
@@ -198,17 +197,15 @@ struct Literal;
/* Describe the result of an expression */
typedef struct ExprDesc ExprDesc;
struct ExprDesc {
struct SymEntry* Sym; /* Symbol table entry if known */
const Type* Type; /* Type array of expression */
unsigned Flags;
const Type* Type; /* C type of the expression */
unsigned Flags; /* Properties of the expression */
uintptr_t Name; /* Name pointer or label number */
struct SymEntry* Sym; /* Symbol table entry if any */
long IVal; /* Integer value if expression constant */
Double FVal; /* Floating point value */
struct Literal* LVal; /* Literal value */
/* Bit field stuff */
unsigned BitOffs; /* Bit offset for bit fields */
unsigned BitWidth; /* Bit width for bit fields */
union {
Double FVal; /* Floating point value */
struct Literal* LVal; /* Literal value */
} V;
/* Start and end of generated code */
CodeMark Start;
@@ -331,29 +328,6 @@ int ED_IsLocQuasiConst (const ExprDesc* Expr);
*/
#endif
#if defined(HAVE_INLINE)
INLINE int ED_IsBitField (const ExprDesc* Expr)
/* Return true if the expression is a bit field */
{
return (Expr->Flags & E_BITFIELD) != 0;
}
#else
# define ED_IsBitField(Expr) (((Expr)->Flags & E_BITFIELD) != 0)
#endif
#if defined(HAVE_INLINE)
INLINE void ED_DisBitField (ExprDesc* Expr)
/* Make the expression no longer a bit field */
{
Expr->Flags &= ~E_BITFIELD;
}
#else
# define ED_DisBitField(Expr) ((Expr)->Flags &= ~E_BITFIELD)
#endif
void ED_MakeBitField (ExprDesc* Expr, unsigned BitOffs, unsigned BitWidth);
/* Make this expression a bit field expression */
#if defined(HAVE_INLINE)
INLINE void ED_RequireTest (ExprDesc* Expr)
/* Mark the expression for a test. */

View File

@@ -644,7 +644,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
/* Now process statements in this block */
while (CurTok.Tok != TOK_RCURLY && CurTok.Tok != TOK_CEOF) {
Statement (0);
AnyStatement (0);
}
/* If this is not a void function, and not the main function in a C99

View File

@@ -124,38 +124,40 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr)
*/
int AdjustBitField = 0;
unsigned BitFieldFullWidthFlags = 0;
if (ED_IsBitField (Expr)) {
unsigned EndBit = Expr->BitOffs + Expr->BitWidth;
AdjustBitField = Expr->BitOffs != 0 || (EndBit != CHAR_BITS && EndBit != INT_BITS);
if ((Flags & CF_TYPEMASK) == 0) {
if (IsTypeBitField (Expr->Type)) {
unsigned EndBit = Expr->Type->A.B.Offs + Expr->Type->A.B.Width;
AdjustBitField = Expr->Type->A.B.Offs != 0 || (EndBit != CHAR_BITS && EndBit != INT_BITS);
/* TODO: This probably needs to be guarded by AdjustBitField when long bit-fields are
** supported.
*/
Flags |= (EndBit <= CHAR_BITS) ? CF_CHAR : CF_INT;
if (IsSignUnsigned (Expr->Type)) {
Flags |= CF_UNSIGNED;
}
/* Flags we need operate on the whole bit-field, without CF_FORCECHAR. */
BitFieldFullWidthFlags = Flags;
/* If we're adjusting, then only load a char (not an int) and do only char ops;
** We will clear the high byte in the adjustment. CF_FORCECHAR does nothing if the
** type is not CF_CHAR.
*/
if (AdjustBitField) {
/* If adjusting, then we're sign extending manually, so do everything unsigned
** to make shifts faster.
/* TODO: This probably needs to be guarded by AdjustBitField when long bit-fields are
** supported.
*/
Flags |= CF_UNSIGNED | CF_FORCECHAR;
BitFieldFullWidthFlags |= CF_UNSIGNED;
Flags |= (EndBit <= CHAR_BITS) ? CF_CHAR : CF_INT;
if (IsSignUnsigned (Expr->Type)) {
Flags |= CF_UNSIGNED;
}
/* Flags we need operate on the whole bit-field, without CF_FORCECHAR. */
BitFieldFullWidthFlags = Flags;
/* If we're adjusting, then only load a char (not an int) and do only char ops;
** We will clear the high byte in the adjustment. CF_FORCECHAR does nothing if the
** type is not CF_CHAR.
*/
if (AdjustBitField) {
/* If adjusting, then we're sign extending manually, so do everything unsigned
** to make shifts faster.
*/
Flags |= CF_UNSIGNED | CF_FORCECHAR;
BitFieldFullWidthFlags |= CF_UNSIGNED;
}
} else {
/* If Expr is an incomplete ESY type, bail out */
if (IsIncompleteESUType (Expr->Type)) {
return;
}
Flags |= TypeOf (Expr->Type);
}
} else if ((Flags & CF_TYPEMASK) == 0) {
/* If Expr is an incomplete ESY type, bail out */
if (IsIncompleteESUType (Expr->Type)) {
return;
}
Flags |= TypeOf (Expr->Type);
}
if (ED_YetToTest (Expr)) {
@@ -254,13 +256,13 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr)
/* We always need to do something with the low byte, so there is no opportunity
** for optimization by skipping it.
*/
CHECK (Expr->BitOffs < CHAR_BITS);
CHECK (Expr->Type->A.B.Offs < CHAR_BITS);
if (ED_YetToTest (Expr)) {
g_testbitfield (Flags, Expr->BitOffs, Expr->BitWidth);
g_testbitfield (Flags, Expr->Type->A.B.Offs, Expr->Type->A.B.Width);
} else {
g_extractbitfield (Flags, BitFieldFullWidthFlags, IsSignSigned (Expr->Type),
Expr->BitOffs, Expr->BitWidth);
Expr->Type->A.B.Offs, Expr->Type->A.B.Width);
}
}

View File

@@ -295,7 +295,7 @@ static void SetSys (const char* Sys)
break;
default:
AbEnd ("Unknown target system type %d", Target);
AbEnd ("Unknown target system '%s'", Sys);
}
/* Initialize the translation tables for the target system */

View File

@@ -71,7 +71,7 @@
unsigned char Preprocessing = 0;
/* Management data for #if */
#define MAX_IFS 64
#define MAX_IFS 256
#define IFCOND_NONE 0x00U
#define IFCOND_SKIP 0x01U
#define IFCOND_ELSE 0x02U

View File

@@ -832,8 +832,8 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
*/
if (ED_IsLocLiteral (&Arg2.Expr) &&
IS_Get (&WritableStrings) == 0 &&
GetLiteralSize (Arg2.Expr.LVal) == 1 &&
GetLiteralStr (Arg2.Expr.LVal)[0] == '\0') {
GetLiteralSize (Arg2.Expr.V.LVal) == 1 &&
GetLiteralStr (Arg2.Expr.V.LVal)[0] == '\0') {
/* Drop the generated code so we have the first argument in the
** primary
@@ -841,7 +841,7 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
RemoveCode (&Arg1.Push);
/* We don't need the literal any longer */
ReleaseLiteral (Arg2.Expr.LVal);
ReleaseLiteral (Arg2.Expr.V.LVal);
/* We do now have Arg1 in the primary. Load the first character from
** this string and cast to int. This is the function result.
@@ -1232,10 +1232,10 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr)
if (ED_IsLocLiteral (&Arg) && IS_Get (&WritableStrings) == 0) {
/* Constant string literal */
ED_MakeConstAbs (Expr, GetLiteralSize (Arg.LVal) - 1, type_size_t);
ED_MakeConstAbs (Expr, GetLiteralSize (Arg.V.LVal) - 1, type_size_t);
/* We don't need the literal any longer */
ReleaseLiteral (Arg.LVal);
ReleaseLiteral (Arg.V.LVal);
/* Bail out, no need for further improvements */
goto ExitPoint;

View File

@@ -163,7 +163,7 @@ static int IfStatement (void)
TestResult = TestInParens (Label1, 0);
/* Parse the if body */
GotBreak = Statement (0);
GotBreak = AnyStatement (0);
/* Else clause present? */
if (CurTok.Tok != TOK_ELSE) {
@@ -195,7 +195,7 @@ static int IfStatement (void)
g_defcodelabel (Label1);
/* Total break only if both branches had a break. */
GotBreak &= Statement (0);
GotBreak &= AnyStatement (0);
/* Generate the label for the else clause */
g_defcodelabel (Label2);
@@ -225,7 +225,7 @@ static void DoStatement (void)
g_defcodelabel (LoopLabel);
/* Parse the loop body */
Statement (0);
AnyStatement (0);
/* Output the label for a continue */
g_defcodelabel (ContinueLabel);
@@ -283,7 +283,7 @@ static void WhileStatement (void)
g_defcodelabel (LoopLabel);
/* Loop body */
Statement (&PendingToken);
AnyStatement (&PendingToken);
/* Emit the while condition label */
g_defcodelabel (CondLabel);
@@ -509,7 +509,7 @@ static void ForStatement (void)
/* Loop body */
g_defcodelabel (BodyLabel);
Statement (&PendingToken);
AnyStatement (&PendingToken);
/* If we had an increment expression, move the code to the bottom of
** the loop. In this case we don't need to jump there at the end of
@@ -536,17 +536,20 @@ static void ForStatement (void)
static int CompoundStatement (void)
static int CompoundStatement (int* PendingToken)
/* Compound statement. Allow any number of statements inside braces. The
** function returns true if the last statement was a break or return.
*/
{
int GotBreak;
int GotBreak = 0;
/* Remember the stack at block entry */
int OldStack = StackPtr;
unsigned OldBlockStackSize = CollCount (&CurrentFunc->LocalsBlockStack);
/* Skip '{' */
NextToken ();
/* Enter a new lexical level */
EnterBlockLevel ();
@@ -554,16 +557,15 @@ static int CompoundStatement (void)
DeclareLocals ();
/* Now process statements in this block */
GotBreak = 0;
while (CurTok.Tok != TOK_RCURLY) {
if (CurTok.Tok != TOK_CEOF) {
GotBreak = Statement (0);
GotBreak = AnyStatement (0);
} else {
break;
}
}
/* Clean up the stack. */
/* Clean up the stack if the codeflow may reach the end */
if (!GotBreak) {
g_space (StackPtr - OldStack);
}
@@ -583,12 +585,80 @@ static int CompoundStatement (void)
/* Leave the lexical level */
LeaveBlockLevel ();
/* Skip '}' */
CheckTok (TOK_RCURLY, "'}' expected", PendingToken);
return GotBreak;
}
int Statement (int* PendingToken)
static void Statement (int* PendingToken)
/* Single-line statement */
{
ExprDesc Expr;
unsigned PrevErrorCount;
CodeMark Start, End;
/* Remember the current error count and code position */
PrevErrorCount = ErrorCount;
GetCodePos (&Start);
/* Actual statement */
ED_Init (&Expr);
Expr.Flags |= E_NEED_NONE;
Expression0 (&Expr);
/* If the statement didn't generate code, and is not of type
** void, emit a warning.
*/
GetCodePos (&End);
if (!ED_YetToLoad (&Expr) &&
!ED_MayHaveNoEffect (&Expr) &&
CodeRangeIsEmpty (&Start, &End) &&
IS_Get (&WarnNoEffect) &&
PrevErrorCount == ErrorCount) {
Warning ("Expression result unused");
}
CheckSemi (PendingToken);
}
static int ParseAnyLabels (void)
/* Return -1 if there are any labels with a statement */
{
unsigned PrevErrorCount = ErrorCount;
int HasLabels = 0;
for (;;) {
if (CurTok.Tok == TOK_IDENT && NextTok.Tok == TOK_COLON) {
/* C 'goto' label */
DoLabel ();
} else if (CurTok.Tok == TOK_CASE) {
/* C 'case' label */
CaseLabel ();
} else if (CurTok.Tok == TOK_DEFAULT) {
/* C 'default' label */
DefaultLabel ();
} else {
/* No labels */
break;
}
HasLabels = 1;
}
if (HasLabels) {
if (PrevErrorCount != ErrorCount || CheckLabelWithoutStatement ()) {
return -1;
}
}
return 0;
}
int AnyStatement (int* PendingToken)
/* Statement parser. Returns 1 if the statement does a return/break, returns
** 0 otherwise. If the PendingToken pointer is not NULL, the function will
** not skip the terminating token of the statement (closing brace or
@@ -598,40 +668,27 @@ int Statement (int* PendingToken)
** NULL, the function will skip the token.
*/
{
ExprDesc Expr;
int GotBreak;
unsigned PrevErrorCount;
CodeMark Start, End;
ED_Init (&Expr);
/* Assume no pending token */
if (PendingToken) {
*PendingToken = 0;
}
/* Check for a label. A label is always part of a statement, it does not
/* Handle any labels. A label is always part of a statement, it does not
** replace one.
*/
while (CurTok.Tok == TOK_IDENT && NextTok.Tok == TOK_COLON) {
/* Handle the label */
DoLabel ();
if (CheckLabelWithoutStatement ()) {
return 0;
}
if (ParseAnyLabels ()) {
return 0;
}
switch (CurTok.Tok) {
case TOK_LCURLY:
NextToken ();
GotBreak = CompoundStatement ();
CheckTok (TOK_RCURLY, "'{' expected", PendingToken);
return GotBreak;
case TOK_IF:
return IfStatement ();
case TOK_SWITCH:
SwitchStatement ();
break;
case TOK_WHILE:
WhileStatement ();
break;
@@ -640,10 +697,15 @@ int Statement (int* PendingToken)
DoStatement ();
break;
case TOK_SWITCH:
SwitchStatement ();
case TOK_FOR:
ForStatement ();
break;
case TOK_GOTO:
GotoStatement ();
CheckSemi (PendingToken);
return 1;
case TOK_RETURN:
ReturnStatement ();
CheckSemi (PendingToken);
@@ -659,55 +721,22 @@ int Statement (int* PendingToken)
CheckSemi (PendingToken);
return 1;
case TOK_FOR:
ForStatement ();
break;
case TOK_GOTO:
GotoStatement ();
CheckSemi (PendingToken);
return 1;
case TOK_SEMI:
/* Ignore it */
CheckSemi (PendingToken);
break;
case TOK_PRAGMA:
DoPragma ();
break;
case TOK_CASE:
CaseLabel ();
CheckLabelWithoutStatement ();
case TOK_SEMI:
/* Empty statement. Ignore it */
CheckSemi (PendingToken);
break;
case TOK_DEFAULT:
DefaultLabel ();
CheckLabelWithoutStatement ();
break;
case TOK_LCURLY:
return CompoundStatement (PendingToken);
default:
/* Remember the current error count and code position */
PrevErrorCount = ErrorCount;
GetCodePos (&Start);
/* Actual statement */
Expr.Flags |= E_NEED_NONE;
Expression0 (&Expr);
/* If the statement didn't generate code, and is not of type
** void, emit a warning.
*/
GetCodePos (&End);
if (!ED_YetToLoad (&Expr) &&
!ED_MayHaveNoEffect (&Expr) &&
CodeRangeIsEmpty (&Start, &End) &&
IS_Get (&WarnNoEffect) &&
PrevErrorCount == ErrorCount) {
Warning ("Expression result unused");
}
CheckSemi (PendingToken);
/* Simple statement */
Statement (PendingToken);
break;
}
return 0;
}

View File

@@ -44,7 +44,7 @@
int Statement (int* PendingToken);
int AnyStatement (int* PendingToken);
/* Statement parser. Returns 1 if the statement does a return/break, returns
** 0 otherwise. If the PendingToken pointer is not NULL, the function will
** not skip the terminating token of the statement (closing brace or

View File

@@ -148,7 +148,7 @@ void SwitchStatement (void)
/* Parse the following statement, which may actually be a compound
** statement if there is a curly brace at the current input position
*/
HaveBreak = Statement (&RCurlyBrace);
HaveBreak = AnyStatement (&RCurlyBrace);
/* Check if we had any labels */
if (CollCount (SwitchData.Nodes) == 0 && SwitchData.DefaultLabel == 0) {

View File

@@ -183,13 +183,6 @@ struct SymEntry {
const Type* Type; /* Underlying type */
} E;
/* Data for bit fields */
struct {
unsigned Offs; /* Byte offset into struct */
unsigned BitOffs; /* Bit offset into storage unit */
unsigned BitWidth; /* Width in bits */
} B;
/* Data for functions */
struct {
struct Segments* Seg; /* Segments for this function */

View File

@@ -881,10 +881,8 @@ SymEntry* AddBitField (const char* Name, const Type* T, unsigned Offs,
Entry = NewSymEntry (Name, SC_BITFIELD);
/* Set the symbol attributes. Bit-fields are always integral types. */
Entry->Type = TypeDup (T);
Entry->V.B.Offs = Offs;
Entry->V.B.BitOffs = BitOffs;
Entry->V.B.BitWidth = BitWidth;
Entry->Type = NewBitFieldType (T, BitOffs, BitWidth);
Entry->V.Offs = Offs;
if (!SignednessSpecified) {
/* int is treated as signed int everywhere except bit-fields; switch it to unsigned,
@@ -896,8 +894,10 @@ SymEntry* AddBitField (const char* Name, const Type* T, unsigned Offs,
*/
CHECK ((Entry->Type->C & T_MASK_SIGN) == T_SIGN_SIGNED ||
IsTypeChar (Entry->Type));
Entry->Type->C &= ~T_MASK_SIGN;
Entry->Type->C |= T_SIGN_UNSIGNED;
Entry->Type[0].C &= ~T_MASK_SIGN;
Entry->Type[0].C |= T_SIGN_UNSIGNED;
Entry->Type[1].C &= ~T_MASK_SIGN;
Entry->Type[1].C |= T_SIGN_UNSIGNED;
}
/* Add the entry to the symbol table */

View File

@@ -278,6 +278,21 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result)
SetResult (Result, TC_STRICT_COMPATIBLE);
}
/* Bit-fields are considered compatible if they have the same
** signedness, bit-offset and bit-width.
*/
if (IsTypeBitField (lhs) || IsTypeBitField (rhs)) {
if (!IsTypeBitField (lhs) ||
!IsTypeBitField (rhs) ||
lhs->A.B.Offs != rhs->A.B.Offs ||
lhs->A.B.Width != rhs->A.B.Width) {
SetResult (Result, TC_INCOMPATIBLE);
}
if (LeftType != RightType) {
SetResult (Result, TC_STRICT_COMPATIBLE);
}
}
/* If the underlying types are not identical, the types are incompatible */
if (LeftType != RightType) {
SetResult (Result, TC_INCOMPATIBLE);

View File

@@ -83,11 +83,16 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
/* Get the sizes of the types. Since we've excluded void types, checking
** for known sizes makes sense here.
*/
if (ED_IsBitField (Expr)) {
OldBits = Expr->BitWidth;
if (IsTypeBitField (OldType)) {
OldBits = OldType->A.B.Width;
} else {
OldBits = CheckedSizeOf (OldType) * CHAR_BITS;
}
/* If the new type is a bit-field, we use its underlying type instead */
if (IsTypeBitField (NewType)) {
NewType = GetUnderlyingType (NewType);
}
NewBits = CheckedSizeOf (NewType) * CHAR_BITS;
/* lvalue? */
@@ -167,9 +172,6 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
ExitPoint:
/* The expression has always the new type */
ReplaceType (Expr, NewType);
/* Bit-fields are converted to integers */
ED_DisBitField (Expr);
}

View File

@@ -321,20 +321,18 @@ long GetExprVal (ExprNode* Expr)
return GetExprVal (Expr->Left) * GetExprVal (Expr->Right);
case EXPR_DIV:
Left = GetExprVal (Expr->Left);
Right = GetExprVal (Expr->Right);
if (Right == 0) {
Error ("Division by zero");
}
return Left / Right;
return GetExprVal (Expr->Left) / Right;
case EXPR_MOD:
Left = GetExprVal (Expr->Left);
Right = GetExprVal (Expr->Right);
if (Right == 0) {
Error ("Modulo operation with zero");
}
return Left % Right;
return GetExprVal (Expr->Left) % Right;
case EXPR_OR:
return GetExprVal (Expr->Left) | GetExprVal (Expr->Right);
@@ -403,17 +401,20 @@ long GetExprVal (ExprNode* Expr)
case EXPR_BANK:
GetSegExprVal (Expr->Left, &D);
if (D.TooComplex || D.Seg == 0) {
Error ("Argument for .BANK is not segment relative or too complex");
if (D.TooComplex) {
Error ("Argument of .BANK() is too complex");
}
if (D.Seg == 0) {
Error ("Argument of .BANK() isn't a label attached to a segment");
}
if (D.Seg->MemArea == 0) {
Error ("Segment '%s' is referenced by .BANK but "
"not assigned to a memory area",
Error ("Segment '%s' is referenced by .BANK(),"
" but not assigned to a memory area",
GetString (D.Seg->Name));
}
if (D.Seg->MemArea->BankExpr == 0) {
Error ("Memory area '%s' is referenced by .BANK but "
"has no BANK attribute",
Error ("Memory area '%s' is referenced by .BANK(),"
" but has no BANK attribute",
GetString (D.Seg->MemArea->Name));
}
return GetExprVal (D.Seg->MemArea->BankExpr);
@@ -457,13 +458,15 @@ long GetExprVal (ExprNode* Expr)
static void GetSegExprValInternal (ExprNode* Expr, SegExprDesc* D, int Sign)
/* Check if the given expression consists of a segment reference and only
** constant values, additions and subtractions. If anything else is found,
** constant values, additions, and subtractions. If anything else is found,
** set D->TooComplex to true.
** Internal, recursive routine.
*/
{
Export* E;
CHECK (Expr != 0);
switch (Expr->Op) {
case EXPR_LITERAL:
@@ -479,7 +482,7 @@ static void GetSegExprValInternal (ExprNode* Expr, SegExprDesc* D, int Sign)
*/
if (ExportHasMark (E)) {
CircularRefError (E);
} else {
} else if (E->Expr != 0) {
MarkExport (E);
GetSegExprValInternal (E->Expr, D, Sign);
UnmarkExport (E);

View File

@@ -1,2 +1,18 @@
@echo off
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" goto vs2017
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" goto vs2019
echo Error: VsDevCmd.bat not found!
goto:eof
:vs2017
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
goto run
:vs2019
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
goto run
:run
msbuild.exe %*