bcgen_instructions.c 132 KB
Newer Older
1
#include "bcgen_instructions.h"
Erin van der Veen's avatar
Erin van der Veen committed
2

3 4 5 6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

7 8 9
#include "abc_instructions.h"
#include "bcgen.h"
#include "util.h"
10

11
#define max_implemented_instruction_n CMAX-1
12

13 14
#define N_ADD_ARG_LABELS 32

15
struct program pgrm;
16
uint32_t last_d, last_jsr_with_d;
17

18
struct label_node *labels;
Camil Staps's avatar
Camil Staps committed
19
uint32_t label_id;
20 21
uint32_t global_label_count;
uint32_t global_label_string_count;
22
static struct label *start_label;
23

24
uint32_t module_n;
25

26
uint32_t list_code = 0;
27

28 29
uint32_t allocated_code_size;
uint32_t allocated_data_size;
30
uint32_t allocated_strings_size;
31 32
uint32_t allocated_code_relocations_size;
uint32_t allocated_data_relocations_size;
33

34
static uint32_t Fadd_arg_label_used[N_ADD_ARG_LABELS];
35

Camil Staps's avatar
Camil Staps committed
36
#ifndef LINK_CLEAN_RUNTIME
37 38 39 40 41 42 43 44 45
int16_t warned_unsupported_instructions[128]={-1};
int warned_unsupported_instructions_i=0;
void unsupported_instruction_warning(int16_t instruction) {
	for (int i=0; i<warned_unsupported_instructions_i; i++)
		if (warned_unsupported_instructions[i] == instruction)
			return;
	warned_unsupported_instructions[warned_unsupported_instructions_i++] = instruction;
	fprintf(stderr,"Warning: instruction %s is not supported by the interpreter\n",instruction_name(instruction));
}
Camil Staps's avatar
Camil Staps committed
46
#endif
47

48
struct program *initialize_code(void) {
49 50 51 52 53
	int i;
	for(i = 0; i < N_ADD_ARG_LABELS; ++i)
		Fadd_arg_label_used[i] = 0;

	labels = NULL;
Camil Staps's avatar
Camil Staps committed
54
	label_id = 0;
55 56
	global_label_count = 0;
	global_label_string_count = 0;
Camil Staps's avatar
Camil Staps committed
57

58 59
	module_n = 0;

60 61 62 63 64
	pgrm = (struct program) {
		0,
		0,
		0,
		0,
65
		0,
66
		0,
67
		0,
Camil Staps's avatar
Camil Staps committed
68
		(struct word*) safe_malloc(512 * sizeof(struct word)),
69
		(uint32_t*) safe_malloc(512 * sizeof(uint32_t)),
70
		(uint64_t*) safe_malloc(512 * sizeof(uint64_t)),
71 72 73 74
		(relocation*) safe_malloc(512 * sizeof(relocation)),
		(relocation*) safe_malloc(512 * sizeof(relocation)),
		};

75 76
	allocated_code_size = 512;
	allocated_data_size = 512;
77
	allocated_strings_size = 512;
78 79
	allocated_code_relocations_size = 512;
	allocated_data_relocations_size = 512;
80 81

	return &pgrm;
82 83
}

Camil Staps's avatar
Camil Staps committed
84
#ifndef LINK_CLEAN_RUNTIME
85 86
void code_next_module(void) {
	module_n++;
87 88 89

	last_d = 0;
	last_jsr_with_d = 0;
90
}
Camil Staps's avatar
Camil Staps committed
91
#endif
92 93 94

static void realloc_code(void) {
	allocated_code_size *= 2;
Camil Staps's avatar
Camil Staps committed
95
	pgrm.code = (struct word*) safe_realloc(pgrm.code, allocated_code_size * sizeof(struct word));
96 97
}

98 99
static void realloc_strings(void) {
	allocated_strings_size *= 2;
100
	pgrm.strings = (uint32_t*) safe_realloc(pgrm.strings, allocated_strings_size * sizeof(uint32_t));
101 102
}

103 104
static void realloc_data(void) {
	allocated_data_size *= 2;
105
	pgrm.data = (uint64_t*) safe_realloc(pgrm.data, allocated_data_size * sizeof(uint64_t));
106 107
}

108
void store_code_elem(uint8_t bytewidth, uint64_t value) {
109 110 111
	if (pgrm.code_size >= allocated_code_size)
		realloc_code();

112
	pgrm.code[pgrm.code_size++] = (struct word) {bytewidth, value};
113
	pgrm.code_byte_size+=bytewidth;
114 115 116 117 118 119 120 121 122
}

struct label *enter_label(char *label_name) {
	struct label_node **label_node_pp;

