Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
llvm.h
Go to the documentation of this file.
1// Enhanced llvm.h - Complete module system declarations
2#pragma once
3// LLVM C API Headers
4#include <llvm-c/Analysis.h>
5#include <llvm-c/BitWriter.h>
6#include <llvm-c/Core.h>
7#include <llvm-c/ExecutionEngine.h>
8#include <llvm-c/Target.h>
9#include <llvm-c/TargetMachine.h>
10#include <llvm-c/DebugInfo.h>
11
12// Standard Library Headers
13#include <llvm-c/Types.h>
14#include <stdalign.h>
15#include <stdbool.h>
16#include <stdint.h>
17#include <stdio.h>
18#include <string.h>
19
20// Project Headers
21#include "../ast/ast.h"
22#include "../c_libs/memory/memory.h"
23
24#define SYMBOL_HASH_SIZE 1024
25#define MAX_LINK_LIBS 64
26
27typedef struct LLVM_Symbol LLVM_Symbol;
30
32 char *name;
33 LLVMValueRef value;
34 LLVMTypeRef type; // The type of the symbol itself
35 LLVMTypeRef element_type; // For pointer types, what it points to
38};
39
40// Individual module compilation unit
43 LLVMModuleRef module;
47
50
51 LLVMDIBuilderRef dibuilder;
52 LLVMMetadataRef compile_unit;
53 LLVMMetadataRef file_metadata;
54};
55
56typedef struct ModuleDependencyInfo {
57 const char *module_name;
58 char **dependencies; // Array of module names this depends on
59 size_t dep_count;
62
68
69typedef struct StructInfo {
70 char *name;
71 LLVMTypeRef llvm_type;
73 LLVMTypeRef *field_types;
74 LLVMTypeRef *field_element_types;
80
81typedef struct CommonTypes {
82 // Integer types
83 LLVMTypeRef i1, i8, i16, i32, i64;
84
85 // Float types
86 LLVMTypeRef f32, f64;
87
88 // Special types
89 LLVMTypeRef void_type;
90 LLVMTypeRef i8_ptr;
91
92 // Common constants (cached for performance)
93 LLVMValueRef const_i32_0, const_i32_1;
94 LLVMValueRef const_i64_0, const_i64_1;
96
97// Code generation context
99 // LLVM Core Components
100 LLVMContextRef context;
101 LLVMBuilderRef builder;
102
103 // Module Management (New System)
106
107 // Legacy Support (for backward compatibility)
108 LLVMModuleRef module;
109
110 // Defer statement tracking
114
115 // Code Generation State
116 LLVMValueRef current_function;
117 LLVMBasicBlockRef loop_continue_block;
118 LLVMBasicBlockRef loop_break_block;
119
122
123 const char *target_os;
124
125 // Debug Info
127 LLVMMetadataRef current_func_di;
128
129 // Memory Management
131};
132
133typedef struct SymbolHashEntry {
134 const char *key; // "module_name:symbol_name"
138
142
143// Hash table for struct types
149
153
154// =============================================================================
155// MODULE MANAGEMENT FUNCTIONS
156// =============================================================================
157
158// Create a new module compilation unit
160 const char *module_name);
161
162// Find module by name
164 const char *module_name);
165
166// Set current module for code generation
168
169// Compile all modules to separate object files
170bool compile_modules_to_objects(CodeGenContext *ctx, const char *output_dir);
171
172// Generate external function declarations for cross-module calls
174 ModuleCompilationUnit *target_module);
176StructInfo *find_struct_type_fast(CodeGenContext *ctx, const char *name);
177void cleanup_module_caches(void);
178void debug_object_files(const char *output_dir);
180 StructInfo *base_info,
181 const char *field_name);
182
183unsigned int hash_string(const char *str);
184
185void init_symbol_cache(void);
186void cache_symbol(const char *module_name, const char *symbol_name,
187 LLVM_Symbol *symbol);
188LLVM_Symbol *lookup_cached_symbol(const char *module_name,
189 const char *symbol_name);
190
191void init_struct_cache(void);
192void cache_struct(const char *name, StructInfo *info);
193StructInfo *lookup_cached_struct(const char *name);
194StructInfo *find_struct_type_fast(CodeGenContext *ctx, const char *name);
196 AstNode *node);
197
198// =============================================================================
199// SYMBOL IMPORT AND MODULE INTEROP
200// =============================================================================
201
202// Import symbols from one module to another
204 ModuleCompilationUnit *source_module,
205 const char *alias);
206
207// Import specific function symbol
208void import_function_symbol(CodeGenContext *ctx, LLVM_Symbol *source_symbol,
209 ModuleCompilationUnit *source_module,
210 const char *alias);
211
212// Import specific variable symbol
213void import_variable_symbol(CodeGenContext *ctx, LLVM_Symbol *source_symbol,
214 ModuleCompilationUnit *source_module,
215 const char *alias);
216
217// Enhanced symbol lookup with module support
219 const char *name);
220
221// Debug info support
223 const char *filename);
226void set_debug_location(CodeGenContext *ctx, unsigned line, unsigned column);
227
228// =============================================================================
229// MODULE UTILITY FUNCTIONS
230// =============================================================================
231
232// Check if module is the main module
234
235// Set a module as the main module
237
238// Print module information for debugging
240void debug_object_files(const char *output_dir);
241
242// =============================================================================
243// ENHANCED CORE API FUNCTIONS
244// =============================================================================
245
246// Context Management
249
250// Enhanced Symbol Table Operations (now module-aware)
251void add_symbol_to_module(ModuleCompilationUnit *module, const char *name,
252 LLVMValueRef value, LLVMTypeRef type,
253 bool is_function);
255 const char *name);
256LLVM_Symbol *find_symbol_global(CodeGenContext *ctx, const char *name,
257 const char *module_name);
258
259// Main Code Generation
261 const char *output_dir);
262
263// Object File Generation (per module)
265 const char *output_path, bool is_debug);
266
267// Existing API (preserved for compatibility)
268void add_symbol(CodeGenContext *ctx, const char *name, LLVMValueRef value,
269 LLVMTypeRef type, bool is_function);
270LLVM_Symbol *find_symbol(CodeGenContext *ctx, const char *name);
271char *print_llvm_ir(CodeGenContext *ctx);
272bool generate_object_file(CodeGenContext *ctx, const char *object_filename);
273bool generate_assembly_file(CodeGenContext *ctx, const char *asm_filename,
274 bool is_debug);
275char *process_escape_sequences(const char *input);
276LLVMLinkage get_function_linkage(AstNode *node);
277
279LLVMTypeRef get_int_type(CodeGenContext *ctx, unsigned bits);
280LLVMTypeRef get_float_type(CodeGenContext *ctx, bool is_double);
281LLVMValueRef get_const_int(CodeGenContext *ctx, unsigned bits, uint64_t value);
282bool is_int_type(LLVMTypeRef type);
283bool is_float_type(LLVMTypeRef type);
284bool pointer_type(LLVMTypeRef type);
285bool types_are_equal(LLVMTypeRef a, LLVMTypeRef b);
286bool needs_conversion(LLVMTypeRef from, LLVMTypeRef to);
287LLVMValueRef get_default_value(LLVMTypeRef type);
288
289LLVMValueRef alloca_and_store(CodeGenContext *ctx, LLVMTypeRef type,
290 LLVMValueRef value, const char *name);
291LLVMValueRef struct_gep_load(CodeGenContext *ctx, LLVMTypeRef struct_type,
292 LLVMValueRef ptr, unsigned index,
293 LLVMTypeRef element_type, const char *name);
294void struct_gep_store(CodeGenContext *ctx, LLVMTypeRef struct_type,
295 LLVMValueRef ptr, unsigned index, LLVMValueRef value);
296LLVMValueRef array_gep(CodeGenContext *ctx, LLVMTypeRef array_type,
297 LLVMValueRef array_ptr, LLVMValueRef index,
298 const char *name);
299bool block_has_terminator(LLVMBuilderRef builder);
300void branch_if_no_terminator(CodeGenContext *ctx, LLVMBasicBlockRef target);
301LLVMValueRef build_global_string(CodeGenContext *ctx, const char *str,
302 const char *name);
303
304LLVMValueRef codegen_module_access(CodeGenContext *ctx, AstNode *node);
305bool is_module_identifier(CodeGenContext *ctx, const char *name);
306bool validate_module_access(CodeGenContext *ctx, const char *prefix,
307 const char *symbol_name);
308const char *get_module_name_from_access(AstNode *node);
309
310// =============================================================================
311// ENHANCED STRUCT SUPPORT FUNCTIONS
312// =============================================================================
313
314// Core struct management
315StructInfo *find_struct_type(CodeGenContext *ctx, const char *name);
316void add_struct_type(CodeGenContext *ctx, StructInfo *struct_info);
317int get_field_index(StructInfo *struct_info, const char *field_name);
319 int field_index);
321 CodeGenContext *ctx,
322 StructInfo *base_info,
323 const char *field_name);
324LLVMValueRef codegen_struct_method(CodeGenContext *ctx, AstNode *func_node,
325 StructInfo *struct_info,
326 const char *method_name, bool is_public,
327 bool is_static);
328
329// Struct literal/initializer support
330LLVMValueRef codegen_struct_literal(CodeGenContext *ctx,
331 const char *struct_name,
332 LLVMValueRef *field_values,
333 size_t field_count);
334
335// =============================================================================
336// STRUCT TYPE SYSTEM INTEGRATION
337// =============================================================================
338
339// Enhanced type checking for structs
340bool is_struct_type(CodeGenContext *ctx, LLVMTypeRef type);
341const char *get_struct_name_from_type(CodeGenContext *ctx, LLVMTypeRef type);
342
343// Struct construction helpers
345 const char *struct_name);
346LLVMValueRef create_struct_copy(CodeGenContext *ctx, LLVMValueRef src_struct,
347 StructInfo *struct_info);
348
349// Struct debugging and introspection
350void print_struct_info(CodeGenContext *ctx, const char *struct_name);
351void debug_struct_layout(CodeGenContext *ctx, const char *struct_name);
352
353StructInfo *find_struct_type(CodeGenContext *ctx, const char *name);
354void add_struct_type(CodeGenContext *ctx, StructInfo *struct_info);
355LLVMValueRef codegen_stmt_struct(CodeGenContext *ctx, AstNode *node);
356LLVMValueRef codegen_stmt_field(CodeGenContext *ctx, AstNode *node);
357LLVMValueRef codegen_expr_struct_access(CodeGenContext *ctx, AstNode *node);
358LLVMTypeRef codegen_type_struct(CodeGenContext *ctx, const char *struct_name);
359
360// =============================================================================
361// AST NODE HANDLERS - PUBLIC INTERFACE
362// =============================================================================
363
364// Primary Dispatch Functions
365LLVMValueRef codegen_expr(CodeGenContext *ctx, AstNode *node);
366LLVMValueRef codegen_stmt(CodeGenContext *ctx, AstNode *node);
367LLVMTypeRef codegen_type(CodeGenContext *ctx, AstNode *node);
368
369// Enhanced handlers for module system
371 AstNode *node);
372LLVMValueRef codegen_stmt_module(CodeGenContext *ctx, AstNode *node);
373LLVMValueRef codegen_stmt_use(CodeGenContext *ctx, AstNode *node);
374LLVMValueRef codegen_stmt_os(CodeGenContext *ctx, AstNode *node);
375LLVMValueRef codegen_stmt_link(CodeGenContext *ctx, AstNode *node);
376
377// =============================================================================
378// AST NODE HANDLERS - EXPRESSION TYPES
379// =============================================================================
380
381LLVMValueRef convert_value_to_type(CodeGenContext *ctx, LLVMValueRef value,
382 LLVMTypeRef from_type, LLVMTypeRef to_type);
384 AstNode *base_expr,
385 AstNode **indices,
386 size_t index_count);
387void copy_array_elements(CodeGenContext *ctx, LLVMValueRef dest_array,
388 LLVMTypeRef dest_type, LLVMValueRef src_array,
389 LLVMTypeRef src_type);
390
391// Enhanced symbol management with element type support
392void add_symbol_with_element_type(CodeGenContext *ctx, const char *name,
393 LLVMValueRef value, LLVMTypeRef type,
394 LLVMTypeRef element_type, bool is_function);
395
397 ModuleCompilationUnit *module, const char *name, LLVMValueRef value,
398 LLVMTypeRef type, LLVMTypeRef element_type, bool is_function);
399
400// Helper function to extract element type from AST
402 AstNode *type_node);
403
404LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node);
405LLVMValueRef codegen_expr_identifier(CodeGenContext *ctx, AstNode *node);
406LLVMValueRef codegen_expr_binary(CodeGenContext *ctx, AstNode *node);
407LLVMValueRef codegen_expr_unary(CodeGenContext *ctx, AstNode *node);
408LLVMValueRef codegen_expr_call(CodeGenContext *ctx, AstNode *node);
409LLVMValueRef codegen_expr_assignment(CodeGenContext *ctx, AstNode *node);
410LLVMValueRef codegen_expr_array(CodeGenContext *ctx, AstNode *node);
411LLVMValueRef codegen_expr_index(CodeGenContext *ctx, AstNode *node);
412LLVMValueRef codegen_expr_cast(CodeGenContext *ctx, AstNode *node);
413LLVMValueRef codegen_expr_input(CodeGenContext *ctx, AstNode *node);
414LLVMValueRef codegen_expr_system(CodeGenContext *ctx, AstNode *node);
415LLVMValueRef codegen_expr_syscall(CodeGenContext *ctx, AstNode *node);
416LLVMValueRef codegen_expr_sizeof(CodeGenContext *ctx, AstNode *node);
417LLVMValueRef codegen_expr_alloc(CodeGenContext *ctx, AstNode *node);
418LLVMValueRef codegen_expr_free(CodeGenContext *ctx, AstNode *node);
419LLVMValueRef codegen_expr_deref(CodeGenContext *ctx, AstNode *node);
420LLVMValueRef codegen_expr_addr(CodeGenContext *ctx, AstNode *node);
421LLVMValueRef codegen_expr_struct_literal(CodeGenContext *ctx, AstNode *node);
422
423// =============================================================================
424// AST NODE HANDLERS - STATEMENT TYPES
425// =============================================================================
426
427LLVMValueRef codegen_stmt_program(CodeGenContext *ctx, AstNode *node);
428LLVMValueRef codegen_stmt_expression(CodeGenContext *ctx, AstNode *node);
429LLVMValueRef codegen_stmt_var_decl(CodeGenContext *ctx, AstNode *node);
430LLVMValueRef codegen_stmt_function(CodeGenContext *ctx, AstNode *node);
431
434LLVMValueRef codegen_stmt_enum(CodeGenContext *ctx, AstNode *node);
435
436LLVMValueRef codegen_stmt_return(CodeGenContext *ctx, AstNode *node);
437LLVMValueRef codegen_stmt_block(CodeGenContext *ctx, AstNode *node);
438LLVMValueRef codegen_stmt_if(CodeGenContext *ctx, AstNode *node);
439LLVMValueRef codegen_stmt_print(CodeGenContext *ctx, AstNode *node);
440LLVMValueRef codegen_stmt_defer(CodeGenContext *ctx, AstNode *node);
441
442LLVMValueRef codegen_infinite_loop(CodeGenContext *ctx, AstNode *node);
443LLVMValueRef codegen_while_loop(CodeGenContext *ctx, AstNode *node);
444LLVMValueRef codegen_for_loop(CodeGenContext *ctx, AstNode *node);
445LLVMValueRef codegen_loop(CodeGenContext *ctx, AstNode *node);
446
447LLVMValueRef codegen_stmt_break_continue(CodeGenContext *ctx, AstNode *node);
448
449LLVMValueRef codegen_stmt_switch(CodeGenContext *ctx, AstNode *node);
450LLVMValueRef codegen_stmt_case(CodeGenContext *ctx, AstNode *node);
451LLVMValueRef codegen_stmt_default(CodeGenContext *ctx, AstNode *node);
452LLVMValueRef codegen_case_value(CodeGenContext *ctx, AstNode *case_value);
454 AstNode *member_expr);
455
456// =============================================================================
457// DEFER MANAGEMENT FUNCTIONS
458// =============================================================================
459
461void push_defer_statement(CodeGenContext *ctx, AstNode *statement);
463 DeferredStatement *defers);
466
467// =============================================================================
468// RANGE SUPPORT FUNCTIONS - Add this new section
469// =============================================================================
470
471// Range type checking and manipulation
472bool is_range_type(LLVMTypeRef type);
473LLVMValueRef get_range_start_value(CodeGenContext *ctx,
474 LLVMValueRef range_struct);
475LLVMValueRef get_range_end_value(CodeGenContext *ctx,
476 LLVMValueRef range_struct);
477
478// Range creation helper (optional - for consistent range creation)
479LLVMValueRef create_range_struct(CodeGenContext *ctx, LLVMValueRef start,
480 LLVMValueRef end);
482 LLVMTypeRef element_type);
483
484// Range operations (add these if you need them later)
485LLVMValueRef range_contains(CodeGenContext *ctx, LLVMValueRef range_struct,
486 LLVMValueRef value);
487LLVMValueRef range_length(CodeGenContext *ctx, LLVMValueRef range_struct);
488
489// =============================================================================
490// AST NODE HANDLERS - TYPE SYSTEM
491// =============================================================================
492
493LLVMTypeRef codegen_type_basic(CodeGenContext *ctx, AstNode *node);
494LLVMTypeRef codegen_type_pointer(CodeGenContext *ctx, AstNode *node);
495LLVMTypeRef codegen_type_array(CodeGenContext *ctx, AstNode *node);
496LLVMTypeRef codegen_type_function(CodeGenContext *ctx, AstNode *node);
const char * get_module_name_from_access(AstNode *node)
Get module name/alias from a compile-time member access node.
Definition member_access.c:214
LLVMValueRef codegen_expr_struct_assignment(CodeGenContext *ctx, AstNode *node)
Definition struct.c:506
void print_struct_info(CodeGenContext *ctx, const char *struct_name)
Definition struct_helpers.c:94
void debug_struct_layout(CodeGenContext *ctx, const char *struct_name)
Definition struct_helpers.c:144
void add_symbol(CodeGenContext *ctx, const char *name, LLVMValueRef value, LLVMTypeRef type, bool is_function)
Definition llvm.c:390
LLVMValueRef codegen_stmt_program(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:9
LLVMLinkage get_function_linkage(AstNode *node)
Definition llvm.c:572
LLVMValueRef range_length(CodeGenContext *ctx, LLVMValueRef range_struct)
Definition expr.c:62
LLVMValueRef codegen_expr_sizeof(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1900
LLVMValueRef codegen_expr_free(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1949
LLVMValueRef codegen_stmt_print(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:840
void add_symbol_to_module_with_element_type(ModuleCompilationUnit *module, const char *name, LLVMValueRef value, LLVMTypeRef type, LLVMTypeRef element_type, bool is_function)
Definition stmt.c:26
LLVMValueRef create_struct_zero_initializer(CodeGenContext *ctx, const char *struct_name)
Definition struct_helpers.c:37
void debug_object_files(const char *output_dir)
Definition module_handles.c:694
LLVMValueRef codegen_stmt_function(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:166
void add_symbol_with_element_type(CodeGenContext *ctx, const char *name, LLVMValueRef value, LLVMTypeRef type, LLVMTypeRef element_type, bool is_function)
Definition stmt.c:17
LLVMValueRef codegen_while_loop(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1020
void branch_if_no_terminator(CodeGenContext *ctx, LLVMBasicBlockRef target)
Definition helpers.c:43
bool is_main_module(ModuleCompilationUnit *unit)
Definition module_handles.c:669
void init_symbol_cache(void)
Definition module_handles.c:19
bool compile_modules_to_objects(CodeGenContext *ctx, const char *output_dir)
Definition llvm.c:224
LLVMValueRef codegen_expr_identifier(CodeGenContext *ctx, AstNode *node)
Definition expr.c:131
LLVMTypeRef codegen_type_struct(CodeGenContext *ctx, const char *struct_name)
Definition struct.c:639
LLVMValueRef codegen_expr_addr(CodeGenContext *ctx, AstNode *node)
Definition expr.c:2077
void execute_deferred_statements_inline(CodeGenContext *ctx, DeferredStatement *defers)
Definition defer.c:21
LLVMValueRef codegen_case_value(CodeGenContext *ctx, AstNode *case_value)
Definition stmt.c:1269
void init_defer_stack(CodeGenContext *ctx)
Definition defer.c:3
LLVMValueRef codegen_stmt_switch(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1162
int get_field_index(StructInfo *struct_info, const char *field_name)
Definition struct.c:43
LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node)
Definition expr.c:72
void cache_struct(const char *name, StructInfo *info)
Definition module_handles.c:79
bool generate_object_file(CodeGenContext *ctx, const char *object_filename)
Definition llvm.c:536
LLVMValueRef codegen_stmt_defer(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:956
void import_variable_symbol(CodeGenContext *ctx, LLVM_Symbol *source_symbol, ModuleCompilationUnit *source_module, const char *alias)
Definition module_handles.c:573
LLVMValueRef codegen_expr_system(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1502
LLVMValueRef create_range_struct(CodeGenContext *ctx, LLVMValueRef start, LLVMValueRef end)
Definition expr.c:19
void set_module_as_main(ModuleCompilationUnit *unit)
Definition module_handles.c:673
LLVMValueRef codegen_expr_struct_literal(CodeGenContext *ctx, AstNode *node)
Definition struct_expr.c:32
LLVMValueRef codegen_expr_binary(CodeGenContext *ctx, AstNode *node)
Definition binary_ops.c:20
LLVMValueRef codegen_stmt_link(CodeGenContext *ctx, AstNode *node)
Definition module_handles.c:462
bool block_has_terminator(LLVMBuilderRef builder)
Definition helpers.c:37
StructInfo * find_struct_type(CodeGenContext *ctx, const char *name)
Definition struct.c:22
ModuleCompilationUnit * find_module(CodeGenContext *ctx, const char *module_name)
Definition llvm.c:323
LLVMValueRef codegen_expr_array(CodeGenContext *ctx, AstNode *node)
Definition expr.c:711
ModuleCompilationUnit * create_module_unit(CodeGenContext *ctx, const char *module_name)
Definition llvm.c:305
bool is_struct_type(CodeGenContext *ctx, LLVMTypeRef type)
Definition struct_helpers.c:8
LLVMValueRef codegen_stmt_default(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1409
LLVMTypeRef get_float_type(CodeGenContext *ctx, bool is_double)
Definition type_cache.c:47
bool generate_module_object_file(ModuleCompilationUnit *module, const char *output_path, bool is_debug)
Definition llvm.c:166
LLVMValueRef codegen_stmt_break_continue(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:962
LLVMValueRef codegen_for_loop(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1072
LLVMValueRef build_global_string(CodeGenContext *ctx, const char *str, const char *name)
Definition helpers.c:54
LLVMValueRef codegen_expr_deref(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1984
char * print_llvm_ir(CodeGenContext *ctx)
Definition llvm.c:529
void init_type_cache(CodeGenContext *ctx)
Definition type_cache.c:4
void cache_symbol(const char *module_name, const char *symbol_name, LLVM_Symbol *symbol)
Definition module_handles.c:25
LLVMValueRef convert_value_to_type(CodeGenContext *ctx, LLVMValueRef value, LLVMTypeRef from_type, LLVMTypeRef to_type)
Definition arrays.c:4
StructInfo * find_struct_type_fast(CodeGenContext *ctx, const char *name)
Definition module_handles.c:116
LLVMValueRef codegen_struct_literal(CodeGenContext *ctx, const char *struct_name, LLVMValueRef *field_values, size_t field_count)
Definition struct.c:649
LLVMValueRef codegen_stmt(CodeGenContext *ctx, AstNode *node)
Definition lookup.c:63
LLVMValueRef codegen_stmt_enum(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:506
LLVMValueRef get_const_int(CodeGenContext *ctx, unsigned bits, uint64_t value)
Definition type_cache.c:52
LLVMValueRef codegen_expr_cast(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1246
void setup_module_debug_info(CodeGenContext *ctx, ModuleCompilationUnit *unit, const char *filename)
Definition llvm.c:645
CodeGenContext * init_codegen_context(ArenaAllocator *arena)
Definition llvm.c:449
LLVMValueRef alloca_and_store(CodeGenContext *ctx, LLVMTypeRef type, LLVMValueRef value, const char *name)
Definition helpers.c:4
LLVM_Symbol * find_symbol_global(CodeGenContext *ctx, const char *name, const char *module_name)
Definition llvm.c:359
bool is_range_type(LLVMTypeRef type)
Definition stmt.c:779
bool types_are_equal(LLVMTypeRef a, LLVMTypeRef b)
Definition type_cache.c:81
void add_symbol_to_module(ModuleCompilationUnit *module, const char *name, LLVMValueRef value, LLVMTypeRef type, bool is_function)
Definition llvm.c:337
LLVMValueRef codegen_stmt_block(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:623
LLVMTypeRef get_int_type(CodeGenContext *ctx, unsigned bits)
Definition type_cache.c:30
LLVMValueRef codegen_stmt_return(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:549
LLVMValueRef codegen_struct_method(CodeGenContext *ctx, AstNode *func_node, StructInfo *struct_info, const char *method_name, bool is_public, bool is_static)
Definition struct.c:330
void generate_external_declarations(CodeGenContext *ctx, ModuleCompilationUnit *target_module)
Definition llvm.c:401
bool pointer_type(LLVMTypeRef type)
Definition type_cache.c:77
void clear_defer_stack(CodeGenContext *ctx)
Definition defer.c:140
LLVMValueRef codegen_expr(CodeGenContext *ctx, AstNode *node)
Definition lookup.c:3
char * process_escape_sequences(const char *input)
Definition llvm.c:585
#define MAX_LINK_LIBS
Definition llvm.h:25
void cleanup_codegen_context(CodeGenContext *ctx)
Definition llvm.c:485
LLVMValueRef array_gep(CodeGenContext *ctx, LLVMTypeRef array_type, LLVMValueRef array_ptr, LLVMValueRef index, const char *name)
Definition helpers.c:29
LLVM_Symbol * find_symbol(CodeGenContext *ctx, const char *name)
Definition llvm.c:397
void struct_gep_store(CodeGenContext *ctx, LLVMTypeRef struct_type, LLVMValueRef ptr, unsigned index, LLVMValueRef value)
Definition helpers.c:21
LLVMTypeRef codegen_type_function(CodeGenContext *ctx, AstNode *node)
Definition type.c:91
LLVMValueRef get_default_value(LLVMTypeRef type)
Definition type_cache.c:83
void cleanup_module_caches(void)
Definition module_handles.c:142
LLVMValueRef range_contains(CodeGenContext *ctx, LLVMValueRef range_struct, LLVMValueRef value)
Definition expr.c:48
void set_debug_location(CodeGenContext *ctx, unsigned line, unsigned column)
Definition llvm.c:684
LLVMValueRef codegen_expr_assignment(CodeGenContext *ctx, AstNode *node)
Definition expr.c:489
LLVMValueRef codegen_expr_unary(CodeGenContext *ctx, AstNode *node)
Definition expr.c:152
void finalize_all_debug_info(CodeGenContext *ctx)
Definition llvm.c:678
LLVMTypeRef codegen_type_array(CodeGenContext *ctx, AstNode *node)
Definition type.c:76
LLVMValueRef codegen_stmt_case(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1394
void import_function_symbol(CodeGenContext *ctx, LLVM_Symbol *source_symbol, ModuleCompilationUnit *source_module, const char *alias)
Definition module_handles.c:518
LLVMValueRef codegen_stmt_use(CodeGenContext *ctx, AstNode *node)
Definition module_handles.c:373
bool generate_program_modules(CodeGenContext *ctx, AstNode *ast_root, const char *output_dir)
Definition llvm.c:516
LLVMValueRef codegen_stmt_field(CodeGenContext *ctx, AstNode *node)
Definition struct.c:490
LLVMTypeRef codegen_type_pointer(CodeGenContext *ctx, AstNode *node)
Definition type.c:68
bool is_field_access_allowed(CodeGenContext *ctx, StructInfo *struct_info, int field_index)
Definition struct.c:53
void copy_array_elements(CodeGenContext *ctx, LLVMValueRef dest_array, LLVMTypeRef dest_type, LLVMValueRef src_array, LLVMTypeRef src_type)
Definition arrays.c:157
LLVMValueRef codegen_stmt_program_multi_module(CodeGenContext *ctx, AstNode *node)
Definition module_handles.c:280
LLVMValueRef codegen_expr_syscall(CodeGenContext *ctx, AstNode *node)
Generate LLVM IR for syscall expression.
Definition expr.c:1561
void set_current_module(CodeGenContext *ctx, ModuleCompilationUnit *module)
Definition llvm.c:333
LLVMValueRef get_range_end_value(CodeGenContext *ctx, LLVMValueRef range_struct)
Definition stmt.c:819
LLVMTypeRef codegen_type_basic(CodeGenContext *ctx, AstNode *node)
Definition type.c:37
StructInfo * lookup_cached_struct(const char *name)
Definition module_handles.c:100
LLVMValueRef codegen_loop(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:1151
void push_defer_statement(CodeGenContext *ctx, AstNode *statement)
Definition defer.c:9
LLVMValueRef codegen_expr_input(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1331
void add_struct_type(CodeGenContext *ctx, StructInfo *struct_info)
Definition struct.c:37
bool is_enum_constant(LLVM_Symbol *sym)
Definition stmt.c:479
LLVMValueRef codegen_expr_index(CodeGenContext *ctx, AstNode *node)
Definition expr.c:827
bool validate_module_access(CodeGenContext *ctx, const char *prefix, const char *symbol_name)
Validate that a module access is permitted.
Definition member_access.c:239
LLVMValueRef codegen_stmt_if(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:662
LLVMTypeRef get_range_struct_type(CodeGenContext *ctx, LLVMTypeRef element_type)
Definition expr.c:10
bool is_module_identifier(CodeGenContext *ctx, const char *name)
Check if an identifier might be a module/alias.
Definition member_access.c:198
int64_t get_enum_constant_value(LLVM_Symbol *sym)
Definition stmt.c:493
void preprocess_all_modules(CodeGenContext *ctx)
Definition module_handles.c:128
LLVMValueRef struct_gep_load(CodeGenContext *ctx, LLVMTypeRef struct_type, LLVMValueRef ptr, unsigned index, LLVMTypeRef element_type, const char *name)
Definition helpers.c:12
void finalize_module_debug_info(ModuleCompilationUnit *unit)
Definition llvm.c:670
bool needs_conversion(LLVMTypeRef from, LLVMTypeRef to)
Definition type_cache.c:104
LLVMValueRef get_range_start_value(CodeGenContext *ctx, LLVMValueRef range_struct)
Definition stmt.c:799
LLVM_Symbol * find_symbol_with_module_support(CodeGenContext *ctx, const char *name)
Definition module_handles.c:643
void init_struct_cache(void)
Definition module_handles.c:73
LLVMValueRef create_struct_copy(CodeGenContext *ctx, LLVMValueRef src_struct, StructInfo *struct_info)
Definition struct_helpers.c:53
LLVMValueRef codegen_enum_member_case(CodeGenContext *ctx, AstNode *member_expr)
Definition stmt.c:1296
void print_module_info(CodeGenContext *ctx)
Definition module_handles.c:679
LLVMValueRef codegen_multidim_array_access(CodeGenContext *ctx, AstNode *base_expr, AstNode **indices, size_t index_count)
Definition arrays.c:89
LLVMValueRef codegen_expr_struct_access(CodeGenContext *ctx, AstNode *node)
Definition struct_access.c:31
void import_module_symbols(CodeGenContext *ctx, ModuleCompilationUnit *source_module, const char *alias)
Definition module_handles.c:482
void generate_cleanup_blocks(CodeGenContext *ctx)
Definition defer.c:65
LLVMValueRef codegen_expr_call(CodeGenContext *ctx, AstNode *node)
Definition expr.c:254
LLVMTypeRef extract_element_type_from_ast(CodeGenContext *ctx, AstNode *type_node)
Definition stmt.c:39
LLVMValueRef codegen_stmt_module(CodeGenContext *ctx, AstNode *node)
Definition module_handles.c:355
bool is_int_type(LLVMTypeRef type)
Definition type_cache.c:68
#define SYMBOL_HASH_SIZE
Definition llvm.h:24
unsigned int hash_string(const char *str)
Definition module_handles.c:8
LLVMValueRef codegen_stmt_os(CodeGenContext *ctx, AstNode *node)
Definition module_handles.c:402
const char * get_struct_name_from_type(CodeGenContext *ctx, LLVMTypeRef type)
Definition struct_helpers.c:23
LLVMTypeRef codegen_type(CodeGenContext *ctx, AstNode *node)
Definition lookup.c:124
bool generate_assembly_file(CodeGenContext *ctx, const char *asm_filename, bool is_debug)
Definition llvm.c:544
LLVM_Symbol * find_symbol_in_module(ModuleCompilationUnit *module, const char *name)
Definition llvm.c:349
LLVMValueRef codegen_module_access(CodeGenContext *ctx, AstNode *node)
Handle compile-time member access (::)
Definition member_access.c:23
LLVMValueRef codegen_stmt_struct(CodeGenContext *ctx, AstNode *node)
Definition struct.c:75
LLVMValueRef codegen_expr_alloc(CodeGenContext *ctx, AstNode *node)
Definition expr.c:1918
bool is_float_type(LLVMTypeRef type)
Definition type_cache.c:72
LLVMValueRef codegen_infinite_loop(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:980
LLVMValueRef codegen_stmt_expression(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:13
LLVMValueRef codegen_stmt_var_decl(CodeGenContext *ctx, AstNode *node)
Definition stmt.c:68
LLVM_Symbol * lookup_cached_symbol(const char *module_name, const char *symbol_name)
Definition module_handles.c:52
StructInfo * find_concrete_struct_for_base(CodeGenContext *ctx, StructInfo *base_info, const char *field_name)
Definition struct.c:6
Type * array_type(Parser *parser)
Definition type.c:22
Arena allocator structure.
Definition memory.h:101
Definition ast.h:142
Definition llvm.h:98
bool is_debug
Definition llvm.h:126
const char * target_os
Definition llvm.h:123
LLVMBasicBlockRef loop_break_block
Definition llvm.h:118
LLVMBuilderRef builder
Definition llvm.h:101
LLVMValueRef current_function
Definition llvm.h:116
LLVMContextRef context
Definition llvm.h:100
ArenaAllocator * arena
Definition llvm.h:130
CommonTypes common_types
Definition llvm.h:120
LLVMMetadataRef current_func_di
Definition llvm.h:127
LLVMModuleRef struct DeferredStatement * deferred_statements
Definition llvm.h:111
size_t deferred_capacity
Definition llvm.h:113
StructInfo * struct_types
Definition llvm.h:121
LLVMBasicBlockRef loop_continue_block
Definition llvm.h:117
size_t deferred_count
Definition llvm.h:112
ModuleCompilationUnit * modules
Definition llvm.h:104
ModuleCompilationUnit * current_module
Definition llvm.h:105
Definition llvm.h:81
LLVMTypeRef void_type
Definition llvm.h:89
LLVMTypeRef i64
Definition llvm.h:83
LLVMTypeRef i32
Definition llvm.h:83
LLVMTypeRef f32
Definition llvm.h:86
LLVMValueRef const_i64_1
Definition llvm.h:94
LLVMTypeRef i8_ptr
Definition llvm.h:90
LLVMTypeRef i8
Definition llvm.h:83
LLVMValueRef const_i32_0
Definition llvm.h:93
LLVMTypeRef f64
Definition llvm.h:86
LLVMValueRef const_i64_0
Definition llvm.h:94
LLVMValueRef const_i32_1
Definition llvm.h:93
LLVMTypeRef i1
Definition llvm.h:83
LLVMTypeRef i16
Definition llvm.h:83
Definition llvm.h:63
struct DeferredStatement * next
Definition llvm.h:66
AstNode * statement
Definition llvm.h:64
LLVMBasicBlockRef cleanup_block
Definition llvm.h:65
Definition llvm.h:31
LLVMTypeRef type
Definition llvm.h:34
bool is_function
Definition llvm.h:36
char * name
Definition llvm.h:32
LLVMValueRef value
Definition llvm.h:33
LLVMTypeRef element_type
Definition llvm.h:35
struct LLVM_Symbol * next
Definition llvm.h:37
Definition llvm.h:41
bool is_main_module
Definition llvm.h:45
size_t link_lib_count
Definition llvm.h:49
LLVMDIBuilderRef dibuilder
Definition llvm.h:51
LLVMMetadataRef compile_unit
Definition llvm.h:52
const char * link_libs[MAX_LINK_LIBS]
Definition llvm.h:48
struct ModuleCompilationUnit * next
Definition llvm.h:46
char * module_name
Definition llvm.h:42
LLVMModuleRef LLVM_Symbol * symbols
Definition llvm.h:44
LLVMMetadataRef file_metadata
Definition llvm.h:53
Definition llvm.h:56
char ** dependencies
Definition llvm.h:58
const char * module_name
Definition llvm.h:57
bool processed
Definition llvm.h:60
size_t dep_count
Definition llvm.h:59
Definition llvm.h:144
StructInfo * info
Definition llvm.h:146
struct StructHashEntry * next
Definition llvm.h:147
const char * name
Definition llvm.h:145
Definition llvm.h:150
StructHashEntry * buckets[SYMBOL_HASH_SIZE]
Definition llvm.h:151
Definition llvm.h:69
bool * field_is_public
Definition llvm.h:75
bool is_public
Definition llvm.h:77
char * name
Definition llvm.h:70
LLVMTypeRef * field_types
Definition llvm.h:73
LLVMTypeRef * field_element_types
Definition llvm.h:74
size_t field_count
Definition llvm.h:76
struct StructInfo * next
Definition llvm.h:78
char ** field_names
Definition llvm.h:72
LLVMTypeRef llvm_type
Definition llvm.h:71
Definition llvm.h:133
const char * key
Definition llvm.h:134
struct SymbolHashEntry * next
Definition llvm.h:136
LLVM_Symbol * symbol
Definition llvm.h:135
Definition llvm.h:139
SymbolHashEntry * buckets[SYMBOL_HASH_SIZE]
Definition llvm.h:140