summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-15 19:54:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-15 19:54:42 -0700
commita1db2093ff49bceb3dfbe6e6a040ec8dc15e5204 (patch)
tree9ffb9b9cb712c1f50c10323df867ae25120a6ce1
parent28ef3e078ee2081b92f169fc29d97bbee600eece (diff)
downloadtxr-a1db2093ff49bceb3dfbe6e6a040ec8dc15e5204.tar.gz
txr-a1db2093ff49bceb3dfbe6e6a040ec8dc15e5204.tar.bz2
txr-a1db2093ff49bceb3dfbe6e6a040ec8dc15e5204.zip
protsym: don't refer to symbols excluded by config.
The protsym.c generated file refers to symbol variables without regard for whether they actually exist. Some symbol variables are defined in source files whose object files are only linked in conditionally. * genprotsym.txr: Update the logic to scan the Makefile to determine which files are conditionally included, based on what makefile flag, which is related to a preprocessor symbol. Thus, with some hashes, for each symbolic variable we subsequently scan, we know whether it came from a file that is associated with a preprocessor symbol. We group the emitted material accordingly, placing the conditionally existent symbols into #if...#endif blocks.
-rw-r--r--genprotsym.txr40
1 files changed, 34 insertions, 6 deletions
diff --git a/genprotsym.txr b/genprotsym.txr
index 7d9f8c2a..b343ce04 100644
--- a/genprotsym.txr
+++ b/genprotsym.txr
@@ -1,6 +1,24 @@
-@(next (open-files (glob "*.c")))
-@(collect :vars (sym))
-val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(end)
+@(bind prepro-sym @(hash :equal-based))
+@(bind file-of @(hash :equal-based))
+@(next "Makefile")
+@(repeat)
+@ (cases)
+OBJS-$(have_@sym) += @file.o
+@ (bind ppsym @(upcase-str `HAVE_@sym`))
+@ (or)
+OBJS-$(@sym) += @file.o
+@ (bind ppsym @(upcase-str `CONFIG_@sym`))
+@ (end)
+@ (do (set [prepro-sym `@file.c`] ppsym))
+@(end)
+@(next :list (glob "*.c"))
+@(collect)
+@file
+@ (next file)
+@ (collect :vars ((sym nil)))
+val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(do (set [file-of sym] file))@(end)
+@ (end)
+@ (flatten sym)
@(end)
@(next "lib.c")
@(collect)
@@ -9,7 +27,9 @@ val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(end)
@(end)
@(flatten sym)
-@(bind gsym @(tuples 5 (sort sym)))
+@(bind pp-groups @[group-by [chain file-of prepro-sym] sym])
+@(bind gsym @[mapcar (opip sort (tuples 5)) (hash-values pp-groups)])
+@(bind gpp @(hash-keys pp-groups))
@(output "protsym.c")
/* This file is generated by genprotsym.txr */
@@ -19,13 +39,21 @@ val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(end)
#include "config.h"
#include "lib.h"
-@ (repeat)
+@ (repeat :vars (gpp))
+@ (if gpp `#if @gpp`)
+@ (repeat)
extern val @(rep)@gsym, @(last)@gsym;@(end)
+@ (end)
+@ (if gpp "#endif")
@ (end)
val *protected_sym[] = {
-@ (repeat)
+@ (repeat :vars (gpp))
+@ (if gpp `#if @gpp`)
+@ (repeat)
@(rep)&@gsym, @(last)&@gsym,@(end)
+@ (end)
+@ (if gpp "#endif")
@ (end)
convert(val *, 0)
};