[RFC PATCH 04/28] cli: lil: Remove most functions by default

Sean Anderson seanga2 at gmail.com
Thu Jul 1 08:15:47 CEST 2021


This helps reduce the size impact of LIL to approximately that of hush. The
builtin functions have been chosen to roughly match the functionality
present in hush. In addition, arithmetic is removed from expr to reduce
size further.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 cmd/Kconfig      | 10 ++++++
 common/cli_lil.c | 83 +++++++++++++++++++++++++++---------------------
 2 files changed, 57 insertions(+), 36 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 8bccc572af..0a7b73cb6d 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -32,6 +32,16 @@ config LIL
 	  like `proc name {args} {body}' functions or `echo [some command]`
 	  command substitution ("tcl scripts").
 
+if LIL
+
+config LIL_FULL
+	bool "Enable all LIL features"
+	help
+	  This enables all LIL builtin functions, as well as expression support
+	  for arithmetic and bitwise operations.
+
+endif
+
 config CMDLINE_EDITING
 	bool "Enable command line editing"
 	depends on CMDLINE
diff --git a/common/cli_lil.c b/common/cli_lil.c
index 294d79e86e..a2e5cdf35a 100644
--- a/common/cli_lil.c
+++ b/common/cli_lil.c
@@ -1321,7 +1321,7 @@ static void ee_unary(struct expreval *ee)
 static void ee_muldiv(struct expreval *ee)
 {
 	ee_unary(ee);
-	if (ee->error)
+	if (ee->error || !IS_ENABLED(CONFIG_LIL_FULL))
 		return;
 
 	ee_skip_spaces(ee);
@@ -1382,8 +1382,10 @@ static void ee_muldiv(struct expreval *ee)
 static void ee_addsub(struct expreval *ee)
 {
 	ee_muldiv(ee);
-	ee_skip_spaces(ee);
+	if (!IS_ENABLED(CONFIG_LIL_FULL))
+		return;
 
+	ee_skip_spaces(ee);
 	while (ee->head < ee->len && !ee->error &&
 	       !ee_invalidpunct(ee->code[ee->head + 1]) &&
 	       (ee->code[ee->head] == '+' || ee->code[ee->head] == '-')) {
@@ -1415,8 +1417,10 @@ static void ee_addsub(struct expreval *ee)
 static void ee_shift(struct expreval *ee)
 {
 	ee_addsub(ee);
-	ee_skip_spaces(ee);
+	if (!IS_ENABLED(CONFIG_LIL_FULL))
+		return;
 
+	ee_skip_spaces(ee);
 	while (ee->head < ee->len && !ee->error &&
 	       ((ee->code[ee->head] == '<' && ee->code[ee->head + 1] == '<') ||
 		(ee->code[ee->head] == '>' && ee->code[ee->head + 1] == '>'))) {
@@ -1545,8 +1549,10 @@ static void ee_equals(struct expreval *ee)
 static void ee_bitand(struct expreval *ee)
 {
 	ee_equals(ee);
-	ee_skip_spaces(ee);
+	if (!IS_ENABLED(CONFIG_LIL_FULL))
+		return;
 
+	ee_skip_spaces(ee);
 	while (ee->head < ee->len && !ee->error &&
 	       (ee->code[ee->head] == '&' &&
 		!ee_invalidpunct(ee->code[ee->head + 1]))) {
@@ -1566,8 +1572,10 @@ static void ee_bitand(struct expreval *ee)
 static void ee_bitor(struct expreval *ee)
 {
 	ee_bitand(ee);
-	ee_skip_spaces(ee);
+	if (!IS_ENABLED(CONFIG_LIL_FULL))
+		return;
 
+	ee_skip_spaces(ee);
 	while (ee->head < ee->len && !ee->error &&
 	       (ee->code[ee->head] == '|' &&
 		!ee_invalidpunct(ee->code[ee->head + 1]))) {
@@ -2932,49 +2940,52 @@ static struct lil_value *fnc_lmap(struct lil *lil, size_t argc,
 
 static void register_stdcmds(struct lil *lil)
 {
-	lil_register(lil, "append", fnc_append);
-	lil_register(lil, "char", fnc_char);
-	lil_register(lil, "charat", fnc_charat);
-	lil_register(lil, "codeat", fnc_codeat);
-	lil_register(lil, "concat", fnc_concat);
-	lil_register(lil, "count", fnc_count);
 	lil_register(lil, "dec", fnc_dec);
-	lil_register(lil, "downeval", fnc_downeval);
-	lil_register(lil, "error", fnc_error);
 	lil_register(lil, "eval", fnc_eval);
 	lil_register(lil, "expr", fnc_expr);
-	lil_register(lil, "filter", fnc_filter);
 	lil_register(lil, "for", fnc_for);
 	lil_register(lil, "foreach", fnc_foreach);
 	lil_register(lil, "func", fnc_func);
 	lil_register(lil, "if", fnc_if);
 	lil_register(lil, "inc", fnc_inc);
-	lil_register(lil, "index", fnc_index);
-	lil_register(lil, "indexof", fnc_indexof);
-	lil_register(lil, "length", fnc_length);
-	lil_register(lil, "list", fnc_list);
-	lil_register(lil, "lmap", fnc_lmap);
 	lil_register(lil, "local", fnc_local);
-	lil_register(lil, "ltrim", fnc_ltrim);
-	lil_register(lil, "quote", fnc_quote);
-	lil_register(lil, "reflect", fnc_reflect);
-	lil_register(lil, "rename", fnc_rename);
-	lil_register(lil, "repstr", fnc_repstr);
-	lil_register(lil, "result", fnc_result);
 	lil_register(lil, "return", fnc_return);
-	lil_register(lil, "rtrim", fnc_rtrim);
 	lil_register(lil, "set", fnc_set);
-	lil_register(lil, "slice", fnc_slice);
-	lil_register(lil, "split", fnc_split);
 	lil_register(lil, "strcmp", fnc_strcmp);
-	lil_register(lil, "streq", fnc_streq);
-	lil_register(lil, "strpos", fnc_strpos);
-	lil_register(lil, "subst", fnc_subst);
-	lil_register(lil, "substr", fnc_substr);
-	lil_register(lil, "topeval", fnc_topeval);
-	lil_register(lil, "trim", fnc_trim);
 	lil_register(lil, "try", fnc_try);
-	lil_register(lil, "unusedname", fnc_unusedname);
-	lil_register(lil, "upeval", fnc_upeval);
 	lil_register(lil, "while", fnc_while);
+
+	if (IS_ENABLED(CONFIG_LIL_FULL)) {
+		lil_register(lil, "append", fnc_append);
+		lil_register(lil, "char", fnc_char);
+		lil_register(lil, "charat", fnc_charat);
+		lil_register(lil, "codeat", fnc_codeat);
+		lil_register(lil, "concat", fnc_concat);
+		lil_register(lil, "count", fnc_count);
+		lil_register(lil, "downeval", fnc_downeval);
+		lil_register(lil, "error", fnc_error);
+		lil_register(lil, "filter", fnc_filter);
+		lil_register(lil, "index", fnc_index);
+		lil_register(lil, "indexof", fnc_indexof);
+		lil_register(lil, "length", fnc_length);
+		lil_register(lil, "list", fnc_list);
+		lil_register(lil, "lmap", fnc_lmap);
+		lil_register(lil, "ltrim", fnc_ltrim);
+		lil_register(lil, "quote", fnc_quote);
+		lil_register(lil, "reflect", fnc_reflect);
+		lil_register(lil, "rename", fnc_rename);
+		lil_register(lil, "repstr", fnc_repstr);
+		lil_register(lil, "result", fnc_result);
+		lil_register(lil, "rtrim", fnc_rtrim);
+		lil_register(lil, "slice", fnc_slice);
+		lil_register(lil, "split", fnc_split);
+		lil_register(lil, "streq", fnc_streq);
+		lil_register(lil, "strpos", fnc_strpos);
+		lil_register(lil, "subst", fnc_subst);
+		lil_register(lil, "substr", fnc_substr);
+		lil_register(lil, "topeval", fnc_topeval);
+		lil_register(lil, "trim", fnc_trim);
+		lil_register(lil, "unusedname", fnc_unusedname);
+		lil_register(lil, "upeval", fnc_upeval);
+	}
 }
-- 
2.32.0



More information about the U-Boot mailing list