tpop_t.h 2.09 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 -- private header.
 * @author  Goetz Lindenmaier, Michael Beck
10
 */
Michael Beck's avatar
Michael Beck committed
11
12
#ifndef FIRM_TR_TPOP_T_H
#define FIRM_TR_TPOP_T_H
13

Christian Würdig's avatar
Christian Würdig committed
14
15
#include <stdlib.h>

16
#include "firm_types.h"
17
#include "typerep.h"
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
18

19
20
21
#define get_tpop_code(op)      _get_tpop_code(op)
#define get_tpop_ident(op)     _get_tpop_ident(op)

22
/** The type opcode. */
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
23
struct tp_op {
Matthias Braun's avatar
Matthias Braun committed
24
25
26
	tp_opcode code;      /**< The tpop code. */
	ident     *name;     /**< The name of the type opcode. */
	size_t    attr_size; /**< The attribute size for a type of this opcode. */
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
27
28
};

Sebastian Felis's avatar
Sebastian Felis committed
29
/**
Michael Beck's avatar
Michael Beck committed
30
 * Returns a new type opcode.
Michael Beck's avatar
Michael Beck committed
31
 *
32
 * Allocates a new tp_op struct and initializes its fields with
Michael Beck's avatar
Michael Beck committed
33
34
 * the passed values.  This function is only to be used during
 * initialization of the library.
Michael Beck's avatar
Michael Beck committed
35
 *
Michael Beck's avatar
Michael Beck committed
36
37
38
39
40
 * @param code        the enum for this type opcode.
 * @param name        an ident for the name of the type opcode.
 * @param attr_size   the size of the attributes necessary for a type with
 *                    this opcode
 * @return A new type opcode.
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
41
 */
42
tp_op const *new_tpop(tp_opcode code, ident *name, size_t attr_size);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
43

44
/**
Michael Beck's avatar
Michael Beck committed
45
 * Free a tpop data structure.
46
 */
Matthias Braun's avatar
Matthias Braun committed
47
void free_tpop(tp_op const *tpop);
48

Sebastian Felis's avatar
Sebastian Felis committed
49
/**
Michael Beck's avatar
Michael Beck committed
50
 * Initialize the tpop module.
Michael Beck's avatar
Michael Beck committed
51
 *
Michael Beck's avatar
Michael Beck committed
52
53
54
55
 * Must be called during the initialization of the library. Allocates
 * opcodes and sets the globals that are external visible as specified
 * in tpop.h.
 * Allocates opcodes for classes, struct, method, union, array,
56
 * pointer and primitive and sets the according values.
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
57
 */
Michael Beck's avatar
Michael Beck committed
58
void init_tpop(void);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
59

60
/**
Michael Beck's avatar
Michael Beck committed
61
 * Finalize the tpop module.
62
 *
Michael Beck's avatar
Michael Beck committed
63
 * Frees all type opcodes.
64
65
66
 */
void finish_tpop(void);

Sebastian Felis's avatar
Sebastian Felis committed
67
/**
Michael Beck's avatar
Michael Beck committed
68
69
 * Returns the size of the attribute to this kind
 * of type.
Michael Beck's avatar
Michael Beck committed
70
 *
Michael Beck's avatar
Michael Beck committed
71
 * Internal feature.
Sebastian Felis's avatar
Sebastian Felis committed
72
 *
Michael Beck's avatar
Michael Beck committed
73
74
 * @param op  The type opcode to get the size for.
 * @return The size of the attribute of types with this opcode.
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
75
 */
Matthias Braun's avatar
Matthias Braun committed
76
static inline size_t get_tpop_attr_size(tp_op const *op)
77
78
79
{
	return op->attr_size;
}
80

Matthias Braun's avatar
Matthias Braun committed
81
static inline tp_opcode _get_tpop_code(tp_op const *op)
82
{
Michael Beck's avatar
Michael Beck committed
83
	return op->code;
84
85
}

Matthias Braun's avatar
Matthias Braun committed
86
static inline ident *_get_tpop_ident(tp_op const *op)
87
{
Michael Beck's avatar
Michael Beck committed
88
	return op->name;
89
90
}

91
#endif