tagged release 0.7.1
[parrot.git] / compilers / pirc / new / pirsymbol.h
blob8cdf057c4ca7537897fc7ab7fa641aca9cf79bfc
1 /*
2 * $Id$
3 * Copyright (C) 2007-2008, The Perl Foundation.
4 */
7 /* This file defines the data structures for symbol management. A symbol
8 * is a declared .local or .param, or a PIR register. Although these
9 * two data structures are very similar, and they could potentially be
10 * merged, this should not be done. Declared symbols are handled a bit
11 * different from PIR registers, as the latter do not need to be
12 * declared. Merging them would only result in more complex code.
16 #ifndef PARROT_PIR_PIRSYMBOL_H_GUARD
17 #define PARROT_PIR_PIRSYMBOL_H_GUARD
19 #include "pircompiler.h"
20 #include "pircompunit.h"
24 /* structure to represent a declared local variable or parameter */
25 typedef struct symbol {
26 char *name; /* name of this symbol */
27 pir_type type; /* type of this symbol */
28 int color; /* allocated PASM register for this symbol, -1 if not allocated. */
29 target_flag flags;
31 struct symbol *next;
33 } symbol;
36 /* structure to represent a PIR register. */
37 typedef struct pir_reg {
38 int regno; /* symbolic (PIR) register number */
39 pir_type type; /* type of ths register */
40 int color; /* register assigned by register allocator, -1 if not allocated. */
42 struct pir_reg *next;
44 } pir_reg;
47 /* structure to represent a global identifier (XXX only labels?) */
48 typedef struct global_ident {
49 char *name;
50 int const_nr;
52 struct global_ident *next;
54 } global_ident;
57 /* symbol constructor */
58 symbol *new_symbol(char * const name, pir_type type);
60 /* to enter a symbol in the symbol table */
61 void declare_local(struct lexer_state * const lexer, pir_type type, symbol *list);
63 /* to find a symbol in the symbol table */
64 symbol *find_symbol(struct lexer_state * const lexer, char * const name);
66 /* to find declared symbols that are never referenced */
67 void check_unused_symbols(struct lexer_state * const lexer);
69 /* find specified register; if it was not used yet, assign a PASM register to it */
70 int color_reg(struct lexer_state * const lexer, pir_type type, int regno);
72 /* store a global identifier (label) */
73 void store_global_ident(struct lexer_state * const lexer, char * const name);
75 /* find a global identifier */
76 global_ident *find_global_ident(struct lexer_state * const lexer, char * const name);
78 /* store a global .const symbol */
79 void store_global_const(struct lexer_state * const lexer, constant * const c);
81 /* find a global .const symbol */
82 constant *find_constant(struct lexer_state * const lexer, char * const name);
84 /* get a new PASM register of the specified type */
85 int next_register(struct lexer_state * const lexer, pir_type type);
87 #endif /* PARROT_PIR_PIRSYMBOL_H_GUARD */
90 * Local variables:
91 * c-file-style: "parrot"
92 * End:
93 * vim: expandtab shiftwidth=4: