Add Printer hook enabling custom user defined file output like -stubs
This PR contains a minimal feature set implementing a general hook enabling user defined solutions for:
- Cpu feature-checks and runtime dispatch helpers (ie. #168)
- Test generation
- Documentation generation
- Etc...
In a nutshell this PR does two things:
- Defines a new global function
AddPrinter, which allows the user to define a new command line flag/description, and define a Builder to handle file generation.
// AddPrinter registers a custom printer
func AddPrinter(flag, desc string, pB printer.Builder, dflt io.WriteCloser)
- In support of the above, lifts the former
avo/internal/prntpackage to the new externally exportedavo/printerpackage. All former internal references toprntnow useprinterinstead andinternal/prntis eliminated.
That's it! I've been using this on my fork for PureGo+CPUID Dispatch and Test generation (driven by text/template) for many months, and it has met all of my needs. Here's what setting that up looks like:
pureGoGen := configurePureGoGeneration(variants, bitWidths, queryWidths, precisions, codeGenerated)
avo.AddPrinter("purego", "produce file of golang implementations", pureGoGen, nil)
testGen := configureTestGeneration(variants, bitWidths, queryWidths, codeGenerated)
avo.AddPrinter("tests", "produce file of tests", testGen, nil)
avo.Generate()
The "Generation" functions use the newly exported avo/printer sub-package to set up the generation code just the way my project needs, and that's it!
This is the last PR (in conjunction with #234 and #233) that I need to stop maintaining my own Avo fork. I don't currently require the functionality in #349, but I decided to just do it as a bonus while I had all of the opcodesextra state mentally loaded up.
Enjoy! And I'm happy to discuss and implement any further suggestions. My goal here was to be minimally disruptive to Avo while providing maximum flexibility to advanced users who need more code generation flexibility.
It's not immediately obvious to me what ci / lint is complaining about in the failed test above, but I'll look into it before next week.
Codecov Report
Merging #350 (12d6fc4) into master (fc7bbb8) will decrease coverage by
0.02%. The diff coverage is0.00%.
:exclamation: Current head 12d6fc4 differs from pull request most recent head a836dd9. Consider uploading reports for the commit a836dd9 to get more accurate results
:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more
@@ Coverage Diff @@
## master #350 +/- ##
==========================================
- Coverage 77.82% 77.81% -0.02%
==========================================
Files 99 99
Lines 23728 23732 +4
==========================================
Hits 18467 18467
- Misses 5169 5173 +4
Partials 92 92
| Flag | Coverage Δ | |
|---|---|---|
| integration | 22.04% <0.00%> (-0.01%) |
:arrow_down: |
| unittests | 72.79% <0.00%> (-0.07%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| build/global.go | 79.03% <0.00%> (-5.46%) |
:arrow_down: |
| internal/gen/asmtest.go | 0.00% <ø> (ø) |
|
| internal/gen/build.go | 0.00% <ø> (ø) |
|
| internal/gen/buildtest.go | 0.00% <ø> (ø) |
|
| internal/gen/ctors.go | 0.00% <ø> (ø) |
|
| internal/gen/ctorstest.go | 0.00% <ø> (ø) |
|
| internal/gen/godata.go | 0.00% <ø> (ø) |
|
| internal/gen/mov.go | 0.00% <ø> (ø) |
|
| internal/gen/optab.go | 0.00% <ø> (ø) |
|
| internal/gen/testing.go | 0.00% <0.00%> (ø) |
|
| ... and 3 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.