8000 Expand macros in listing by pm100 · Pull Request #2279 · cc65/cc65 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Expand macros in listing #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Expand macros in listing #2279

wants to merge 9 commits into from

Conversation

pm100
Copy link
Contributor
@pm100 pm100 commented Dec 2, 2023

This code expands macros in the listing. This is extremely useful for macros that include segment switches (its what made me do this) but is also generally useful.

adds command line switches

  • -x
  • --expand_ 8000 macros

It does not try to save to macro source code, instead the macro is 'disassembled' when it is expanded. This was, I felt, less invasive on the internal data structures. This does mean that the expansion is not 100% like the input but is certainly sufficient to work out what line generated what code, and importantly what segment it went into.

Here is sample from msbasic.s (from https://github.com/mist64/msbasic) with and without expansion, it target 3 different segments

without

000000r 2  rr rr 45 4E  		keyword_rts "END", END
000004r 2  C4 xx 

with expansion

000000r 2               		keyword_rts "END", END
000000r 0               >  .SEGMENT VECTORS
000000r 0  rr rr        >  .WORD vec-1
000002r 0               >  keyword key, token
000002r 0               >>  .SEGMENT KEYWORDS
000000r 0               >>  htasc key
000000r 0               >>>  .REPEAT .STRLEN(str)-1,I
000000r 0               >>>  .BYTE .STRAT(str,I)
000001r 0  45 4E        >>>  .ENDREP
000002r 0  C4           >>>  .BYTE .STRAT(str,.STRLEN(str)-1) | 128
000003r 0               >>  define_token token
000003r 0               >>>  .SEGMENT DUMMY
000000r 0               >>>  .IFNBLANK token
000000r 0               >>>  token := <(*-DUMMY_START)+128
000000r 0               >>>  .ENDIF
000000r 0  xx           >>>  .RES 1

these macros are nested 3 deep (thats what the > characters show)

@spiro-trikaliotis
Copy link

But you see the disadvantage?

000000r 0               >>>  .REPEAT .STRLEN(str)-1,I
000000r 0               >>>  .BYTE .STRAT(str,I)
000001r 0  45 4E        >>>  .ENDREP

The bytes are emmited in the line with .BYTE, not with the .ENDREP. Note also that the address at the beginning has already progressed (to 000001r), and thus, it is wrong for this line.

If you have more than a simple .BYTE in .REPEAT .ENDREP (think of segment changes!), it will not work, either.

@pm100
Copy link
Contributor Author
pm100 commented Dec 2, 2023

@spiro-trikaliotis - ty for pointing this out. I will fix it

8000

@pm100 pm100 closed this Dec 2, 2023
@pm100
Copy link
Contributor Author
pm100 commented Dec 3, 2023

A big rework of original PR - thanks to @spiro-trikaliotis for pointing out deficiencies.

Now 2 modes of macro expansion , short and long.

  • -x is short, only shows code generating lines and .segment statements
  • -x -x is long, shows full expansion

Samples from msbasic (nested 3 deep, with repeats, and segment switches)

Original output

000000r 2  rr rr 45 4E  		keyword_rts "END", END
000004r 2  C4 xx   

Short expansion. With code lines, segments statements and the macro invocation lines

000000r 2               		keyword_rts "END", END
000000r 0               >  .SEGMENT VECTORS
000000r 0  rr rr        >  .WORD vec-1
000002r 0               >  keyword key, token
000002r 0               >>  .SEGMENT KEYWORDS
000000r 0               >>  htasc key
000000r 0  45           >>>>  .BYTE .STRAT( END,I)
000001r 0  4E           >>>>  .BYTE .STRAT( END,I)
000002r 0  C4           >>>  .BYTE .STRAT(str,.STRLEN(str)-1) | 128
000003r 0               >>  define_token token
000003r 0               >>>  .SEGMENT DUMMY
000000r 0  xx           >>>  .RES 1

Full expansion

000000r 2               		keyword_rts "END", END
000000r 0               >  .SEGMENT VECTORS
000000r 0  rr rr        >  .WORD vec-1
000002r 0               >  keyword key, token
000002r 0               >>  .SEGMENT KEYWORDS
000000r 0               >>  htasc key
000000r 0               >>>  .REPEAT .STRLEN(str)-1,I
000000r 0               >>>  .BYTE .STRAT(str,I)
000000r 0               >>>  .ENDREP
000000r 0  45           >>>>  .BYTE .STRAT( END,I)
000001r 0  4E           >>>>  .BYTE .STRAT( END,I)
000002r 0  C4           >>>  .BYTE .STRAT(str,.STRLEN(str)-1) | 128
000003r 0               >>  define_token token
000003r 0               >>>  .SEGMENT DUMMY
000000r 0               >>>  .IFNBLANK token
000000r 0               >>>  token := <(*-DUMMY_START)+128
000000r 0               >>>  .ENDIF
000000r 0  xx           >>>  .RES 1

@pm100 pm100 reopened this Dec 3, 2023
@mrdudz
Copy link
Contributor
mrdudz commented Dec 3, 2023

Do we still see the non-expanded macro somewhere? Could you perhaps make it output the non expanded one before the first expansion or something like that?

Also, please use --expand-macros instead of --expand_macros

@pm100
Copy link
Contributor Author
pm100 commented Dec 3, 2023

@mrdudz - not sure what you mean. The macro definition is still output like before. Is that what you meant. This patch doesnt remove anything from the listing, only adds stuff

Will fix the long option name

@mrdudz
Copy link
Contributor
mrdudz commented Dec 3, 2023

I see, sorry - i thought for a moment that the above excerpt is a complete listing

@mrdudz
Copy link
Contributor
mrdudz commented Jan 30, 2024

Why close this?

@mrdudz mrdudz reopened this Jan 30, 2024
@pm100
Copy link
Contributor Author
pm100 commented Jan 30, 2024

closed for the same reason as the macro one - certainly this one is better served by a different solution (I now know my way around the dbgfile output of the linker - it provides all the info I need, I am using it to do a huge upgrade of db65 ), and it just sat for 2 months, I dont like to leave PRs dangling

@mrdudz
Copy link
Contributor
mrdudz commented Jan 31, 2024

it just sat for 2 months, I don't like to leave PRs dangling

2 months is nothing really :) Especially when it comes to the assembler (compiler and library has priority) - i don't have a lot of time for these things, so please be patient - i will look at it at some point.

Obviously, if you have a better solution, then make a PR for that instead :)

@mrdudz
Copy link
Contributor
mrdudz commented Mar 17, 2024

The added options should also be added to the documentation.

@pm100
Copy link
Contributor Author
pm100 commented Mar 18, 2024

@mrdudz Not sure If i have fixed the sgml correctly. I dont know how to render it. Especially as I needed two lines

@dominicbeesley
Copy link

Upvote for this - do you need help with the SGML?

@pm100
Copy link
Contributor Author
pm100 commented Mar 28, 2024

@dominicbeesley - I just copied what was already there, but I do not know how to render the sgml to make sure that I did it right.

@dominicbeesley
Copy link

I think you just do a

make html

at the top level then check the ca65.html file.

D

@mrdudz
Copy link
Contributor
mrdudz commented Jun 27, 2025

diff looks ok to me, does it still work? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0