	label_node_pp = &labels;
	while (*label_node_pp!=NULL) {
		struct label_node *label_node_p;
		int r;
Camil Staps's avatar
Camil Staps committed
123

124 125 126 127 128 129
		label_node_p=*label_node_pp;
		r=strcmp(label_name,label_node_p->label_node_label_p->label_name);
		if (r==0) {
			if (label_node_p->label_node_label_p->label_module_n>=0 && label_node_p->label_node_label_p->label_module_n!=module_n) {
				if (label_node_p->label_node_label_p->label_offset<0) {
					label_node_p->label_node_label_p->label_module_n = -1;
Camil Staps's avatar
Camil Staps committed
130

131 132 133
					return label_node_p->label_node_label_p;
				} else {
					struct label *new_label_p;
Camil Staps's avatar
Camil Staps committed
134

135
					new_label_p = (struct label*) safe_malloc(sizeof(struct label));
136
					new_label_p->label_name=label_node_p->label_node_label_p->label_name;
Camil Staps's avatar
Camil Staps committed
137
					new_label_p->label_id=label_id++;
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
					new_label_p->label_module_n=module_n;
					new_label_p->label_offset=-1;

					label_node_p->label_node_label_p=new_label_p;
					return new_label_p;
				}
			}

			return label_node_p->label_node_label_p;
		}
		if (r<0)
			label_node_pp=&label_node_p->label_node_left;
		else
			label_node_pp=&label_node_p->label_node_right;
	}

	struct label_node *new_label_node_p;
	struct label *new_label_p;

157 158
	new_label_node_p = (struct label_node*) safe_malloc(sizeof(struct label_node));
	new_label_p = (struct label*) safe_malloc(sizeof(struct label));
159 160 161
	new_label_node_p->label_node_left = NULL;
	new_label_node_p->label_node_right = NULL;
	new_label_node_p->label_node_label_p = new_label_p;
162
	new_label_p->label_name = (char*) safe_malloc(strlen(label_name) + 1);
Camil Staps's avatar
Camil Staps committed
163
	new_label_p->label_id=label_id++;
164 165 166
	strcpy(new_label_p->label_name, label_name);
	new_label_p->label_module_n = module_n;
	new_label_p->label_offset = -1;
Camil Staps's avatar
Camil Staps committed
167

168 169 170 171
	*label_node_pp = new_label_node_p;
	return new_label_p;
}

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
#ifdef LINKER
struct label *find_label(char *label_name) {
	struct label_node *label_node_p=labels;

	while (label_node_p!=NULL) {
		int r=strcmp(label_name,label_node_p->label_node_label_p->label_name);
		if (r==0)
			return label_node_p->label_node_label_p;
		else if (r<0)
			label_node_p=label_node_p->label_node_left;
		else
			label_node_p=label_node_p->label_node_right;
	}

	return NULL;
}

189 190
static struct label_node **move_label_tree_to_list(
		struct label_node **dest, struct label_node *tree) {
191
	if (tree->label_node_left!=NULL)
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
		dest=move_label_tree_to_list(dest,tree->label_node_left);
	*dest++=tree;
	if (tree->label_node_right!=NULL)
		dest=move_label_tree_to_list(dest,tree->label_node_right);
	return dest;
}

static struct label_node **merge_label_tree_with_list(
		struct label_node **dest,struct label_node *tree,
		struct label_node **list,unsigned int *list_i,unsigned int list_size) {
	int i=*list_i;

	if (i>=list_size)
		return move_label_tree_to_list(dest,tree);

	int r=strcmp(list[i]->label_node_label_p->label_name,tree->label_node_label_p->label_name);
	if (r>0) { /* prune: left side does not need to consider label list */
		if (tree->label_node_left!=NULL)
			dest=move_label_tree_to_list(dest,tree->label_node_left);
	} else {
		if (tree->label_node_left!=NULL)
			dest=merge_label_tree_with_list(dest,tree->label_node_left,list,list_i,list_size);

		i=*list_i;
		while (i<list_size && (r=strcmp(list[i]->label_node_label_p->label_name,tree->label_node_label_p->label_name))<0)
			*dest++=list[i++];
		*list_i=i;

		if (r==0) {
			EPRINTF("internal error: %s redefined\n",tree->label_node_label_p->label_name);
			exit(-1);
		}
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
	}

	*dest++=tree;

	if (tree->label_node_right!=NULL)
		dest=merge_label_tree_with_list(dest,tree->label_node_right,list,list_i,list_size);

	return dest;
}

static struct label_node *update_label_node_pointers(
		struct label_node **sorted_list,int lft,int rgt) {
	if (rgt<lft)
		return NULL;

	if (rgt==lft) {
		sorted_list[lft]->label_node_left=NULL;
		sorted_list[lft]->label_node_right=NULL;
		return sorted_list[lft];
	}

	int middle=lft+(rgt-lft)/2;
	sorted_list[middle]->label_node_left =update_label_node_pointers(sorted_list,lft,middle-1);
	sorted_list[middle]->label_node_right=update_label_node_pointers(sorted_list,middle+1,rgt);
	return sorted_list[middle];
}

