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

LLVM Backend #23

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28 FATAL_ERROR)

project(endo VERSION "0.0.0" LANGUAGES CXX)
project(endo VERSION "0.0.0")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand All @@ -12,6 +12,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


option(ENDO_USE_LLVM "Use llvm as a backend for the shell" ON)

if(NOT DEFINED ENDO_TRACE_VM)
option(ENDO_TRACE_VM "Enables debug output" OFF)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Expand Down
2 changes: 1 addition & 1 deletion src/CoreVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ target_include_directories(CoreVM PUBLIC
$<INSTALL_INTERFACE:include>
)

target_link_libraries(CoreVM PUBLIC fmt::fmt-header-only range-v3::range-v3)
target_link_libraries(CoreVM PUBLIC fmt::fmt-header-only range-v3::range-v3 crispy::core)
2 changes: 2 additions & 0 deletions src/CoreVM/transform/MergeBlockPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
module;

#include <list>
#include <algorithm>


module CoreVM;
namespace CoreVM
Expand Down
6 changes: 3 additions & 3 deletions src/shell/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module;
#include <shell/Visitor.h>
#include <fmt/format.h>

#include <crispy/assert.h>
#include <crispy/utils.h>

import Lexer;

Expand Down Expand Up @@ -146,8 +146,8 @@ export class ASTPrinter: public Visitor
}

void visit(LiteralExpr const& node) override { _result += fmt::format("{}", node.value); }
void visit(SubstitutionExpr const& node) override { crispy::ignore_unused(node); }
void visit(CommandFileSubst const& node) override { crispy::ignore_unused(node); }
void visit(SubstitutionExpr const& node) override {}
void visit(CommandFileSubst const& node) override {}
};

} // namespace endo::ast
33 changes: 32 additions & 1 deletion src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_sources(Shell
ASTPrinter.cpp
IRGenerator.cpp
Parser.cpp
llvm_executor.cpp
)

find_package(Threads REQUIRED)
Expand All @@ -23,7 +24,36 @@ find_package(Threads REQUIRED)
# see https://github.com/llvm/llvm-project/issues/75108
# and https://github.com/ericniebler/range-v3/blob/f013aef2ae81f3661a560e7922a968665bedebff/include/meta/meta_fwd.hpp#L37
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)
set(shell_libs
fmt::fmt-header-only
vtparser
CoreVM
crispy::core
InputEditor
Threads::Threads
util)


if(ENDO_USE_LLVM)
find_package(LLVM)
if(LLVM_FOUND)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include("${LLVM_DIR}/AddLLVM.cmake")

include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs analysis core executionengine instcombine object orcjit runtimedyld scalaropts support native)
# Link against LLVM libraries
set(shell_libs
${shell_libs}
${llvm_libs})

target_compile_definitions(Shell PUBLIC ENDO_USE_LLVM)
endif()
else()
endif()


if(ENDO_TRACE_VM)
Expand All @@ -36,6 +66,7 @@ if(ENDO_TRACE_LEXER)
target_compile_definitions(Shell PUBLIC ENDO_TRACE_LEXER)
endif()

target_link_libraries(Shell PUBLIC ${shell_libs})

add_executable(endo
main.cpp
Expand Down
13 changes: 11 additions & 2 deletions src/shell/Shell.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
module;
#include <shell/ProcessGroup.h>

#include <crispy/assert.h>
#include <crispy/utils.h>

Expand All @@ -20,9 +19,10 @@ import Lexer;
import ASTPrinter;
import IRGenerator;
import Parser;

import CoreVM;

import LLVMBack;

export module Shell;

auto inline debugLog = logstore::category("debug ", "Debug log", logstore::category::state::Enabled);
Expand Down Expand Up @@ -206,7 +206,16 @@ export class Shell final: public CoreVM::Runtime

return _quit ? _exitCode : EXIT_SUCCESS;
}

int execute(std::string const& lineBuffer)
{
#if defined(ENDO_USE_LLVM)
return llvm_backend::executeLLVM(lineBuffer);
#else
return executeCoreVM(lineBuffer);
#endif
}
int executeCoreVM(std::string const& lineBuffer)
{
try
{
Expand Down
Loading
Loading