Support pre-processor macros and includes #406
+195
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello! I've been trying to express CPU-feature guards with avo, using the new microarchitecture level groups. Here's an example from the Go standard library:
https://github.com/golang/go/blob/f79c99fe8ae4a5e4380af22ee6cb38c3eb3a0416/src/internal/bytealg/compare_amd64.s#L48-L54
As far as I can tell, the main thing missing from Avo to achieve this today is the ability to emit calls pre-processor macros (
#ifndef
,#else
, etc.) The other missing piece is to provide custom includes to the file to use the constants referenced in these macros, so I also added a helper for that.I'm submitting this PR as a concrete basis to discuss achieving this capability. I'm sorry if I missed something, and this is already possible!
Other options I've considered:
Allow emitting arbitrary text. A function like
RAW("#ifndef hasAVX2")
would create a literal IR node which would be printed as-is. This felt too low-level compared to the rest of Avo. However, it would be nice to have this escape hatch.Another option was to narrow the problem to this specific macro:
#ifndef CPU feature
. For example (fictitious Avo code):It would provide a higher level abstraction, and avoid exposing includes. I think it would add too much complexity to Avo to validate the control flow of those expressions.