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

Add cmake options to handle logging #7

Merged
merged 4 commits into from
Dec 18, 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
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


if(NOT DEFINED ENDO_TRACE_VM)
option(ENDO_TRACE_VM "Enables debug output" OFF)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ENDO_TRACE_VM ON)
endif()
endif()

if(NOT DEFINED ENDO_TRACE_PARSER)
option(ENDO_TRACE_PARSER "Enables debug output for Parser" OFF)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ENDO_TRACE_PARSER ON)
endif()
endif()


if(NOT DEFINED ENDO_TRACE_LEXER)
option(ENDO_TRACE_LEXER "Enables debug output for Lexer" OFF)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ENDO_TRACE_LEXER ON)
endif()
endif()


include(EnableCcache)
include(EndoThirdParties)
Expand All @@ -35,3 +57,10 @@ enable_testing()

add_subdirectory(src)
EndoThirdPartiesSummary2()
message(STATUS "--------------------------------")
message(STATUS " output flags ")
message(STATUS "--------------------------------")
message(STATUS "endo trace vm ${ENDO_TRACE_VM}")
message(STATUS "endo trace parser ${ENDO_TRACE_PARSER}")
message(STATUS "endo trace lexer ${ENDO_TRACE_LEXER}")
message(STATUS "--------------------------------")
12 changes: 12 additions & 0 deletions src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ find_package(Threads REQUIRED)
target_compile_definitions(Shell PUBLIC META_WORKAROUND_LLVM_28385)
target_link_libraries(Shell PUBLIC fmt::fmt-header-only vtparser crispy::core CoreVM InputEditor Threads::Threads util)


if(ENDO_TRACE_VM)
target_compile_definitions(Shell PUBLIC ENDO_TRACE_VM)
endif()
if(ENDO_TRACE_PARSER)
target_compile_definitions(Shell PUBLIC ENDO_TRACE_PARSER)
endif()
if(ENDO_TRACE_LEXER)
target_compile_definitions(Shell PUBLIC ENDO_TRACE_LEXER)
endif()


add_executable(endo
main.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion src/shell/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module;
#include <vector>

// clang-format off
#if 0 // defined(TRACE_LEXER)
#if defined(ENDO_TRACE_LEXER)
#define TRACE(message, ...) do { ::fmt::print("Lexer: " message, __VA_ARGS__); } while (0)
#else
#define TRACE(message, ...) do {} while (0)
Expand Down
2 changes: 1 addition & 1 deletion src/shell/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module;

// {{{ trace macros
// clang-format off
#if 0 // defined(TRACE_PARSER)
#if defined(ENDO_TRACE_PARSER)
#define TRACE_SCOPE(message) ScopedLogger _logger { message }
#define TRACE_FMT(message, ...) do { ScopedLogger::write(::fmt::format(message, __VA_ARGS__)); } while (0)
#define TRACE(message) do { ScopedLogger::write(::fmt::format(message)); } while (0)
Expand Down
11 changes: 6 additions & 5 deletions src/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export module Shell;

// {{{ trace macros
// clang-format off
#if 0
#if defined(ENDO_TRACE)
#define DEBUG(msg) do { fmt::print("{}\n", (msg)); } while (0)
#define DEBUGF(msg, ...) do { fmt::print("{}\n", fmt::format((msg), __VA_ARGS__)); } while (0)
#else
Expand Down Expand Up @@ -192,10 +192,6 @@ export class Shell final: public CoreVM::Runtime

// NB: These lines could go away once we have a proper command line parser and
// the ability to set these options from the command line.
_optimize = _env.get("SHELL_IR_OPTIMIZE").value_or("0") != "0";
_debugIR = _env.get("SHELL_IR_DEBUG").value_or("0") != "0";
_traceVM = _env.get("SHELL_VM_TRACE").value_or("0") != "0";

registerBuiltinFunctions();

// for (CoreVM::NativeCallback const* callback: builtins())
Expand Down Expand Up @@ -645,8 +641,13 @@ export class Shell final: public CoreVM::Runtime
std::unique_ptr<CoreVM::Program> _currentProgram;
CoreVM::Runner::Globals _globals;

#if defined(ENDO_TRACE_VM)
bool _debugIR = true;
bool _traceVM = true;
#else
bool _debugIR = false;
bool _traceVM = false;
#endif
bool _optimize = false;

PipelineBuilder _currentPipelineBuilder;
Expand Down
10 changes: 9 additions & 1 deletion src/shell/Shell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,21 @@ TEST_CASE("shell.builtin.set_variable")
CHECK(shell.env.get("BRU").value_or("NONE") == "hello");
}

TEST_CASE("shell.builtin.get_variable")
{
TestShell shell;
shell("set BRU hello");
CHECK(shell.env.get("BRU").value_or("NONE") == "hello");
shell("$BRU");
}


// TEST_CASE("shell.builtin.set_and_export_variable")
// {
// TestShell shell;
// shell("set BRU hello");
// CHECK(shell.env.get("BRU").value_or("NONE") == "hello");
//

// shell("export $BRU");
// CHECK(shell("echo $BRU").output() == "hello\n");
// }
Expand Down