Skip to content

Conversation

@vsivsi
Copy link
Contributor

@vsivsi vsivsi commented Dec 16, 2022

This PR contains a minimal feature set implementing a general hook enabling user defined solutions for:

In a nutshell this PR does two things:

  1. 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)
  1. In support of the above, lifts the former avo/internal/prnt package to the new externally exported avo/printer package. All former internal references to prnt now use printer instead and internal/prnt is 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.

@vsivsi
Copy link
Contributor Author

vsivsi commented Dec 16, 2022

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-commenter
Copy link

Codecov Report

Merging #350 (12d6fc4) into master (fc7bbb8) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

❗ Current head 12d6fc4 differs from pull request most recent head a836dd9. Consider uploading reports for the commit a836dd9 to get more accurate results

📣 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%) ⬇️
unittests 72.79% <0.00%> (-0.07%) ⬇️

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%) ⬇️
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.

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