Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
help.h File Reference

Declarations for command-line parsing, file reading, and build configuration. More...

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../ast/ast.h"
#include "../c_libs/memory/memory.h"
#include "../lexer/lexer.h"
#include "../llvm/llvm.h"
Include dependency graph for help.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BuildConfig
 Configuration structure to hold build options parsed from CLI. More...
 
struct  CompileTimer
 

Macros

#define TOKEN_AT(i)   (((Token *)tokens.data)[(i)])
 
#define MAX_TOKENS   300
 
#define BAR_WIDTH   40
 
#define DEBUG_ARENA_ALLOC   1
 
#define Luma_Compiler_version   "v0.2.6"
 

Enumerations

enum  ErrorCode {
  ARGC_ERROR = 1 , FILE_ERROR = 2 , MEMORY_ERROR = 3 , LEXER_ERROR = 4 ,
  PARSER_ERROR = 5 , RUNTIME_ERROR = 6 , UNKNOWN_ERROR = 99
}
 

Functions

bool check_argc (int argc, int expected)
 Checks if the number of command-line arguments is at least expected.
 
const char * read_file (const char *filename)
 Reads entire file content into a newly allocated buffer.
 
int print_help ()
 Prints help message describing usage and options.
 
int print_version ()
 Prints version information.
 
int print_license ()
 Prints license information.
 
const char * detect_target_os (void)
 
AstNodelex_and_parse_file (const char *path, ArenaAllocator *allocator, BuildConfig *config)
 
bool PathExist (const char *p)
 
bool PathIsDir (const char *p)
 
bool parse_args (int argc, char *argv[], BuildConfig *config, ArenaAllocator *arena)
 Parses command-line arguments and configures the build.
 
bool run_build (BuildConfig config, ArenaAllocator *allocator)
 
bool run_formatter (BuildConfig config, ArenaAllocator *allocator)
 
void print_token (const Token *t)
 Prints a token's text and its token type with color formatting.
 
void print_progress (int step, int total, const char *stage)
 
void ensure_clean_line ()
 
void timer_start (CompileTimer *timer)
 
void timer_stop (CompileTimer *timer)
 
double timer_get_elapsed_ms (CompileTimer *timer)
 
void print_progress_with_time (int step, int total, const char *stage, CompileTimer *timer)
 
bool link_with_ld (const char *obj_filename, const char *exe_filename)
 Links object file using ld to create an executable (Unix/Linux)
 
bool get_gcc_file_path (const char *filename, char *buffer, size_t buffer_size)
 Get a file path from gcc.
 
bool get_lib_paths (char *buffer, size_t buffer_size)
 Get the system's library search paths.
 
bool link_with_ld_simple (const char *obj_filename, const char *exe_filename)
 Alternative simpler linking approach using system()
 
bool link_object_files (const char *output_dir, const char *executable_name, int opt_level, bool is_debug, CodeGenContext *ctx)
 
bool validate_module_system (CodeGenContext *ctx)
 
void save_module_output_files (CodeGenContext *ctx, const char *output_dir)
 

Detailed Description

Declarations for command-line parsing, file reading, and build configuration.

Provides functions to parse arguments, read files, print help/version/license, and print token debug info.

Macro Definition Documentation

◆ BAR_WIDTH

#define BAR_WIDTH   40

◆ DEBUG_ARENA_ALLOC

#define DEBUG_ARENA_ALLOC   1

Enable debug logs for arena allocator (comment to disable)

◆ Luma_Compiler_version

#define Luma_Compiler_version   "v0.2.6"

◆ MAX_TOKENS

#define MAX_TOKENS   300

◆ TOKEN_AT

#define TOKEN_AT (   i)    (((Token *)tokens.data)[(i)])

Macro to access token at index in a token growable array

Enumeration Type Documentation

◆ ErrorCode

enum ErrorCode

Error codes returned by the compiler

Enumerator
ARGC_ERROR 
FILE_ERROR 
MEMORY_ERROR 
LEXER_ERROR 
PARSER_ERROR 
RUNTIME_ERROR 
UNKNOWN_ERROR 

