Init ps5
This commit is contained in:
30
exercises/05/vslc/include/ir.h
Normal file
30
exercises/05/vslc/include/ir.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef IR_H
|
||||
#define IR_H
|
||||
|
||||
/* This is the tree node structure */
|
||||
typedef struct n {
|
||||
node_index_t type;
|
||||
void *data;
|
||||
struct s *entry;
|
||||
uint64_t n_children;
|
||||
struct n **children;
|
||||
} node_t;
|
||||
|
||||
// Export the initializer function, it is needed by the parser
|
||||
void node_init (
|
||||
node_t *nd, node_index_t type, void *data, uint64_t n_children, ...
|
||||
);
|
||||
|
||||
typedef enum {
|
||||
SYM_GLOBAL_VAR, SYM_FUNCTION, SYM_PARAMETER, SYM_LOCAL_VAR
|
||||
} symtype_t;
|
||||
|
||||
typedef struct s {
|
||||
char *name;
|
||||
symtype_t type;
|
||||
node_t *node;
|
||||
size_t seq;
|
||||
size_t nparms;
|
||||
tlhash_t *locals;
|
||||
} symbol_t;
|
||||
#endif
|
||||
37
exercises/05/vslc/include/nodetypes.h
Normal file
37
exercises/05/vslc/include/nodetypes.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef NODETYPES_H
|
||||
#define NODETYPES_H
|
||||
typedef enum {
|
||||
PROGRAM,
|
||||
GLOBAL_LIST,
|
||||
GLOBAL,
|
||||
STATEMENT_LIST,
|
||||
PRINT_LIST,
|
||||
EXPRESSION_LIST,
|
||||
VARIABLE_LIST,
|
||||
ARGUMENT_LIST,
|
||||
PARAMETER_LIST,
|
||||
DECLARATION_LIST,
|
||||
FUNCTION,
|
||||
STATEMENT,
|
||||
BLOCK,
|
||||
ASSIGNMENT_STATEMENT,
|
||||
ADD_STATEMENT,
|
||||
SUBTRACT_STATEMENT,
|
||||
MULTIPLY_STATEMENT,
|
||||
DIVIDE_STATEMENT,
|
||||
RETURN_STATEMENT,
|
||||
PRINT_STATEMENT,
|
||||
NULL_STATEMENT,
|
||||
IF_STATEMENT,
|
||||
WHILE_STATEMENT,
|
||||
EXPRESSION,
|
||||
RELATION,
|
||||
DECLARATION,
|
||||
PRINT_ITEM,
|
||||
IDENTIFIER_DATA,
|
||||
NUMBER_DATA,
|
||||
STRING_DATA
|
||||
} node_index_t;
|
||||
|
||||
extern char *node_string[26];
|
||||
#endif
|
||||
28
exercises/05/vslc/include/tlhash.h
Normal file
28
exercises/05/vslc/include/tlhash.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef TLHASH_H
|
||||
#define TLHASH_H
|
||||
#include <stddef.h>
|
||||
typedef struct el {
|
||||
void *key, *value;
|
||||
size_t key_length;
|
||||
struct el *next;
|
||||
} tlhash_element_t;
|
||||
|
||||
typedef struct {
|
||||
size_t n_buckets, size;
|
||||
tlhash_element_t **buckets;
|
||||
} tlhash_t;
|
||||
|
||||
int tlhash_init ( tlhash_t *tab, size_t n_buckets );
|
||||
int tlhash_finalize ( tlhash_t *tab );
|
||||
int tlhash_insert ( tlhash_t *tab, void *key, size_t keylen, void *val );
|
||||
int tlhash_lookup ( tlhash_t *tab, void *key, size_t keylen, void **val );
|
||||
int tlhash_remove ( tlhash_t *tab, void *key, size_t key_length );
|
||||
size_t tlhash_size ( tlhash_t *tab );
|
||||
void tlhash_keys ( tlhash_t *tab, void **keys );
|
||||
void tlhash_values ( tlhash_t *tab, void **values );
|
||||
|
||||
#define TLHASH_SUCCESS 0 /* Success */
|
||||
#define TLHASH_ENOMEM 1 /* No memory available */
|
||||
#define TLHASH_ENOENT 2 /* No such table entry */
|
||||
#define TLHASH_EEXIST 3 /* Table entry already exists */
|
||||
#endif
|
||||
50
exercises/05/vslc/include/vslc.h
Normal file
50
exercises/05/vslc/include/vslc.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef VSLC_H
|
||||
#define VSLC_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// Prototypes for the hash table functions
|
||||
#include "tlhash.h"
|
||||
|
||||
// Numbers and names for the types of syntax tree nodes
|
||||
#include "nodetypes.h"
|
||||
|
||||
// Definition of the tree node type
|
||||
#include "ir.h"
|
||||
|
||||
// Token definitions and other things from bison, needs def. of node type
|
||||
#include "y.tab.h"
|
||||
|
||||
/* This is generated from the bison grammar, calls on the flex specification */
|
||||
int yyerror ( const char *error );
|
||||
|
||||
/* These are defined in the parser generated by bison */
|
||||
extern int yylineno;
|
||||
extern int yylex ( void );
|
||||
extern char yytext[];
|
||||
|
||||
/* Global state */
|
||||
extern node_t *root;
|
||||
|
||||
// Moving global defs to global header
|
||||
|
||||
extern tlhash_t *global_names; // Defined in ir.c, used by generator.c
|
||||
extern char **string_list; // Defined in ir.c, used by generator.c
|
||||
extern size_t stringc; // Defined in ir.c, used by generator.c
|
||||
|
||||
/* Global routines, called from main in vslc.c */
|
||||
void simplify_syntax_tree ( void );
|
||||
void print_syntax_tree ( void );
|
||||
void destroy_syntax_tree ( void );
|
||||
|
||||
void create_symbol_table ( void );
|
||||
void print_symbol_table ( void );
|
||||
void destroy_symbol_table ( void );
|
||||
|
||||
void generate_program ( void );
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user