Skip to content

Add a special #ifdef for decomp.me convenience#296

Merged
simonlindholm merged 4 commits into
matt-kempster:masterfrom
thefoxcam:ifdef
Aug 14, 2025
Merged

Add a special #ifdef for decomp.me convenience#296
simonlindholm merged 4 commits into
matt-kempster:masterfrom
thefoxcam:ifdef

Conversation

@thefoxcam

Copy link
Copy Markdown
Contributor

This addresses a longstanding issue particularly affecting users trying to match Melee code on the m2c + decomp.me setup, where it's desirable to have the same context file able to both provide the correct type to m2c for the user_data of our custom *_GObj structs, as well as typedef the *_GObj structs back to HSD_GObj. Since it's undesirable to run a C preprocessor in m2c, a regular expression is used that mimics the functionality of an #ifdef, but only specific expressions are allowed to be used with it. Currently the only expression supported is hardcoded to be M2CTX_DUAL. Use of any other expression will raise a Directives not supported yet error like it currently does. The #ifdef also must contain an #else clause. For instance:

#ifdef M2CTX_DUAL
typedef struct Fighter_GObj Fighter_GObj;
struct Fighter_GObj {
    /* +2C */ Fighter* user_data;
};
#else
typedef struct HSD_GObj Fighter_GObj;
#endif

If this kind of functionality is acceptable, I can write documentation for it, as other games may find this useful as well.

@simonlindholm

Copy link
Copy Markdown
Collaborator

This sounds like a nice idea to me! Can we let the macro name be just M2C maybe?

I am thinking of just running the preprocessor for real, but haven't yet looked into what options exist for e.g. disallowing includes, and it might take a little bit until I get time to look. Merging this in the meantime sounds like a good plan.

@thefoxcam

Copy link
Copy Markdown
Contributor Author

Yeah, sure. I'm a bit hesitant to make the name look like a "real" macro since you can only use it in this specific pattern, but since Melee will likely only be using it until a full preprocessor gets implemented and it'll get changed anyways, I'll change it.

Here's some information on preprocessors (which also was discussed recently in the Melee decomp channel):

  • The command-line tool for pcpp supports ignoring includes with --passthru-includes <regex>. For more control/speed the library also allows you to subclass the Preprocessor class directly, which I did in the Melee context builder to produce a context file that only contains the allowed macro. This is basically a compressed vesrion of the pcpp CLI code, found here.

  • When you do implement the full preprocessor it would be nice if the macro was defined by default either in m2c itself or decomp.me, since there's no way to adjust m2c flags from the decomp.me UI currently. Someone was working on a PR for that a few months ago, but it seems to be stalled.

Comment thread README.md Outdated
@simonlindholm simonlindholm merged commit 6983af4 into matt-kempster:master Aug 14, 2025
@simonlindholm

Copy link
Copy Markdown
Collaborator

Oh, pcpp looks neat! Thanks for the pointer. For sure I'll pre-define the same macro when integrating preprocessor support.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants