39 #define CHECK_REPORTS(reports, msg) \
42 int err = end_reports(reports, msg, kReportConfig); \
51 .
id =
"frontend-harness",
52 .name =
"Test Harness",
55 .desc =
"End to end test harness",
56 .author =
"Elliot Haisley",
99 "out of memory (size: %zu)",
size);
115 char *data = (
char *)ptr;
119 static void *user_malloc(
size_t size,
void *user)
127 static void *user_realloc(
void *ptr,
size_t new_size,
size_t old_size,
void *user)
135 if (old->
size >= new_size)
return old->data;
145 static void user_free(
void *ptr,
size_t size,
void *user)
157 char *memory = malloc(
size);
161 .memory_start = memory,
162 .memory_cursor = memory,
163 .memory_end = memory +
size,
183 .fn_malloc = user_malloc,
184 .fn_realloc = user_realloc,
185 .fn_free = user_free,
199 #define CHECK_LOG(logger, fmt) \
202 int log_ok = check_reports(logger, report_config, fmt); \
203 if (log_ok != CT_EXIT_OK) \
222 const char *name = argv[1];
249 .text_config = text_config,
256 CTASSERTF(start < argc,
"no files to parse");
258 for (
int i = start; i < argc; i++)
260 const char *path = argv[i];
261 const char *ext =
str_ext(path, arena);
262 CTASSERTF(ext != NULL,
"no extension for file `%s`", path);
264 CTASSERTF(lang != NULL,
"no language for extension `%s`", ext);
266 io_t *io = make_file(path, eOsAccessRead, arena);
273 for (
size_t stage = 0; stage <
ePassCount; stage++)
304 .
layout = eFileLayoutFlat,
312 CHECK_LOG(logger,
"emitting cfamily ssa");
315 emit_options_t base_options = {
324 ssa_emit_options_t emit_options = {.opts = base_options};
326 ssa_emit_result_t ssa_emit_result = emit_ssa(&emit_options);
331 c89_emit_options_t c89_emit_options = {.opts = base_options};
333 c89_emit_result_t c89_emit_result = emit_c89(&c89_emit_options);
342 msg_notify(logger, &kEvent_FailedToCreateOutputDirectory, node,
343 "failed to create output directory");
345 CHECK_LOG(logger,
"creating output directory");
348 if (result.
path != NULL)
350 msg_notify(logger, &kEvent_FailedToWriteOutputFile, node,
"failed to sync %s",
353 CHECK_LOG(logger,
"syncing output directory");
357 for (
size_t i = 0; i < len; i++)
370 char *cmd =
str_format(arena,
"cl /nologo /WX /W2 /c %s /I%s\\include /Fo%s\\",
str_join(
" ", sources, arena), run_dir, lib_dir);
371 int status = system(cmd);
374 msg_notify(logger, &kEvent_FailedToWriteOutputFile, node,
375 "compilation failed `%d`", status);
378 # define CC_FLAGS "-Werror -Wno-format-contains-nul -Wno-unused-variable -Wno-unused-function"
380 int status = system(cmd);
383 msg_notify(logger, &kEvent_FailedToWriteOutputFile, node,
384 "compilation failed %d", WEXITSTATUS(status));
395 int main(
int argc,
const char **argv)
399 size_t size = (size_t)(1024U * 1024U * 64U);
401 arena_t user = new_alloc(&arena);
CT_OS_API char * os_cwd_string(arena_t *arena)
get the current working directory
CT_NODISCARD STA_RET_STRING CT_OS_API char * os_error_string(os_error_t error, arena_t *arena)
convert an os error code to a string
os_access_t
file access mode
int main(int argc, const char **argv)
#define STA_FIELD_SIZE(of)
annotate a field as being an array of of elements
CT_NOALIAS CT_BASE_API void * ctu_memcpy(STA_WRITES(size) void *CT_RESTRICT dst, STA_READS(size) const void *CT_RESTRICT src, size_t size)
copy memory from one location to another equivalent to memcpy but with safety checks
CT_NODISCARD CT_PUREFN CT_BASE_API size_t ctu_strlen(const char *str)
get the length of a string not including the null terminator equivalent to strlen but with safety che...
CT_BROKER_API const node_t * broker_get_node(broker_t *broker)
CT_BROKER_API emit_result_t target_emit_ssa(target_runtime_t *runtime, const ssa_result_t *ssa, target_emit_t *emit)
CT_BROKER_API void broker_parse(language_runtime_t *runtime, io_t *io)
CT_BROKER_API void broker_run_pass(broker_t *broker, broker_pass_t pass)
CT_BROKER_API void broker_resolve(broker_t *broker)
CT_BROKER_API void broker_deinit(broker_t *broker)
CT_BROKER_API broker_t * broker_new(const frontend_t *frontend, arena_t *arena)
CT_CONSTFN CT_BROKER_API const char * broker_pass_name(broker_pass_t pass)
extra stuff
CT_BROKER_API void broker_init(broker_t *broker)
CT_BROKER_API vector_t * broker_get_modules(broker_t *broker)
get all the modules in the broker this does not include the root module
CT_BROKER_API logger_t * broker_get_logger(broker_t *broker)
CT_BEGIN_API CT_CHECK_API void check_tree(logger_t *reports, vector_t *mods, arena_t *arena)
check the tree form IR all found errors are reported to the reports object
CT_FORMAT_API const colour_pallete_t kColourNone
a colour pallete that applies no colours
#define CT_NATIVE_PATH_SEPARATOR
#define CT_NEW_VERSION(major, minor, patch)
creates a new ctu_version_t from major, minor and patch
#define CT_EXIT_OK
no user errors or internal errors
CT_NODISCARD CT_FS_API fs_t * fs_virtual(const char *name, arena_t *arena)
create a virtual filesystem interface
CT_NODISCARD CT_FS_API fs_t * fs_physical(const char *root, arena_t *arena)
create a filesystem interface to a physical location on disk
CT_FS_API sync_result_t fs_sync(fs_t *dst, fs_t *src)
synchronize 2 filesystems copies all folders and files from src to dst
CT_MEMORY_API void init_gmp_arena(arena_t *arena)
initialize gmp with a custom allocator
CT_MEMORY_API void init_global_arena(arena_t *arena)
initialize the global memory arena
CT_NODISCARD CT_IO_API io_t * io_file(const char *path, os_access_t mode, arena_t *arena)
create an IO object from a file
CT_NODISCARD CT_IO_API os_error_t io_error(const io_t *io)
get the last error from the io object
CT_IO_API io_t * io_stdout(void)
get the global stdout IO object
CT_SUPPORT_API language_runtime_t * support_get_lang(support_t *support, const char *ext)
CT_SUPPORT_API void support_load_default_modules(support_t *support)
load all default modules
CT_SUPPORT_API bool support_load_module(support_t *support, module_type_t mask, const char *name, loaded_module_t *out)
CT_SUPPORT_API target_runtime_t * support_get_target(support_t *support, const char *name)
CT_SUPPORT_API support_t * support_new(broker_t *broker, loader_t *loader, arena_t *arena)
create a support instance from an existing loader and broker configures the broker with the modules i...
CT_BASE_API void ctu_log_update(bool enable)
update the verbosity of the logging system
#define CT_ALIGN_POW2(X, ALIGN)
#define CT_UNUSED(x)
mark a variable as unused
CT_NOTIFY_API event_builder_t msg_notify(INOUT_NOTNULL logger_t *logs, const diagnostic_t *diagnostic, const node_t *node, STA_FORMAT_STRING const char *fmt,...)
notify the logger of a new message
CT_NOTIFY_API void logger_reset(logger_t *logs)
reset the loggers messages
CT_NODISCARD CT_NOTIFY_API typevec_t * logger_get_events(const logger_t *logs)
get the events from the logger
#define CTASSERT(expr)
assert a condition, prints the condition as a message
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
CT_SETUP_API void setup_default(arena_t *arena)
initialise the runtime with default options
CT_SSA_API void ssa_opt(logger_t *reports, ssa_result_t mod, arena_t *arena)
Optimize a given module.
CT_SSA_API ssa_result_t ssa_compile(vector_t *mods, arena_t *arena)
compile a set of trees into their ssa form
CT_NODISCARD CT_STD_API char * str_ext(const char *path, arena_t *arena)
get the last file extension from a path
CT_NODISCARD CT_STD_API char * str_join(const char *sep, const vector_t *parts, arena_t *arena)
join strings
CT_NODISCARD CT_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from a vector
CT_NODISCARD CT_STD_API vector_t * vector_of(size_t len, arena_t *arena)
create a new vector with a specified length
CT_STD_API void vector_set(vector_t *vector, size_t index, void *value)
set a value in a vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t vector_len(const vector_t *vector)
get the length of a vector
CT_SUPPORT_API loader_t * loader_new(arena_t *arena)
CT_SUPPORT_API const char * load_error_string(load_error_t error)
CT_OS_API os_error_t os_dir_create(const char *path)
check if a directory exists
STA_DECL char * str_format(arena_t *arena, const char *fmt,...)
const char * name
the name of the allocator
bool zeroth_line
the zeroth line of a file is the first line
the frontend running the mediator
module_info_t info
information about the frontend
const char * id
unique id for the module
a position in a source file
text_format_t report_format
the result of a fs_sync call this is here because we cant use Compiler message notification in the fs...
const char * path
the file that failed to sync
a generic vector of pointers
CT_STATIC_ASSERT(sizeof(user_ptr_t)==16, "user_ptr_t must be 16 byte aligned")
#define CHECK_LOG(logger, fmt)
int run_test_harness(int argc, const char **argv, arena_t *arena)