36 .
id =
"frontend/example",
37 .name =
"Example Frontend",
40 .desc =
"Example compiler frontend",
41 .author =
"Elliot Haisley",
60 #define CHECK_LOG(logger, fmt) \
63 int err = check_reports(logger, report_config, fmt); \
64 if (err != CT_EXIT_OK) \
84 int main(
int argc,
const char **argv)
110 .text_config = text_config,
115 for (
int i = 1; i < argc; i++)
117 const char *path = argv[i];
120 const char *ext =
str_ext(path, arena);
124 io_printf(con,
"no language found for file: %s\n", path);
127 io_t *io = make_file(logger, path, eOsAccessRead, arena);
136 for (
size_t pass = 0; pass <
ePassCount; pass++)
161 .
layout = eFileLayoutFlat,
175 CHECK_LOG(logger,
"emitting cfamily ssa");
178 for (
size_t i = 0; i < len; i++)
187 msg_notify(logger, &kEvent_FailedToCreateOutputDirectory, node,
"failed to create output directory");
189 CHECK_LOG(logger,
"creating output directory");
192 if (result.
path != NULL)
194 msg_notify(logger, &kEvent_FailedToWriteOutputFile, node,
"failed to sync %s", result.
path);
196 CHECK_LOG(logger,
"syncing output 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 CHECK_LOG(logger, fmt)
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 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 kColourDefault
a colour pallete that applies ANSI VT100 colours
#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_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_IO_API size_t io_printf(io_t *io, STA_FORMAT_STRING const char *fmt,...)
printf to an 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 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_NODISCARD CT_SCAN_API node_t * node_builtin(const char *name, arena_t *arena)
get the builtin node node used for drivers that declare builtin symbols
CT_BASE_API void ctu_log_update(bool enable)
update the verbosity of the logging system
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
#define CTASSERT(expr)
assert a condition, prints the condition as a message
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_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_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
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