summaryrefslogtreecommitdiff
path: root/cgptoc.c
blob: adb54de2dea922bc40ce30606390e60afcd59240 (plain) (blame)
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
63
64
65
#include <stdlib.h>

#include "cgport.h"

#ifdef G_POWER

#include "cgrconst.h"
#include "cgtypes.h"
#include "cg.h"
#include "cgptoc.h"

int t_label_number;

struct toc_label *toc_labels,**last_toc_next_p;

struct toc_label *new_toc_label (struct label *label,int offset)
{
	struct toc_label *new_toc_label,**toc_label_p;
	int label_number;

	toc_label_p=&label->label_toc_labels;

	if (label->label_flags & HAS_TOC_LABELS){
		struct toc_label *toc_label;
		
		while (toc_label=*toc_label_p,toc_label!=NULL){
			if (toc_label->toc_label_offset==offset)
				return toc_label;
			
			toc_label_p=&toc_label->toc_label_next;
		}
	} else
		label->label_flags |= HAS_TOC_LABELS;
		
	new_toc_label=(struct toc_label*)allocate_memory_from_heap (sizeof (struct toc_label));
	
	label_number=t_label_number++;

	new_toc_label->toc_t_label_number=label_number;
	new_toc_label->toc_label_label=label;
	new_toc_label->toc_label_offset=offset;
	
	*toc_label_p=new_toc_label;
	new_toc_label->toc_label_next=NULL;
	
	*last_toc_next_p=new_toc_label;
	last_toc_next_p=&new_toc_label->toc_next;

	return new_toc_label;
}

int make_toc_label (struct label *label,int offset)
{
	return new_toc_label (label,offset)->toc_t_label_number;
}

void initialize_toc (void)
{
	t_label_number=0;
	last_toc_next_p=&toc_labels;
	toc_labels=NULL;
}

#endif