void merge_new_labels_and_rebalance(struct label_node **new_labels,unsigned int n_new_labels) {
	for (int i=0; i<n_new_labels; i++) {
		struct label *label=new_labels[i]->label_node_label_p;
		label->label_id=label_id++;
		make_label_global(label);
	}

	if (labels==NULL) {
		labels=update_label_node_pointers(new_labels,0,label_id-1);
		return;
	}

	struct label_node **temp_list=safe_malloc(label_id*sizeof(struct label_node*));
	unsigned int list_i=0;
	struct label_node **temp_list_end=merge_label_tree_with_list(temp_list,labels,new_labels,&list_i,n_new_labels);
	while (list_i<n_new_labels)
		*temp_list_end++=new_labels[list_i++];

	labels=update_label_node_pointers(temp_list,0,label_id-1);

	free(temp_list);
}
#endif

275 276 277 278 279 280 281 282 283
struct label *new_label_at_offset(uint32_t offset) {
	char name[16];
	snprintf(name, 16, "i%x", offset);
	name[15] = '\0';
	struct label *label = enter_label(name);
	label->label_offset = offset;
	return label;
}

Camil Staps's avatar
Camil Staps committed
284 285 286
int internal_label_id = 0;
struct label *new_internal_label(void) {
	char label_name[14];
287
	sprintf(label_name,"%%%x",internal_label_id++);
Camil Staps's avatar
Camil Staps committed
288 289 290 291
	struct label *label = enter_label(label_name);
	return label;
}

292
void make_label_global(struct label *label) {
293 294 295 296 297
	if (label->label_module_n != -1) {
		label->label_module_n = -1;
		global_label_count++;
		global_label_string_count+=strlen(label->label_name);
	}
298 299
}

300
void store_data_l(uint64_t v) {
301 302
	if (pgrm.data_size >= allocated_data_size)
		realloc_data();
303
	*(uint64_t*)&pgrm.data[pgrm.data_size++] = v;
304 305
}

306 307 308 309 310
struct relocation *add_code_relocation(struct label *label, uint32_t offset) {
	if (pgrm.code_reloc_size>=allocated_code_relocations_size) {
		allocated_code_relocations_size *= 2;
		pgrm.code_relocations = (relocation*) safe_realloc(pgrm.code_relocations, allocated_code_relocations_size * sizeof(relocation));
	}
311

312 313 314 315 316 317 318 319
	struct relocation *relocation_p;

	relocation_p=&pgrm.code_relocations[pgrm.code_reloc_size++];
	relocation_p->relocation_offset=offset;
	relocation_p->relocation_label=label;

	return relocation_p;
}
Camil Staps's avatar
Camil Staps committed
320

321 322 323 324
struct relocation *add_data_relocation(struct label *label, uint32_t offset) {
	if (pgrm.data_reloc_size>=allocated_data_relocations_size) {
		allocated_data_relocations_size *= 2;
		pgrm.data_relocations = (relocation*) safe_realloc(pgrm.data_relocations, allocated_data_relocations_size * sizeof(relocation));
325 326
	}

327 328 329 330 331 332 333 334 335
	struct relocation *relocation_p;

	relocation_p=&pgrm.data_relocations[pgrm.data_reloc_size++];
	relocation_p->relocation_offset=offset;
	relocation_p->relocation_label=label;

	return relocation_p;
}

Camil Staps's avatar
Camil Staps committed
336
#ifndef LINK_CLEAN_RUNTIME
337 338
void store_code_internal_label_value(struct label *label,uint32_t offset) {
	add_code_relocation(label, pgrm.code_size);
339
	store_code_elem(4, offset);
340 341
}

342
void store_code_label_value(char *label_name,int32_t offset) {
343
	struct label *label;
Camil Staps's avatar
Camil Staps committed
344

345 346
	label=enter_label(label_name);

347
	add_code_relocation(label, pgrm.code_size);
348

349
	store_code_elem(4, offset);
350 351
}

352
static void store_data_label_value_of_label(struct label *label,uint32_t offset) {
353
	add_data_relocation(label, pgrm.data_size);
354 355 356
	store_data_l(offset);
}

357
void store_data_label_value(char *label_name,uint32_t offset) {
358 359 360 361 362 363
	store_data_label_value_of_label(enter_label (label_name),offset);
}

void add_data2_to_code(int i) {
	if (list_code)
		printf("%d\t.data2 %d\n",pgrm.code_size,i);
Camil Staps's avatar
Camil Staps committed
364

365
	store_code_elem(2, i);
366 367
}

368 369 370 371 372 373 374
void add_data4_to_code(int i) {
	if (list_code)
		printf("%d\t.data4 %d\n",pgrm.code_size,i);

	store_code_elem(4, i);
}

