From 0fbf2af09d9cdff1f73a47d79b7735258db4a34b Mon Sep 17 00:00:00 2001 From: mrdudz Date: Fri, 7 May 2021 18:38:26 +0200 Subject: [PATCH 1/6] Fix the warning that is produced for unused functions --- src/cc65/error.c | 2 ++ src/cc65/error.h | 1 + src/cc65/symtab.c | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/src/cc65/error.c b/src/cc65/error.c index 0118d50b8..b1529d0b5 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -78,6 +78,7 @@ IntStack WarnUnreachableCode= INTSTACK(1); /* - unreachable code */ IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */ IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */ IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */ +IntStack WarnUnusedFunc = INTSTACK(1); /* - unused functions */ /* Map the name of a warning to the intstack that holds its state */ typedef struct WarnMapEntry WarnMapEntry; @@ -97,6 +98,7 @@ static WarnMapEntry WarnMap[] = { { &WarnStructParam, "struct-param" }, { &WarnUnknownPragma, "unknown-pragma" }, { &WarnUnreachableCode, "unreachable-code" }, + { &WarnUnusedFunc, "unused-func" }, { &WarnUnusedLabel, "unused-label" }, { &WarnUnusedParam, "unused-param" }, { &WarnUnusedVar, "unused-var" }, diff --git a/src/cc65/error.h b/src/cc65/error.h index 31c46f513..c4420c434 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -75,6 +75,7 @@ extern IntStack WarnUnreachableCode; /* - unreachable code */ extern IntStack WarnUnusedLabel; /* - unused labels */ extern IntStack WarnUnusedParam; /* - unused parameters */ extern IntStack WarnUnusedVar; /* - unused variables */ +extern IntStack WarnUnusedFunc; /* - unused functions */ /* Forward */ struct StrBuf; diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 6ec255497..4073a38bc 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -173,6 +173,10 @@ static void CheckSymTable (SymTable* Tab) if (IS_Get (&WarnUnusedParam)) { Warning ("Parameter '%s' is never used", Entry->Name); } + } else if (Flags & SC_FUNC) { + if (IS_Get (&WarnUnusedFunc)) { + Warning ("Function '%s' is defined but never used", Entry->Name); + } } else { if (IS_Get (&WarnUnusedVar)) { Warning ("Variable '%s' is defined but never used", Entry->Name); From 3ea330f15fb3829dcab038647dd930481d51b7d1 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Fri, 7 May 2021 21:32:04 +0200 Subject: [PATCH 2/6] update docs --- doc/cc65.sgml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index dc754cb31..ae80b11b0 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -563,6 +563,8 @@ Here is a description of all the command line options: Warn about #pragmas that aren't recognized by cc65. Warn about unreachable code in cases of comparing constants, etc. + + Warn about unused functions. Warn about unused labels. From 4c37f12a4d5a35e113a59b9f8299801f616564da Mon Sep 17 00:00:00 2001 From: Polluks Date: Sat, 8 May 2021 18:23:19 +0200 Subject: [PATCH 3/6] Optimised strlen --- libsrc/common/strlen.s | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libsrc/common/strlen.s b/libsrc/common/strlen.s index e89039179..8d5bc20fc 100644 --- a/libsrc/common/strlen.s +++ b/libsrc/common/strlen.s @@ -5,17 +5,27 @@ ; the usage of only ptr2 here! Keep in mind when appling changes ; and check the other implementations too! ; -; int strlen (const char* s); +; size_t __fastcall__ strlen (const char* s); ; .export _strlen .importzp ptr2 + .macpack cpu _strlen: sta ptr2 ; Save s stx ptr2+1 +.if (.cpu .bitand ::CPU_ISET_HUC6280) + clx + cly +.else ldx #0 ; YX used as counter +.if (.cpu .bitand ::CPU_ISET_65816) + txy +.else ldy #0 +.endif +.endif L1: lda (ptr2),y beq L9 From b1f81d5e21c1965b9d1592d1c20b0c2940edc9e3 Mon Sep 17 00:00:00 2001 From: polluks2 <74630735+polluks2@users.noreply.github.com> Date: Sat, 8 May 2021 16:50:08 +0000 Subject: [PATCH 4/6] Optimised code --- libsrc/atari5200/y2k.inc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libsrc/atari5200/y2k.inc b/libsrc/atari5200/y2k.inc index a44d027a1..f8531451c 100644 --- a/libsrc/atari5200/y2k.inc +++ b/libsrc/atari5200/y2k.inc @@ -32,10 +32,8 @@ Y2K3 STA $0732,X LDA #$60 ; Store RTS opcode @ end STA $0750 JSR $0600 ; Show title screen - LDY #$00 ; Clear RAM from $0600-$3FFF + LDY #<$0600 ; Clear RAM from $0600-$3FFF STY $80 - LDA #$06 + LDA #>$0600 STA $81 - JSR CLRRAM - RTS - + JMP CLRRAM From 07bd5089ec502a4aab1e2cfd381ba8a7d86d22c8 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 9 May 2021 19:27:33 +0200 Subject: [PATCH 5/6] Define CLOCKS_PER_SEC as _clocks_per_sec() if _clocks_per_sec() is actually available. There are programs checking for the existence of CLOCKS_PER_SEC before usage. We don't want to mislead them. --- include/time.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/time.h b/include/time.h index 49d7e6870..92cbeee37 100644 --- a/include/time.h +++ b/include/time.h @@ -98,11 +98,11 @@ extern struct _timezone { # define CLOCKS_PER_SEC 50 #elif defined(__PCE__) # define CLOCKS_PER_SEC 60 -#elif defined(__GAMATE__) +#elif defined(__GAMATE__) # define CLOCKS_PER_SEC 135 /* FIXME */ -#elif defined(__GEOS__) +#elif defined(__GEOS__) # define CLOCKS_PER_SEC 1 -#else +#elif defined(__ATARI__) || defined (__LYNX__) /* Read the clock rate at runtime */ clock_t _clocks_per_sec (void); # define CLOCKS_PER_SEC _clocks_per_sec() From b7856ddd4f9b73b0a40a284bd782de545986f801 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 11 May 2021 10:40:44 +0200 Subject: [PATCH 6/6] Just some source formatting adjustments. --- src/cc65/funcdesc.c | 16 ++++++++-------- src/cc65/funcdesc.h | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cc65/funcdesc.c b/src/cc65/funcdesc.c index 4c959fb6c..2291b35ee 100644 --- a/src/cc65/funcdesc.c +++ b/src/cc65/funcdesc.c @@ -54,14 +54,14 @@ FuncDesc* NewFuncDesc (void) FuncDesc* F = (FuncDesc*) xmalloc (sizeof (FuncDesc)); /* Nullify the fields */ - F->Flags = 0; - F->SymTab = 0; - F->TagTab = 0; - F->ParamCount = 0; - F->ParamSize = 0; - F->LastParam = 0; - F->FuncDef = 0; - F->WrappedCall = 0; + F->Flags = 0; + F->SymTab = 0; + F->TagTab = 0; + F->ParamCount = 0; + F->ParamSize = 0; + F->LastParam = 0; + F->FuncDef = 0; + F->WrappedCall = 0; F->WrappedCallData = 0; /* Return the new struct */ diff --git a/src/cc65/funcdesc.h b/src/cc65/funcdesc.h index 423e7621f..b69cfa850 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -45,15 +45,15 @@ /* Masks for the Flags field in FuncDesc */ -#define FD_NONE 0x0000U /* No flags */ -#define FD_EMPTY 0x0001U /* Function with empty param list */ -#define FD_VOID_PARAM 0x0002U /* Function with a void param list */ -#define FD_VARIADIC 0x0004U /* Function with variable param list */ +#define FD_NONE 0x0000U /* No flags */ +#define FD_EMPTY 0x0001U /* Function with empty param list */ +#define FD_VOID_PARAM 0x0002U /* Function with a void param list */ +#define FD_VARIADIC 0x0004U /* Function with variable param list */ #define FD_INCOMPLETE_PARAM 0x0008U /* Function with param of unknown size */ -#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */ -#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */ -#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */ -#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */ +#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */ +#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */ +#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */ +#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */ /* Bits that must be ignored when comparing funcs */ #define FD_IGNORE (FD_INCOMPLETE_PARAM | FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER) @@ -63,15 +63,15 @@ /* Function descriptor */ typedef struct FuncDesc FuncDesc; struct FuncDesc { - unsigned Flags; /* Bitmapped flags FD_... */ - struct SymTable* SymTab; /* Symbol table */ - struct SymTable* TagTab; /* Symbol table for structs/enums */ - unsigned ParamCount; /* Number of parameters */ - unsigned ParamSize; /* Size of the parameters */ - struct SymEntry* LastParam; /* Pointer to last parameter */ - struct FuncDesc* FuncDef; /* Descriptor used in definition */ - struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ - unsigned char WrappedCallData;/* The WrappedCall's user data */ + unsigned Flags; /* Bitmapped flags FD_... */ + struct SymTable* SymTab; /* Symbol table */ + struct SymTable* TagTab; /* Symbol table for structs/enums */ + unsigned ParamCount; /* Number of parameters */ + unsigned ParamSize; /* Size of the parameters */ + struct SymEntry* LastParam; /* Pointer to last parameter */ + struct FuncDesc* FuncDef; /* Descriptor used in definition */ + struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ + unsigned char WrappedCallData; /* The WrappedCall's user data */ };