tpop.c 2.79 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Michael Beck's avatar
Michael Beck committed
6
7
8
9
/**
 * @file
 * @brief   Opcode of types.
 * @author  Goetz Lindenmaier, Michael Beck
10
 */
11
#include "ident_t.h"
Michael Beck's avatar
Michael Beck committed
12
13
14
#include "xmalloc.h"
#include "tpop_t.h"
#include "type_t.h"
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
15

Matthias Braun's avatar
Matthias Braun committed
16
17
18
19
20
21
22
23
24
const tp_op *type_class;     const tp_op *get_tpop_class    (void) { return type_class;     }
const tp_op *type_struct;    const tp_op *get_tpop_struct   (void) { return type_struct;    }
const tp_op *type_method;    const tp_op *get_tpop_method   (void) { return type_method;    }
const tp_op *type_union;     const tp_op *get_tpop_union    (void) { return type_union;     }
const tp_op *type_array;     const tp_op *get_tpop_array    (void) { return type_array;     }
const tp_op *type_pointer;   const tp_op *get_tpop_pointer  (void) { return type_pointer;   }
const tp_op *type_primitive; const tp_op *get_tpop_primitive(void) { return type_primitive; }
const tp_op *tpop_code;      const tp_op *get_tpop_code_type(void) { return tpop_code;      }
const tp_op *tpop_unknown;   const tp_op *get_tpop_unknown  (void) { return tpop_unknown;   }
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
25

26
const tp_op *new_tpop(tp_opcode code, ident *name, size_t attr_size)
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
27
{
28
	tp_op *res = XMALLOC(tp_op);
29
30
31
	res->code      = code;
	res->name      = name;
	res->attr_size = attr_size;
Michael Beck's avatar
Michael Beck committed
32
	return res;
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
33
34
}

35
void free_tpop(const tp_op *tpop)
36
{
Matthias Braun's avatar
Matthias Braun committed
37
	free((void*)tpop);
38
39
}

40
41
void init_tpop(void)
{
42
43
44
45
46
47
48
49
50
	type_class     = new_tpop(tpo_class,     NEW_IDENT("class"),     sizeof(cls_attr)     );
	type_struct    = new_tpop(tpo_struct,    NEW_IDENT("struct"),    sizeof(compound_attr));
	type_method    = new_tpop(tpo_method,    NEW_IDENT("method"),    sizeof(mtd_attr)     );
	type_union     = new_tpop(tpo_union,     NEW_IDENT("union"),     sizeof(compound_attr));
	type_array     = new_tpop(tpo_array,     NEW_IDENT("array"),     sizeof(arr_attr)     );
	type_pointer   = new_tpop(tpo_pointer,   NEW_IDENT("pointer"),   sizeof(ptr_attr)     );
	type_primitive = new_tpop(tpo_primitive, NEW_IDENT("primitive"), 0                    );
	tpop_code      = new_tpop(tpo_code,      NEW_IDENT("code"),      0                    );
	tpop_unknown   = new_tpop(tpo_unknown,   NEW_IDENT("Unknown"),   0                    );
51
}
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
52

53
54
void finish_tpop(void)
{
Matthias Braun's avatar
Matthias Braun committed
55
56
57
58
59
60
61
62
63
	free_tpop(type_class    ); type_class       = NULL;
	free_tpop(type_struct   ); type_struct      = NULL;
	free_tpop(type_method   ); type_method      = NULL;
	free_tpop(type_union    ); type_union       = NULL;
	free_tpop(type_array    ); type_array       = NULL;
	free_tpop(type_pointer  ); type_pointer     = NULL;
	free_tpop(type_primitive); type_primitive   = NULL;
	free_tpop(tpop_code     ); tpop_code        = NULL;
	free_tpop(tpop_unknown  ); tpop_unknown     = NULL;
Michael Beck's avatar
Michael Beck committed
64
}
65

66
const char *get_tpop_name(const tp_op *op)
67
{
Michael Beck's avatar
Michael Beck committed
68
	return get_id_str(op->name);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
69
70
}

71
72
tp_opcode (get_tpop_code)(const tp_op *op)
{
Michael Beck's avatar
Michael Beck committed
73
	return _get_tpop_code(op);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
74
}