375
void add_data8_to_code(int i) {
376
	if (list_code)
377
		printf("%d\t.data8 %d\n",pgrm.code_size,i);
Camil Staps's avatar
Camil Staps committed
378

Camil Staps's avatar
Camil Staps committed
379
	store_code_elem(8, i);
380 381
}

Camil Staps's avatar
Camil Staps committed
382
void add_instruction(int16_t i) {
383 384 385
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s\n",pgrm.code_size,instruction_name (i));

386
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
387 388
}

389 390
struct word *add_add_arg_labels(void) {
	int i;
Camil Staps's avatar
Camil Staps committed
391

392 393
	for(i=0; i<N_ADD_ARG_LABELS; ++i)
		if (Fadd_arg_label_used[i]) {
Camil Staps's avatar
Camil Staps committed
394 395 396 397 398 399 400
			char label_name[11];
			sprintf(label_name,"_add_arg%d",i);
			struct label *label = enter_label(label_name);
			if (label->label_module_n != -1) {
				make_label_global(label);
				label->label_offset = pgrm.code_size<<2;
			}
401 402 403
			add_instruction(Cadd_arg0+i);
		}

Camil Staps's avatar
Camil Staps committed
404
	return pgrm.code;
405 406 407 408
}

void add_code_and_data_offsets(void) {
	int i;
Camil Staps's avatar
Camil Staps committed
409
	size_t code_offset,data_offset;
Camil Staps's avatar
Camil Staps committed
410

Camil Staps's avatar
Camil Staps committed
411 412
	code_offset = (size_t) pgrm.code;
	data_offset = (size_t) pgrm.data;
413

414
	for(i=0; i<pgrm.code_reloc_size; ++i) {
415 416
		struct relocation *relocation_p;

Camil Staps's avatar
Camil Staps committed
417
		relocation_p=&pgrm.code_relocations[i];
418
		if ((relocation_p->relocation_label->label_offset & 1)==0)
Camil Staps's avatar
Camil Staps committed
419
			*(int32_t*)&pgrm.code[relocation_p->relocation_offset] += code_offset;
420
		else
Camil Staps's avatar
Camil Staps committed
421
			*(int32_t*)&pgrm.code[relocation_p->relocation_offset] += data_offset;
422 423
	}

424
	for(i=0; i<pgrm.data_reloc_size; ++i) {
425 426
		struct relocation *relocation_p;

Camil Staps's avatar
Camil Staps committed
427
		relocation_p=&pgrm.data_relocations[i];
428
		if ((relocation_p->relocation_label->label_offset & 1)==0)
Camil Staps's avatar
Camil Staps committed
429
			*(int32_t*)&pgrm.data[relocation_p->relocation_offset] += code_offset;
430
		else
Camil Staps's avatar
Camil Staps committed
431
			*(int32_t*)&pgrm.data[relocation_p->relocation_offset] += data_offset;
432 433 434
	}
}

Camil Staps's avatar
Camil Staps committed
435
void add_instruction_label(uint16_t i,char *label_name) {
436 437 438
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s\n",pgrm.code_size,instruction_name (i),label_name);

439
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
440 441 442
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
443
void add_instruction_label_offset(uint16_t i,char *label_name,uint32_t offset) {
444 445 446
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s%+d\n",pgrm.code_size,instruction_name (i),label_name,offset);

447
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
448 449 450
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
451
void add_instruction_label_offset_label(int16_t i,char *label_name1,uint32_t offset,char *label_name2) {
452 453 454
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s%+d %s\n",pgrm.code_size,instruction_name (i),label_name1,offset,label_name2);

455
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
456 457 458 459
	store_code_label_value(label_name1,offset);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
460
void add_instruction_label_offset_w(uint16_t i,char *label_name,uint32_t offset,int32_t n1) {
461 462 463
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s%+d %d\n",pgrm.code_size,instruction_name (i),label_name,offset,(int)n1);

464
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
465
	store_code_label_value(label_name,offset);
466
	store_code_elem(2, n1);
467 468
}

Camil Staps's avatar
Camil Staps committed
469
void add_instruction_label_offset_w_label(uint16_t i,char *label_name1,uint32_t offset,int32_t n1,char *label_name2) {
470 471 472
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s%+d %d %s\n",pgrm.code_size,instruction_name (i),label_name1,offset,(int)n1,label_name2);

473
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
474
	store_code_label_value(label_name1,offset);
475
	store_code_elem(2, n1);
476 477 478 479
	store_code_label_value(label_name2,0);
}

void add_instruction_label_offset_label_label_offset_label
Camil Staps's avatar
Camil Staps committed
480
	(int16_t i,char *label_name1,uint32_t offset1,char *label_name2,char *label_name3,uint32_t offset2,char *label_name4) {
481 482 483 484
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s%+d %s %s%+d %s\n",pgrm.code_size,instruction_name (i),label_name1,offset1,label_name2,
																			label_name3,offset2,label_name4);

485
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
486 487 488 489 490 491
	store_code_label_value(label_name1,offset1);
	store_code_label_value(label_name2,0);
	store_code_label_value(label_name3,offset2);
	store_code_label_value(label_name4,0);
}

Camil Staps's avatar
Camil Staps committed
492
void add_instruction_label_w_w(int16_t i,char *label_name,int32_t n1,int32_t n2) {
493 494 495
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %s %d %d\n",pgrm.code_size,instruction_name (i),label_name,(int)n1,(int)n2);

496
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
497
	store_code_label_value(label_name,0);
498 499
	store_code_elem(2, n1);
	store_code_elem(2, n2);
500 501
}

Camil Staps's avatar
Camil Staps committed
502
void add_instruction_c(int16_t i,char n) {
503 504 505 506 507 508 509
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),(int)n);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(1, n);
}

