From db07b55dddf37c436216ec41c6b532cc110ec6de Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 06:22:01 -0700 Subject: [PATCH 1/7] Preparation for OCLA Parser --- src/Compiler/Compiler.cpp | 4 ++ src/Compiler/Compiler.h | 2 + src/Configuration/CFGCommon/CFGCommon.cpp | 16 ++++---- src/Configuration/CFGCommon/CFGCommon.h | 41 ++++++++++--------- src/Configuration/CFGCompiler/CFGCompiler.cpp | 9 +++- tests/unittest/CFGCommon/CFGArg_test.cpp | 2 +- tests/unittest/CFGCommon/CFGCommon_test.cpp | 2 +- .../unittest/CFGCompiler/CFGCompiler_test.cpp | 2 +- 8 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/Compiler/Compiler.cpp b/src/Compiler/Compiler.cpp index c874543a0..1fe3e98d2 100644 --- a/src/Compiler/Compiler.cpp +++ b/src/Compiler/Compiler.cpp @@ -3033,3 +3033,7 @@ int Compiler::add_files(Compiler* compiler, Tcl_Interp* interp, int argc, } return TCL_OK; } + +std::filesystem::path Compiler::GetBinPath() const { + return GlobalSession->Context()->BinaryPath(); +} \ No newline at end of file diff --git a/src/Compiler/Compiler.h b/src/Compiler/Compiler.h index 5e7fa42da..fc204f0c0 100644 --- a/src/Compiler/Compiler.h +++ b/src/Compiler/Compiler.h @@ -304,6 +304,8 @@ class Compiler { return m_configFileSearchDir; } + std::filesystem::path GetBinPath() const; + std::string Name() const { return m_name; } static constexpr SynthesisOpt SYNTH_OPT_DEFAULT{SynthesisOpt::Mixed}; diff --git a/src/Configuration/CFGCommon/CFGCommon.cpp b/src/Configuration/CFGCommon/CFGCommon.cpp index 9e59354ef..1d0419928 100644 --- a/src/Configuration/CFGCommon/CFGCommon.cpp +++ b/src/Configuration/CFGCommon/CFGCommon.cpp @@ -65,8 +65,8 @@ std::string CFG_print(const char* format_string, ...) { void CFG_assertion(const char* file, const char* func, size_t line, std::string msg) { - std::string filepath = change_directory_to_linux_format(file); - filepath = get_configuration_relative_path(filepath); + std::string filepath = CFG_change_directory_to_linux_format(file); + filepath = CFG_get_configuration_relative_path(filepath); std::string err = func != nullptr ? CFG_print("Assertion at %s (func: %s, line: %d)", filepath.c_str(), func, (uint32_t)(line)) @@ -110,9 +110,9 @@ float CFG_time_elapse(CFG_TIME begin) { return float(CFG_nano_time_elapse(begin) * 1e-9); } -void set_callback_message_function(cfg_callback_post_msg_function msg, - cfg_callback_post_err_function err, - cfg_callback_execute_command exec) { +void CFG_set_callback_message_function(cfg_callback_post_msg_function msg, + cfg_callback_post_err_function err, + cfg_callback_execute_command exec) { CFG_ASSERT(msg != nullptr); CFG_ASSERT(err != nullptr); CFG_ASSERT(exec != nullptr); @@ -121,7 +121,7 @@ void set_callback_message_function(cfg_callback_post_msg_function msg, m_execute_cmd_function = exec; } -void unset_callback_message_function() { +void CFG_unset_callback_message_function() { m_msg_function = nullptr; m_err_function = nullptr; m_execute_cmd_function = nullptr; @@ -150,7 +150,7 @@ void CFG_post_err(const std::string& message, bool append) { } } -std::string change_directory_to_linux_format(std::string path) { +std::string CFG_change_directory_to_linux_format(std::string path) { std::replace(path.begin(), path.end(), '\\', '/'); size_t index = path.find("//"); while (index != std::string::npos) { @@ -160,7 +160,7 @@ std::string change_directory_to_linux_format(std::string path) { return path; } -std::string get_configuration_relative_path(std::string path) { +std::string CFG_get_configuration_relative_path(std::string path) { size_t index = path.find("/src/Configuration"); if (index != std::string::npos) { path.erase(0, index + 5); diff --git a/src/Configuration/CFGCommon/CFGCommon.h b/src/Configuration/CFGCommon/CFGCommon.h index 14f083c7f..2d4602196 100644 --- a/src/Configuration/CFGCommon/CFGCommon.h +++ b/src/Configuration/CFGCommon/CFGCommon.h @@ -38,6 +38,9 @@ struct CFGCommon_ARG { std::string projectName; std::string projectPath; std::string taskPath; + std::string analyzePath; + std::string synthesisPath; + std::string binPath; std::string compilerName; std::filesystem::path toolPath; // for any tool path std::filesystem::path searchPath; // for any search path @@ -51,30 +54,30 @@ void CFG_assertion(const char* file, const char* func, size_t line, std::string msg); #define CFG_INTERNAL_ERROR(...) \ - { CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); } + { CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); } #if defined(_MSC_VER) -#define CFG_ASSERT(truth) \ - if (!(truth)) { \ - CFG_assertion(__FILE__, __func__, __LINE__, #truth); \ +#define CFG_ASSERT(truth) \ + if (!(truth)) { \ + CFG_assertion(__FILENAME__, __func__, __LINE__, #truth); \ } -#define CFG_ASSERT_MSG(truth, ...) \ - if (!(truth)) { \ - CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ +#define CFG_ASSERT_MSG(truth, ...) \ + if (!(truth)) { \ + CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ } #else -#define CFG_ASSERT(truth) \ - if (!(__builtin_expect(!!(truth), 0))) { \ - CFG_assertion(__FILE__, __func__, __LINE__, #truth); \ +#define CFG_ASSERT(truth) \ + if (!(__builtin_expect(!!(truth), 0))) { \ + CFG_assertion(__FILENAME__, __func__, __LINE__, #truth); \ } -#define CFG_ASSERT_MSG(truth, ...) \ - if (!(__builtin_expect(!!(truth), 0))) { \ - CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ +#define CFG_ASSERT_MSG(truth, ...) \ + if (!(__builtin_expect(!!(truth), 0))) { \ + CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ } #endif @@ -87,11 +90,11 @@ uint64_t CFG_nano_time_elapse(CFG_TIME begin); float CFG_time_elapse(CFG_TIME begin); -void set_callback_message_function(cfg_callback_post_msg_function msg, - cfg_callback_post_err_function err, - cfg_callback_execute_command exec); +void CFG_set_callback_message_function(cfg_callback_post_msg_function msg, + cfg_callback_post_err_function err, + cfg_callback_execute_command exec); -void unset_callback_message_function(); +void CFG_unset_callback_message_function(); void CFG_post_msg(const std::string& message, const std::string pre_msg = "INFO: ", @@ -105,9 +108,9 @@ int CFG_execute_and_monitor_system_command( const std::string& command, const std::string logFile = std::string{}, bool appendLog = false); -std::string change_directory_to_linux_format(std::string path); +std::string CFG_change_directory_to_linux_format(std::string path); -std::string get_configuration_relative_path(std::string path); +std::string CFG_get_configuration_relative_path(std::string path); void CFG_get_rid_trailing_whitespace(std::string& string, const std::vector whitespaces = { diff --git a/src/Configuration/CFGCompiler/CFGCompiler.cpp b/src/Configuration/CFGCompiler/CFGCompiler.cpp index 100300099..5f32b2093 100644 --- a/src/Configuration/CFGCompiler/CFGCompiler.cpp +++ b/src/Configuration/CFGCompiler/CFGCompiler.cpp @@ -54,8 +54,8 @@ static bool programmer_flow(CFGCompiler* cfgcompiler, int argc, CFGCompiler::CFGCompiler(Compiler* compiler) : m_compiler(compiler) { m_CFGCompiler = this; - set_callback_message_function(Message, ErrorMessage, - ExecuteAndMonitorSystemCommand); + CFG_set_callback_message_function(Message, ErrorMessage, + ExecuteAndMonitorSystemCommand); } Compiler* CFGCompiler::GetCompiler() const { return m_compiler; } @@ -111,7 +111,12 @@ int CFGCompiler::Compile(CFGCompiler* cfgcompiler, bool batchMode) { cfgcompiler->m_cmdarg.projectPath = compiler->ProjManager()->projectPath(); cfgcompiler->m_cmdarg.taskPath = compiler->FilePath(Compiler::Action::Bitstream).string(); + cfgcompiler->m_cmdarg.analyzePath = + compiler->FilePath(Compiler::Action::Analyze).string(); + cfgcompiler->m_cmdarg.synthesisPath = + compiler->FilePath(Compiler::Action::Synthesis).string(); cfgcompiler->m_cmdarg.searchPath = compiler->GetConfigFileSearchDirectory(); + cfgcompiler->m_cmdarg.binPath = compiler->GetBinPath().c_str(); // Call Compile() if (batchMode) { diff --git a/tests/unittest/CFGCommon/CFGArg_test.cpp b/tests/unittest/CFGCommon/CFGArg_test.cpp index 25f30d4c3..d04634a3f 100644 --- a/tests/unittest/CFGCommon/CFGArg_test.cpp +++ b/tests/unittest/CFGCommon/CFGArg_test.cpp @@ -24,7 +24,7 @@ along with this program. If not, see . #include "gtest/gtest.h" TEST(CFGArg, test_arg) { - unset_callback_message_function(); + CFG_unset_callback_message_function(); CFGArg_UTST arg; CFGArg_UTST_SUB0 sub0arg; EXPECT_EQ(sub0arg.debug, true); diff --git a/tests/unittest/CFGCommon/CFGCommon_test.cpp b/tests/unittest/CFGCommon/CFGCommon_test.cpp index cf9cc522c..202048301 100644 --- a/tests/unittest/CFGCommon/CFGCommon_test.cpp +++ b/tests/unittest/CFGCommon/CFGCommon_test.cpp @@ -118,7 +118,7 @@ TEST(CFGCommon, test_string_split) { } TEST(CFGCommon, test_exception) { - unset_callback_message_function(); + CFG_unset_callback_message_function(); int a = 10; int exception_count = 0; try { diff --git a/tests/unittest/CFGCompiler/CFGCompiler_test.cpp b/tests/unittest/CFGCompiler/CFGCompiler_test.cpp index 1ed25d759..3d59e81a3 100644 --- a/tests/unittest/CFGCompiler/CFGCompiler_test.cpp +++ b/tests/unittest/CFGCompiler/CFGCompiler_test.cpp @@ -48,7 +48,7 @@ void test_callback_bad_function(const CFGCommon_ARG* cmdarg) { } TEST(CFGCompiler, test_CallbackFunction) { - unset_callback_message_function(); + CFG_unset_callback_message_function(); // New registration - OK EXPECT_EQ(cfgcompiler.RegisterCallbackFunction("good_testing", test_callback_good_function), true); EXPECT_EQ(cfgcompiler.RegisterCallbackFunction("bad_testing", test_callback_bad_function), true); From 0e486dbbe57e98f6d8f9c1641ec1d0b29f0b5815 Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 06:34:35 -0700 Subject: [PATCH 2/7] Add test --- src/Configuration/CFGCommon/CFGCommon.cpp | 3 ++- tests/unittest/CFGCommon/CFGCommon_test.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Configuration/CFGCommon/CFGCommon.cpp b/src/Configuration/CFGCommon/CFGCommon.cpp index 1d0419928..7ae3282ac 100644 --- a/src/Configuration/CFGCommon/CFGCommon.cpp +++ b/src/Configuration/CFGCommon/CFGCommon.cpp @@ -161,7 +161,8 @@ std::string CFG_change_directory_to_linux_format(std::string path) { } std::string CFG_get_configuration_relative_path(std::string path) { - size_t index = path.find("/src/Configuration"); + path = CFG_change_directory_to_linux_format(path); + size_t index = path.rfind("/src/Configuration"); if (index != std::string::npos) { path.erase(0, index + 5); } diff --git a/tests/unittest/CFGCommon/CFGCommon_test.cpp b/tests/unittest/CFGCommon/CFGCommon_test.cpp index 202048301..c2d3ee4cd 100644 --- a/tests/unittest/CFGCommon/CFGCommon_test.cpp +++ b/tests/unittest/CFGCommon/CFGCommon_test.cpp @@ -22,6 +22,16 @@ along with this program. If not, see . #include "Configuration/CFGCommon/CFGCommon.h" #include "gtest/gtest.h" +TEST(CFGCommon, test_change_directory_to_linux_format) { + std::string linux_format = CFG_change_directory_to_linux_format("c:\\\\\\ abc \\ efg /////xyz //123"); + EXPECT_EQ(linux_format, "c:/ abc / efg /xyz /123"); +} + +TEST(CFGCommon, test_configuration_relative_path) { + std::string path = CFG_get_configuration_relative_path("/usr/src/ConfigurationRS/abc"); + EXPECT_EQ(path, "ConfigurationRS/abc"); +} + TEST(CFGCommon, test_get_rid_whitespace) { std::string str = "\t \t \r \n \tThis is Love\t \r \n \n"; CFG_get_rid_trailing_whitespace(str, {'\t'}); From d87f21631ad26d2d1bd06a638e600c71153722f7 Mon Sep 17 00:00:00 2001 From: chungshien Date: Mon, 28 Aug 2023 06:02:18 +0000 Subject: [PATCH 3/7] Incremented patch version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b12194bb8..de6569498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ set(VERSION_MINOR 0) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/third_party/exprtk) -set(VERSION_PATCH 235) +set(VERSION_PATCH 236) option( WITH_LIBCXX From 5adde8516d6bc4bb65cf60419cb234efc7125cf4 Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 08:28:42 -0700 Subject: [PATCH 4/7] Empty-Commit From b125eb9f38e0c7386d49dbf99c2ae9a585a64f57 Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 09:04:23 -0700 Subject: [PATCH 5/7] Fix warning-error --- src/Configuration/CFGCompiler/CFGCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration/CFGCompiler/CFGCompiler.cpp b/src/Configuration/CFGCompiler/CFGCompiler.cpp index 5f32b2093..8a096b3b7 100644 --- a/src/Configuration/CFGCompiler/CFGCompiler.cpp +++ b/src/Configuration/CFGCompiler/CFGCompiler.cpp @@ -116,7 +116,7 @@ int CFGCompiler::Compile(CFGCompiler* cfgcompiler, bool batchMode) { cfgcompiler->m_cmdarg.synthesisPath = compiler->FilePath(Compiler::Action::Synthesis).string(); cfgcompiler->m_cmdarg.searchPath = compiler->GetConfigFileSearchDirectory(); - cfgcompiler->m_cmdarg.binPath = compiler->GetBinPath().c_str(); + cfgcompiler->m_cmdarg.binPath = compiler->GetBinPath().u8string(); // Call Compile() if (batchMode) { From dd2c0d661a72123a2d89e2c8e1d7918aa63146c7 Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 09:05:36 -0700 Subject: [PATCH 6/7] Fix warning-error --- src/Configuration/CFGCompiler/CFGCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration/CFGCompiler/CFGCompiler.cpp b/src/Configuration/CFGCompiler/CFGCompiler.cpp index 8a096b3b7..8b528f199 100644 --- a/src/Configuration/CFGCompiler/CFGCompiler.cpp +++ b/src/Configuration/CFGCompiler/CFGCompiler.cpp @@ -116,7 +116,7 @@ int CFGCompiler::Compile(CFGCompiler* cfgcompiler, bool batchMode) { cfgcompiler->m_cmdarg.synthesisPath = compiler->FilePath(Compiler::Action::Synthesis).string(); cfgcompiler->m_cmdarg.searchPath = compiler->GetConfigFileSearchDirectory(); - cfgcompiler->m_cmdarg.binPath = compiler->GetBinPath().u8string(); + cfgcompiler->m_cmdarg.binPath = compiler->GetBinPath().string(); // Call Compile() if (batchMode) { From 755331bff41cbb744bf03ba2c315910837085330 Mon Sep 17 00:00:00 2001 From: chungshien Date: Sun, 27 Aug 2023 09:30:36 -0700 Subject: [PATCH 7/7] Use __FILE__ --- src/Configuration/CFGCommon/CFGCommon.h | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Configuration/CFGCommon/CFGCommon.h b/src/Configuration/CFGCommon/CFGCommon.h index 2d4602196..ea7965144 100644 --- a/src/Configuration/CFGCommon/CFGCommon.h +++ b/src/Configuration/CFGCommon/CFGCommon.h @@ -54,30 +54,30 @@ void CFG_assertion(const char* file, const char* func, size_t line, std::string msg); #define CFG_INTERNAL_ERROR(...) \ - { CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); } + { CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); } #if defined(_MSC_VER) -#define CFG_ASSERT(truth) \ - if (!(truth)) { \ - CFG_assertion(__FILENAME__, __func__, __LINE__, #truth); \ +#define CFG_ASSERT(truth) \ + if (!(truth)) { \ + CFG_assertion(__FILE__, __func__, __LINE__, #truth); \ } -#define CFG_ASSERT_MSG(truth, ...) \ - if (!(truth)) { \ - CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ +#define CFG_ASSERT_MSG(truth, ...) \ + if (!(truth)) { \ + CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ } #else -#define CFG_ASSERT(truth) \ - if (!(__builtin_expect(!!(truth), 0))) { \ - CFG_assertion(__FILENAME__, __func__, __LINE__, #truth); \ +#define CFG_ASSERT(truth) \ + if (!(__builtin_expect(!!(truth), 0))) { \ + CFG_assertion(__FILE__, __func__, __LINE__, #truth); \ } -#define CFG_ASSERT_MSG(truth, ...) \ - if (!(__builtin_expect(!!(truth), 0))) { \ - CFG_assertion(__FILENAME__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ +#define CFG_ASSERT_MSG(truth, ...) \ + if (!(__builtin_expect(!!(truth), 0))) { \ + CFG_assertion(__FILE__, __func__, __LINE__, CFG_print(__VA_ARGS__)); \ } #endif