Add support for editline as replacement for readline
authorClifford Wolf <clifford@clifford.at>
Wed, 8 Nov 2017 01:54:24 +0000 (02:54 +0100)
committerClifford Wolf <clifford@clifford.at>
Wed, 8 Nov 2017 01:55:00 +0000 (02:55 +0100)
Makefile
kernel/driver.cc
kernel/yosys.cc
passes/cmds/show.cc

index eb8f0f5946dd4e9b6c8dbba77a9e0881e631cb5f..924fd88b712c8856cd0c2275bbaaa0c3bba4f682 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ ENABLE_TCL := 1
 ENABLE_ABC := 1
 ENABLE_PLUGINS := 1
 ENABLE_READLINE := 1
+ENABLE_EDITLINE := 0
 ENABLE_VERIFIC := 0
 ENABLE_COVER := 1
 ENABLE_LIBYOSYS := 0
@@ -226,6 +227,11 @@ endif
 ifeq ($(CONFIG),mxe)
 LDLIBS += -ltermcap
 endif
+else
+ifeq ($(ENABLE_EDITLINE),1)
+CXXFLAGS += -DYOSYS_ENABLE_EDITLINE
+LDLIBS += -ledit -ltinfo -lbsd
+endif
 endif
 
 ifeq ($(ENABLE_PLUGINS),1)
index 1fe61b499304ef0d3371a9aaec005b30b0ded30f..c5e31d7189e8a80a96188080ce0da1244669f7a5 100644 (file)
 #  include <readline/history.h>
 #endif
 
+#ifdef YOSYS_ENABLE_EDITLINE
+#  include <editline/readline.h>
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
@@ -119,27 +123,33 @@ const char *prompt()
 
 #else /* EMSCRIPTEN */
 
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
 int yosys_history_offset = 0;
 std::string yosys_history_file;
 #endif
 
 void yosys_atexit()
 {
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
        if (!yosys_history_file.empty()) {
+#if defined(YOSYS_ENABLE_READLINE)
                if (yosys_history_offset > 0) {
                        history_truncate_file(yosys_history_file.c_str(), 100);
                        append_history(where_history() - yosys_history_offset, yosys_history_file.c_str());
                } else
                        write_history(yosys_history_file.c_str());
+#else
+               write_history(yosys_history_file.c_str());
+#endif
        }
 
        clear_history();
+#if defined(YOSYS_ENABLE_READLINE)
        HIST_ENTRY **hist_list = history_list();
        if (hist_list != NULL)
                free(hist_list);
 #endif
+#endif
 }
 
 int main(int argc, char **argv)
@@ -159,7 +169,7 @@ int main(int argc, char **argv)
        bool mode_v = false;
        bool mode_q = false;
 
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
        if (getenv("HOME") != NULL) {
                yosys_history_file = stringf("%s/.yosys_history", getenv("HOME"));
                read_history(yosys_history_file.c_str());
index e5b22eba710786b8a6290cc8016b24a606339ba0..34665a0ade3efc245d7c5eab28f721005f6c6ad0 100644 (file)
 #  include <readline/history.h>
 #endif
 
+#ifdef YOSYS_ENABLE_EDITLINE
+#  include <editline/readline.h>
+#endif
+
 #ifdef YOSYS_ENABLE_PLUGINS
 #  include <dlfcn.h>
 #endif
@@ -938,7 +942,7 @@ void run_backend(std::string filename, std::string command, RTLIL::Design *desig
        Backend::backend_call(design, NULL, filename, command);
 }
 
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
 static char *readline_cmd_generator(const char *text, int state)
 {
        static std::map<std::string, Pass*>::iterator it;
@@ -1025,14 +1029,14 @@ void shell(RTLIL::Design *design)
        recursion_counter++;
        log_cmd_error_throw = true;
 
-#ifdef YOSYS_ENABLE_READLINE
-       rl_readline_name = "yosys";
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
+       rl_readline_name = (char*)"yosys";
        rl_attempted_completion_function = readline_completion;
-       rl_basic_word_break_characters = " \t\n";
+       rl_basic_word_break_characters = (char*)" \t\n";
 #endif
 
        char *command = NULL;
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
        while ((command = readline(create_prompt(design, recursion_counter))) != NULL)
        {
 #else
@@ -1046,7 +1050,7 @@ void shell(RTLIL::Design *design)
 #endif
                if (command[strspn(command, " \t\r\n")] == 0)
                        continue;
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
                add_history(command);
 #endif
 
@@ -1114,7 +1118,7 @@ struct ShellPass : public Pass {
        }
 } ShellPass;
 
-#ifdef YOSYS_ENABLE_READLINE
+#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
 struct HistoryPass : public Pass {
        HistoryPass() : Pass("history", "show last interactive commands") { }
        virtual void help() {
@@ -1128,8 +1132,13 @@ struct HistoryPass : public Pass {
        }
        virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
                extra_args(args, 1, design, false);
+#ifdef YOSYS_ENABLE_READLINE
                for(HIST_ENTRY **list = history_list(); *list != NULL; list++)
                        log("%s\n", (*list)->line);
+#else
+               for (int i = where_history(); history_get(i); i++)
+                       log("%s\n", history_get(i)->line);
+#endif
        }
 } HistoryPass;
 #endif
index 3a3939a81934deb95a6f9a05eaa100534f50f404..02624cf30b792ccae5f810d72be88398c3c5ee50 100644 (file)
 #  include <readline/readline.h>
 #endif
 
+#ifdef YOSYS_ENABLE_EDITLINE
+#  include <editline/readline.h>
+#endif
+
 USING_YOSYS_NAMESPACE
 PRIVATE_NAMESPACE_BEGIN