Zen-C
Loading...
Searching...
No Matches
codegen.h File Reference
#include "../ast/ast.h"
#include "../parser/parser.h"
#include "../zprep.h"
#include <stdio.h>
Include dependency graph for codegen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_DEFER   1024
 
#define MAX_LOOP_DEPTH   64
 

Functions

void codegen_node (ParserContext *ctx, ASTNode *node, FILE *out)
 Generates code for a given AST node.
 
void codegen_node_single (ParserContext *ctx, ASTNode *node, FILE *out)
 Generates code for a single AST node (non-recursive for siblings).
 
void codegen_walker (ParserContext *ctx, ASTNode *node, FILE *out)
 Walker for list of nodes (calls codegen_node recursively).
 
void codegen_expression (ParserContext *ctx, ASTNode *node, FILE *out)
 Generates code for an expression node.
 
void codegen_match_internal (ParserContext *ctx, ASTNode *node, FILE *out, int use_result)
 Internal handler for match statements.
 
char * infer_type (ParserContext *ctx, ASTNode *node)
 
ASTNodefind_struct_def_codegen (ParserContext *ctx, const char *name)
 
char * get_field_type_str (ParserContext *ctx, const char *struct_name, const char *field_name)
 
char * extract_call_args (const char *args)
 
void emit_var_decl_type (ParserContext *ctx, FILE *out, const char *type_str, const char *var_name)
 
char * replace_string_type (const char *args)
 
const char * parse_original_method_name (const char *mangled)
 
void emit_auto_type (ParserContext *ctx, ASTNode *init_expr, Token t, FILE *out)
 
char * codegen_type_to_string (Type *t)
 
void emit_func_signature (ParserContext *ctx, FILE *out, ASTNode *func, const char *name_override)
 
char * strip_template_suffix (const char *name)
 
int emit_move_invalidation (ParserContext *ctx, ASTNode *node, FILE *out)
 
void codegen_expression_with_move (ParserContext *ctx, ASTNode *node, FILE *out)
 
void emit_preamble (ParserContext *ctx, FILE *out)
 Emits the standard preamble (includes, macros) to the output file.
 
void emit_includes_and_aliases (ASTNode *node, FILE *out)
 
void emit_type_aliases (ASTNode *node, FILE *out)
 
void emit_global_aliases (ParserContext *ctx, FILE *out)
 
void emit_struct_defs (ParserContext *ctx, ASTNode *node, FILE *out)
 
void emit_trait_defs (ASTNode *node, FILE *out)
 
void emit_enum_protos (ASTNode *node, FILE *out)
 
void emit_globals (ParserContext *ctx, ASTNode *node, FILE *out)
 
void emit_lambda_defs (ParserContext *ctx, FILE *out)
 
void emit_protos (ParserContext *ctx, ASTNode *node, FILE *out)
 
void emit_impl_vtables (ParserContext *ctx, FILE *out)
 
int emit_tests_and_runner (ParserContext *ctx, ASTNode *node, FILE *out)
 Emits test runner and test cases if testing is enabled.
 
void print_type_defs (ParserContext *ctx, FILE *out, ASTNode *nodes)
 

Variables

ASTNodeglobal_user_structs
 List of user defined structs.
 
char * g_current_impl_type
 Type currently being implemented (in impl block).
 
int tmp_counter
 Counter for temporary variables.
 
int defer_count
 Counter for defer statements in current scope.
 
ASTNodedefer_stack []
 Stack of deferred nodes.
 
ASTNodeg_current_lambda
 Current lambda being generated.
 
char * g_current_func_ret_type
 Return type of current function.
 
int loop_defer_boundary []
 Defer stack index at start of each loop.
 
int loop_depth
 Current loop nesting depth.
 
int func_defer_boundary
 Defer stack index at function entry.
 

Macro Definition Documentation

◆ MAX_DEFER

#define MAX_DEFER   1024

◆ MAX_LOOP_DEPTH

#define MAX_LOOP_DEPTH   64

Function Documentation

◆ codegen_expression()

void codegen_expression ( ParserContext ctx,
ASTNode node,
FILE *  out 
)

Generates code for an expression node.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_expression_with_move()

