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#include "config.h"
22
24#define TOKEN_AT(i) (((Token *)tokens.data)[(i)])
25#define MAX_TOKENS 300
26
27#define BAR_WIDTH 40
28
30#define DEBUG_ARENA_ALLOC 1
31
42
47typedef struct {
48 const char *filepath;
49 const char *name;
50 const char *target_os;
51 bool save;
52 bool clean;
54 bool format; // Add format flag
55 bool format_check; // Add format check flag
56 bool format_in_place; // Add in-place formatting flag
57 bool lsp_mode; // Run as Language Server
58 bool is_document; // generate the docs
60 GrowableArray files; // Change from char** to GrowableArray
61 size_t file_count; // Keep for convenience, or remove and use files.count
62 int opt_level; // 0, 1, 2, or
63
67
68typedef struct {
69 clock_t start_time;
70 clock_t end_time;
71 double elapsed_ms;
73
74bool check_argc(int argc, int expected);
75const char *read_file(const char *filename);
76
77int print_help();
78int print_version();
79int print_license();
80
81const char *detect_target_os(void);
82
83AstNode *lex_and_parse_file(const char *path, ArenaAllocator *allocator,
84 BuildConfig *config);
85
86bool PathExist(const char *p);
87bool PathIsDir(const char *p);
88bool parse_args(int argc, char *argv[], BuildConfig *config,
89 ArenaAllocator *arena);
90bool run_build(BuildConfig config, ArenaAllocator *allocator);
91bool run_formatter(BuildConfig config,
92 ArenaAllocator *allocator); // Add formatter function
93
94void print_token(const Token *t);
95
96void print_progress(int step, int total, const char *stage);
98
99void timer_start(CompileTimer *timer);
100void timer_stop(CompileTimer *timer);
102void print_progress_with_time(int step, int total, const char *stage,
103 CompileTimer *timer);
104
105bool link_with_ld(const char *obj_filename, const char *exe_filename);
106bool get_gcc_file_path(const char *filename, char *buffer, size_t buffer_size);
107bool get_lib_paths(char *buffer, size_t buffer_size);
108bool link_with_ld_simple(const char *obj_filename, const char *exe_filename);
109bool link_object_files(const char *output_dir, const char *executable_name,
110 int opt_level, bool is_debug, CodeGenContext *ctx);
112void save_module_output_files(CodeGenContext *ctx, const char *output_dir);
bool PathIsDir(const char *p)
Definition help.c:151
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:528
bool parse_args(int argc, char *argv[], BuildConfig *config, ArenaAllocator *arena)
Parses command-line arguments and configures the build.
Definition help.c:261
const char * detect_target_os(void)
Definition help.c:209
bool get_gcc_file_path(const char *filename, char *buffer, size_t buffer_size)
Get a file path from gcc.
Definition help.c:611
void save_module_output_files(CodeGenContext *ctx, const char *output_dir)
Definition run.c:45
ErrorCode
Definition help.h:33
@ MEMORY_ERROR
Definition help.h:36
@ RUNTIME_ERROR
Definition help.h:39
@ ARGC_ERROR
Definition help.h:34
@ FILE_ERROR
Definition help.h:35
@ UNKNOWN_ERROR
Definition help.h:40
@ PARSER_ERROR
Definition help.h:38
@ LEXER_ERROR
Definition help.h:37
AstNode * lex_and_parse_file(const char *path, ArenaAllocator *allocator, BuildConfig *config)
Definition run.c:418
int print_license()
Prints license information.
Definition help.c:127
void print_token(const Token *t)
Prints a token's text and its token type with color formatting.
Definition help.c:380
void timer_stop(CompileTimer *timer)
Definition help.c:767
void ensure_clean_line()
Definition help.c:760
void print_progress(int step, int total, const char *stage)
Definition help.c:735
bool get_lib_paths(char *buffer, size_t buffer_size)
Get the system's library search paths.
Definition help.c:643
bool link_with_ld_simple(const char *obj_filename, const char *exe_filename)
Alternative simpler linking approach using system()
Definition help.c:670
bool link_object_files(const char *output_dir, const char *executable_name, int opt_level, bool is_debug, CodeGenContext *ctx)
Definition run.c:262
bool run_formatter(BuildConfig config, ArenaAllocator *allocator)
Definition help.c:159
bool validate_module_system(CodeGenContext *ctx)
int print_help()
Prints help message describing usage and options.
Definition help.c:73
double timer_get_elapsed_ms(CompileTimer *timer)
Definition help.c:773
const char * read_file(const char *filename)
Reads entire file content into a newly allocated buffer.
Definition help.c:43
int print_version()
Prints version information.
Definition help.c:117
bool run_build(BuildConfig config, ArenaAllocator *allocator)
Definition run.c:466
void print_progress_with_time(int step, int total, const char *stage, CompileTimer *timer)
Definition help.c:778
bool PathExist(const char *p)
Definition help.c:145
bool check_argc(int argc, int expected)
Checks if the number of command-line arguments is at least expected.
Definition help.c:27
void timer_start(CompileTimer *timer)
Definition help.c:765
Arena allocator structure.
Definition memory.h:101
Definition ast.h:142
Configuration structure to hold build options parsed from CLI.
Definition help.h:47
bool format_check
Definition help.h:55
GrowableArray files
Definition help.h:60
bool check_mem
Definition help.h:53
int opt_level
Definition help.h:62
GrowableArray tokens
Definition help.h:64
bool format_in_place
Definition help.h:56
bool is_document
Definition help.h:58
const char * target_os
Definition help.h:50
const char * filepath
Definition help.h:48
bool lsp_mode
Definition help.h:57
bool save
Definition help.h:51
bool is_debug
Definition help.h:59
bool format
Definition help.h:54
size_t file_count
Definition help.h:61
bool clean
Definition help.h:52
size_t token_count
Definition help.h:65
const char * name
Definition help.h:49
Definition llvm.h:104
Definition help.h:68
clock_t end_time
Definition help.h:70
clock_t start_time
Definition help.h:69
double elapsed_ms
Definition help.h:71
Growable array backed by an arena allocator.
Definition memory.h:112
Represents a single token extracted by the lexer.
Definition lexer.h:151