added proper handling of arguments
This commit is contained in:
parent
fcbfb548c3
commit
33988beb10
130
src/cfg/opt.c
130
src/cfg/opt.c
|
@ -6,6 +6,84 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <io/files.h>
|
#include <io/files.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
static GHashTable* args = NULL;
|
||||||
|
|
||||||
|
static void clean(void) {
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer key, value;
|
||||||
|
g_hash_table_iter_init(&iter, args);
|
||||||
|
|
||||||
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
|
free(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_destroy(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_options(int argc, char* argv[]) {
|
||||||
|
args = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
atexit(clean);
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
Option* option = malloc(sizeof(Option));
|
||||||
|
option->is_opt = g_str_has_prefix(argv[i], "--");
|
||||||
|
option->string = argv[i] + (option->is_opt ? 2 : 0);
|
||||||
|
option->index = i;
|
||||||
|
option->value = NULL;
|
||||||
|
|
||||||
|
char* equals = strchr(argv[i], '=');
|
||||||
|
if (equals != NULL) {
|
||||||
|
option->value = equals;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_insert(args, (gpointer) option->string, (gpointer) option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_option_set(const char* option) {
|
||||||
|
assert(option != NULL);
|
||||||
|
assert(args != NULL);
|
||||||
|
return g_hash_table_contains(args, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Option* get_option(const char* option) {
|
||||||
|
if (g_hash_table_contains(args, option)) {
|
||||||
|
return g_hash_table_lookup(args, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GArray* get_non_options_after(const char* command) {
|
||||||
|
const Option* command_option = get_option(command);
|
||||||
|
|
||||||
|
if (command_option == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GArray* array = g_array_new(FALSE, FALSE, sizeof(const char*));
|
||||||
|
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer key, value;
|
||||||
|
g_hash_table_iter_init(&iter, args);
|
||||||
|
|
||||||
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
|
Option* option = (Option*) value;
|
||||||
|
if (!option->is_opt && command_option->index < option->index) {
|
||||||
|
g_array_append_val(array, option->string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array->len == 0) {
|
||||||
|
g_array_free(array, FALSE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
TargetConfig* default_target_config() {
|
TargetConfig* default_target_config() {
|
||||||
DEBUG("generating default target config...");
|
DEBUG("generating default target config...");
|
||||||
|
@ -25,32 +103,44 @@ TargetConfig* default_target_config() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetConfig* default_target_config_from_args(int argc, char *argv[]) {
|
TargetConfig* default_target_config_from_args() {
|
||||||
DEBUG("generating default target from command line...");
|
DEBUG("generating default target from command line...");
|
||||||
|
|
||||||
TargetConfig* config = default_target_config();
|
TargetConfig* config = default_target_config();
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++) {
|
if (is_option_set("print-ast")) {
|
||||||
DEBUG("processing argument: %ld %s", i, argv[i]);
|
config->print_ast = true;
|
||||||
char *option = argv[i];
|
} else if (is_option_set("print-asm")) {
|
||||||
|
config->print_asm = true;
|
||||||
|
} else if (is_option_set("print-ir")) {
|
||||||
|
config->print_ir = true;
|
||||||
|
} else if (is_option_set("mode")) {
|
||||||
|
const Option* opt = get_option("mode");
|
||||||
|
|
||||||
if (strcmp(option, "--print-ast") == 0) {
|
if (opt->value != NULL) {
|
||||||
config->print_ast = true;
|
if (strcmp(opt->value, "app") == 0) {
|
||||||
} else if (strcmp(option, "--print-asm") == 0) {
|
config->mode = Application;
|
||||||
config->print_asm = true;
|
} else if (strcmp(opt->value, "lib") == 0) {
|
||||||
} else if (strcmp(option, "--print-ir") == 0) {
|
config->mode = Library;
|
||||||
config->print_ir = true;
|
} else {
|
||||||
} else if (strcmp(option, "--mode=app") == 0) {
|
print_message(Warning, "Invalid compilation mode: %s", opt->value);
|
||||||
config->mode = Application;
|
}
|
||||||
} else if (strcmp(option, "--mode=lib") == 0) {
|
|
||||||
config->mode = Library;
|
|
||||||
} else if (config->root_module == NULL) {
|
|
||||||
config->root_module = strdup(option);
|
|
||||||
} else {
|
|
||||||
print_message(Warning, "Got more than one file to compile, using first by ignoring others.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GArray* files = get_non_options_after("compile");
|
||||||
|
|
||||||
|
if (files == NULL) {
|
||||||
|
print_message(Error, "No input file provided.");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (files->len > 1) {
|
||||||
|
print_message(Warning, "Got more than one file to compile, using first, ignoring others.");
|
||||||
|
}
|
||||||
|
|
||||||
|
config->root_module = strdup( ((char**) files->data) [0]);
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +156,9 @@ void print_help(void) {
|
||||||
" --print-ast print resulting abstract syntax tree to a file",
|
" --print-ast print resulting abstract syntax tree to a file",
|
||||||
" --print-asm print resulting assembly language to a file",
|
" --print-asm print resulting assembly language to a file",
|
||||||
" --print-ir print resulting LLVM-IR to a file",
|
" --print-ir print resulting LLVM-IR to a file",
|
||||||
" --mode=[app|lib] set the compilation mode to either application or library"
|
" --mode=[app|lib] set the compilation mode to either application or library",
|
||||||
|
" --verbose print logs with level information or higher",
|
||||||
|
" --debug print debug logs (if not disabled at compile time)"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(lines) / sizeof(const char *); i++) {
|
for (unsigned int i = 0; i < sizeof(lines) / sizeof(const char *); i++) {
|
||||||
|
|
|
@ -52,11 +52,18 @@ typedef struct ProjectConfig_t {
|
||||||
GHashTable* targets;
|
GHashTable* targets;
|
||||||
} ProjectConfig;
|
} ProjectConfig;
|
||||||
|
|
||||||
|
typedef struct Option_t {
|
||||||
|
int index;
|
||||||
|
const char* string;
|
||||||
|
const char* value;
|
||||||
|
bool is_opt;
|
||||||
|
} Option;
|
||||||
|
|
||||||
TargetConfig* default_target_config();
|
TargetConfig* default_target_config();
|
||||||
|
|
||||||
ProjectConfig* default_project_config();
|
ProjectConfig* default_project_config();
|
||||||
|
|
||||||
TargetConfig* default_target_config_from_args(int argc, char* argv[]);
|
TargetConfig* default_target_config_from_args();
|
||||||
|
|
||||||
int load_project_config(ProjectConfig *config);
|
int load_project_config(ProjectConfig *config);
|
||||||
|
|
||||||
|
@ -66,4 +73,16 @@ void delete_project_config(ProjectConfig* config);
|
||||||
|
|
||||||
void delete_target_config(TargetConfig*);
|
void delete_target_config(TargetConfig*);
|
||||||
|
|
||||||
|
void parse_options(int argc, char* argv[]);
|
||||||
|
|
||||||
|
[[gnu::nonnull(1)]]
|
||||||
|
bool is_option_set(const char* option);
|
||||||
|
|
||||||
|
[[gnu::nonnull(1)]]
|
||||||
|
const Option* get_option(const char* option);
|
||||||
|
|
||||||
|
[[gnu::nonnull(1)]]
|
||||||
|
[[nodiscard("must be freed")]]
|
||||||
|
GArray* get_non_options_after(const char* command);
|
||||||
|
|
||||||
#endif //GEMSTONE_OPT_H
|
#endif //GEMSTONE_OPT_H
|
||||||
|
|
|
@ -160,10 +160,10 @@ static void build_target(ModuleFileStack *unit, TargetConfig *target) {
|
||||||
* @param argc
|
* @param argc
|
||||||
* @param argv
|
* @param argv
|
||||||
*/
|
*/
|
||||||
static void compile_file(ModuleFileStack *unit, int argc, char *argv[]) {
|
static void compile_file(ModuleFileStack *unit) {
|
||||||
INFO("compiling basic files...");
|
INFO("compiling basic files...");
|
||||||
|
|
||||||
TargetConfig *target = default_target_config_from_args(argc, argv);
|
TargetConfig *target = default_target_config_from_args();
|
||||||
|
|
||||||
if (target->root_module == NULL) {
|
if (target->root_module == NULL) {
|
||||||
print_message(Error, "No input file specified.");
|
print_message(Error, "No input file specified.");
|
||||||
|
@ -180,11 +180,9 @@ static void compile_file(ModuleFileStack *unit, int argc, char *argv[]) {
|
||||||
* @brief Build all project targets specified by the command line arguments.
|
* @brief Build all project targets specified by the command line arguments.
|
||||||
* @param unit
|
* @param unit
|
||||||
* @param config
|
* @param config
|
||||||
* @param argc
|
|
||||||
* @param argv
|
|
||||||
*/
|
*/
|
||||||
static void build_project_targets(ModuleFileStack *unit, ProjectConfig *config, int argc, char *argv[]) {
|
static void build_project_targets(ModuleFileStack *unit, ProjectConfig *config) {
|
||||||
if (argc == 1 && strcmp(argv[0], "all") == 0) {
|
if (is_option_set("all")) {
|
||||||
// build all targets in the project
|
// build all targets in the project
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
|
|
||||||
|
@ -195,52 +193,51 @@ static void build_project_targets(ModuleFileStack *unit, ProjectConfig *config,
|
||||||
while (g_hash_table_iter_next(&iter, (gpointer) &key, (gpointer) &val)) {
|
while (g_hash_table_iter_next(&iter, (gpointer) &key, (gpointer) &val)) {
|
||||||
build_target(unit, val);
|
build_target(unit, val);
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
// build all targets given in the arguments
|
}
|
||||||
for (int i = 0; i < argc; i++) {
|
|
||||||
char *target_name = argv[i];
|
// build all targets given in the arguments
|
||||||
|
GArray* targets = get_non_options_after("build");
|
||||||
|
|
||||||
|
if (targets != NULL) {
|
||||||
|
for (guint i = 0; i < targets->len; i++) {
|
||||||
|
const char *target_name = (((Option*) targets->data) + i)->string;
|
||||||
|
|
||||||
if (g_hash_table_contains(config->targets, target_name)) {
|
if (g_hash_table_contains(config->targets, target_name)) {
|
||||||
build_target(unit, g_hash_table_lookup(config->targets, target_name));
|
build_target(unit, g_hash_table_lookup(config->targets, target_name));
|
||||||
|
} else {
|
||||||
|
print_message(Error, "Unknown target: %s", target_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_array_free(targets, FALSE);
|
||||||
|
} else {
|
||||||
|
print_message(Error, "No targets specified.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Build targets from project. Configuration is provided by command line arguments.
|
* @brief Build targets from project. Configuration is provided by command line arguments.
|
||||||
* @param unit File storage
|
* @param unit File storage
|
||||||
* @param argc Number of arguments
|
|
||||||
* @param argv Array of Arguments
|
|
||||||
*/
|
*/
|
||||||
static void build_project(ModuleFileStack *unit, int argc, char *argv[]) {
|
static void build_project(ModuleFileStack *unit) {
|
||||||
if (argc <= 0) {
|
|
||||||
print_message(Error, "No targets specified.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectConfig *config = default_project_config();
|
ProjectConfig *config = default_project_config();
|
||||||
int err = load_project_config(config);
|
int err = load_project_config(config);
|
||||||
|
|
||||||
if (err == PROJECT_OK) {
|
if (err == PROJECT_OK) {
|
||||||
build_project_targets(unit, config, argc, argv);
|
build_project_targets(unit, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_project_config(config);
|
delete_project_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_compiler(int argc, char *argv[]) {
|
void run_compiler() {
|
||||||
if (argc <= 0) {
|
|
||||||
INFO("no arguments provided");
|
|
||||||
print_help();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ModuleFileStack files = new_file_stack();
|
ModuleFileStack files = new_file_stack();
|
||||||
|
|
||||||
if (strcmp(argv[0], "build") == 0) {
|
if (is_option_set("build")) {
|
||||||
build_project(&files, argc - 1, &argv[1]);
|
build_project(&files);
|
||||||
} else if (strcmp(argv[0], "compile") == 0) {
|
} else if (is_option_set("compile")) {
|
||||||
compile_file(&files, argc - 1, &argv[1]);
|
compile_file(&files);
|
||||||
} else {
|
} else {
|
||||||
print_message(Error, "Invalid mode of operation. Rerun with --help.");
|
print_message(Error, "Invalid mode of operation. Rerun with --help.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Run the gemstone compiler with the provided command arguments.
|
* @brief Run the gemstone compiler with the provided command arguments.
|
||||||
* @param argc
|
|
||||||
* @param argv
|
|
||||||
*/
|
*/
|
||||||
void run_compiler(int argc, char *argv[]);
|
void run_compiler();
|
||||||
|
|
||||||
#endif //GEMSTONE_COMPILER_H
|
#endif //GEMSTONE_COMPILER_H
|
||||||
|
|
13
src/main.c
13
src/main.c
|
@ -4,6 +4,7 @@
|
||||||
#include <sys/col.h>
|
#include <sys/col.h>
|
||||||
#include <lex/util.h>
|
#include <lex/util.h>
|
||||||
#include <io/files.h>
|
#include <io/files.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
#include <compiler.h>
|
#include <compiler.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,8 +17,9 @@ void notify_exit(void) { DEBUG("Exiting gemstone..."); }
|
||||||
* @brief Run compiler setup here
|
* @brief Run compiler setup here
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void setup(void) {
|
void setup(int argc, char *argv[]) {
|
||||||
// setup preample
|
// setup preample
|
||||||
|
parse_options(argc, argv);
|
||||||
|
|
||||||
log_init();
|
log_init();
|
||||||
DEBUG("starting gemstone...");
|
DEBUG("starting gemstone...");
|
||||||
|
@ -37,11 +39,16 @@ void setup(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
setup();
|
if (argc <= 1) {
|
||||||
|
print_help();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(argc, argv);
|
||||||
|
|
||||||
print_message(Info, "Running GSC version %s", GSC_VERSION);
|
print_message(Info, "Running GSC version %s", GSC_VERSION);
|
||||||
|
|
||||||
run_compiler(argc - 1, &argv[1]);
|
run_compiler();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,29 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
static struct Logger_t {
|
static struct Logger_t {
|
||||||
FILE** streams;
|
FILE** streams;
|
||||||
size_t stream_count;
|
size_t stream_count;
|
||||||
} GlobalLogger;
|
} GlobalLogger;
|
||||||
|
|
||||||
void log_init(void)
|
int runtime_log_level = LOG_LEVEL_WARNING;
|
||||||
|
|
||||||
|
void set_log_level(int level)
|
||||||
{
|
{
|
||||||
|
runtime_log_level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_init()
|
||||||
|
{
|
||||||
|
if (is_option_set("verbose")) {
|
||||||
|
set_log_level(LOG_LEVEL_INFORMATION);
|
||||||
|
} else if (is_option_set("debug")) {
|
||||||
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
assert(LOG_DEFAULT_STREAM != NULL);
|
assert(LOG_DEFAULT_STREAM != NULL);
|
||||||
log_register_stream(LOG_DEFAULT_STREAM);
|
log_register_stream(LOG_DEFAULT_STREAM);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +45,7 @@ void log_register_stream(FILE* restrict stream)
|
||||||
if (GlobalLogger.streams == NULL)
|
if (GlobalLogger.streams == NULL)
|
||||||
{
|
{
|
||||||
PANIC("failed to allocate stream buffer");
|
PANIC("failed to allocate stream buffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,12 +53,22 @@ will not print.
|
||||||
#define INFO(format, ...) __LOG(LOG_STRING_INFORMATION, LOG_LEVEL_INFORMATION, format"\n", ##__VA_ARGS__)
|
#define INFO(format, ...) __LOG(LOG_STRING_INFORMATION, LOG_LEVEL_INFORMATION, format"\n", ##__VA_ARGS__)
|
||||||
#define DEBUG(format, ...) __LOG(LOG_STRING_DEBUG, LOG_LEVEL_DEBUG, format"\n", ##__VA_ARGS__)
|
#define DEBUG(format, ...) __LOG(LOG_STRING_DEBUG, LOG_LEVEL_DEBUG, format"\n", ##__VA_ARGS__)
|
||||||
|
|
||||||
|
extern int runtime_log_level;
|
||||||
|
|
||||||
#define __LOG(level, priority, format, ...) \
|
#define __LOG(level, priority, format, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (LOG_LEVEL <= priority) \
|
if (LOG_LEVEL <= priority) \
|
||||||
syslog_logf(level, __FILE_NAME__, __LINE__, __func__, format, ##__VA_ARGS__); \
|
if (runtime_log_level <= priority) \
|
||||||
|
syslog_logf(level, __FILE_NAME__, __LINE__, __func__, format, ##__VA_ARGS__); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the runtime log level. Must be one of: LOG_LEVEL_ERROR, LOG_LEVEL_WARNING,
|
||||||
|
* LOG_LEVEL_INFORMATION, LOG_LEVEL_DEBUG
|
||||||
|
* @param level the new log level
|
||||||
|
*/
|
||||||
|
void set_log_level(int level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log a message into all registered streams
|
* @brief Log a message into all registered streams
|
||||||
*
|
*
|
||||||
|
|
|
@ -10,6 +10,12 @@ find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# ------------------------------------------------ #
|
||||||
|
# Setup TOML-C99 #
|
||||||
|
# ------------------------------------------------ #
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/dep/tomlc99)
|
||||||
|
|
||||||
# ------------------------------------------------------- #
|
# ------------------------------------------------------- #
|
||||||
# CTEST 1
|
# CTEST 1
|
||||||
# test building the syntax tree
|
# test building the syntax tree
|
||||||
|
@ -19,6 +25,8 @@ add_executable(ast_build_tree
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/io/files.c
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/dep/tomlc99/toml.c
|
||||||
build_tree.c)
|
build_tree.c)
|
||||||
set_target_properties(ast_build_tree
|
set_target_properties(ast_build_tree
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
@ -38,6 +46,8 @@ add_executable(ast_print_node
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/io/files.c
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/dep/tomlc99/toml.c
|
||||||
print_node.c)
|
print_node.c)
|
||||||
set_target_properties(ast_print_node
|
set_target_properties(ast_print_node
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
@ -57,6 +67,8 @@ add_executable(ast_graphviz
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/io/files.c
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/dep/tomlc99/toml.c
|
||||||
print_graphviz.c)
|
print_graphviz.c)
|
||||||
set_target_properties(ast_graphviz
|
set_target_properties(ast_graphviz
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
|
|
@ -12,7 +12,7 @@ def check_accept():
|
||||||
|
|
||||||
test_file_name = sys.argv[1]
|
test_file_name = sys.argv[1]
|
||||||
|
|
||||||
p = subprocess.run(["./gsc", test_file_name], capture_output=True, text=True)
|
p = subprocess.run(["./gsc", "compile", test_file_name], capture_output=True, text=True)
|
||||||
|
|
||||||
assert p.returncode == 0
|
assert p.returncode == 0
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ def check_abort():
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
p = subprocess.run("./gsc", capture_output=True, text=True)
|
p = subprocess.run(["./gsc", "compile"], capture_output=True, text=True)
|
||||||
|
|
||||||
assert p.returncode == 1
|
assert p.returncode == 1
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,13 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
|
include_directories(PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# ------------------------------------------------ #
|
||||||
|
# Setup TOML-C99 #
|
||||||
|
# ------------------------------------------------ #
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/dep/tomlc99)
|
||||||
|
|
||||||
# ------------------------------------------------------- #
|
# ------------------------------------------------------- #
|
||||||
# CTEST 1
|
# CTEST 1
|
||||||
|
@ -16,11 +23,15 @@ pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||||
add_executable(logging_output
|
add_executable(logging_output
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
output.c)
|
output.c)
|
||||||
set_target_properties(logging_output
|
set_target_properties(logging_output
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "output"
|
OUTPUT_NAME "output"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
||||||
|
target_link_libraries(logging_output PkgConfig::GLIB)
|
||||||
|
target_link_libraries(logging_output tomlc99)
|
||||||
add_test(NAME logging_output
|
add_test(NAME logging_output
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output)
|
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_output)
|
||||||
|
@ -32,11 +43,15 @@ add_test(NAME logging_output
|
||||||
add_executable(logging_panic
|
add_executable(logging_panic
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
panic.c)
|
panic.c)
|
||||||
set_target_properties(logging_panic
|
set_target_properties(logging_panic
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "panic"
|
OUTPUT_NAME "panic"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
||||||
|
target_link_libraries(logging_panic PkgConfig::GLIB)
|
||||||
|
target_link_libraries(logging_panic tomlc99)
|
||||||
add_test(NAME logging_panic
|
add_test(NAME logging_panic
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic)
|
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_panic)
|
||||||
|
@ -48,11 +63,15 @@ add_test(NAME logging_panic
|
||||||
add_executable(logging_streams
|
add_executable(logging_streams
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
streams.c)
|
streams.c)
|
||||||
set_target_properties(logging_streams
|
set_target_properties(logging_streams
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "stream"
|
OUTPUT_NAME "stream"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
||||||
|
target_link_libraries(logging_streams PkgConfig::GLIB)
|
||||||
|
target_link_libraries(logging_streams tomlc99)
|
||||||
add_test(NAME logging_streams
|
add_test(NAME logging_streams
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_stream)
|
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_stream)
|
||||||
|
@ -64,11 +83,15 @@ add_test(NAME logging_streams
|
||||||
add_executable(logging_level
|
add_executable(logging_level
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
${PROJECT_SOURCE_DIR}/src/sys/log.c
|
||||||
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
${PROJECT_SOURCE_DIR}/src/sys/col.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/cfg/opt.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/io/files.c
|
||||||
level.c)
|
level.c)
|
||||||
set_target_properties(logging_level
|
set_target_properties(logging_level
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
OUTPUT_NAME "level"
|
OUTPUT_NAME "level"
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
|
||||||
|
target_link_libraries(logging_level PkgConfig::GLIB)
|
||||||
|
target_link_libraries(logging_level tomlc99)
|
||||||
add_test(NAME logging_level
|
add_test(NAME logging_level
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_level)
|
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_level)
|
||||||
|
|
|
@ -4,11 +4,14 @@
|
||||||
|
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#include <sys/col.h>
|
#include <sys/col.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
#define LOG_LEVEL LOG_LEVEL_WARNING
|
#define LOG_LEVEL LOG_LEVEL_WARNING
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char* argv[]) {
|
||||||
|
parse_options(argc, argv);
|
||||||
log_init();
|
log_init();
|
||||||
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
col_init();
|
col_init();
|
||||||
|
|
||||||
DEBUG("logging some debug...");
|
DEBUG("logging some debug...");
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
|
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#include <sys/col.h>
|
#include <sys/col.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char* argv[]) {
|
||||||
|
parse_options(argc, argv);
|
||||||
log_init();
|
log_init();
|
||||||
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
col_init();
|
col_init();
|
||||||
|
|
||||||
DEBUG("logging some debug...");
|
DEBUG("logging some debug...");
|
||||||
|
|
|
@ -3,9 +3,12 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char* argv[]) {
|
||||||
|
parse_options(argc, argv);
|
||||||
log_init();
|
log_init();
|
||||||
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
// this should appear in stderr
|
// this should appear in stderr
|
||||||
INFO("before exit");
|
INFO("before exit");
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <cfg/opt.h>
|
||||||
|
|
||||||
static FILE* file;
|
static FILE* file;
|
||||||
|
|
||||||
|
@ -13,8 +14,10 @@ void close_file(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char* argv[]) {
|
||||||
|
parse_options(argc, argv);
|
||||||
log_init();
|
log_init();
|
||||||
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
// this should appear in stderr
|
// this should appear in stderr
|
||||||
INFO("should only be in stderr");
|
INFO("should only be in stderr");
|
||||||
|
|
Loading…
Reference in New Issue