Skip to content

Commit

Permalink
Add a simple code generator
Browse files Browse the repository at this point in the history
Often we want to use macros to simplify writing boilerplate.
On one hand this is good as it avoid tedious, error-prone work.
OTOH it makes reading and debugging code harder when trying to simply
traverse complex code bases either with code indexers/taggers or even
just in debuggers that get often confused when the source code file does
not match the compiled code.

This simple generator allows to write macros to auto generate parts of
code and uses the compiler pre-processor to spit out actual readable
code that can be formatted by clang-format and committed to the tree.

Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Jan 5, 2023
1 parent 7f0b9ab commit 5a6d22d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Cpp11BracedListStyle: false
AlignArrayOfStructures: None
AlignTrailingComments: false
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakBeforeMultilineStrings: false
IndentGotoLabels: true
SortIncludes: Never
SpaceBeforeCpp11BracedList: true
Expand Down
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Files: **/Makefile.am
configure.ac
src/Makefile.am
src/provider.exports
src/*.gen.c
tests/Makefile.am
tests/README
tests/openssl.cnf.in
Expand Down
13 changes: 13 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ check-style-show:
check-style-fix:
git diff -U0 --no-color --relative origin/main | clang-format-diff -i -p1

generate-code:
for pfile in src/*.pre; do \
gfile=`echo $${pfile} | sed s/\.pre/\.gen\.c/`; \
echo "/* DO NOT EDIT, autogenerated from $${pfile} */" > "$${gfile}"; \
echo "/* Modify $${pfile} then run make generate-code */" >> "$${gfile}"; \
cat $${pfile} | $(CC) -E - | grep -v "^#" > "$${gfile}.tmp"; \
sed -i -n -e '/^BEGIN:$$/,$$p' "$${gfile}.tmp"; \
sed -i 's/^BEGIN:$$//' "$${gfile}.tmp"; \
cat "$${gfile}.tmp" >> $${gfile}; \
clang-format -i --verbose "$${gfile}"; \
rm "$${gfile}.tmp"; \
done

DISTCLEANFILES = \
*~

Expand Down

0 comments on commit 5a6d22d

Please sign in to comment.