42 .name =
"Cthulhu CLI",
45 .desc =
"Cthulhu Compiler Collection CLI",
46 .author =
"Elliot Haisley",
57 const char *ext =
str_ext(path, arena);
60 msg_notify(reports, &kEvent_NoFileExtension, node,
61 "could not identify compiler for `%s` (no extension)", path);
70 "could not identify compiler for `%s` by extension `%s`", basepath,
72 msg_note(
id,
"extra extensions can be provided with -ext=id:ext");
81 "failed to open source `%s`", path);
126 ctu_log(
"loaded language module `%s`", path);
134 static bool on_add_plugin(
ap_t *ap,
const cfg_field_t *param,
const void *value,
void *data)
139 return add_shared_module(data, value, eModPlugin);
142 static bool on_add_target(
ap_t *ap,
const cfg_field_t *param,
const void *value,
void *data)
147 return add_shared_module(data, value, eModTarget);
150 static bool on_add_language(
ap_t *ap,
const cfg_field_t *param,
const void *value,
void *data)
155 return add_shared_module(data, value, eModLanguage);
158 #define CHECK_LOG(logger, fmt) \
161 int err = check_reports(logger, report_config, fmt); \
162 if (err != CT_EXIT_OK) \
168 int main(
int argc,
const char **argv)
216 .text_config = text_config,
224 if (total_sources == 0)
226 msg_notify(reports, &kEvent_NoSourceFiles, node,
"no source files provided");
231 for (
size_t i = 0; i < total_sources; i++)
234 parse_source(broker, support, path);
239 for (
size_t pass = 0; pass <
ePassCount; pass++)
264 target_output =
"cfamily";
271 msg_notify(reports, &kEvent_InvalidTarget, node,
272 "could not identify target `%s`", target_output);
279 msg_notify(reports, &kEvent_FailedToCreateOutputDirectory, node,
280 "failed to create output directory `%s`", output_dir);
283 CHECK_LOG(reports,
"creating output directory");
291 CHECK_LOG(reports,
"emitting target ssa");
294 emit_options_t base_emit_options = {
305 ssa_emit_options_t emit_options = {.opts = base_emit_options};
307 emit_ssa(&emit_options);
311 c89_emit_options_t c89_emit_options = {
312 .opts = base_emit_options,
314 c89_emit_result_t c89_emit_result = emit_c89(&c89_emit_options);
tool_t make_tool(version_info_t version, arena_t *arena)
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
int main(int argc, const char **argv)
#define CHECK_LOG(logger, fmt)
CT_ARGPARSE_API void ap_event(ap_t *self, const cfg_field_t *param, ap_event_t callback, void *data)
add a callback event to a parameter
CT_ARGPARSE_API vector_t * ap_get_posargs(ap_t *self)
get all positional arguments
CT_BACKTRACE_API void bt_update(void)
update the loaded module cache
CT_NODISCARD CT_PUREFN CT_BASE_API bool str_equal(const char *lhs, const char *rhs)
compare strings equality
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 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 arena_t * broker_get_arena(broker_t *broker)
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 kColourDefault
a colour pallete that applies ANSI VT100 colours
CT_PUREFN CT_CONFIG_API const char * cfg_string_value(const cfg_field_t *field)
get the current string value of a configuration field
CT_PUREFN CT_CONFIG_API bool cfg_bool_value(const cfg_field_t *field)
get the current boolean value of a configuration field
CT_PUREFN CT_CONFIG_API int cfg_int_value(const cfg_field_t *field)
get the current integer value of a configuration field
CT_PUREFN CT_CONFIG_API size_t cfg_enum_value(const cfg_field_t *field)
get the current enum value of a configuration field
#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_physical(const char *root, arena_t *arena)
create a filesystem interface to a physical location on disk
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(STA_FORMAT_STRING const char *fmt,...)
log a message
#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_NOTIFY_API void msg_note(event_builder_t builder, STA_FORMAT_STRING const char *fmt,...)
add a note to an existing message
CT_NODISCARD CT_NOTIFY_API typevec_t * logger_get_events(const logger_t *logs)
get the events from the logger
CT_SETUP_API setup_init_t setup_parse(int argc, const char **argv, setup_options_t setup)
parse the command line
CT_PUREFN CT_SETUP_API bool setup_should_exit(const setup_init_t *init)
accessor functions
CT_SETUP_API void setup_default(arena_t *arena)
initialise the runtime with default options
CT_BEGIN_API CT_SETUP_API arena_t * ctu_default_alloc(void)
get the default allocator
CT_PUREFN CT_SETUP_API int setup_exit_code(const setup_init_t *init)
get the exit code
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_filename(const char *path, arena_t *arena)
get the filename from a path
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_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from 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)
STA_DECL char * str_format(arena_t *arena, const char *fmt,...)
an event builder handles adding additional information to an event
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
version_info_t version
the version of the module
const char * id
unique id for the module
a position in a source file
text_format_t report_format
the result of parsing the command line
a generic vector of pointers