Turnstone Operating System
Loading...
Searching...
No Matches
compiler.h File Reference

Turnstone OS compiler header. More...

#include <types.h>
#include <buffer.h>
#include <list.h>
#include <hashmap.h>

Classes

struct  compiler_token_t
 
struct  compiler_symbol_t
 
struct  compiler_type_field_t
 
struct  compiler_type_t
 
struct  compiler_ast_node_t
 
struct  compiler_ast_t
 
struct  compiler_symbol_table_t
 
struct  compiler_t
 

Macros

#define ___COMPILER_H   0
 
#define COMPILER_VM_REG_COUNT   13
 
#define compiler_destroy_symbol_list(list)   list_destroy_with_type(list, LIST_DESTROY_WITH_DATA, compiler_symbol_destroyer)
 
#define SYS_exit   60ULL
 
#define SYS_write   1ULL
 

Typedefs

typedef enum compiler_token_type_t compiler_token_type_t
 
typedef struct compiler_token_t compiler_token_t
 
typedef enum compiler_ast_node_type_t compiler_ast_node_type_t
 
typedef enum compiler_symbol_type_t compiler_symbol_type_t
 
typedef struct compiler_symbol_t compiler_symbol_t
 
typedef struct compiler_type_field_t compiler_type_field_t
 
typedef struct compiler_type_t compiler_type_t
 
typedef struct compiler_ast_node_t compiler_ast_node_t
 
typedef struct compiler_ast_t compiler_ast_t
 
typedef struct compiler_symbol_table_t compiler_symbol_table_t
 
typedef struct compiler_t compiler_t
 
typedef enum compiler_reg_ids_t compiler_reg_ids_t
 

Enumerations

enum  compiler_token_type_t {
  COMPILER_TOKEN_TYPE_EOF = 0 , COMPILER_TOKEN_TYPE_UNKNOWN , COMPILER_TOKEN_TYPE_INTEGER_CONST , COMPILER_TOKEN_TYPE_REAL_CONST ,
  COMPILER_TOKEN_TYPE_STRING_CONST , COMPILER_TOKEN_TYPE_PLUS , COMPILER_TOKEN_TYPE_MINUS , COMPILER_TOKEN_TYPE_OR ,
  COMPILER_TOKEN_TYPE_XOR , COMPILER_TOKEN_TYPE_MULTIPLY , COMPILER_TOKEN_TYPE_REAL_DIVIDE , COMPILER_TOKEN_TYPE_INTEGER_DIVIDE ,
  COMPILER_TOKEN_TYPE_MOD , COMPILER_TOKEN_TYPE_AND , COMPILER_TOKEN_TYPE_NOT , COMPILER_TOKEN_TYPE_LPAREN ,
  COMPILER_TOKEN_TYPE_RPAREN , COMPILER_TOKEN_TYPE_ID , COMPILER_TOKEN_TYPE_ASSIGN , COMPILER_TOKEN_TYPE_SEMI ,
  COMPILER_TOKEN_TYPE_DOT , COMPILER_TOKEN_TYPE_COMMA , COMPILER_TOKEN_TYPE_COLON , COMPILER_TOKEN_TYPE_EQUAL ,
  COMPILER_TOKEN_TYPE_NOT_EQUAL , COMPILER_TOKEN_TYPE_LESS_THAN , COMPILER_TOKEN_TYPE_LESS_THAN_OR_EQUAL , COMPILER_TOKEN_TYPE_GREATER_THAN ,
  COMPILER_TOKEN_TYPE_GREATER_THAN_OR_EQUAL , COMPILER_TOKEN_TYPE_IN , COMPILER_TOKEN_TYPE_SHL , COMPILER_TOKEN_TYPE_SHR ,
  COMPILER_TOKEN_TYPE_BEGIN , COMPILER_TOKEN_TYPE_END , COMPILER_TOKEN_TYPE_PROGRAM , COMPILER_TOKEN_TYPE_PROCEDURE ,
  COMPILER_TOKEN_TYPE_FUNCTION , COMPILER_TOKEN_TYPE_VAR , COMPILER_TOKEN_TYPE_CONST , COMPILER_TOKEN_TYPE_INTEGER ,
  COMPILER_TOKEN_TYPE_REAL , COMPILER_TOKEN_TYPE_CHAR , COMPILER_TOKEN_TYPE_STRING , COMPILER_TOKEN_TYPE_BOOLEAN ,
  COMPILER_TOKEN_TYPE_NULL , COMPILER_TOKEN_TYPE_IF , COMPILER_TOKEN_TYPE_THEN , COMPILER_TOKEN_TYPE_ELSE ,
  COMPILER_TOKEN_TYPE_WHILE , COMPILER_TOKEN_TYPE_DO , COMPILER_TOKEN_TYPE_REPEAT , COMPILER_TOKEN_TYPE_UNTIL ,
  COMPILER_TOKEN_TYPE_FOR , COMPILER_TOKEN_TYPE_TO , COMPILER_TOKEN_TYPE_DOWNTO , COMPILER_TOKEN_TYPE_STEP ,
  COMPILER_TOKEN_TYPE_CONTINUE , COMPILER_TOKEN_TYPE_BREAK , COMPILER_TOKEN_TYPE_LBRACKET , COMPILER_TOKEN_TYPE_RBRACKET ,
  COMPILER_TOKEN_TYPE_TYPE , COMPILER_TOKEN_TYPE_RECORD , COMPILER_TOKEN_TYPE_WITH , COMPILER_TOKEN_TYPE_PACKED
}
 