void codegen_expression_with_move ( ParserContext ctx,
ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_match_internal()

void codegen_match_internal ( ParserContext ctx,
ASTNode node,
FILE *  out,
int  use_result 
)

Internal handler for match statements.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_node()

void codegen_node ( ParserContext ctx,
ASTNode node,
FILE *  out 
)

Generates code for a given AST node.

Parameters
ctxParser context.
nodeThe AST node to generate code for.
outOutput file stream.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_node_single()

void codegen_node_single ( ParserContext ctx,
ASTNode node,
FILE *  out 
)

Generates code for a single AST node (non-recursive for siblings).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_type_to_string()

char * codegen_type_to_string ( Type t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ codegen_walker()

void codegen_walker ( ParserContext ctx,
ASTNode node,
FILE *  out 
)

Walker for list of nodes (calls codegen_node recursively).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_auto_type()

void emit_auto_type ( ParserContext ctx,
ASTNode init_expr,
Token  t,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_enum_protos()

void emit_enum_protos ( ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_func_signature()

void emit_func_signature ( ParserContext ctx,
FILE *  out,
ASTNode func,
const char *  name_override 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_global_aliases()

void emit_global_aliases ( ParserContext ctx,
FILE *  out 
)
Here is the caller graph for this function:

◆ emit_globals()

void emit_globals ( ParserContext ctx,
ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_impl_vtables()

void emit_impl_vtables ( ParserContext ctx,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_includes_and_aliases()

void emit_includes_and_aliases ( ASTNode node,
FILE *  out 
)
Here is the caller graph for this function:

◆ emit_lambda_defs()

void emit_lambda_defs ( ParserContext ctx,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_move_invalidation()

int emit_move_invalidation ( ParserContext ctx,
ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_preamble()

void emit_preamble ( ParserContext ctx,
FILE *  out 
)

Emits the standard preamble (includes, macros) to the output file.

Here is the caller graph for this function:

◆ emit_protos()

void emit_protos ( ParserContext ctx,
ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_struct_defs()

void emit_struct_defs ( ParserContext ctx,
ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_tests_and_runner()

int emit_tests_and_runner ( ParserContext ctx,
ASTNode node,
FILE *  out 
)

Emits test runner and test cases if testing is enabled.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_trait_defs()

void emit_trait_defs ( ASTNode node,
FILE *  out 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ emit_type_aliases()

void emit_type_aliases ( ASTNode node,
FILE *  out 
)
Here is the caller graph for this function:

◆ emit_var_decl_type()

void emit_var_decl_type ( ParserContext ctx,
FILE *  out,
const char *  type_str,
const char *  var_name 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_call_args()

char * extract_call_args ( const char *  args)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_struct_def_codegen()

ASTNode * find_struct_def_codegen ( ParserContext ctx,
const char *  name 
)
Here is the caller graph for this function:

◆ get_field_type_str()

char * get_field_type_str ( ParserContext ctx,
const char *  struct_name,
const char *  field_name 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ infer_type()

char * infer_type ( ParserContext ctx,
ASTNode node 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_original_method_name()

const char * parse_original_method_name ( const char *  mangled)
Here is the caller graph for this function:

◆ print_type_defs()

void print_type_defs ( ParserContext ctx,
FILE *  out,
ASTNode nodes 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_string_type()

char * replace_string_type ( const char *  args)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strip_template_suffix()

char * strip_template_suffix ( const char *  name)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ defer_count

int defer_count
extern

Counter for defer statements in current scope.

◆ defer_stack

ASTNode* defer_stack[]
extern

Stack of deferred nodes.

◆ func_defer_boundary

int func_defer_boundary
extern

Defer stack index at function entry.

◆ g_current_func_ret_type

char* g_current_func_ret_type
extern

Return type of current function.

◆ g_current_impl_type

char* g_current_impl_type
extern

Type currently being implemented (in impl block).

◆ g_current_lambda

ASTNode* g_current_lambda
extern

Current lambda being generated.

◆ global_user_structs

ASTNode* global_user_structs
extern

List of user defined structs.

◆ loop_defer_boundary

int loop_defer_boundary[]
extern

Defer stack index at start of each loop.

◆ loop_depth

int loop_depth
extern

Current loop nesting depth.

◆ tmp_counter

int tmp_counter
extern

Counter for temporary variables.