This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stab.c
63 lines (55 loc) · 1.45 KB
/
stab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifdef NGDEBUG
#include <assert.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "stab.h"
#include "env.h"
int func_cnt = 0;
int type_top = 0;
int sym_top = 0;
int str_cnt = 0;
int dbl_cnt = 0;
struct Stab *stab_new(const char *name, int lineno)
{
struct Stab *symbol = (struct Stab *)malloc(sizeof(struct Stab));
memset(symbol, 0, sizeof(struct Stab));
symbol->name = strdup(name);
symbol->lineno = lineno;
symbol->funcno = -1;
return symbol;
}
struct Arysize_entry *arysize_new(size_t size)
{
struct Arysize_entry *ae = (struct Arysize_entry *)malloc(sizeof(struct Arysize_entry));
ae->size = size;
ae->next = NULL;
return ae;
}
struct Param_entry *param_new(struct Stab *symbol)
{
struct Param_entry *pe = (struct Param_entry *)malloc(sizeof(struct Param_entry));
pe->symbol = symbol;
pe->next = NULL;
return pe;
}
struct Type_info *type_new(enum Type_kind kind, struct Stab *struct_sym)
{
struct Type_info *ti = (struct Type_info *)malloc(sizeof(struct Type_info));
ti->kind = kind;
ti->struct_sym = struct_sym;
return ti;
}
size_t type_size(struct Type_info *ti)
{
switch (ti->kind) {
case T_CHAR: return CHAR_SIZE;
case T_STR: return PTR_SIZE;
case T_INT: return INT_SIZE;
case T_FLOAT: return FLOAT_SIZE;
case T_DOUBLE: return DOUBLE_SIZE;
case T_STRUCT: return ti->struct_sym->size;
default: return 0;
}
return 0;
}