24.09.2020 03:18, Eric Blake wrote:
On 9/15/20 11:44 AM, Vladimir Sementsov-Ogievskiy wrote:
We have a very frequent pattern of creating coroutine from function
with several arguments:
+++ b/scripts/block-coroutine-wrapper.py
@@ -0,0 +1,187 @@
+#!/usr/bin/env python3
+"""Generate coroutine wrappers for block subsystem.
Looking at the generated file after patch 5 is applied,...
+
+def gen_header():
+ copyright = re.sub('^.*Copyright', 'Copyright', __doc__, flags=re.DOTALL)
+ copyright = re.sub('^(?=.)', ' * ', copyright.strip(), flags=re.MULTILINE)
+ copyright = re.sub('^$', ' *', copyright, flags=re.MULTILINE)
+ return f"""\
This generated comment...
+
+
+def gen_wrappers_file(input_code: str) -> str:
+ res = gen_header()
...is getting inserted into the generated file...
+ for func in func_decl_iter(input_code):
+ res += '\n\n\n'
+ res += gen_wrapper(func)
+
+ return prettify(res) # prettify to wrap long lines
+
+
+if __name__ == '__main__':
+ if len(sys.argv) < 3:
+ exit(f'Usage: {sys.argv[0]} OUT_FILE.c IN_FILE.[ch]...')
+
+ with open(sys.argv[1], 'w') as f_out:
+ for fname in sys.argv[2:]:
+ with open(fname) as f_in:
+ f_out.write(gen_wrappers_file(f_in.read()))
multiple times. You'll want to hoist the call to gen_header outside the loop
over fname in sys.argv[2:].
Right, thanks for fixing. I missed it when rebasing on meson system (and move
to calling gen_wrappers_file() several times). Hmm, gen_wrappers_file() is now
a bit misleading name, it would better be just gen_wrappers()
--
Best regards,
Vladimir