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

Add #define logic #180

Open
Lutymane opened this issue Dec 28, 2022 · 3 comments · Fixed by #259
Open

Add #define logic #180

Lutymane opened this issue Dec 28, 2022 · 3 comments · Fixed by #259

Comments

@Lutymane
Copy link

Hello,

The minifier doesn't consider #define/#undef and doesn't optimize #if blocks

Example input:

#define MUT_0
#undef MUT_1

float f(){
  float r = 1.;

  #ifdef MUT_0
    r = mut0(r);
  #endif

  #ifdef MUT_1
    r = mut1(r);
  #endif

  return r;
}

1.3.1 gives:

#define MUT_0
#undef MUT_1
float M(){float M=1.;
#ifdef MUT_0
M=mut0(M);
#endif

#ifdef MUT_1
M=mut1(M);
#endif
return M;}

So it would make sense to preserve #if blocks only if there are no corresponding #define/#undef statements and process them if they are present

@laurentlb
Copy link
Owner

Thanks for the idea, that would be nice to have, indeed.

laurentlb added a commit that referenced this issue Mar 20, 2023
- Fix issue with spaces / newline confusion
- Use an enum for better readability
- Remove unused code
- Better handling of macro functions
- Skip unknown directives when the status is inactive

#180
laurentlb added a commit that referenced this issue Mar 21, 2023
laurentlb added a commit that referenced this issue Mar 22, 2023
@Lutymane
Copy link
Author

Lutymane commented Apr 2, 2023

@laurentlb Thank you! Also would it be possible to specify defines as arguments (to skip having #defines in code)? Like so -d SOME_DEF -d DEF_WITH_VALUE=1

@laurentlb
Copy link
Owner

Yeah, that would make sense.

@laurentlb laurentlb reopened this Apr 2, 2023
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 a pull request may close this issue.

2 participants