Function Documentation

◆ check_argc()

bool check_argc ( int  argc,
int  expected 
)

Checks if the number of command-line arguments is at least expected.

Prints usage info if not enough arguments.

Parameters
argcActual argument count.
expectedMinimum expected argument count.
Returns
true if argc >= expected, false otherwise.

◆ detect_target_os()

const char * detect_target_os ( void  )

◆ ensure_clean_line()

void ensure_clean_line ( )

◆ get_gcc_file_path()

bool get_gcc_file_path ( const char *  filename,
char *  buffer,
size_t  buffer_size 
)

Get a file path from gcc.

Parameters
filenameThe filename to search for
bufferBuffer to store the result
buffer_sizeSize of the buffer
Returns
true if path was found, false otherwise

◆ get_lib_paths()

bool get_lib_paths ( char *  buffer,
size_t  buffer_size 
)

Get the system's library search paths.

Parameters
bufferBuffer to store library paths
buffer_sizeSize of the buffer
Returns
true if paths were found

◆ lex_and_parse_file()

AstNode * lex_and_parse_file ( const char *  path,
ArenaAllocator allocator,
BuildConfig config 
)

◆ link_object_files()

bool link_object_files ( const char *  output_dir,
const char *  executable_name,
int  opt_level,
bool  is_debug,
CodeGenContext ctx 
)

◆ link_with_ld()

bool link_with_ld ( const char *  obj_filename,
const char *  exe_filename 
)

Links object file using ld to create an executable (Unix/Linux)

Parameters
obj_filenamePath to the object file
exe_filenamePath for the output executable
Returns
true if linking succeeded, false otherwise

◆ link_with_ld_simple()

bool link_with_ld_simple ( const char *  obj_filename,
const char *  exe_filename 
)

Alternative simpler linking approach using system()

Parameters
obj_filenamePath to the object file
exe_filenamePath for the output executable
Returns
true if linking succeeded, false otherwise

◆ parse_args()

bool parse_args ( int  argc,
char *  argv[],
BuildConfig config,
ArenaAllocator arena 
)

Parses command-line arguments and configures the build.

Supports options for version, help, license, build, save, clean, and debug.

Parameters
argcArgument count.
argvArgument vector.
configPointer to BuildConfig struct to fill.
Returns
false if help/version/license was printed or error occurred, true otherwise.

◆ PathExist()

bool PathExist ( const char *  p)

◆ PathIsDir()

bool PathIsDir ( const char *  p)

◆ print_help()

int print_help ( )

Prints help message describing usage and options.

Returns
Always returns 0.

◆ print_license()

int print_license ( )

Prints license information.

Returns
Always returns 0.

◆ print_progress()

void print_progress ( int  step,
int  total,
const char *  stage 
)

◆ print_progress_with_time()

void print_progress_with_time ( int  step,
int  total,
const char *  stage,
CompileTimer timer 
)

◆ print_token()

void print_token ( const Token t)

Prints a token's text and its token type with color formatting.

Parameters
tPointer to the Token to print.

◆ print_version()

int print_version ( )

Prints version information.

Returns
Always returns 0.

◆ read_file()

const char * read_file ( const char *  filename)

Reads entire file content into a newly allocated buffer.

The caller must free the returned buffer.

Parameters
filenamePath to the file to read.
Returns
Pointer to null-terminated file content, or NULL on failure.

◆ run_build()

bool run_build ( BuildConfig  config,
ArenaAllocator allocator 
)

◆ run_formatter()

bool run_formatter ( BuildConfig  config,
ArenaAllocator allocator 
)

◆ save_module_output_files()

void save_module_output_files ( CodeGenContext ctx,
const char *  output_dir 
)

◆ timer_get_elapsed_ms()

double timer_get_elapsed_ms ( CompileTimer timer)

◆ timer_start()

void timer_start ( CompileTimer timer)

◆ timer_stop()

void timer_stop ( CompileTimer timer)

◆ validate_module_system()

bool validate_module_system ( CodeGenContext ctx)