Purple
0.1
Standard Language Specification
|
Function headers for LLVM-IR emission. More...
Go to the source code of this file.
Classes | |
struct | LLVMValue |
Value returned by ast_to_llvm. More... | |
Macros | |
#define | REFSTRING_BUF_MAXLEN 256 |
Size of buffer for generating refstrings. More... | |
#define | PRINT_LLVMVALUE(val) |
Debug print method for LLVMValues. More... | |
#define | LLVMVALUE_NULL |
A standard "null" LLVMValue struct returned in some scenarios. More... | |
#define | LLVMVALUE_CONSTANT(c) |
Generates an LLVMValue struct with a constant value. More... | |
#define | LLVMVALUE_VIRTUAL_REGISTER(register_number, n_t) |
Inline-initializes an LLVMValue struct from a virtual register number. More... | |
#define | LLVMVALUE_VIRTUAL_REGISTER_POINTER(register_number, n_t, depth) |
Inline-initializes an LLVMValue struct from the number of a virtual register that stores a pointer. More... | |
#define | LLVMVALUE_LABEL(label_number) |
Inline initializes an LLVMValue struct from a label number. More... | |
#define | LLVMVALUE_REGMARKER(llvmvalue) (llvmvalue.value_type == LLVMVALUETYPE_CONSTANT ? "" : "%") |
Shorthand for providing a "%" string if needed in generation statements. More... | |
#define | LLVMVALUE_SET_JUSTLOADED(llvmvalue, symbol_name) |
#define | PURPLE_LABEL_PREFIX "L" |
#define | REFSTRING(depth) refstring(_refstring_buf, depth) |
Wrapper for _refstring - WARNING - only one call to REFSTRING may be made per statement, due to _refstring_buf being used in it. Multiple uses will overwrite all but the last occurrance. More... | |
#define | LLVM_REPR_NOTYPE(reg) llvmvalue_repr_notype(_llvm_name_buf, reg) |
Typedefs | |
typedef struct LLVMValue | LLVMValue |
Value returned by ast_to_llvm. More... | |
Enumerations | |
enum | LLVMValueType { LLVMVALUETYPE_NONE , LLVMVALUETYPE_VIRTUAL_REGISTER , LLVMVALUETYPE_LABEL , LLVMVALUETYPE_CONSTANT } |
Types of values possibly returned by ast_to_llvm. More... | |
Functions | |
LLVMValue * | llvm_ensure_registers_loaded (int n_registers, LLVMValue registers[], int load_depth) |
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... | |
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 | get_next_label (void) |
Get the next valid label. 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... | |
void | llvm_declare_global_number_variable (char *symbol_name, Number n) |
Declare a global variable. More... | |
LLVMValue | llvm_int_resize (LLVMValue reg, NumberType new_tye) |
Generates an extend or truncate statement to change the bit-width of an integer. 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 (LLVMValue print_vr) |
Generate code to print an integer. More... | |
void | llvm_print_bool (LLVMValue print_vr) |
Generate code to print a boolean value. More... | |
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... | |
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... | |
LLVMValue * | llvm_function_preamble (char *symbol_name) |
Generates the preamble for a function. More... | |
void | llvm_function_postamble (void) |
Generates the postamble for a function. More... | |
LLVMValue | llvm_call_function (LLVMValue *args, unsigned long long int num_args, char *symbol_name) |
Generate a function call statement. More... | |
const char * | type_to_llvm_type (TokenType type) |
Convert a TokenType to the string representation of that type in LLVM. More... | |
void | llvm_return (LLVMValue virtual_register, char *symbol_name) |
Generate a return statement. More... | |
char * | refstring (char *buf, int pointer_depth) |
Generate a string containing pointer stars. More... | |
char * | llvmvalue_repr_notype (char *buf, LLVMValue reg) |
LLVMValue | llvm_get_address (char *symbol_name) |
Generate an addressing statement. More... | |
LLVMValue | llvm_dereference (LLVMValue reg) |
Generate a dereference (load) statement. More... | |
void | llvm_store_dereference (LLVMValue destination, LLVMValue value) |
Generates code to store a value into a dereferenced value. More... | |
void | llvm_store_local (char *symbol_name, LLVMValue val) |
Variables | |
static const char * | numberTypeLLVMReprs [] = {"i1", "i8", "i16", "i32", "i64"} |
LLVM-IR representations of data types. More... | |
LLVMStackEntryNode * | freeVirtualRegistersHead |
Head node of linked list containing register indices that are free to have values stored in them. More... | |
static char | _refstring_buf [REFSTRING_BUF_MAXLEN] |
Temporary buffer used to generate pointer star strings for LLVM code. More... | |
static char | _llvm_name_buf [MAX_IDENTIFIER_LENGTH+3] |
static const char * | valueTypeStrings [] = {"None", "Virtual Register", "Label", "Constant"} |
String representations of LLVMValueTypes for debugging. More... | |
Function headers for LLVM-IR emission.
#define LLVM_REPR_NOTYPE | ( | reg | ) | llvmvalue_repr_notype(_llvm_name_buf, reg) |
#define LLVMVALUE_CONSTANT | ( | c | ) |
Generates an LLVMValue struct with a constant value.
#define LLVMVALUE_LABEL | ( | label_number | ) |
Inline initializes an LLVMValue struct from a label number.
#define LLVMVALUE_NULL |
A standard "null" LLVMValue struct returned in some scenarios.
#define LLVMVALUE_REGMARKER | ( | llvmvalue | ) | (llvmvalue.value_type == LLVMVALUETYPE_CONSTANT ? "" : "%") |
Shorthand for providing a "%" string if needed in generation statements.
#define LLVMVALUE_SET_JUSTLOADED | ( | llvmvalue, | |
symbol_name | |||
) |
#define LLVMVALUE_VIRTUAL_REGISTER | ( | register_number, | |
n_t | |||
) |
Inline-initializes an LLVMValue struct from a virtual register number.
#define LLVMVALUE_VIRTUAL_REGISTER_POINTER | ( | register_number, | |
n_t, | |||
depth | |||
) |
Inline-initializes an LLVMValue struct from the number of a virtual register that stores a pointer.
#define PRINT_LLVMVALUE | ( | val | ) |
Debug print method for LLVMValues.
#define PURPLE_LABEL_PREFIX "L" |
Prefix to prepend to LLVM label indices
#define REFSTRING | ( | depth | ) | refstring(_refstring_buf, depth) |
Wrapper for _refstring - WARNING - only one call to REFSTRING may be made per statement, due to _refstring_buf being used in it. Multiple uses will overwrite all but the last occurrance.
#define REFSTRING_BUF_MAXLEN 256 |
Size of buffer for generating refstrings.
enum LLVMValueType |
type_register get_next_local_virtual_register | ( | void | ) |
Retrieves the next valid virtual register index.
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, |
Number | n | ||
) |
Declare a global variable.
symbol_name | Name of global variable |
n | Number information of global variable |
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 |
load_depth | Pointer depth to be considered "loaded" |
void llvm_function_postamble | ( | void | ) |
Generates the postamble for a function.
LLVMValue * llvm_function_preamble | ( | char * | symbol_name | ) |
Generates the preamble for a function.
symbol_name | Name of function to generate for |
LLVMValue llvm_get_address | ( | char * | symbol_name | ) |
LLVMValue llvm_int_resize | ( | LLVMValue | reg, |
NumberType | new_type | ||
) |
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 |
void llvm_postamble | ( | void | ) |
Generated program's postamble.
void llvm_preamble | ( | void | ) |
Generated program's preamble.
void llvm_print_bool | ( | LLVMValue | print_vr | ) |
Generate code to print a boolean value.
print_vr | Register holding value to print |
void llvm_print_int | ( | LLVMValue | print_vr | ) |
Generate code to print an integer.
print_vr | Register holding value to print |
void llvm_return | ( | LLVMValue | value, |
char * | symbol_name | ||
) |
Generate a return statement.
value | Value to return |
symbol_name | Name of function to return from |
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 |
Generates code to store a value into a dereferenced value.
destination | Destination register or variable to store into |
value | Value to store |
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 |
void llvm_store_local | ( | char * | symbol_name, |
LLVMValue | val | ||
) |
char * llvmvalue_repr_notype | ( | char * | buf, |
LLVMValue | reg | ||
) |
char * refstring | ( | char * | buf, |
int | pointer_depth | ||
) |
Generate a string containing pointer stars.
buf | Buffer to fill with pointer stars |
pointer_depth | Number of pointer stars to fill |
const char * type_to_llvm_type | ( | TokenType | type | ) |
Convert a TokenType to the string representation of that type in LLVM.
type | TokenType to convert |
|
static |
|
static |
Temporary buffer used to generate pointer star strings for LLVM code.
|
extern |
Head node of linked list containing register indices that are free to have values stored in them.
|
static |
LLVM-IR representations of data types.
|
static |
String representations of LLVMValueTypes for debugging.