-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from clEsperanto/add-JIT-cache
add JIT cache on disk
- Loading branch information
Showing
12 changed files
with
386 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,3 @@ if(BUILD_TESTING) | |
include(CTest) | ||
add_subdirectory(${PROJECT_SOURCE_DIR}/tests) | ||
endif(BUILD_TESTING) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifndef __INCLUDE_CACHE_HPP | ||
#define __INCLUDE_CACHE_HPP | ||
|
||
#include <cstdlib> | ||
#include <filesystem> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include "device.hpp" | ||
|
||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | ||
# define NOMINMAX | ||
# include <ShlObj.h> | ||
# include <windows.h> | ||
#endif | ||
|
||
namespace cle | ||
{ | ||
|
||
static const std::string CACHE_FOLDER = "clesperanto"; | ||
static const std::string CACHE_DIR_WIN = "AppData\\Local"; | ||
static const std::string CACHE_DIR_UNIX = ".cache"; | ||
|
||
static auto | ||
get_path_with_cache_folder(const std::filesystem::path & base_path) -> std::filesystem::path | ||
{ | ||
return base_path / std::filesystem::path(CACHE_FOLDER); | ||
} | ||
|
||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | ||
static auto | ||
get_cache_directory_path() -> std::filesystem::path | ||
{ | ||
TCHAR path[MAX_PATH]; | ||
if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path))) | ||
{ | ||
std::cerr << "Failed to get " << CACHE_DIR_WIN << " directory\n"; | ||
return get_path_with_cache_folder(std::filesystem::current_path()); | ||
} | ||
return get_path_with_cache_folder(std::filesystem::path(path)); | ||
} | ||
#else | ||
static auto | ||
get_cache_directory_path() -> std::filesystem::path | ||
{ | ||
char * home_dir = std::getenv("HOME"); | ||
if (home_dir != nullptr) | ||
{ | ||
return get_path_with_cache_folder(std::filesystem::path(home_dir) / std::filesystem::path(CACHE_DIR_UNIX)); | ||
} | ||
std::cerr << "Failed to get user home directory\n"; | ||
return get_path_with_cache_folder(std::filesystem::current_path() / std::filesystem::path(CACHE_DIR_UNIX)); | ||
} | ||
#endif | ||
|
||
static auto | ||
is_cache_enabled() -> bool | ||
{ | ||
const char * env_var = std::getenv("CLESPERANTO_NO_CACHE"); | ||
bool cache_disabled = (env_var != nullptr); | ||
return !cache_disabled; | ||
} | ||
|
||
|
||
static const auto CACHE_FOLDER_PATH = get_cache_directory_path(); | ||
|
||
} // namespace cle | ||
|
||
#endif // __INCLUDE_CACHE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.