Skip to content
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

Conditional compilation of structures #136

Open
specke opened this issue Mar 7, 2021 · 2 comments
Open

Conditional compilation of structures #136

specke opened this issue Mar 7, 2021 · 2 comments
Milestone

Comments

@specke
Copy link

specke commented Mar 7, 2021

Is your feature request related to a problem?

Currently, sjasmplus does not seem to support commands for conditional compilation (e.g. IF/ENDIF) inside of STRUCT. However, I have seen on several occasions now that it would be a nice way to adapt data structures to changes in the setup due to user-specified configuration defined via a selection of definitions in the header. Because of this limitation I end up having to

  IFDEF AddField3
    STRUCT DATA
Field1  DB 0
Field2  DW 0
Field3 DB 0
    ENDS
  ELSE
    STRUCT DATA
Field1  DB 0
Field2  DW 0
    ENDS
  ENDIF

instead of simply saying

  STRUCT DATA
Field1  DB 0
Field2  DW 0
    IFDEF AddField3
Field3 DB 0
    ENDIF
  ENDS

The issue is not even to do with the fact that we end up with more lines of code, but more to do with the fact that we have to copy and edit separately two identical copies of essentially the same code.

Describe the suggested solution:

It would be nice to be able to use IF/ELSE/ENDIF (as well as other conditional compilation commands) inside of STRUCT/ENDS.

@ped7g
Copy link
Collaborator

ped7g commented Jul 21, 2021

workaround-proposal: you can substitute whole line of the struct definition through DEFINE, ie.:

  DEFINE OPT_FIELD3 Field3 DB 0

  STRUCT DATA
Field1  DB 0
Field2  DW 0
OPT_FIELD3
Field4  DB 1
  ENDS
  ASSERT 5 == DATA  ; DATA is 5 bytes in total

  ; redefine OPT_FIELD3 to empty define
  DEFINE+ OPT_FIELD3

  STRUCT DATA2
Field1  DB 2
Field2  DW 3
OPT_FIELD3
Field4  DB 4
  ENDS
  ASSERT 4 == DATA2 ; DATA2 is 4 bytes in total

  DATA  {0,1,2,3}
  DATA2 {4,5,6}

I still like the idea of conditionals working inside struct def, but not going to try to bend current parser for it, the current architecture would either need quite some duplicity of code to parse it, or refactoring the architecture first to parse source a bit differently, so marking this as "v2.x" proposal.

@ped7g ped7g added this to the v2.x milestone Jul 21, 2021
@ped7g
Copy link
Collaborator

ped7g commented Jul 21, 2021

workaround applied to your initial example:

  IFDEF AddField3
    DEFINE OPT_FIELD3 Field3 DB 0
  ELSE
    DEFINE OPT_FIELD3
  ENDIF

  STRUCT DATA
Field1  DB 0
Field2  DW 0
OPT_FIELD3
  ENDS

Still a bit spaghetti-taste, but seems practical enough to me (especially compared to rewriting sjasmplus parser from scratch :) )

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

No branches or pull requests

2 participants