You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This is GCC plugin, made to eliminate cost for parsing printf-like format strings in runtime by doing this at compile time.It uses GCC plugin API to walk through gimple tree, get format-string value and insert calls to specifiedto plugin functions instead of printf-alike. Note:this can be done only to constant format-stringparameters.
So, the idea is to change the function calls like this:
This will speed up the runtime by eliminating needless parsing of format string.All is done by GCC plugin during compilation.One should specify printf-alike functionprint_on_level andprint_str_level,print_int_levelas a plugin parameters.
TL;DR
To use this GCC compiler plugin, you need compile it with:
make
Then change your makefile so GCC will use plugin like this:
Whereprintf(0) means that format string is the first parameter.If you provide function likefprintf(1) which has some (one) parameters before format string,they will be passed to handlers in the same order.
Handlers:putchar function for%c specifier and so on.Note, specifier may be any length, ending with space symbol. I.e.,%h$up is a valid specifierh$up.
Reserved specifiers
For some user-defined functionfoo(arg1, arg2, const char *fmt, ...) cprintfplugin expects that following specifiers have their special meaning ifhandler-functions have been specified in plugin args:
%s is for strings (const char*). Cprintf will use it to output parts offormat string between specifiers; Function prototype in example:bar(arg1, arg2, const char *str);
%c is for chars (const char). Cprintf will use it to output single charsfrom format string; Function prototype in example:baz(arg1, arg2, const char s);
%% special meaning for raw string output; Function prototype in example:quux(arg1, arg2, void *ptr, size_t size, size_t nmemb);
Tip: consider using%% specifier asfwrite() function as it willgive great performance enhance.
About
Compile-time printf-like function's format string parsing