13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 33d3250a0SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 53d3250a0SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 73d3250a0SJeremy L Thompson 86eb0d8b4SJeremy L Thompson #include <ceed-impl.h> 949aac155SJeremy L Thompson #include <ceed.h> 102b730f8bSJeremy L Thompson #include <ceed/backend.h> 112b730f8bSJeremy L Thompson #include <ceed/jit-tools.h> 123d3250a0SJeremy L Thompson #include <stdbool.h> 133d3250a0SJeremy L Thompson #include <stdio.h> 143d3250a0SJeremy L Thompson #include <string.h> 153d3250a0SJeremy L Thompson 163d3250a0SJeremy L Thompson /** 17ee5a26f2SJeremy L Thompson @brief Check if valid file exists at path given 18ee5a26f2SJeremy L Thompson 19ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 20ee5a26f2SJeremy L Thompson @param[in] source_file_path Absolute path to source file 21ea61e9acSJeremy L Thompson @param[out] is_valid Boolean flag indicating if file can be opened 22ee5a26f2SJeremy L Thompson 23ee5a26f2SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 24ee5a26f2SJeremy L Thompson 25ee5a26f2SJeremy L Thompson @ref Backend 26ee5a26f2SJeremy L Thompson **/ 27ee5a26f2SJeremy L Thompson int CeedCheckFilePath(Ceed ceed, const char *source_file_path, bool *is_valid) { 28ee5a26f2SJeremy L Thompson // Sometimes we have path/to/file.h:function_name 29ea61e9acSJeremy L Thompson // Create temporary file path without name, if needed 30ee5a26f2SJeremy L Thompson char *source_file_path_only; 31ee5a26f2SJeremy L Thompson char *last_colon = strrchr(source_file_path, ':'); 321c66c397SJeremy L Thompson 33ee5a26f2SJeremy L Thompson if (last_colon) { 34ee5a26f2SJeremy L Thompson size_t source_file_path_length = (last_colon - source_file_path + 1); 35ee5a26f2SJeremy L Thompson 362b730f8bSJeremy L Thompson CeedCall(CeedCalloc(source_file_path_length, &source_file_path_only)); 37d602d780SJeremy L Thompson memcpy(source_file_path_only, source_file_path, source_file_path_length - 1); 38ee5a26f2SJeremy L Thompson } else { 39ee5a26f2SJeremy L Thompson source_file_path_only = (char *)source_file_path; 40ee5a26f2SJeremy L Thompson } 41ee5a26f2SJeremy L Thompson 42ee5a26f2SJeremy L Thompson // Debug 4323d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Checking for source file: "); 4413f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", source_file_path_only); 45ee5a26f2SJeremy L Thompson 46ee5a26f2SJeremy L Thompson // Check for valid file path 47ee5a26f2SJeremy L Thompson FILE *source_file; 48ee5a26f2SJeremy L Thompson source_file = fopen(source_file_path_only, "rb"); 491c66c397SJeremy L Thompson *is_valid = source_file; 50ee5a26f2SJeremy L Thompson 51ee5a26f2SJeremy L Thompson if (*is_valid) { 52ee5a26f2SJeremy L Thompson // Debug 5323d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Found JiT source file: "); 5413f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", source_file_path_only); 55ee5a26f2SJeremy L Thompson fclose(source_file); 56ee5a26f2SJeremy L Thompson } 57ee5a26f2SJeremy L Thompson 58ee5a26f2SJeremy L Thompson // Free temp file path, if used 592b730f8bSJeremy L Thompson if (last_colon) CeedCall(CeedFree(&source_file_path_only)); 60ee5a26f2SJeremy L Thompson return CEED_ERROR_SUCCESS; 61ee5a26f2SJeremy L Thompson } 62ee5a26f2SJeremy L Thompson 63ee5a26f2SJeremy L Thompson /** 64ea61e9acSJeremy L Thompson @brief Load source file into initialized string buffer, including full text of local files in place of `#include "local.h"` 653d3250a0SJeremy L Thompson 66ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 673d3250a0SJeremy L Thompson @param[in] source_file_path Absolute path to source file 68*430da97aSJeremy L Thompson @param[in] depth Depth of recursion 69*430da97aSJeremy L Thompson @param[in,out] num_files Number of files already included 70*430da97aSJeremy L Thompson @param[in,out] filepaths Paths of files already included 713d3250a0SJeremy L Thompson @param[out] buffer String buffer for source file contents 723d3250a0SJeremy L Thompson 733d3250a0SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 743d3250a0SJeremy L Thompson 753d3250a0SJeremy L Thompson @ref Backend 763d3250a0SJeremy L Thompson **/ 77*430da97aSJeremy L Thompson static int CeedLoadSourceToInitializedBuffer_Private(Ceed ceed, const char *source_file_path, CeedInt depth, CeedInt *num_files, char ***filepaths, 78*430da97aSJeremy L Thompson char **buffer) { 793d3250a0SJeremy L Thompson FILE *source_file; 803d3250a0SJeremy L Thompson long file_size, file_offset = 0; 813d3250a0SJeremy L Thompson char *temp_buffer; 823d3250a0SJeremy L Thompson 833d3250a0SJeremy L Thompson // Debug 8423d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "---------- Ceed JiT ----------\n"); 8523d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Current source file: "); 8613f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", source_file_path); 8723d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Current buffer:\n"); 8813f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", *buffer); 893d3250a0SJeremy L Thompson 903d3250a0SJeremy L Thompson // Read file to temporary buffer 913d3250a0SJeremy L Thompson source_file = fopen(source_file_path, "rb"); 926574a04fSJeremy L Thompson CeedCheck(source_file, ceed, CEED_ERROR_MAJOR, "Couldn't open source file: %s", source_file_path); 933d3250a0SJeremy L Thompson // -- Compute size of source 943d3250a0SJeremy L Thompson fseek(source_file, 0L, SEEK_END); 953d3250a0SJeremy L Thompson file_size = ftell(source_file); 963d3250a0SJeremy L Thompson rewind(source_file); 973d3250a0SJeremy L Thompson // -- Allocate memory for entire source file 982b730f8bSJeremy L Thompson CeedCall(CeedCalloc(file_size + 1, &temp_buffer)); 993d3250a0SJeremy L Thompson // -- Copy the file into the buffer 1003d3250a0SJeremy L Thompson if (1 != fread(temp_buffer, file_size, 1, source_file)) { 1013d3250a0SJeremy L Thompson // LCOV_EXCL_START 1023d3250a0SJeremy L Thompson fclose(source_file); 1032b730f8bSJeremy L Thompson CeedCall(CeedFree(&temp_buffer)); 1042b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_MAJOR, "Couldn't read source file: %s", source_file_path); 1053d3250a0SJeremy L Thompson // LCOV_EXCL_STOP 1063d3250a0SJeremy L Thompson } 1073d3250a0SJeremy L Thompson fclose(source_file); 1083d3250a0SJeremy L Thompson 1093d3250a0SJeremy L Thompson // Search for headers to include 1103d3250a0SJeremy L Thompson const char *first_hash = strchr(temp_buffer, '#'); 1111c66c397SJeremy L Thompson 1123d3250a0SJeremy L Thompson while (first_hash) { 1133d3250a0SJeremy L Thompson // -- Check for 'include' keyword 1143d3250a0SJeremy L Thompson const char *next_e = strchr(first_hash, 'e'); 1153d3250a0SJeremy L Thompson char keyword[8] = ""; 1161c66c397SJeremy L Thompson 117c9c2c079SJeremy L Thompson if (next_e && next_e - first_hash >= 7) memcpy(keyword, &next_e[-6], 7); 1183d3250a0SJeremy L Thompson bool is_hash_include = !strcmp(keyword, "include"); 1191c66c397SJeremy L Thompson 1203d3250a0SJeremy L Thompson // ---- Spaces allowed in '# include <header.h>' 121c9c2c079SJeremy L Thompson if (next_e) { 122c9c2c079SJeremy L Thompson for (CeedInt i = 1; first_hash - next_e + i < -6; i++) { 1233d3250a0SJeremy L Thompson is_hash_include &= first_hash[i] == ' '; 124c9c2c079SJeremy L Thompson } 125c9c2c079SJeremy L Thompson } 1263d3250a0SJeremy L Thompson if (is_hash_include) { 1273d3250a0SJeremy L Thompson // -- Copy into buffer all preceding # 1283d3250a0SJeremy L Thompson long current_size = strlen(*buffer); 1293d3250a0SJeremy L Thompson long copy_size = first_hash - &temp_buffer[file_offset]; 1301c66c397SJeremy L Thompson 1312b730f8bSJeremy L Thompson CeedCall(CeedRealloc(current_size + copy_size + 2, buffer)); 132d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size], "\n", 2); 133d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size); 134d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size + copy_size], "", 1); 1353d3250a0SJeremy L Thompson // -- Load local "header.h" 1363d3250a0SJeremy L Thompson char *next_quote = strchr(first_hash, '"'); 1373d3250a0SJeremy L Thompson char *next_new_line = strchr(first_hash, '\n'); 1382b730f8bSJeremy L Thompson bool is_local_header = is_hash_include && next_quote && (next_new_line - next_quote > 0); 139c9c2c079SJeremy L Thompson char *next_left_chevron = strchr(first_hash, '<'); 1402b730f8bSJeremy L Thompson bool is_ceed_header = is_hash_include && next_left_chevron && (next_new_line - next_left_chevron > 0) && 1412b730f8bSJeremy L Thompson (!strncmp(next_left_chevron, "<ceed/jit-source/", 17) || !strncmp(next_left_chevron, "<ceed/types.h>", 14) || 1422b730f8bSJeremy L Thompson !strncmp(next_left_chevron, "<ceed/ceed-f32.h>", 17) || !strncmp(next_left_chevron, "<ceed/ceed-f64.h>", 17)); 1431c66c397SJeremy L Thompson 144c9c2c079SJeremy L Thompson if (is_local_header || is_ceed_header) { 1453d3250a0SJeremy L Thompson // ---- Build source path 146*430da97aSJeremy L Thompson bool is_included = false; 1473d3250a0SJeremy L Thompson char *include_source_path; 1481c66c397SJeremy L Thompson 149c9c2c079SJeremy L Thompson if (is_local_header) { 1503d3250a0SJeremy L Thompson long root_length = strrchr(source_file_path, '/') - source_file_path; 1513d3250a0SJeremy L Thompson long include_file_name_len = strchr(&next_quote[1], '"') - next_quote - 1; 1521c66c397SJeremy L Thompson 1532b730f8bSJeremy L Thompson CeedCall(CeedCalloc(root_length + include_file_name_len + 2, &include_source_path)); 154d602d780SJeremy L Thompson memcpy(include_source_path, source_file_path, root_length + 1); 1552b730f8bSJeremy L Thompson memcpy(&include_source_path[root_length + 1], &next_quote[1], include_file_name_len); 156d602d780SJeremy L Thompson memcpy(&include_source_path[root_length + include_file_name_len + 1], "", 1); 157c9c2c079SJeremy L Thompson } else { 158c9c2c079SJeremy L Thompson char *next_right_chevron = strchr(first_hash, '>'); 159c9c2c079SJeremy L Thompson char *ceed_relative_path; 160c9c2c079SJeremy L Thompson long ceed_relative_path_length = next_right_chevron - next_left_chevron - 1; 1611c66c397SJeremy L Thompson 1622b730f8bSJeremy L Thompson CeedCall(CeedCalloc(ceed_relative_path_length + 1, &ceed_relative_path)); 163c9c2c079SJeremy L Thompson memcpy(ceed_relative_path, &next_left_chevron[1], ceed_relative_path_length); 16422070f95SJeremy L Thompson CeedCall(CeedGetJitAbsolutePath(ceed, ceed_relative_path, (const char **)&include_source_path)); 1652b730f8bSJeremy L Thompson CeedCall(CeedFree(&ceed_relative_path)); 166c9c2c079SJeremy L Thompson } 1673d3250a0SJeremy L Thompson // ---- Recursive call to load source to buffer 168*430da97aSJeremy L Thompson for (CeedInt i = 0; i < *num_files; i++) is_included |= !strcmp(include_source_path, (*filepaths)[i]); 169*430da97aSJeremy L Thompson if (!is_included) { 17023d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "JiT Including: %s\n", include_source_path); 171*430da97aSJeremy L Thompson CeedCall(CeedLoadSourceToInitializedBuffer_Private(ceed, include_source_path, depth + 1, num_files, filepaths, buffer)); 172*430da97aSJeremy L Thompson CeedCall(CeedRealloc(*num_files + 1, filepaths)); 173*430da97aSJeremy L Thompson CeedCall(CeedStringAllocCopy(include_source_path, &(*filepaths)[*num_files])); 174*430da97aSJeremy L Thompson (*num_files)++; 175*430da97aSJeremy L Thompson } 1762b730f8bSJeremy L Thompson CeedCall(CeedFree(&include_source_path)); 1773d3250a0SJeremy L Thompson } 1783d3250a0SJeremy L Thompson file_offset = strchr(first_hash, '\n') - temp_buffer + 1; 1793d3250a0SJeremy L Thompson } 1803d3250a0SJeremy L Thompson // -- Next hash 1813d3250a0SJeremy L Thompson first_hash = strchr(&first_hash[1], '#'); 1823d3250a0SJeremy L Thompson } 1833d3250a0SJeremy L Thompson // Copy rest of source file into buffer 1843d3250a0SJeremy L Thompson long current_size = strlen(*buffer); 1853d3250a0SJeremy L Thompson long copy_size = strlen(&temp_buffer[file_offset]); 1861c66c397SJeremy L Thompson 1872b730f8bSJeremy L Thompson CeedCall(CeedRealloc(current_size + copy_size + 2, buffer)); 188d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size], "\n", 2); 189d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size); 190d602d780SJeremy L Thompson memcpy(&(*buffer)[current_size + copy_size + 1], "", 1); 1913d3250a0SJeremy L Thompson 1923d3250a0SJeremy L Thompson // Cleanup 1932b730f8bSJeremy L Thompson CeedCall(CeedFree(&temp_buffer)); 194*430da97aSJeremy L Thompson if (depth == 0) { 195*430da97aSJeremy L Thompson for (CeedInt i = 0; i < *num_files; i++) CeedCall(CeedFree(&(*filepaths)[i])); 196*430da97aSJeremy L Thompson CeedCall(CeedFree(filepaths)); 197*430da97aSJeremy L Thompson } 1983d3250a0SJeremy L Thompson 1993d3250a0SJeremy L Thompson // Debug 20023d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "---------- Ceed JiT ----------\n"); 20123d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Current source file: "); 20213f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", source_file_path); 20323d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Final buffer:\n"); 20413f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", *buffer); 2053d3250a0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2063d3250a0SJeremy L Thompson } 2073d3250a0SJeremy L Thompson 2083d3250a0SJeremy L Thompson /** 209*430da97aSJeremy L Thompson @brief Load source file into initialized string buffer, including full text of local files in place of `#include "local.h"` 210*430da97aSJeremy L Thompson 211*430da97aSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 212*430da97aSJeremy L Thompson @param[in] source_file_path Absolute path to source file 213*430da97aSJeremy L Thompson @param[out] buffer String buffer for source file contents 214*430da97aSJeremy L Thompson 215*430da97aSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 216*430da97aSJeremy L Thompson 217*430da97aSJeremy L Thompson @ref Backend 218*430da97aSJeremy L Thompson **/ 219*430da97aSJeremy L Thompson int CeedLoadSourceToInitializedBuffer(Ceed ceed, const char *source_file_path, char **buffer) { 220*430da97aSJeremy L Thompson char **filepaths = NULL; 221*430da97aSJeremy L Thompson CeedInt num_files = 0; 222*430da97aSJeremy L Thompson 223*430da97aSJeremy L Thompson CeedCall(CeedLoadSourceToInitializedBuffer_Private(ceed, source_file_path, 0, &num_files, &filepaths, buffer)); 224*430da97aSJeremy L Thompson return CEED_ERROR_SUCCESS; 225*430da97aSJeremy L Thompson } 226*430da97aSJeremy L Thompson 227*430da97aSJeremy L Thompson /** 228ea61e9acSJeremy L Thompson @brief Initialize and load source file into string buffer, including full text of local files in place of `#include "local.h"`. 2294385fb7fSSebastian Grimberg 230ca94c3ddSJeremy L Thompson Note: Caller is responsible for freeing the string buffer with @ref CeedFree(). 2313d3250a0SJeremy L Thompson 232ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 2333d3250a0SJeremy L Thompson @param[in] source_file_path Absolute path to source file 2343d3250a0SJeremy L Thompson @param[out] buffer String buffer for source file contents 2353d3250a0SJeremy L Thompson 2363d3250a0SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 2373d3250a0SJeremy L Thompson 2383d3250a0SJeremy L Thompson @ref Backend 2393d3250a0SJeremy L Thompson **/ 2402b730f8bSJeremy L Thompson int CeedLoadSourceToBuffer(Ceed ceed, const char *source_file_path, char **buffer) { 241ecc88aebSJeremy L Thompson // Initialize buffer 2429d61c3a3SJeremy L Thompson CeedCall(CeedCalloc(1, buffer)); 2433d3250a0SJeremy L Thompson 2443d3250a0SJeremy L Thompson // Load to initalized buffer 2452b730f8bSJeremy L Thompson CeedCall(CeedLoadSourceToInitializedBuffer(ceed, source_file_path, buffer)); 2463d3250a0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2473d3250a0SJeremy L Thompson } 248437930d1SJeremy L Thompson 249437930d1SJeremy L Thompson /** 250437930d1SJeremy L Thompson @brief Build an absolute filepath from a base filepath and an absolute filepath. 2514385fb7fSSebastian Grimberg 252ca94c3ddSJeremy L Thompson This helps construct source file paths for @ref CeedLoadSourceToBuffer(). 2534385fb7fSSebastian Grimberg 254ca94c3ddSJeremy L Thompson Note: Caller is responsible for freeing the string buffer with @ref CeedFree(). 255437930d1SJeremy L Thompson 256ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 257437930d1SJeremy L Thompson @param[in] base_file_path Absolute path to current file 258437930d1SJeremy L Thompson @param[in] relative_file_path Relative path to target file 259437930d1SJeremy L Thompson @param[out] new_file_path String buffer for absolute path to target file 260437930d1SJeremy L Thompson 261437930d1SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 262437930d1SJeremy L Thompson 263437930d1SJeremy L Thompson @ref Backend 264437930d1SJeremy L Thompson **/ 2652b730f8bSJeremy L Thompson int CeedPathConcatenate(Ceed ceed, const char *base_file_path, const char *relative_file_path, char **new_file_path) { 266437930d1SJeremy L Thompson char *last_slash = strrchr(base_file_path, '/'); 2672b730f8bSJeremy L Thompson size_t base_length = (last_slash - base_file_path + 1), relative_length = strlen(relative_file_path), 268437930d1SJeremy L Thompson new_file_path_length = base_length + relative_length + 1; 269437930d1SJeremy L Thompson 2702b730f8bSJeremy L Thompson CeedCall(CeedCalloc(new_file_path_length, new_file_path)); 271d602d780SJeremy L Thompson memcpy(*new_file_path, base_file_path, base_length); 272d602d780SJeremy L Thompson memcpy(&((*new_file_path)[base_length]), relative_file_path, relative_length); 273437930d1SJeremy L Thompson return CEED_ERROR_SUCCESS; 274437930d1SJeremy L Thompson } 2756eb0d8b4SJeremy L Thompson 2766eb0d8b4SJeremy L Thompson /** 277032e71eaSJeremy L Thompson @brief Find the relative filepath to an installed JiT file 2786eb0d8b4SJeremy L Thompson 279032e71eaSJeremy L Thompson @param[in] absolute_file_path Absolute path to installed JiT file 28091e18578SJeremy L Thompson @param[out] relative_file_path Relative path to installed JiT file, a substring of the absolute path 2816eb0d8b4SJeremy L Thompson 2826eb0d8b4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 2836eb0d8b4SJeremy L Thompson 2846eb0d8b4SJeremy L Thompson @ref Backend 2856eb0d8b4SJeremy L Thompson **/ 2862b730f8bSJeremy L Thompson int CeedGetJitRelativePath(const char *absolute_file_path, const char **relative_file_path) { 287032e71eaSJeremy L Thompson *(relative_file_path) = strstr(absolute_file_path, "ceed/jit-source"); 2886574a04fSJeremy L Thompson CeedCheck(*relative_file_path, NULL, CEED_ERROR_MAJOR, "Couldn't find relative path including 'ceed/jit-source' for: %s", absolute_file_path); 2896eb0d8b4SJeremy L Thompson return CEED_ERROR_SUCCESS; 2906eb0d8b4SJeremy L Thompson } 291032e71eaSJeremy L Thompson 292032e71eaSJeremy L Thompson /** 293032e71eaSJeremy L Thompson @brief Build an absolute filepath to a JiT file 294032e71eaSJeremy L Thompson 295ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 296032e71eaSJeremy L Thompson @param[in] relative_file_path Relative path to installed JiT file 29791e18578SJeremy L Thompson @param[out] absolute_file_path String buffer for absolute path to target file, to be freed by caller 298032e71eaSJeremy L Thompson 299032e71eaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 300032e71eaSJeremy L Thompson 301032e71eaSJeremy L Thompson @ref Backend 302032e71eaSJeremy L Thompson **/ 303f8608ea8SJed Brown int CeedGetJitAbsolutePath(Ceed ceed, const char *relative_file_path, const char **absolute_file_path) { 3046155f12fSJeremy L Thompson Ceed ceed_parent; 305032e71eaSJeremy L Thompson 306032e71eaSJeremy L Thompson // Debug 30723d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "---------- Ceed JiT ----------\n"); 30823d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Relative JiT source file: "); 30913f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", relative_file_path); 310032e71eaSJeremy L Thompson 3112b730f8bSJeremy L Thompson CeedCall(CeedGetParent(ceed, &ceed_parent)); 3126155f12fSJeremy L Thompson for (CeedInt i = 0; i < ceed_parent->num_jit_source_roots; i++) { 313ee5a26f2SJeremy L Thompson bool is_valid; 314ee5a26f2SJeremy L Thompson 315032e71eaSJeremy L Thompson // Debug 31623d4529eSJeremy L Thompson CeedDebug256(ceed, CEED_DEBUG_COLOR_SUCCESS, "Checking JiT root: "); 31713f886e9SJeremy L Thompson CeedDebug(ceed, "%s\n", ceed_parent->jit_source_roots[i]); 318032e71eaSJeremy L Thompson 319ee5a26f2SJeremy L Thompson // Build and check absolute path with current root 32022070f95SJeremy L Thompson CeedCall(CeedPathConcatenate(ceed, ceed_parent->jit_source_roots[i], relative_file_path, (char **)absolute_file_path)); 3212b730f8bSJeremy L Thompson CeedCall(CeedCheckFilePath(ceed, *absolute_file_path, &is_valid)); 322032e71eaSJeremy L Thompson 3232b730f8bSJeremy L Thompson if (is_valid) return CEED_ERROR_SUCCESS; 32491e18578SJeremy L Thompson // LCOV_EXCL_START 3252b730f8bSJeremy L Thompson else CeedCall(CeedFree(absolute_file_path)); 32691e18578SJeremy L Thompson // LCOV_EXCL_STOP 327032e71eaSJeremy L Thompson } 328032e71eaSJeremy L Thompson // LCOV_EXCL_START 3292b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_MAJOR, "Couldn't find matching JiT source file: %s", relative_file_path); 330032e71eaSJeremy L Thompson // LCOV_EXCL_STOP 331032e71eaSJeremy L Thompson } 332