510 511 512 513 514 515 516 517 518
void add_instruction_c_label(int16_t i,char n,char *label_name) {
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s\n",pgrm.code_size,instruction_name (i),(int)n,label_name);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(1, n);
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
519
void add_instruction_w(int16_t i,int32_t n) {
520 521 522
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),(int)n);

523 524 525 526
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n);
}

527
void add_instruction_w_i(int16_t i,int32_t n1,int64_t n2) {
528
	if (list_code || i>max_implemented_instruction_n)
529
		printf("%d\t%s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2);
530

531
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
532
	store_code_elem(2, n1);
Camil Staps's avatar
Camil Staps committed
533
	store_code_elem(8, n2);
534 535
}

Camil Staps's avatar
Camil Staps committed
536
void add_instruction_w_label(int16_t i,int32_t n,char *label_name) {
537 538 539
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s\n",pgrm.code_size,instruction_name (i),(int)n,label_name);

540 541 542 543 544
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n);
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
545
void add_instruction_w_label_offset(int16_t i,int32_t n,char *label_name,uint32_t offset) {
546 547 548
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s%+d\n",pgrm.code_size,instruction_name (i),(int)n,label_name,offset);

549
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
550
	store_code_elem(2, n);
551 552 553
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
554
void add_instruction_w_label_offset_label(int16_t i,int32_t n,char *label_name1,uint32_t offset,char *label_name2) {
555 556 557
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s%+d %s\n",pgrm.code_size,instruction_name (i),(int)n,label_name1,offset,label_name2);

558
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
559
	store_code_elem(2, n);
560 561 562 563
	store_code_label_value(label_name1,offset);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
564
void add_instruction_w_label_w(int16_t i,int32_t n1,char *label_name,int32_t n2) {
565 566 567
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s %d\n",pgrm.code_size,instruction_name (i),(int)n1,label_name,(int)n2);

568
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
569
	store_code_elem(2, n1);
570
	store_code_label_value(label_name,0);
571
	store_code_elem(2, n2);
572 573 574
}

void add_instruction_w_label_offset_label_label_offset_label
Camil Staps's avatar
Camil Staps committed
575
	(int16_t i,int32_t n1,char *label_name1,uint32_t offset1,char *label_name2,char *label_name3,uint32_t offset2,char *label_name4) {
576 577 578 579
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s%+d %s %s%+d %s\n",pgrm.code_size,instruction_name (i),n1,label_name1,offset1,label_name2,
																				  label_name3,offset2,label_name4);

580
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
581
	store_code_elem(2, n1);
582 583 584 585 586 587
	store_code_label_value(label_name1,offset1);
	store_code_label_value(label_name2,0);
	store_code_label_value(label_name3,offset2);
	store_code_label_value(label_name4,0);
}

Camil Staps's avatar
Camil Staps committed
588
void add_instruction_w_label_offset_w(int16_t i,int32_t n1,char *label_name,uint32_t offset,int32_t n2) {
589 590 591
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s+%d %d\n",pgrm.code_size,instruction_name (i),(int)n1,label_name,offset,(int)n2);

592
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
593
	store_code_elem(2, n1);
594
	store_code_label_value(label_name,offset);
595
	store_code_elem(2, n2);
596 597
}

Camil Staps's avatar
Camil Staps committed
598
void add_instruction_w_label_offset_w_w(int16_t i,int32_t n1,char *label_name,uint32_t offset,int32_t n2,int32_t n3) {
599 600 601
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s+%d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,label_name,offset,(int)n2,(int)n3);

602
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
603
	store_code_elem(2, n1);
604
	store_code_label_value(label_name,offset);
605 606
	store_code_elem(2, n2);
	store_code_elem(2, n3);
607 608
}

Camil Staps's avatar
Camil Staps committed
609
void add_instruction_w_label_offset_w_w_w(int16_t i,int32_t n1,char *label_name,uint32_t offset,int32_t n2,int32_t n3,int32_t n4) {
610 611 612
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s+%d %d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,label_name,offset,(int)n2,(int)n3,(int)n4);

613
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
614
	store_code_elem(2, n1);
615
	store_code_label_value(label_name,offset);
616 617 618
	store_code_elem(2, n2);
	store_code_elem(2, n3);
	store_code_elem(2, n4);
619 620
}