enum  compiler_ast_node_type_t {
  COMPILER_AST_NODE_TYPE_INTEGER_CONST = 0 , COMPILER_AST_NODE_TYPE_REAL_CONST , COMPILER_AST_NODE_TYPE_STRING_CONST , COMPILER_AST_NODE_TYPE_RELATIONAL_OP ,
  COMPILER_AST_NODE_TYPE_BINARY_OP , COMPILER_AST_NODE_TYPE_UNARY_OP , COMPILER_AST_NODE_TYPE_NO_OP , COMPILER_AST_NODE_TYPE_ASSIGN ,
  COMPILER_AST_NODE_TYPE_PROGRAM , COMPILER_AST_NODE_TYPE_DECLS , COMPILER_AST_NODE_TYPE_VAR , COMPILER_AST_NODE_TYPE_ARRAY_SUBSCRIPT ,
  COMPILER_AST_NODE_TYPE_FUNCTION_CALL , COMPILER_AST_NODE_TYPE_TYPE , COMPILER_AST_NODE_TYPE_BLOCK , COMPILER_AST_NODE_TYPE_COMPOUND ,
  COMPILER_AST_NODE_TYPE_IF , COMPILER_AST_NODE_TYPE_WHILE , COMPILER_AST_NODE_TYPE_GOTO , COMPILER_AST_NODE_TYPE_LABEL
}
 
enum  compiler_symbol_type_t {
  COMPILER_SYMBOL_TYPE_UNKNOWN = -1 , COMPILER_SYMBOL_TYPE_VOID = 0 , COMPILER_SYMBOL_TYPE_BOOLEAN , COMPILER_SYMBOL_TYPE_INTEGER ,
  COMPILER_SYMBOL_TYPE_REAL , COMPILER_SYMBOL_TYPE_STRING , COMPILER_SYMBOL_TYPE_CUSTOM
}
 
enum  compiler_reg_ids_t {
  COMPILER_VM_REG_RAX = 0 , COMPILER_VM_REG_RBX , COMPILER_VM_REG_RCX , COMPILER_VM_REG_RDX ,
  COMPILER_VM_REG_RSI , COMPILER_VM_REG_RDI , COMPILER_VM_REG_R8 , COMPILER_VM_REG_R9 ,
  COMPILER_VM_REG_R10 , COMPILER_VM_REG_R11 , COMPILER_VM_REG_R12 , COMPILER_VM_REG_R13 ,
  COMPILER_VM_REG_R14
}
 

Functions

int8_t compiler_token_destroy (compiler_token_t *token)
 
int8_t compiler_symbol_destroyer (memory_heap_t *heap, void *symbol)
 
int8_t compiler_ast_node_destroy (compiler_ast_node_t *node)
 
int8_t compiler_ast_node_destroyer (memory_heap_t *heap, void *node)
 
int8_t compiler_ast_init (compiler_ast_t *ast)
 
int8_t compiler_ast_destroy (compiler_ast_t *ast)
 
int8_t compiler_init (compiler_t *compiler, compiler_ast_t *ast)
 
int8_t compiler_destroy (compiler_t *compiler)
 
int8_t compiler_execute_ast_node (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_unary_op (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_binary_op (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_relational_op (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_block (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_compound (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute (compiler_t *compiler, int64_t *result)
 
int8_t compiler_print_symbol_table (compiler_t *compiler)
 
int8_t compiler_destroy_symbol_table (compiler_t *compiler)
 
int8_t compiler_build_stack (compiler_t *compiler)
 
int8_t compiler_find_free_reg (compiler_t *compiler)
 
const compiler_symbol_tcompiler_find_symbol (compiler_t *compiler, const char_t *name)
 
int8_t compiler_execute_function_call (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_string_const (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_if (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_while (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_goto (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_label (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_var_resolver (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_save (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
int8_t compiler_execute_load (compiler_t *compiler, compiler_ast_node_t *node, int64_t *result)
 
const char_tcompiler_cast_reg_to_size (const char_t *reg, uint8_t size)
 
char_t compiler_get_reg_suffix (uint8_t size)
 
int8_t compiler_define_symbol (compiler_t *compiler, compiler_symbol_t *symbol, size_t symbol_size)
 
int8_t compiler_destroy_external_symbols (compiler_t *compiler)
 
int8_t compiler_add_external_symbol (compiler_t *compiler, const char_t *name, compiler_symbol_type_t type, int64_t size, boolean_t is_const)
 

Variables

const int16_t compiler_fcall_reg_order []
 
const char_t *const compiler_regs []
 

Detailed Description

Turnstone OS compiler header.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Variable Documentation

◆ compiler_fcall_reg_order

const int16_t compiler_fcall_reg_order[]
Initial value:
= {
COMPILER_VM_REG_RDI,
COMPILER_VM_REG_RSI,
COMPILER_VM_REG_RDX,
COMPILER_VM_REG_R10,
COMPILER_VM_REG_R8,
COMPILER_VM_REG_R9,
}