Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for OCLA Parser #1246

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions src/Compiler/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
19 changes: 10 additions & 9 deletions src/Configuration/CFGCommon/CFGCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -160,8 +160,9 @@ std::string change_directory_to_linux_format(std::string path) {
return path;
}

std::string get_configuration_relative_path(std::string path) {
size_t index = path.find("/src/Configuration");
std::string CFG_get_configuration_relative_path(std::string path) {
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);
}
Expand Down
15 changes: 9 additions & 6 deletions src/Configuration/CFGCommon/CFGCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ",
Expand All @@ -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<char> whitespaces = {
Expand Down
9 changes: 7 additions & 2 deletions src/Configuration/CFGCompiler/CFGCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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().string();

// Call Compile()
if (batchMode) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/CFGCommon/CFGArg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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);
Expand Down
12 changes: 11 additions & 1 deletion tests/unittest/CFGCommon/CFGCommon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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'});
Expand Down Expand Up @@ -118,7 +128,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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/CFGCompiler/CFGCompiler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down