Camil Staps's avatar
Camil Staps committed
621
void add_instruction_w_c(int16_t i,int32_t n1,char n2) {
622 623 624 625 626 627 628 629
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(1, n2);
}

Camil Staps's avatar
Camil Staps committed
630
void add_instruction_w_w(int16_t i,int32_t n1,int32_t n2) {
631 632
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2);
Camil Staps's avatar
Camil Staps committed
633

634
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
635 636
	store_code_elem(2, n1);
	store_code_elem(2, n2);
637 638
}

639
void add_instruction_i_w(int16_t i,int64_t n1,int32_t n2) {
640 641
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2);
Camil Staps's avatar
Camil Staps committed
642

643 644 645 646 647
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(8, n1);
	store_code_elem(2, n2);
}

648 649 650 651 652 653 654 655 656
void add_instruction_i_label(int16_t i,int64_t n,char *label_name) {
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %s\n",pgrm.code_size,instruction_name (i),(int)n,label_name);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(8, n);
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
657
void add_instruction_w_c_label(int16_t i,int32_t n1,char n2,char *label_name) {
658 659 660 661 662 663 664 665 666
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(1, n2);
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
667
void add_instruction_w_w_label(int16_t i,int32_t n1,int32_t n2,char *label_name) {
668 669
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name);
670 671 672 673

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(2, n2);
674
	store_code_label_value(label_name,0);
675 676
}

677
void add_instruction_w_i_label(int16_t i,int32_t n1,int64_t n2,char *label_name) {
678 679 680
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name);

681
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
682
	store_code_elem(2, n1);
Camil Staps's avatar
Camil Staps committed
683
	store_code_elem(8, n2);
684 685 686
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
687
void add_instruction_w_w_label_offset(int32_t i,int32_t n1,int32_t n2,char *label_name,uint32_t offset) {
688 689 690
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s%+d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name,offset);

691
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
692 693
	store_code_elem(2, n1);
	store_code_elem(2, n2);
694 695 696
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
697
void add_instruction_w_w_label_w(int16_t i,int32_t n1,int32_t n2,char *label_name,int32_t n3) {
698 699 700
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name,(int)n3);

701
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
702 703
	store_code_elem(2, n1);
	store_code_elem(2, n2);
704
	store_code_label_value(label_name,0);
705
	store_code_elem(2, n3);
706 707
}

Camil Staps's avatar
Camil Staps committed
708
void add_instruction_w_c_label_c_label(int16_t i,int32_t n1,char n2,char *label_name1,char n3,char *label_name2) {
709 710 711 712 713 714 715 716 717 718 719
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name1,(int)n3,label_name2);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(1, n2);
	store_code_label_value(label_name1,0);
	store_code_elem(1, n3);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
720
void add_instruction_w_w_label_w_label(int16_t i,int32_t n1,int32_t n2,char *label_name1,int32_t n3,char *label_name2) {
721 722 723
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name1,(int)n3,label_name2);

724
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
725 726
	store_code_elem(2, n1);
	store_code_elem(2, n2);
727
	store_code_label_value(label_name1,0);
728
	store_code_elem(2, n3);
729 730 731
	store_code_label_value(label_name2,0);
}

732
void add_instruction_w_i_label_i_label(int16_t i,int32_t n1,int64_t n2,char *label_name1,int64_t n3,char *label_name2) {
733 734 735 736 737 738 739 740 741 742 743
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name1,(int)n3,label_name2);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(8, n2);
	store_code_label_value(label_name1,0);
	store_code_elem(8, n3);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
744
void add_instruction_w_w_label_offset_w(int16_t i,int32_t n1,int32_t n2,char *label_name,uint32_t offset,int32_t n3) {
745 746 747
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s+%d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name,offset,(int)n3);

748
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
749 750
	store_code_elem(2, n1);
	store_code_elem(2, n2);
751
	store_code_label_value(label_name,offset);
752
	store_code_elem(2, n3);
753 754
}

Camil Staps's avatar
Camil Staps committed
755
void add_instruction_w_w_label_w_w(int16_t i,int32_t n1,int32_t n2,char *label_name,int32_t n3,int32_t n4) {
756 757 758
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name,(int)n3,(int)n4);

759
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
760 761
	store_code_elem(2, n1);
	store_code_elem(2, n2);
762
	store_code_label_value(label_name,0);
763 764
	store_code_elem(2, n3);
	store_code_elem(2, n4);
765 766
}

Camil Staps's avatar
Camil Staps committed
767
void add_instruction_w_w_label_offset_w_w(int16_t i,int32_t n1,int32_t n2,char *label_name,uint32_t offset,int32_t n3,int32_t n4) {
768 769 770
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s+%d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,label_name,offset,(int)n3,(int)n4);

