Purple
0.1
Standard Language Specification
|
LLVM-IR emission. More...
#include <string.h>
#include "data.h"
#include "translate/llvm.h"
#include "translate/translate.h"
#include "types/type.h"
#include "utils/clang.h"
#include "utils/formatting.h"
#include "utils/logging.h"
Functions | |
void | prepend_loaded (type_register reg) |
Update loaded register linked list to include new register. More... | |
type_register * | llvm_ensure_registers_loaded (int n_registers, type_register registers[], NumberType number_type) |
Ensure that the values of a set of registers are loaded. More... | |
void | llvm_preamble (void) |
Generated program's preamble. More... | |
void | llvm_postamble (void) |
Generated program's postamble. More... | |
bool | llvm_stack_allocation (LLVMStackEntryNode *stack_entries) |
Allocate space on stack for variables. More... | |
static type_register | llvm_add (LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generate code for binary addition. More... | |
static type_register | llvm_subtract (LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generate code for binary subtraction. More... | |
static type_register | llvm_multiply (LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generate code for binary multiplication. More... | |
static type_register | llvm_divide (LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generate code for unsigned binary division. More... | |
LLVMValue | llvm_binary_arithmetic (TokenType operation, LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generates LLVM-IR for various binary arithmetic expressions. More... | |
LLVMValue | llvm_store_constant (Number value) |
Store a constant number value into a register. More... | |
type_register | get_next_local_virtual_register (void) |
Retrieves the next valid virtual register index. More... | |
LLVMValue | llvm_load_global_variable (char *symbol_name) |
Load a global variable's value into a new virtual register. More... | |
void | llvm_store_global_variable (char *symbol_name, LLVMValue rvalue_register) |
Store a value into a global variable. More... | |
LLVMValue | llvm_signed_extend (LLVMValue reg, NumberType new_type, NumberType old_type) |
LLVMValue | llvm_truncate (LLVMValue reg, NumberType new_type, NumberType old_type) |
void | llvm_declare_global_number_variable (char *symbol_name, NumberType number_type) |
Declare a global variable. More... | |
void | llvm_declare_assign_global_number_variable (char *symbol_name, Number number) |
Declare a global variable with an assigned number value. More... | |
void | llvm_print_int (type_register print_vr, TokenType type) |
Generate code to print an integer. More... | |
void | llvm_print_bool (type_register print_vr) |
Generate code to print a boolean value. More... | |
static void | llvm_relational_compare (TokenType comparison_type, type_register out_register, LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
static void | llvm_logical_compare (TokenType comparison_type, type_register out_register, LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
LLVMValue | llvm_compare (TokenType comparison_type, LLVMValue left_virtual_register, LLVMValue right_virtual_register) |
Generate code to compare two registers. More... | |
LLVMValue | llvm_compare_jump (TokenType comparison_type, LLVMValue left_virtual_register, LLVMValue right_virtual_register, LLVMValue false_label) |
Generate code to compare two registers and conditionally jump based on the result. More... | |
LLVMValue | get_next_label (void) |
Get the next valid label. More... | |
void | llvm_label (LLVMValue label) |
Generate label code. More... | |
void | llvm_jump (LLVMValue label) |
Generate an unconditional jump statement. More... | |
void | llvm_conditional_jump (LLVMValue condition_register, LLVMValue true_label, LLVMValue false_label) |
Generate a conditional jump statement. More... | |
void | llvm_function_preamble (char *symbol_name) |
void | llvm_function_postamble (void) |
const char * | type_to_llvm_type (TokenType type) |
LLVMValue | llvm_call_function (LLVMValue virtual_register, char *symbol_name) |
void | llvm_return (LLVMValue value, char *symbol_name) |
Variables | |
LLVMStackEntryNode * | buffered_stack_entries_head = NULL |
LLVM-IR emission.
type_register get_next_local_virtual_register | ( | void | ) |
Retrieves the next valid virtual register index.
|
static |
Generate code for binary addition.
left_virtual_register | Lvalue to be added |
right_virtual_register | Rvalue to be added |
LLVMValue llvm_binary_arithmetic | ( | TokenType | operation, |
LLVMValue | left_virtual_register, | ||
LLVMValue | right_virtual_register | ||
) |
Generates LLVM-IR for various binary arithmetic expressions.
operation | Operation to perform |
left_virtual_register | Operand left of operation |
right_virtual_register | Operand right of operation |
LLVMValue llvm_compare_jump | ( | TokenType | comparison_type, |
LLVMValue | left_virtual_register, | ||
LLVMValue | right_virtual_register, | ||
LLVMValue | false_label | ||
) |
Generate code to compare two registers and conditionally jump based on the result.
comparison_type | Type of comparison to make |
left_virtual_register | LLVMValue storing left value register index |
right_virtual_register | LLVMValue storing right value register index |
false_label | LLVMValue storing label data for the branch in which the condition is false |
void llvm_conditional_jump | ( | LLVMValue | condition_register, |
LLVMValue | true_label, | ||
LLVMValue | false_label | ||
) |
Generate a conditional jump statement.
condition_register | LLVMValue holding information about the register from the prior condition |
true_label | Label to jump to if condition is true |
false_label | Label to jump to if condition is false |
void llvm_declare_assign_global_number_variable | ( | char * | symbol_name, |
Number | number | ||
) |
Declare a global variable with an assigned number value.
symbol_name | Name of global variable |
number | Default value of global variable |
void llvm_declare_global_number_variable | ( | char * | symbol_name, |
NumberType | number_type | ||
) |
Declare a global variable.
symbol_name | Name of global variable |
number_type | Type of number of global variable |
|
static |
Generate code for unsigned binary division.
left_virtual_register | Lvalue to be divided |
right_virtual_register | Rvalue to be divided |
type_register * llvm_ensure_registers_loaded | ( | int | n_registers, |
type_register | registers[], | ||
NumberType | number_type | ||
) |
Ensure that the values of a set of registers are loaded.
n_registers | Number of registers to ensure |
registers | Array of register indices to ensure |
number_type | NumberType of registers to ensure |
void llvm_function_postamble | ( | void | ) |
void llvm_function_preamble | ( | char * | symbol_name | ) |
void llvm_jump | ( | LLVMValue | label | ) |
Generate an unconditional jump statement.
label | Label to jump to |
void llvm_label | ( | LLVMValue | label | ) |
Generate label code.
label | LLVMValue containing label information |
LLVMValue llvm_load_global_variable | ( | char * | symbol_name | ) |
Load a global variable's value into a new virtual register.
symbol_name | Identifier name of variable to load |
|
static |
|
static |
Generate code for binary multiplication.
left_virtual_register | Lvalue to be multiplied |
right_virtual_register | Rvalue to be multiplied |
void llvm_postamble | ( | void | ) |
Generated program's postamble.
void llvm_preamble | ( | void | ) |
Generated program's preamble.
void llvm_print_bool | ( | type_register | print_vr | ) |
Generate code to print a boolean value.
print_vr | Register holding value to print |
void llvm_print_int | ( | type_register | print_vr, |
TokenType | type | ||
) |
Generate code to print an integer.
print_vr | Register holding value to print |
type | Type of int (byte, char, int, long) to print |
|
static |
void llvm_return | ( | LLVMValue | value, |
char * | symbol_name | ||
) |
LLVMValue llvm_signed_extend | ( | LLVMValue | reg, |
NumberType | new_type, | ||
NumberType | old_type | ||
) |
bool llvm_stack_allocation | ( | LLVMStackEntryNode * | stack_entries | ) |
Allocate space on stack for variables.
stack_entries | LLVMStackEntryNode pointers holding stack allocation information |
Store a constant number value into a register.
value | Number struct containing information about the constant |
void llvm_store_global_variable | ( | char * | symbol_name, |
LLVMValue | rvalue_register | ||
) |
Store a value into a global variable.
symbol_name | Identifier name of variable to store new value to |
rvalue_register | Register number of statement's RValue to store |
|
static |
Generate code for binary subtraction.
left_virtual_register | Lvalue to be subtracted |
right_virtual_register | Rvalue to be subtracted |
LLVMValue llvm_truncate | ( | LLVMValue | reg, |
NumberType | new_type, | ||
NumberType | old_type | ||
) |
void prepend_loaded | ( | type_register | reg | ) |
Update loaded register linked list to include new register.
reg | Register to include in list |
const char * type_to_llvm_type | ( | TokenType | type | ) |
LLVMStackEntryNode* buffered_stack_entries_head = NULL |