1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-17 16:29:32 +00:00

more cleanup

This commit is contained in:
mrdudz 2022-07-21 02:06:47 +02:00
parent 63024cd056
commit 77ce005d0a
8 changed files with 114 additions and 73 deletions

View File

@ -31,7 +31,7 @@
/* */
/*****************************************************************************/
//#define DEBUG
/* cc65 */
#include "asmcode.h"
@ -47,7 +47,13 @@
#include "typecmp.h"
#include "typeconv.h"
#ifdef DEBUG
#define LOG(x) printf x
#define FIXME(x) printf x
#else
#define LOG(x)
#define FIXME(x)
#endif
/*****************************************************************************/
/* Data */
@ -434,7 +440,7 @@ static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char*
unsigned Flags;
int MustScale;
printf("OpAssignArithmetic (Gen=%d)\n", (int)Gen);
LOG(("OpAssignArithmetic (Gen=%d)\n", (int)Gen));
ED_Init (&Expr2);
Expr2.Flags |= Expr->Flags & E_MASK_KEEP_SUBEXPR;
@ -464,9 +470,9 @@ static void OpAssignArithmetic (const GenDesc* Gen, ExprDesc* Expr, const char*
/* If necessary, load the value into the primary register */
LoadExpr (CF_NONE, &Expr2);
printf("OpAssignArithmetic (0) 2 lhs: %s rhs: %s\n",
(TypeOf (Expr->Type) == CF_FLOAT) ? "float" : "int",
(TypeOf (Expr2.Type) == CF_FLOAT) ? "float" : "int");
LOG(("OpAssignArithmetic (0) 2 lhs: %s rhs: %s\n",
(TypeOf (Expr->Type) == CF_FLOAT) ? "float" : "int",
(TypeOf (Expr2.Type) == CF_FLOAT) ? "float" : "int"));
} else {
/* Load the original value if necessary */
@ -567,7 +573,7 @@ void OpAssign (const GenDesc* Gen, ExprDesc* Expr, const char* Op)
{
const Type* ltype = Expr->Type;
printf("OpAssign\n");
LOG(("OpAssign\n"));
ExprDesc Expr2;
ED_Init (&Expr2);

View File

@ -39,6 +39,8 @@
#include <string.h>
#include <stdarg.h>
//#define DEBUG
/* common */
#include "addrsize.h"
#include "check.h"
@ -64,7 +66,13 @@
#include "util.h"
#include "codegen.h"
#ifdef DEBUG
#define LOG(x) printf x
#define FIXME(x) printf x
#else
#define LOG(x)
#define FIXME(x)
#endif
/*****************************************************************************/
/* Helpers */
@ -689,15 +697,19 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
/* Fetching memory cells */
/*****************************************************************************/
//void _g_getimmed (unsigned Flags, uintptr_t Val, long Offs, char *file, int line);
#ifdef DEBUG
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, char *func, int line)
#else
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
#endif
/* Load a constant into the primary register */
{
unsigned char B1, B2, B3, B4;
unsigned Done;
printf("g_getimmed %s:%d:%s Flags:%04x Val: %08x Offs:%04x\n", file, line, func, Flags, Val, Offs);
LOG(("g_getimmed %s:%d:%s Flags:%04x Val: %08x Offs:%04x\n", file, line, func, Flags, Val, Offs));
if ((Flags & CF_CONST) != 0) {
@ -716,7 +728,8 @@ printf("g_getimmed %s:%d:%s Flags:%04x Val: %08x Offs:%04x\n", file, line, func,
break;
case CF_FLOAT: /* FIXME float - handle like long here */
printf("g_getimmed CF_FLOAT Val: %08lx\n", Val);
LOG(("g_getimmed CF_FLOAT Val: %08lx\n", Val));
case CF_LONG:
/* Split the value into 4 bytes */
B1 = (unsigned char) (Val >> 0);
@ -899,7 +912,7 @@ void g_getind (unsigned Flags, unsigned Offs)
** into the primary register
*/
{
printf("g_getind flags:%04x offs:%04x\n", Flags, Offs);
LOG(("g_getind flags:%04x offs:%04x\n", Flags, Offs));
/* If the offset is greater than 255, add the part that is > 255 to
** the primary. This way we get an easy addition and use the low byte
** as the offset
@ -1106,7 +1119,7 @@ void g_putstatic (unsigned flags, uintptr_t label, long offs)
void g_putlocal (unsigned Flags, int Offs, long Val)
/* Put data into local object. */
{
printf("g_putlocal Flags:%04x Offs:%d val: %ld\n", Flags, Offs, Val);
LOG(("g_putlocal Flags:%04x Offs:%d val: %ld\n", Flags, Offs, Val));
Offs -= StackPtr;
CheckLocalOffs (Offs);
switch (Flags & CF_TYPEMASK) {
@ -1324,7 +1337,7 @@ static void g_regchar (unsigned Flags)
void g_regint (unsigned Flags)
/* Make sure, the value in the primary register is an int. Convert if necessary */
{
printf("g_regint flags: %04x\n", Flags);
LOG(("g_regint flags: %04x\n", Flags));
switch (Flags & CF_TYPEMASK) {
case CF_CHAR:
@ -1408,7 +1421,7 @@ void g_reglong (unsigned Flags)
void g_regfloat (unsigned Flags)
/* Make sure, the value in the primary register is a float. Convert if necessary */
{
printf("g_regfloat flags: %04x\n", Flags);
LOG(("g_regfloat flags: %04x\n", Flags));
switch (Flags & CF_TYPEMASK) {
case CF_CHAR:
@ -1498,11 +1511,11 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs)
return const_flag | CF_FLOAT;
}
if (ltype == CF_FLOAT) {
printf("FIXME: conversion to float format missing\n");
FIXME(("FIXME: conversion to float format missing\n"));
return (lhs & CF_CONST) | CF_FLOAT;
}
if (rtype == CF_FLOAT) {
printf("FIXME: conversion to float format missing\n");
FIXME("FIXME: conversion to float format missing\n");
return (rhs & CF_CONST) | CF_FLOAT;
}
@ -1597,11 +1610,11 @@ unsigned g_typecast (unsigned lhs, unsigned rhs)
** by the lhs value. Return the result value.
*/
{
printf("g_typecast 2 rhs: %s lhs: %s (rhs is %s)\n",
((rhs & CF_TYPEMASK) == CF_FLOAT) ? "float" : "int",
((lhs & CF_TYPEMASK) == CF_FLOAT) ? "float" : "int",
((rhs & CF_CONST) == 0) ? "not const" : "const"
);
LOG(("g_typecast 2 rhs: %s lhs: %s (rhs is %s)\n",
((rhs & CF_TYPEMASK) == CF_FLOAT) ? "float" : "int",
((lhs & CF_TYPEMASK) == CF_FLOAT) ? "float" : "int",
((rhs & CF_CONST) == 0) ? "not const" : "const"
));
/* Check if a conversion is needed */
if ((rhs & CF_CONST) == 0) {
switch (lhs & CF_TYPEMASK) {
@ -2531,7 +2544,7 @@ void g_push (unsigned flags, unsigned long val)
void g_push_float (unsigned flags, float val)
/* Push the primary register or a constant value onto the stack */
{
// printf("g_push_float flags:%04x val:%f\n", flags, val);
// LOG(("g_push_float flags:%04x val:%f\n", flags, val));
/* Push the primary register */
switch (flags & CF_TYPEMASK) {
@ -2539,11 +2552,18 @@ void g_push_float (unsigned flags, float val)
/* Value is not 16 bit or not constant */
// if (flags & CF_CONST)
{
float f = val;
// float f = val;
#if 0
uintptr_t *p = &val; /* FIXME: float - we shouldnt do this :) */
/* Constant 32 bit value, load into eax */
printf("g_push_float flags:%04x f:%p\n", flags, *p);
LOG(("g_push_float flags:%04x f:%p\n", flags, *p));
g_getimmed (flags | CF_CONST, *p, 0); // ?? FIXME
#else
uint32_t *p = ((uint32_t*)&val); /* FIXME: float - we shouldnt do this :) */
/* Constant 32 bit value, load into eax */
LOG(("g_push_float flags:%04x f:%p\n", flags, *p));
g_getimmed (flags | CF_CONST, *p, 0); // ?? FIXME
#endif
// g_getimmed (0x41,*p,0);
}
AddCodeLine ("jsr pusheax");
@ -2818,7 +2838,7 @@ void g_mul (unsigned flags, unsigned long val)
"ftosmuleax"
};
printf("g_mul flags:%04x val:%d\n", flags, val);
LOG(("g_mul flags:%04x val:%d\n", flags, val));
/* Do strength reduction if the value is constant and a power of two */
if (flags & CF_CONST) {
@ -2946,7 +2966,7 @@ void g_div (unsigned flags, unsigned long val)
"ftosdiveax"
};
printf("g_div flags:%04x val:%d\n", flags, val);
LOG(("g_div flags:%04x val:%d\n", flags, val));
/* Do strength reduction if the value is constant and a power of two */
if (flags & CF_CONST) {
@ -3696,7 +3716,7 @@ void g_inc (unsigned flags, unsigned long val)
if flags contain CF_FLOAT, then val can be a raw binary float.
*/
{
printf("g_inc flags:%04x val:%08lx\n", flags, val);
LOG(("g_inc flags:%04x val:%08lx\n", flags, val));
/* Don't inc by zero */
if (val == 0) {
return;
@ -3917,7 +3937,7 @@ void g_eq (unsigned flags, unsigned long val)
};
unsigned L;
printf("g_eq flags:%04x val:%ld\n", flags, val);
LOG(("g_eq flags:%04x val:%ld\n", flags, val));
/* If the right hand side is const, the lhs is not on stack but still
** in the primary register.
*/
@ -4698,7 +4718,7 @@ void g_defdata (unsigned flags, uintptr_t val, long offs)
void g_defdata_float (unsigned flags, uintptr_t val, long offs)
/* Define data with the size given in flags */
{
printf("g_defdata_float flags:%04x val:%f offs:%04lx\n", flags, (float)val, offs);
LOG(("g_defdata_float flags:%04x val:%f offs:%04lx\n", flags, (float)val, offs));
if (flags & CF_CONST) {
/* Numeric constant */

View File

@ -270,13 +270,14 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
/*****************************************************************************/
//void g_getimmed (unsigned Flags, uintptr_t Val, long Offs);
/* Load a constant into the primary register */
#ifdef DEBUG
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, char *func, int line);
#else
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
void _g_getimmed (unsigned Flags, uintptr_t Val, long Offs);
#endif
/* Load a constant into the primary register */
void g_getstatic (unsigned Flags, uintptr_t Label, long Offs);
/* Fetch an static memory cell into the primary register */

View File

@ -2067,6 +2067,8 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
case TOK_DIV:
floatop = 1;
break;
default:
break;
}
/* FIXME: float ---start end code*/

View File

@ -31,10 +31,11 @@
/* */
/*****************************************************************************/
//#define DEBUG
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@ -65,7 +66,13 @@
#include "typeconv.h"
#include "initdata.h"
#ifdef DEBUG
#define LOG(x) printf x
#define FIXME(x) printf x
#else
#define LOG(x)
#define FIXME(x)
#endif
/*****************************************************************************/
/* Data */
@ -166,8 +173,8 @@ static void DefineData (ExprDesc* Expr)
{
int isfloat = (TypeOf (Expr->Type) == CF_FLOAT);
printf("%s:%d DefineData IVal: %ld V.FVal: %f isfloat:%d %d\n", __FILE__, __LINE__,
Expr->IVal, (double)(Expr->V.FVal.V), isfloat, ED_GetLoc (Expr));
LOG(("%s:%d DefineData IVal: %ld V.FVal: %f isfloat:%d %d\n", __FILE__, __LINE__,
Expr->IVal, (double)(Expr->V.FVal.V), isfloat, ED_GetLoc (Expr)));
switch (ED_GetLoc (Expr)) {
case E_LOC_NONE:

View File

@ -31,7 +31,7 @@
/* */
/*****************************************************************************/
#include <stdlib.h>
/* cc65 */
#include "codegen.h"

View File

@ -1,4 +1,9 @@
CC65=../../bin/cc65
CL65=../../bin/cl65
CA65=../../bin/ca65
SIM65=../../bin/sim65
OPT=
FILES=\
@ -80,61 +85,61 @@ WOZRUNTIME=\
all: $(FILES)
float-minimal.s: float-minimal.c $(HEADER) $(IEEERUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-minimal.s float-minimal.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-minimal.s float-minimal.c
float-minimal.bin: float-minimal.s $(HEADER) $(IEEERUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-minimal.bin float-minimal.s $(IEEERUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-minimal.bin float-minimal.s $(IEEERUNTIME)
float-basic.s: float-basic.c $(HEADER) $(IEEERUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-basic.s float-basic.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-basic.s float-basic.c
float-basic.bin: float-basic.s $(HEADER) $(IEEERUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-basic.bin float-basic.s $(IEEERUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-basic.bin float-basic.s $(IEEERUNTIME)
float-basic-cmp.s: float-basic-cmp.c $(HEADER) $(IEEERUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-basic-cmp.s float-basic-cmp.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-basic-cmp.s float-basic-cmp.c
float-basic-cmp.bin: float-basic-cmp.s $(HEADER) $(IEEERUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-basic-cmp.bin float-basic-cmp.s $(IEEERUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-basic-cmp.bin float-basic-cmp.s $(IEEERUNTIME)
###############################################################################
float-minimal.woz.s: float-minimal.c $(HEADER) $(WOZRUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-minimal.woz.s float-minimal.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-minimal.woz.s float-minimal.c
float-minimal.woz.bin: float-minimal.woz.s $(HEADER) $(WOZRUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-minimal.woz.bin float-minimal.woz.s $(WOZRUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-minimal.woz.bin float-minimal.woz.s $(WOZRUNTIME)
float-basic.woz.s: float-basic.c $(HEADER) $(WOZRUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-basic.woz.s float-basic.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-basic.woz.s float-basic.c
float-basic.woz.bin: float-basic.woz.s $(HEADER) $(WOZRUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-basic.woz.bin float-basic.woz.s $(WOZRUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-basic.woz.bin float-basic.woz.s $(WOZRUNTIME)
float-basic-cmp.woz.s: float-basic-cmp.c $(HEADER) $(WOZRUNTIME)
cc65 $(OPT) -t sim6502 -I ./include --add-source -o float-basic-cmp.woz.s float-basic-cmp.c
$(CC65) $(OPT) -t sim6502 -I ./include --add-source -o float-basic-cmp.woz.s float-basic-cmp.c
float-basic-cmp.woz.bin: float-basic-cmp.woz.s $(HEADER) $(WOZRUNTIME)
cl65 $(OPT) -t sim6502 -I ./include -o float-basic-cmp.woz.bin float-basic-cmp.woz.s $(WOZRUNTIME)
$(CL65) $(OPT) -t sim6502 -I ./include -o float-basic-cmp.woz.bin float-basic-cmp.woz.s $(WOZRUNTIME)
###############################################################################
float-minimal.c64.s: float-minimal.c $(HEADER) $(CBMRUNTIME)
cc65 $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-minimal.c64.s float-minimal.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-minimal.c64.s float-minimal.c
float-minimal.prg: float-minimal.c64.s $(HEADER) $(CBMRUNTIME)
cl65 $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-minimal.prg float-minimal.c64.s $(CBMRUNTIME)
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-minimal.prg float-minimal.c64.s $(CBMRUNTIME)
float-basic.c64.s: float-basic.c $(HEADER) $(CBMRUNTIME)
cc65 $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-basic.c64.s float-basic.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-basic.c64.s float-basic.c
float-basic.prg: float-basic.c64.s $(HEADER) $(CBMRUNTIME)
cl65 $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-basic.prg float-basic.c64.s $(CBMRUNTIME)
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-basic.prg float-basic.c64.s $(CBMRUNTIME)
float-basic-cmp.c64.s: float-basic-cmp.c $(HEADER) $(CBMRUNTIME)
cc65 $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-basic-cmp.c64.s float-basic-cmp.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o float-basic-cmp.c64.s float-basic-cmp.c
float-basic-cmp.prg: float-basic-cmp.c64.s $(HEADER) $(CBMRUNTIME)
cl65 $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-basic-cmp.prg float-basic-cmp.c64.s $(CBMRUNTIME)
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o float-basic-cmp.prg float-basic-cmp.c64.s $(CBMRUNTIME)
floattest.c64.s: floattest.c $(HEADER) $(CBMRUNTIME)
cc65 $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o floattest.c64.s floattest.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o floattest.c64.s floattest.c
floattest.prg: floattest.c64.s $(HEADER) $(CBMRUNTIME)
cl65 $(OPT) -t c64 -I ./include -I ./cbmkernal -o floattest.prg floattest.c64.s $(CBMRUNTIME)
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o floattest.prg floattest.c64.s $(CBMRUNTIME)
quick.c64.s: quick.c $(HEADER) $(CBMRUNTIME)
cc65 $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o quick.c64.s quick.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o quick.c64.s quick.c
quick.prg: quick.c64.s $(HEADER) $(CBMRUNTIME)
cl65 $(OPT) -t c64 -I ./include -I ./cbmkernal -o quick.prg quick.c64.s $(CBMRUNTIME)
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o quick.prg quick.c64.s $(CBMRUNTIME)
runquick: quick.prg
x64sc -autostartprgmode 1 quick.prg
###############################################################################
@ -156,21 +161,21 @@ rungcc: gccminimal gccbasic gccbasiccmp gccfloattest
###############################################################################
runminimal: float-minimal.bin
sim65 float-minimal.bin
$(SIM65) float-minimal.bin
runbasic: float-basic.bin
sim65 float-basic.bin
$(SIM65) float-basic.bin
runbasiccmp: float-basic-cmp.bin
sim65 float-basic-cmp.bin
$(SIM65) float-basic-cmp.bin
run: runminimal runbasic runbasiccmp
sim65 float-minimal.bin
sim65 float-basic.bin
sim65 float-basic-cmp.bin
$(SIM65) float-minimal.bin
$(SIM65) float-basic.bin
$(SIM65) float-basic-cmp.bin
runwoz: float-minimal.woz.bin float-basic.woz.bin float-basic-cmp.woz.bin
sim65 float-minimal.woz.bin
sim65 float-basic.woz.bin
sim65 float-basic-cmp.woz.bin
$(SIM65) float-minimal.woz.bin
$(SIM65) float-basic.woz.bin
$(SIM65) float-basic-cmp.woz.bin
###############################################################################

View File

@ -63,7 +63,7 @@ int main(void)
#endif
/* addition, constant + constant (already tested by minimal) (omitted) */
#ifdef CONIO
cgetc();
printf("<key>\n");cgetc();
#endif
#if 0