771
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
772 773
	store_code_elem(2, n1);
	store_code_elem(2, n2);
774
	store_code_label_value(label_name,offset);
775 776
	store_code_elem(2, n3);
	store_code_elem(2, n4);
777 778
}

Camil Staps's avatar
Camil Staps committed
779
void add_instruction_w_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3) {
780 781 782
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3);

783
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
784 785 786
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
787 788
}

Camil Staps's avatar
Camil Staps committed
789
void add_instruction_w_w_w_label(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name) {
790 791 792
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %s\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,label_name);

793
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
794 795 796
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
797 798 799
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
800
void add_instruction_w_w_w_label_offset(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name,uint32_t offset) {
801 802 803
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %s+%d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,label_name,offset);

804
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
805 806 807
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
808 809 810
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
811
void add_instruction_w_w_w_label_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name,int32_t n4) {
812 813 814
	if (list_code || i>max_implemented_instruction_n)
		printf("\t%s %d %d %d %s %d\n",instruction_name (i),(int)n1,(int)n2,(int)n3,label_name,(int)n4);

815
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
816 817 818
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
819
	store_code_label_value(label_name,0);
820
	store_code_elem(2, n4);
821 822
}

Camil Staps's avatar
Camil Staps committed
823
void add_instruction_w_w_w_label_offset_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name,uint32_t offset,int32_t n4) {
824 825 826
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %s+%d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,label_name,offset,(int)n4);

827
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
828 829 830
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
831
	store_code_label_value(label_name,offset);
832
	store_code_elem(2, n4);
833 834
}

Camil Staps's avatar
Camil Staps committed
835
void add_instruction_w_w_w_label_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name,int32_t n4,int32_t n5) {
836 837 838
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,label_name,(int)n4,(int)n5);

839
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
840 841 842
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
843
	store_code_label_value(label_name,0);
844 845
	store_code_elem(2, n4);
	store_code_elem(2, n5);
846 847
}

Camil Staps's avatar
Camil Staps committed
848
void add_instruction_w_w_w_label_offset_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name,uint32_t offset,int32_t n4,int32_t n5) {
849 850 851
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %s+%d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,label_name,offset,(int)n4,(int)n5);

852
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
853 854 855
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
856
	store_code_label_value(label_name,offset);
857 858
	store_code_elem(2, n4);
	store_code_elem(2, n5);
859 860
}

Camil Staps's avatar
Camil Staps committed
861
void add_instruction_w_w_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,int32_t n4) {
862 863 864
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,(int)n4);

865
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
866 867 868 869
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
	store_code_elem(2, n4);
870 871
}

Camil Staps's avatar
Camil Staps committed
872
void add_instruction_w_w_w_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,int32_t n4,int32_t n5) {
873 874 875
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %d %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2,(int)n3,(int)n4,(int)n5);

876
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
877 878 879 880 881
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
	store_code_elem(2, n4);
	store_code_elem(2, n5);
882 883
}

884
void add_instruction_i(int16_t i,int64_t n) {
885
	if (list_code || i>max_implemented_instruction_n)
886
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),(int)n);
887

888
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
Camil Staps's avatar
Camil Staps committed
889
	store_code_elem(8, n);
890 891
}

Camil Staps's avatar
Camil Staps committed
892
void add_instruction_r(int16_t i,double r) {
893 894 895 896 897 898 899
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %f\n",pgrm.code_size,instruction_name (i),r);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(8, *((uint64_t*)(&r)));
}

900 901 902 903 904 905 906 907 908
void add_instruction_w_r(int16_t i,int32_t n,double r) {
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %f\n",pgrm.code_size,instruction_name (i),r);

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n);
	store_code_elem(8, *((uint64_t*)(&r)));
}

Camil Staps's avatar
Camil Staps committed
909
void add_instruction_internal_label(int16_t i,struct label *label) {
910 911 912
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),label->label_offset);

913
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
914 915 916
	store_code_internal_label_value(label,0);
}

Camil Staps's avatar
Camil Staps committed
917
void add_instruction_w_internal_label_label(int16_t i,int32_t n1,struct label *label,char *label_name) {
918 919 920
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d %d %s\n",pgrm.code_size,instruction_name (i),n1,label->label_offset,label_name);

921
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
922
	store_code_elem(2, n1);
923 924 925 926
	store_code_internal_label_value(label,0);
	store_code_label_value(label_name,0);
}

