Purple  0.1
Standard Language Specification
Functions | Variables
translate.c File Reference

Functions for LLVM-IR translation. More...

#include "translate/translate.h"
#include "data.h"
#include "utils/logging.h"
Include dependency graph for translate.c:

Functions

static void translate_init (void)
 Initialize any values required for LLVM translation. More...
 
LLVMStackEntryNodedetermine_binary_expression_stack_allocation (ASTNode *root)
 Perform a DFS on an AST to determine the stack allocation needed for a binary expression. More...
 
static LLVMValue if_ast_to_llvm (ASTNode *n)
 Generate LLVM-IR for an if statement AST. More...
 
static LLVMValue while_else_ast_to_llvm (ASTNode *n)
 Generate LLVM-IR for a while-else statement AST. More...
 
static LLVMValue print_ast_to_llvm (ASTNode *root, LLVMValue virtual_register)
 Generate LLVM-IR for a print statement. More...
 
LLVMValue ast_to_llvm (ASTNode *root, LLVMValue llvm_value, TokenType parent_operation)
 Generates LLVM-IR from a given AST. More...
 
void generate_llvm (void)
 Wrapper function for generating LLVM. More...
 

Variables

LLVMStackEntryNodefreeVirtualRegistersHead = NULL
 Head node of linked list containing register indices that are free to have values stored in them. More...
 

Detailed Description

Functions for LLVM-IR translation.

Author
Charles Averill
Date
10-Sep-2022

Function Documentation

◆ ast_to_llvm()

LLVMValue ast_to_llvm ( ASTNode root,
LLVMValue  llvm_value,
TokenType  parent_operation 
)

Generates LLVM-IR from a given AST.

Parameters
nThe AST Node from which LLVM will be generated
llvm_valueLLVMValue storing register or label information
parent_operationTokenType of parent of n
Returns
LLVMValue LLVMValue struct containing information about what code this AST Node generated

◆ determine_binary_expression_stack_allocation()

LLVMStackEntryNode * determine_binary_expression_stack_allocation ( ASTNode root)

Perform a DFS on an AST to determine the stack allocation needed for a binary expression.

Parameters
rootRoot of AST to find stack allocation for
Returns
LLVMStackEntryNode* Pointer to front of the stack allocation linked list

◆ generate_llvm()

void generate_llvm ( void  )

Wrapper function for generating LLVM.

◆ if_ast_to_llvm()

static LLVMValue if_ast_to_llvm ( ASTNode n)
static

Generate LLVM-IR for an if statement AST.

jump false_label if !condition body() jump end_label false_label: falsebody() end_label:

Parameters
nRoot AST node
Returns
LLVMValue LLVMVALUE_NULL

◆ print_ast_to_llvm()

static LLVMValue print_ast_to_llvm ( ASTNode root,
LLVMValue  virtual_register 
)
static

Generate LLVM-IR for a print statement.

Parameters
nRoot AST node
Returns
LLVMValue LLVMVALUE_NULL

◆ translate_init()

static void translate_init ( void  )
static

Initialize any values required for LLVM translation.

◆ while_else_ast_to_llvm()

static LLVMValue while_else_ast_to_llvm ( ASTNode n)
static

Generate LLVM-IR for a while-else statement AST.

condition_label: jump else_label if !condition body() jump condition_label else_label: elsebody()

Parameters
nRoot AST node
Returns
LLVMValue LLVMVALUE_NULL

Variable Documentation

◆ freeVirtualRegistersHead

LLVMStackEntryNode* freeVirtualRegistersHead = NULL

Head node of linked list containing register indices that are free to have values stored in them.