aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-09-14 06:34:51 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-11-12 10:11:48 +0100
commita5f0d96243ac8597e46c6713cbafb197a1b7d35c (patch)
tree98f4f31855cfc0eff7fdef6a61471561cd81b038
parente7a9d67e1834758a9a5f6e3ce9b497cf32a52674 (diff)
downloadsparse-dev-a5f0d96243ac8597e46c6713cbafb197a1b7d35c.tar.gz
dump-ir: allow to specify the passes to execute via cli's options
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--Documentation/options.md18
-rwxr-xr-xcgcc1
-rw-r--r--lib.c34
-rw-r--r--lib.h1
4 files changed, 54 insertions, 0 deletions
diff --git a/Documentation/options.md b/Documentation/options.md
new file mode 100644
index 00000000..5677789e
--- /dev/null
+++ b/Documentation/options.md
@@ -0,0 +1,18 @@
+# Options
+
+This file is a complement of man page for sparse but meant
+for options not to be used by sparse itself but by the other
+tools.
+
+## Developer options:
+
+### Select the passes
+
+* '-f\<name-of-the-pass\>[-disable|-enable|=last]'
+
+ If '=last' is used, all passes after the specified one are disabled.
+ By default all passes are enabled.
+
+ The passes currently understood are:
+ * 'mem2reg'
+ * 'optim'
diff --git a/cgcc b/cgcc
index a8d7b4f2..75eee26f 100755
--- a/cgcc
+++ b/cgcc
@@ -104,6 +104,7 @@ sub check_only_option {
return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
return 1 if $arg =~ /^-f(dump-linearize|memcpy-max-count)(=\S*)?$/;
+ return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/;
return 0;
}
diff --git a/lib.c b/lib.c
index a03a94d6..a714dc2b 100644
--- a/lib.c
+++ b/lib.c
@@ -260,6 +260,7 @@ int dbg_dead = 0;
int fmem_report = 0;
int fdump_linearize;
unsigned long long fmemcpy_max_count = 100000;
+unsigned long fpasses = ~0UL;
int preprocess_only;
@@ -760,6 +761,37 @@ static int handle_ftabstop(const char *arg, const char *opt, const struct flag *
return 1;
}
+static int handle_fpasses(const char *arg, const char *opt, const struct flag *flag, int options)
+{
+ unsigned long mask;
+
+ mask = flag->mask;
+ if (*opt == '\0') {
+ if (options & OPT_INVERSE)
+ fpasses &= ~mask;
+ else
+ fpasses |= mask;
+ return 1;
+ }
+ if (options & OPT_INVERSE)
+ return 0;
+ if (!strcmp(opt, "-enable")) {
+ fpasses |= mask;
+ return 1;
+ }
+ if (!strcmp(opt, "-disable")) {
+ fpasses &= ~mask;
+ return 1;
+ }
+ if (!strcmp(opt, "=last")) {
+ // clear everything above
+ mask |= mask - 1;
+ fpasses &= mask;
+ return 1;
+ }
+ return 0;
+}
+
static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options)
{
if (*opt == '\0')
@@ -783,6 +815,8 @@ static struct flag fflags[] = {
{ "mem-report", &fmem_report },
{ "memcpy-max-count=", NULL, handle_fmemcpy_max_count },
{ "tabstop=", NULL, handle_ftabstop },
+ { "mem2reg", NULL, handle_fpasses, PASS_MEM2REG },
+ { "optim", NULL, handle_fpasses, PASS_OPTIM },
{ },
};
diff --git a/lib.h b/lib.h
index 27c99025..5111a0eb 100644
--- a/lib.h
+++ b/lib.h
@@ -169,6 +169,7 @@ extern int dbg_dead;
extern int fmem_report;
extern int fdump_linearize;
extern unsigned long long fmemcpy_max_count;
+extern unsigned long fpasses;
extern int arch_m64;
extern int arch_msize_long;