927 928 929 930 931 932 933
static char *specialized_jsr_labels[] = {
	/* 0*/ "eqAC",
	/* 1*/ "cmpAC",
	/* 2*/ "catAC",
	/* 3*/ "sliceAC",
	/* 4*/ "ItoAC",
	/* 5*/ "BtoAC",
934 935 936 937 938 939 940 941 942 943 944
	/* 6*/ "RtoAC",
	/* 7*/ "print__string__",
	/* 8*/ "openF",
	/* 9*/ "stdioF",
	/*10*/ "closeF",
	/*11*/ "readLineF",
	/*12*/ "endF",
	/*13*/ "writeFI",
	/*14*/ "writeFS",
	/*15*/ "writeFC",
	/*16*/ "openSF"
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
};

static int get_specialized_jsr_label_n(char label_name[]) {
	int i,n;

	n = sizeof(specialized_jsr_labels) / sizeof (char*);
	for(i=0; i<n; ++i)
		if (!strcmp (label_name,specialized_jsr_labels[i]))
			return i;

	return -1;
}

void add_specialized_jsr_instruction(unsigned int n) {
	switch (n) {
		case  0: add_instruction(CeqAC); return;
		case  1: add_instruction(CcmpAC); return;
		case  2: add_instruction(CcatAC); return;
		case  3: add_instruction(CsliceAC); return;
		case  4: add_instruction(CItoAC); return;
965 966 967
		case  5: add_instruction(CBtoAC); return;
		case  6: add_instruction(CRtoAC); return;
		case  7: add_instruction(Cprint_string); return;
968
		default:
969 970 971 972 973 974
			if (n < sizeof(specialized_jsr_labels)/sizeof(char*)) {
				fprintf(stderr,"Warning: jsr %s is not supported by the interpreter\n",specialized_jsr_labels[n]);
			} else {
				fprintf(stderr,"internal error in add_specialized_jsr_instruction: %d\n",n);
				exit(1);
			}
975 976 977
	}
}

978 979 980 981 982 983 984
void add_label(char *label_name) {
	if (list_code)
		printf("%d\t.label %s\n",pgrm.code_size,label_name);

	store_code_label_value(label_name,0);
}

985 986 987 988 989 990 991 992
void code_absR(void) {
	add_instruction(CabsR);
}

void code_acosR(void) {
	add_instruction(CacosR);
}

993 994 995 996
void code_addI(void) {
	add_instruction(CaddI);
}

997 998 999 1000 1001 1002 1003 1004
void code_addIo(void) {
	add_instruction(CaddIo);
}

void code_addLU(void) {
	add_instruction(CaddLU);
}

1005 1006 1007 1008
void code_addR(void) {
	add_instruction(CaddR);
}

1009 1010 1011 1012
void code_and(void) {
	add_instruction(CandI);
}

1013 1014 1015 1016 1017 1018 1019 1020
void code_asinR(void) {
	add_instruction(CasinR);
}

void code_atanR(void) {
	add_instruction(CatanR);
}

1021 1022 1023 1024 1025 1026 1027 1028 1029
void code_buildh(char descriptor_name[],int arity);

void code_build(char descriptor_name[],int arity,char *code_name) {
	if (code_name[0]=='_' && code_name[1]=='_' && code_name[2]=='h' && code_name[3]=='n' && code_name[4]=='f' && code_name[5]=='\0') {
		code_buildh(descriptor_name,arity);
		return;
	}
/*
	if (! (descriptor_name[0]=='_' && descriptor_name[1]=='_' && descriptor_name[2]=='\0')) {
1030
		fprintf(stderr, "Error: build %s %d %s\n",descriptor_name,arity,code_name);
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
		exit(1);
	}
*/
	switch(arity) {
		case 0:
			add_instruction_label(Cbuild0,code_name);
			break;
		case 1:
			add_instruction_label(Cbuild1,code_name);
			break;
		case 2:
			add_instruction_label(Cbuild2,code_name);
			break;
		case 3:
			add_instruction_label(Cbuild3,code_name);
			break;
		case 4:
			add_instruction_label(Cbuild4,code_name);
			break;
		default:
			if (arity<1)
				add_instruction_label(Cbuild1,code_name);
			else
				add_instruction_w_label(Cbuild,arity,code_name);
	}
}

void code_buildh(char descriptor_name[],int arity) {
	switch(arity) {
		case 0:
			add_instruction_label_offset(Cbuildh0,descriptor_name,-4);
			return;
		case 1:
			add_instruction_label_offset(Cbuildh1,descriptor_name,(1<<3)+2);
			return;
		case 2:
			add_instruction_label_offset(Cbuildh2,descriptor_name,(2<<3)+2);
			return;
		case 3:
			add_instruction_label_offset(Cbuildh3,descriptor_name,(3<<3)+2);
			return;
		case 4:
			add_instruction_label_offset(Cbuildh4,descriptor_name,(4<<3)+2);
			return;
		default:
			add_instruction_w_label_offset(Cbuildh,arity+2,descriptor_name,(arity<<3)+2);
			return;
	}
}

void code_buildB(int value) {
	if (value==0)
		add_instruction(CbuildBFALSE);
	else
		add_instruction(CbuildBTRUE);
}