From 39744f1bde411e1ec4b27763e51de2b29494e493 Mon Sep 17 00:00:00 2001 From: paul moore Date: Fri, 1 Dec 2023 15:40:33 -0800 Subject: [PATCH 1/8] initial commit --- src/ca65/global.c | 1 + src/ca65/global.h | 1 + src/ca65/istack.c | 8 ++- src/ca65/istack.h | 2 +- src/ca65/macro.c | 141 ++++++++++++++++++++++++++++++++++++++++++++- src/ca65/main.c | 20 +++++-- src/ca65/scanner.c | 13 ++++- 7 files changed, 177 insertions(+), 9 deletions(-) diff --git a/src/ca65/global.c b/src/ca65/global.c index 050d19e09..e8599a675 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -69,6 +69,7 @@ unsigned char RelaxChecks = 0; /* Relax a few assembler checks */ unsigned char StringEscapes = 0; /* Allow C-style escapes in strings */ unsigned char LongJsrJmpRts = 0; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */ unsigned char WarningsAsErrors = 0; /* Error if any warnings */ +unsigned char ExpandMacros = 0; /* Expand macros in listing */ /* Emulation features */ unsigned char DollarIsPC = 0; /* Allow the $ symbol as current PC */ diff --git a/src/ca65/global.h b/src/ca65/global.h index b3de99df5..5ec4a8d82 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -71,6 +71,7 @@ extern unsigned char RelaxChecks; /* Relax a few assembler checks */ extern unsigned char StringEscapes; /* Allow C-style escapes in strings */ extern unsigned char LongJsrJmpRts; /* Allow JSR/JMP/RTS as alias for JSL/JML/RTL */ extern unsigned char WarningsAsErrors; /* Error if any warnings */ +extern unsigned char ExpandMacros; /* Expand macros in listing */ /* Emulation features */ extern unsigned char DollarIsPC; /* Allow the $ symbol as current PC */ diff --git a/src/ca65/istack.c b/src/ca65/istack.c index 7a95e7e8c..b9c45ac55 100644 --- a/src/ca65/istack.c +++ b/src/ca65/istack.c @@ -93,6 +93,7 @@ void PushInput (int (*Func) (void*), void* Data, const char* Desc) /* Push it */ E->Next = IStack; + ICount++; IStack = E; } @@ -111,7 +112,7 @@ void PopInput (void) /* Pop it */ IStack = IStack->Next; - + ICount--; /* And delete it */ xfree (E); } @@ -156,3 +157,8 @@ void CheckInputStack (void) Error ("Open %s", IStack->Desc); } } + +unsigned GetStackDepth (void) +{ + return ICount; +} diff --git a/src/ca65/istack.h b/src/ca65/istack.h index aa37bab14..90ba513b0 100644 --- a/src/ca65/istack.h +++ b/src/ca65/istack.h @@ -63,7 +63,7 @@ void CheckInputStack (void); ** stuff on the input stack. */ - +unsigned GetStackDepth (void); /* End of istack.h */ diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 904c80756..bd0dd9030 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -53,6 +53,7 @@ #include "pseudo.h" #include "toklist.h" #include "macro.h" +#include "listing.h" @@ -74,7 +75,8 @@ static int HT_Compare (const void* Key1, const void* Key2); ** than zero if Key1 is greater then Key2. */ - +static StrBuf MakeLineFromTokens (TokNode* first); +static char* GetTokenString (Token* T); /*****************************************************************************/ /* Data */ @@ -689,6 +691,8 @@ ExpandParam: Mac->ParamLI = 0; } + /* boolean to indicate that we need to start a new macro expansion line*/ + static int new_expand_line = 1; /* We're not expanding macro parameters. Check if we have tokens left from ** the macro itself. @@ -697,7 +701,16 @@ ExpandParam: /* Use next macro token */ TokSet (Mac->Exp); - + if (ExpandMacros) { + if (new_expand_line) { + StrBuf mac_line = MakeLineFromTokens (Mac->Exp); + NewListingLine (&mac_line, 0, 0); + new_expand_line = 0; + } + if (CurTok.Tok == TOK_SEP) { + new_expand_line = 1; + } + } /* Create new line info for this token */ if (Mac->LI) { EndLine (Mac->LI); @@ -1065,3 +1078,127 @@ void EnableDefineStyleMacros (void) PRECONDITION (DisableDefines > 0); --DisableDefines; } + +static StrBuf MakeLineFromTokens (TokNode* first) +{ + /* This code reconstitutes a Macro line from the 'compiled' tokens*/ + unsigned I; + /* string to be returned */ + StrBuf S = STATIC_STRBUF_INITIALIZER; + + + /* prepend depth indicator */ + for (I = 0; I < GetStackDepth (); I++) { + SB_AppendStr (&S, ">"); + } + SB_AppendStr (&S, " "); + + TokNode* tn = first; + while (tn) { + /* per token string */ + StrBuf T = STATIC_STRBUF_INITIALIZER; + + Token* token = &tn->T; + tn = tn->Next; + char* token_string; + /* leading white space?*/ + if (token->WS) SB_AppendChar (&T, ' '); + /* is it a string of some sort?*/ + unsigned len = SB_GetLen (&token->SVal); + if (len > 0) { + token_string = xmalloc (len + 1); + memcpy (token_string, SB_GetBuf (&token->SVal), len); + token_string[len] = 0; + SB_AppendStr (&T, token_string); + xfree (token_string); + } else if (token->Tok == TOK_INTCON) { + char ival[11]; // max size a long can be + snprintf (ival, 11, "%d", token->IVal); + SB_AppendStr (&T, ival); + } else if ((token_string = GetTokenString (token)) != NULL) + { + SB_AppendStr (&T, token_string); + } + SB_Append (&S, &T); + if (token->Tok == TOK_SEP) { + return S; + } + } + return S; +} + +static char* GetTokenString (Token* T) +{ + switch (T->Tok) { + + case TOK_ASSIGN: return ":="; /* := */ + case TOK_ULABEL: return ":++"; /* :++ or :-- */ + + case TOK_EQ:return "="; /* = */ + case TOK_NE: return "<>"; /* <> */ + case TOK_LT: return "<"; /* < */ + case TOK_GT:return ">"; /* > */ + case TOK_LE: return "<="; /* <= */ + case TOK_GE:return ">="; /* >= */ + + //TOK_BOOLAND, /* .and */ + //TOK_BOOLOR, /* .or */ + ///TOK_BOOLXOR, /* .xor */ + //TOK_BOOLNOT, /* .not */ + + case TOK_PLUS: return "+"; /* + */ + case TOK_MINUS:return "-"; /* - */ + case TOK_MUL: return "*"; /* * */ + case TOK_DIV: return "/"; /* / */ + case TOK_MOD:return "!"; /* ! */ + case TOK_OR: return "|"; /* | */ + case TOK_XOR: return "^"; /* ^ */ + case TOK_AND:return "&"; /* & */ + case TOK_SHL: return "<<"; /* << */ + case TOK_SHR: return ">>"; /* >> */ + case TOK_NOT:return "~"; /* ~ */ + + case TOK_PC: return "$"; /* $ if enabled */ + case TOK_NAMESPACE:return "::"; /* :: */ + case TOK_DOT:return "."; /* . */ + case TOK_COMMA:return ","; /* , */ + case TOK_HASH: return "#"; /* # */ + case TOK_COLON:return ":"; /* : */ + case TOK_LPAREN:return "("; /* ( */ + case TOK_RPAREN:return ")"; /* ) */ + case TOK_LBRACK:return "["; /* [ */ + case TOK_RBRACK:return "]"; /* ] */ + case TOK_LCURLY:return "{"; /* { */ + case TOK_RCURLY:return "}"; /* } */ + case TOK_AT:return "@"; /* @ - in Sweet16 mode */ + + case TOK_OVERRIDE_ZP:return "z:"; /* z: */ + case TOK_OVERRIDE_ABS:return "a:"; /* a: */ + case TOK_OVERRIDE_FAR:return "f:"; /* f: */ + default: return NULL; + } +} +StrBuf xMakeLineFromTokens (TokNode* first) +{ + StrBuf S = STATIC_STRBUF_INITIALIZER; + StrBuf T = STATIC_STRBUF_INITIALIZER; + SB_AppendStr (&S, ">> "); + TokNode* tn = first; + while (tn) { + Token* t = &tn->T; + tn = tn->Next; + char str[100]; + int len = SB_GetLen (&t->SVal); + if (len > 0) { + memcpy (str, SB_GetBuf (&t->SVal), len); + str[len] = 0; + } else str[0] = 0; + SB_Printf (&T, "%s ", str); + SB_Append (&S, &T); + if (t->Tok == TOK_SEP) { + + return S; + } + } + return S; +} diff --git a/src/ca65/main.c b/src/ca65/main.c index 3ec6c84ee..cc5f99786 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -107,6 +107,7 @@ static void Usage (void) " -s\t\t\t\tEnable smart mode\n" " -t sys\t\t\tSet the target system\n" " -v\t\t\t\tIncrease verbosity\n" + " -x\t\t\t\tExpand macros\n" "\n" "Long options:\n" " --auto-import\t\t\tMark unresolved symbols as import\n" @@ -129,7 +130,8 @@ static void Usage (void) " --smart\t\t\tEnable smart mode\n" " --target sys\t\t\tSet the target system\n" " --verbose\t\t\tIncrease verbosity\n" - " --version\t\t\tPrint the assembler version\n", + " --version\t\t\tPrint the assembler version\n" + " --expand_macros\t\tExpand macros in the listing\n", ProgName); } @@ -670,7 +672,12 @@ static void OptWarningsAsErrors (const char* Opt attribute ((unused)), WarningsAsErrors = 1; } - +static void OptExpandMacros (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) + /* Exapnd macros in listing */ +{ + ExpandMacros = 1; +} static void DoPCAssign (void) /* Start absolute code */ @@ -695,9 +702,9 @@ static void OneLine (void) int Instr = -1; /* Initialize the new listing line if we are actually reading from file - ** and not from internally pushed input. + ** and not from internally pushed input, unless expanding macros */ - if (!HavePushedInput ()) { + if (!HavePushedInput () || ExpandMacros) { InitListingLine (); } @@ -962,6 +969,7 @@ int main (int argc, char* argv []) { "--verbose", 0, OptVerbose }, { "--version", 0, OptVersion }, { "--warnings-as-errors", 0, OptWarningsAsErrors }, + { "--expand_macros", 0, OptExpandMacros }, }; /* Name of the global name space */ @@ -1069,6 +1077,10 @@ int main (int argc, char* argv []) case 'W': WarnLevel = atoi (GetArg (&I, 2)); break; + case 'x': + ExpandMacros = 1; + break; + default: UnknownOption (Arg); diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 185100025..b7de4f9b5 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -378,6 +378,16 @@ static void IFMarkStart (CharSource* S) static void IFNextChar (CharSource* S) /* Read the next character from the input file */ { + /* if expanding macros the next input line gets pushed too early + ** to the output. So defer the push. + ** Its harmless to do it regardless of expansion or not + */ + static int pending_line = 0; + if (pending_line) { + NewListingLine (&S->V.File.Line, S->V.File.Pos.Name, FCount); + pending_line = 0; + }; + /* Check for end of line, read the next line if needed */ while (SB_GetIndex (&S->V.File.Line) >= SB_GetLen (&S->V.File.Line)) { @@ -443,7 +453,8 @@ static void IFNextChar (CharSource* S) S->V.File.Pos.Line++; /* Remember the new line for the listing */ - NewListingLine (&S->V.File.Line, S->V.File.Pos.Name, FCount); + + pending_line = 1; } From b7af5ac43858cd34a8bf82b9d8b09af6f8f83303 Mon Sep 17 00:00:00 2001 From: paul moore Date: Fri, 1 Dec 2023 16:17:42 -0800 Subject: [PATCH 2/8] fix gcc warning --- src/ca65/macro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index bd0dd9030..2628f56d7 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -1112,8 +1112,8 @@ static StrBuf MakeLineFromTokens (TokNode* first) SB_AppendStr (&T, token_string); xfree (token_string); } else if (token->Tok == TOK_INTCON) { - char ival[11]; // max size a long can be - snprintf (ival, 11, "%d", token->IVal); + char ival[12]; // max size a long can be + snprintf (ival, sizeof(ival), "%ld", token->IVal); SB_AppendStr (&T, ival); } else if ((token_string = GetTokenString (token)) != NULL) { From ca2cf4bf5403d0878ef1c6aded5cee00ab5522cb Mon Sep 17 00:00:00 2001 From: paul moore Date: Fri, 1 Dec 2023 16:34:47 -0800 Subject: [PATCH 3/8] forgot to free retport line, remove old code --- src/ca65/macro.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 2628f56d7..4b9f1370b 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -705,6 +705,7 @@ ExpandParam: if (new_expand_line) { StrBuf mac_line = MakeLineFromTokens (Mac->Exp); NewListingLine (&mac_line, 0, 0); + SB_Done (&mac_line); new_expand_line = 0; } if (CurTok.Tok == TOK_SEP) { @@ -1141,10 +1142,6 @@ static char* GetTokenString (Token* T) case TOK_LE: return "<="; /* <= */ case TOK_GE:return ">="; /* >= */ - //TOK_BOOLAND, /* .and */ - //TOK_BOOLOR, /* .or */ - ///TOK_BOOLXOR, /* .xor */ - //TOK_BOOLNOT, /* .not */ case TOK_PLUS: return "+"; /* + */ case TOK_MINUS:return "-"; /* - */ @@ -1178,27 +1175,3 @@ static char* GetTokenString (Token* T) default: return NULL; } } -StrBuf xMakeLineFromTokens (TokNode* first) -{ - StrBuf S = STATIC_STRBUF_INITIALIZER; - StrBuf T = STATIC_STRBUF_INITIALIZER; - SB_AppendStr (&S, ">> "); - TokNode* tn = first; - while (tn) { - Token* t = &tn->T; - tn = tn->Next; - char str[100]; - int len = SB_GetLen (&t->SVal); - if (len > 0) { - memcpy (str, SB_GetBuf (&t->SVal), len); - str[len] = 0; - } else str[0] = 0; - SB_Printf (&T, "%s ", str); - SB_Append (&S, &T); - if (t->Tok == TOK_SEP) { - - return S; - } - } - return S; -} From 116f678180f97fee749b16ea6e7432877aee74af Mon Sep 17 00:00:00 2001 From: paul moore Date: Sat, 2 Dec 2023 11:04:25 -0800 Subject: [PATCH 4/8] fixed incorrect offsets , cleaned out redundant code --- src/ca65/macro.c | 10 +++------- src/ca65/main.c | 6 ++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 4b9f1370b..f8c9b81e6 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -705,6 +705,7 @@ ExpandParam: if (new_expand_line) { StrBuf mac_line = MakeLineFromTokens (Mac->Exp); NewListingLine (&mac_line, 0, 0); + InitListingLine (); SB_Done (&mac_line); new_expand_line = 0; } @@ -1107,17 +1108,12 @@ static StrBuf MakeLineFromTokens (TokNode* first) /* is it a string of some sort?*/ unsigned len = SB_GetLen (&token->SVal); if (len > 0) { - token_string = xmalloc (len + 1); - memcpy (token_string, SB_GetBuf (&token->SVal), len); - token_string[len] = 0; - SB_AppendStr (&T, token_string); - xfree (token_string); + SB_Append (&T, &token->SVal); } else if (token->Tok == TOK_INTCON) { char ival[12]; // max size a long can be snprintf (ival, sizeof(ival), "%ld", token->IVal); SB_AppendStr (&T, ival); - } else if ((token_string = GetTokenString (token)) != NULL) - { + } else if ((token_string = GetTokenString (token)) != NULL) { SB_AppendStr (&T, token_string); } SB_Append (&S, &T); diff --git a/src/ca65/main.c b/src/ca65/main.c index cc5f99786..bbb82736f 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -702,9 +702,11 @@ static void OneLine (void) int Instr = -1; /* Initialize the new listing line if we are actually reading from file - ** and not from internally pushed input, unless expanding macros + ** and not from internally pushed input */ - if (!HavePushedInput () || ExpandMacros) { + + + if (!HavePushedInput () ) { InitListingLine (); } From 617eb0e065de12aff25411042ce1ae27ee10289c Mon Sep 17 00:00:00 2001 From: paul moore Date: Sun, 3 Dec 2023 11:59:05 -0800 Subject: [PATCH 5/8] Added repeat support. Added short vs long expansion --- src/ca65/macro.c | 27 ++++++++++++++++++++++----- src/ca65/macro.h | 4 ++-- src/ca65/main.c | 11 ++++++++--- src/ca65/toklist.c | 24 +++++++++++++++++++++++- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index f8c9b81e6..9d8499388 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -75,8 +75,8 @@ static int HT_Compare (const void* Key1, const void* Key2); ** than zero if Key1 is greater then Key2. */ -static StrBuf MakeLineFromTokens (TokNode* first); static char* GetTokenString (Token* T); +/* decompile a token back to a string */ /*****************************************************************************/ /* Data */ @@ -135,6 +135,7 @@ struct MacExp { TokNode* ParamExp; /* Node for expanding parameters */ LineInfo* LI; /* Line info for the expansion */ LineInfo* ParamLI; /* Line info for parameter expansion */ + unsigned ExpandStart; /* First pass through expansion ?*/ }; /* Maximum number of nested macro expansions */ @@ -314,6 +315,7 @@ static MacExp* NewMacExp (Macro* M) E->ParamExp = 0; E->LI = 0; E->ParamLI = 0; + E->ExpandStart = 1; /* set up detection of first call */ /* Mark the macro as expanding */ ++M->Expansions; @@ -703,9 +705,24 @@ ExpandParam: TokSet (Mac->Exp); if (ExpandMacros) { if (new_expand_line) { - StrBuf mac_line = MakeLineFromTokens (Mac->Exp); + /* Suppress unneeded lines if short expansion + ** the ExpandStart is used to ensure that + ** the invokation line itself isnt suppress + ** This is becuase we are always working a line behind + ** Lines we want to keep are upvoted so that this downvote + ** will not suppress them + */ + if (LineLast->FragList == 0 && ExpandMacros == 1 && !Mac->ExpandStart) { + LineCur->Output--; + } + Mac->ExpandStart = 0; + StrBuf mac_line = MakeLineFromTokens (Mac->Exp); NewListingLine (&mac_line, 0, 0); InitListingLine (); + if (CurTok.Tok == TOK_SEGMENT) { + /* upvote the lines to keep*/ + LineCur->Output = 2; + } SB_Done (&mac_line); new_expand_line = 0; } @@ -809,6 +826,7 @@ MacEnd: PopInput (); /* No token available */ + new_expand_line = 1; return 0; } @@ -1080,8 +1098,7 @@ void EnableDefineStyleMacros (void) PRECONDITION (DisableDefines > 0); --DisableDefines; } - -static StrBuf MakeLineFromTokens (TokNode* first) +StrBuf MakeLineFromTokens (TokNode* first) { /* This code reconstitutes a Macro line from the 'compiled' tokens*/ unsigned I; @@ -1115,7 +1132,7 @@ static StrBuf MakeLineFromTokens (TokNode* first) SB_AppendStr (&T, ival); } else if ((token_string = GetTokenString (token)) != NULL) { SB_AppendStr (&T, token_string); - } + } SB_Append (&S, &T); if (token->Tok == TOK_SEP) { return S; diff --git a/src/ca65/macro.h b/src/ca65/macro.h index 7f4335706..a1ed455f8 100644 --- a/src/ca65/macro.h +++ b/src/ca65/macro.h @@ -36,7 +36,7 @@ #ifndef MACRO_H #define MACRO_H - +#include "toklist.h" /*****************************************************************************/ /* Forwards */ @@ -105,7 +105,7 @@ void EnableDefineStyleMacros (void); ** DisableDefineStyleMacros. */ - +StrBuf MakeLineFromTokens (TokNode* first); /* End of macro.h */ diff --git a/src/ca65/main.c b/src/ca65/main.c index bbb82736f..a86110269 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -674,9 +674,13 @@ static void OptWarningsAsErrors (const char* Opt attribute ((unused)), static void OptExpandMacros (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) - /* Exapnd macros in listing */ + /* Expand macros in listing + ** one -m means short listing + ** two means full listing + */ { - ExpandMacros = 1; + + ExpandMacros++; } static void DoPCAssign (void) @@ -895,6 +899,7 @@ static void Assemble (void) while (CurTok.Tok != TOK_EOF) { OneLine (); } + } @@ -1080,7 +1085,7 @@ int main (int argc, char* argv []) WarnLevel = atoi (GetArg (&I, 2)); break; case 'x': - ExpandMacros = 1; + ExpandMacros++; break; diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index 16efd24df..7fd8cfcd3 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -46,7 +46,9 @@ #include "nexttok.h" #include "scanner.h" #include "toklist.h" - +#include "macro.h" +#include "listing.h" +#include "global.h" /*****************************************************************************/ @@ -248,6 +250,26 @@ static int ReplayTokList (void* List) } L->LI = StartLine (&CurTok.Pos, LI_TYPE_ASM, PushCounter); + /* see description in macro.c */ + static int new_expand_line = 1; + if (ExpandMacros) { + if (new_expand_line) { + if (LineLast->FragList == 0 && ExpandMacros==1) { + LineCur->Output--; + } + StrBuf mac_line = MakeLineFromTokens (L->Last); + if (L->Last->T.Tok == TOK_SEGMENT) { + LineCur->Output = 2; + } + NewListingLine (&mac_line, 0, 0); + InitListingLine (); + SB_Done (&mac_line); + new_expand_line = 0; + } + if (L->Last->T.Tok == TOK_SEP) { + new_expand_line = 1; + } + } /* If a check function is defined, call it, so it may look at the token ** just set and changed it as apropriate. */ From b527549dd2150d706fc1818875a740268bddf03e Mon Sep 17 00:00:00 2001 From: paul moore Date: Sun, 3 Dec 2023 13:19:42 -0800 Subject: [PATCH 6/8] fix spaces at end of line --- src/ca65/macro.c | 2 +- src/ca65/main.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 9d8499388..81fcdae2b 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -1132,7 +1132,7 @@ StrBuf MakeLineFromTokens (TokNode* first) SB_AppendStr (&T, ival); } else if ((token_string = GetTokenString (token)) != NULL) { SB_AppendStr (&T, token_string); - } + } SB_Append (&S, &T); if (token->Tok == TOK_SEP) { return S; diff --git a/src/ca65/main.c b/src/ca65/main.c index a86110269..5db880012 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -676,7 +676,7 @@ static void OptExpandMacros (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Expand macros in listing ** one -m means short listing - ** two means full listing + ** two means full listing */ { @@ -709,7 +709,6 @@ static void OneLine (void) ** and not from internally pushed input */ - if (!HavePushedInput () ) { InitListingLine (); } @@ -899,7 +898,7 @@ static void Assemble (void) while (CurTok.Tok != TOK_EOF) { OneLine (); } - + } From ac6d43adc91b8647fb25967665173b1b2ab1b6ea Mon Sep 17 00:00:00 2001 From: paul moore Date: Sun, 3 Dec 2023 15:27:49 -0800 Subject: [PATCH 7/8] fix option name --- src/ca65/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ca65/main.c b/src/ca65/main.c index 5db880012..0b8adab2e 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -131,7 +131,7 @@ static void Usage (void) " --target sys\t\t\tSet the target system\n" " --verbose\t\t\tIncrease verbosity\n" " --version\t\t\tPrint the assembler version\n" - " --expand_macros\t\tExpand macros in the listing\n", + " --expand-macros\t\tExpand macros in the listing\n", ProgName); } @@ -975,7 +975,7 @@ int main (int argc, char* argv []) { "--verbose", 0, OptVerbose }, { "--version", 0, OptVersion }, { "--warnings-as-errors", 0, OptWarningsAsErrors }, - { "--expand_macros", 0, OptExpandMacros }, + { "--expand-macros", 0, OptExpandMacros }, }; /* Name of the global name space */ From eb2acfc3e4849ecfb5624d8ff42cb047ce29df56 Mon Sep 17 00:00:00 2001 From: paul moore Date: Mon, 18 Mar 2024 15:58:00 -0700 Subject: [PATCH 8/8] move options, add doc --- doc/ca65.sgml | 4 ++++ src/ca65/main.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index b0ccf6f5e..5789a7b42 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -94,6 +94,8 @@ Short options: -W n Set warning level n -d Debug mode -g Add debug info to object file + -x Expand macros in the listing + repeat -x for full expansion -h Help (this text) -i Ignore case of symbols -l name Create a listing file if assembly was ok @@ -111,6 +113,8 @@ Long options: --create-full-dep name Create a full make dependency file --debug Debug mode --debug-info Add debug info to object file + --expand-macros Expand macros in listing + Repeat to get full expansion --feature name Set an emulation feature --help Help (this text) --ignore-case Ignore case of symbols diff --git a/src/ca65/main.c b/src/ca65/main.c index 0b8adab2e..a313bb9c1 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -117,6 +117,7 @@ static void Usage (void) " --create-full-dep name\tCreate a full make dependency file\n" " --debug\t\t\tDebug mode\n" " --debug-info\t\t\tAdd debug info to object file\n" + " --expand-macros\t\tExpand macros in the listing\n" " --feature name\t\tSet an emulation feature\n" " --help\t\t\tHelp (this text)\n" " --ignore-case\t\t\tIgnore case of symbols\n" @@ -130,8 +131,7 @@ static void Usage (void) " --smart\t\t\tEnable smart mode\n" " --target sys\t\t\tSet the target system\n" " --verbose\t\t\tIncrease verbosity\n" - " --version\t\t\tPrint the assembler version\n" - " --expand-macros\t\tExpand macros in the listing\n", + " --version\t\t\tPrint the assembler version\n", ProgName); } @@ -675,7 +675,7 @@ static void OptWarningsAsErrors (const char* Opt attribute ((unused)), static void OptExpandMacros (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Expand macros in listing - ** one -m means short listing + ** one -x means short listing ** two means full listing */ { @@ -960,6 +960,7 @@ int main (int argc, char* argv []) { "--create-full-dep", 1, OptCreateFullDep }, { "--debug", 0, OptDebug }, { "--debug-info", 0, OptDebugInfo }, + { "--expand-macros", 0, OptExpandMacros }, { "--feature", 1, OptFeature }, { "--help", 0, OptHelp }, { "--ignore-case", 0, OptIgnoreCase }, @@ -975,7 +976,6 @@ int main (int argc, char* argv []) { "--verbose", 0, OptVerbose }, { "--version", 0, OptVersion }, { "--warnings-as-errors", 0, OptWarningsAsErrors }, - { "--expand-macros", 0, OptExpandMacros }, }; /* Name of the global name space */