Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
help.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <stdbool.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <time.h>
16
17#include "../ast/ast.h"
18#include "../c_libs/memory/memory.h"
19#include "../lexer/lexer.h"
20#include "../llvm/llvm.h"
21
23#define TOKEN_AT(i) (((Token *)tokens.data)[(i)])
24#define MAX_TOKENS 300
25
26#define BAR_WIDTH 40
27
29#define DEBUG_ARENA_ALLOC 1
30
31#define Luma_Compiler_version "v0.2.6"
32
43
48typedef struct {
49 const char *filepath;
50 const char *name;
51 const char *target_os;
52 bool save;
53 bool clean;
55 bool format; // Add format flag
56 bool format_check; // Add format check flag
57 bool format_in_place; // Add in-place formatting flag
58 bool lsp_mode; // Run as Language Server
59 bool is_document; // generate the docs
61 GrowableArray files; // Change from char** to GrowableArray
62 size_t file_count; // Keep for convenience, or remove and use files.count
63 int opt_level; // 0, 1, 2, or
64
68
69typedef struct {
70 clock_t start_time;
71 clock_t end_time;
72 double elapsed_ms;
74
75bool check_argc(int argc, int expected);
76const char *read_file(const char *filename);
77
78int print_help();
79int print_version();
80int print_license();
81
82const char *detect_target_os(void);
83
84AstNode *lex_and_parse_file(const char *path, ArenaAllocator *allocator,
85 BuildConfig *config);
86
87bool PathExist(const char *p);
88bool PathIsDir(const char *p);
89bool parse_args(int argc, char *argv[], BuildConfig *config,
90 ArenaAllocator *arena);
91bool run_build(BuildConfig config, ArenaAllocator *allocator);
92bool run_formatter(BuildConfig config,
93 ArenaAllocator *allocator); // Add formatter function
94
95void print_token(const Token *t);
96
97void print_progress(int step, int total, const char *stage);
99
100void timer_start(CompileTimer *timer);
101void timer_stop(CompileTimer *timer);
103void print_progress_with_time(int step, int total, const char *stage,
104 CompileTimer *timer);
105
106bool link_with_ld(const char *obj_filename, const char *exe_filename);
107bool get_gcc_file_path(const char *filename, char *buffer, size_t buffer_size);
108bool get_lib_paths(char *buffer, size_t buffer_size);
109bool link_with_ld_simple(const char *obj_filename, const char *exe_filename);
110bool link_object_files(const char *output_dir, const char *executable_name,
111 int opt_level, bool is_debug, CodeGenContext *ctx);
113void save_module_output_files(CodeGenContext *ctx, const char *output_dir);
bool PathIsDir(const char *p)
Definition help.c:158
bool link_with_ld(const char *obj_filename, const char *exe_filename)
Links object file using ld to create an executable (Unix/Linux)
Definition help.c:535
bool parse_args(int argc, char *argv[], BuildConfig *config, ArenaAllocator *arena)
Parses command-line arguments and configures the build.
Definition help.c:268
const char * detect_target_os(void)
Definition help.c:216
bool get_gcc_file_path(const char *filename, char *buffer, size_t buffer_size)
Get a file path from gcc.
Definition help.c:618
void save_module_output_files(CodeGenContext *ctx, const char *output_dir)
Definition run.c:45
ErrorCode
Definition help.h:34
@ MEMORY_ERROR
Definition help.h:37
@ RUNTIME_ERROR
Definition help.h:40
@ ARGC_ERROR
Definition help.h:35
@ FILE_ERROR
Definition help.h:36
@ UNKNOWN_ERROR
Definition help.h:41
@ PARSER_ERROR
Definition help.h:39
@ LEXER_ERROR
Definition help.h:38
AstNode * lex_and_parse_file(const char *path, ArenaAllocator *allocator, BuildConfig *config)
Definition run.c:402
int print_license()
Prints license information.
Definition help.c:134
void print_token(const Token *t)
Prints a token's text and its token type with color formatting.
Definition help.c:387
void timer_stop(CompileTimer *timer)
Definition help.c:774
void ensure_clean_line()
Definition help.c:767
void print_progress(int step, int total, const char *stage)
Definition help.c:742
bool get_lib_paths(char *buffer, size_t buffer_size)
Get the system's library search paths.
Definition help.c:650
bool link_with_ld_simple(const char *obj_filename, const char *exe_filename)
Alternative simpler linking approach using system()
Definition help.c:677
bool link_object_files(const char *output_dir, const char *executable_name, int opt_level, bool is_debug, CodeGenContext *ctx)
Definition run.c:248
bool run_formatter(BuildConfig config, ArenaAllocator *allocator)
Definition help.c:166
bool validate_module_system(CodeGenContext *ctx)
int print_help()
Prints help message describing usage and options.
Definition help.c:80
double timer_get_elapsed_ms(CompileTimer *timer)
Definition help.c:780
const char * read_file(const char *filename)
Reads entire file content into a newly allocated buffer.
Definition help.c:50
int print_version()
Prints version information.
Definition help.c:124
bool run_build(BuildConfig config, ArenaAllocator *allocator)
Definition run.c:450
void print_progress_with_time(int step, int total, const char *stage, CompileTimer *timer)
Definition help.c:785
bool PathExist(const char *p)
Definition help.c:152
bool check_argc(int argc, int expected)
Checks if the number of command-line arguments is at least expected.
Definition help.c:34
void timer_start(CompileTimer *timer)
Definition help.c:772
Arena allocator structure.
Definition memory.h:101
Definition ast.h:142
Configuration structure to hold build options parsed from CLI.
Definition help.h:48
bool format_check
Definition help.h:56
GrowableArray files
Definition help.h:61
bool check_mem
Definition help.h:54
int opt_level
Definition help.h:63
GrowableArray tokens
Definition help.h:65
bool format_in_place
Definition help.h:57
bool is_document
Definition help.h:59
const char * target_os
Definition help.h:51
const char * filepath
Definition help.h:49
bool lsp_mode
Definition help.h:58
bool save
Definition help.h:52
bool is_debug
Definition help.h:60
bool format
Definition help.h:55
size_t file_count
Definition help.h:62
bool clean
Definition help.h:53
size_t token_count
Definition help.h:66
const char * name
Definition help.h:50
Definition llvm.h:98
Definition help.h:69
clock_t end_time
Definition help.h:71
clock_t start_time
Definition help.h:70
double elapsed_ms
Definition help.h:72
Growable array backed by an arena allocator.
Definition memory.h:112
Represents a single token extracted by the lexer.
Definition lexer.h:151