bcgen_instructions.c 133 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
struct program pgrm;
14
uint32_t last_d, last_jsr_with_d;
15

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

22
uint32_t module_n;
23

24
uint32_t list_code = 0;
25

26 27
uint32_t allocated_code_size;
uint32_t allocated_data_size;
28
uint32_t allocated_strings_size;
29 30
uint32_t allocated_code_relocations_size;
uint32_t allocated_data_relocations_size;
31

32
#define N_ADD_ARG_LABELS 32
33
static uint32_t Fadd_arg_label_used[N_ADD_ARG_LABELS];
Camil Staps's avatar
Camil Staps committed
34
#ifndef LINK_CLEAN_RUNTIME
35
static int general_add_arg_label_used=0;
Camil Staps's avatar
Camil Staps committed
36
#endif
37

Camil Staps's avatar
Camil Staps committed
38
#ifndef LINK_CLEAN_RUNTIME
39 40 41 42 43 44 45 46 47
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
48
#endif
49

50
struct program *initialize_code(void) {
51 52 53 54 55
	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
56
	label_id = 0;
57 58
	global_label_count = 0;
	global_label_string_count = 0;
Camil Staps's avatar
Camil Staps committed
59

60 61
	module_n = 0;

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

77 78
	allocated_code_size = 512;
	allocated_data_size = 512;
79
	allocated_strings_size = 512;
80 81
	allocated_code_relocations_size = 512;
	allocated_data_relocations_size = 512;
82 83

	return &pgrm;
84 85
}

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

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

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

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

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

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

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

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
125

126 127 128 129 130 131
		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
132

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

137
					new_label_p = (struct label*) safe_malloc(sizeof(struct label));
138
					new_label_p->label_name=label_node_p->label_node_label_p->label_name;
Camil Staps's avatar
Camil Staps committed
139
					new_label_p->label_id=label_id++;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
					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;

159 160
	new_label_node_p = (struct label_node*) safe_malloc(sizeof(struct label_node));
	new_label_p = (struct label*) safe_malloc(sizeof(struct label));
161 162 163
	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;
164
	new_label_p->label_name = (char*) safe_malloc(strlen(label_name) + 1);
Camil Staps's avatar
Camil Staps committed
165
	new_label_p->label_id=label_id++;
166 167 168
	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
169

170 171 172 173
	*label_node_pp = new_label_node_p;
	return new_label_p;
}

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
#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;
}

191 192
static struct label_node **move_label_tree_to_list(
		struct label_node **dest, struct label_node *tree) {
193
	if (tree->label_node_left!=NULL)
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 224 225
		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);
		}
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 275 276
	}

	*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

277 278 279 280 281 282 283 284 285
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
286 287 288
int internal_label_id = 0;
struct label *new_internal_label(void) {
	char label_name[14];
289
	sprintf(label_name,"%%%x",internal_label_id++);
Camil Staps's avatar
Camil Staps committed
290 291 292 293
	struct label *label = enter_label(label_name);
	return label;
}

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

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

308 309 310 311 312
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));
	}
313

314 315 316 317 318 319 320 321
	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
322

323 324 325 326
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));
327 328
	}

329 330 331 332 333 334 335 336 337
	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
338
#ifndef LINK_CLEAN_RUNTIME
339 340
void store_code_internal_label_value(struct label *label,uint32_t offset) {
	add_code_relocation(label, pgrm.code_size);
341
	store_code_elem(2, offset);
342 343
}

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

347 348
	label=enter_label(label_name);

349
	add_code_relocation(label, pgrm.code_size);
350

351
	store_code_elem(2, offset);
352 353
}

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

359
void store_data_label_value(char *label_name,uint32_t offset) {
360 361 362 363 364 365
	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
366

367
	store_code_elem(2, i);
368 369
}

370 371 372 373 374 375 376
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);
}

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

Camil Staps's avatar
Camil Staps committed
381
	store_code_elem(8, i);
382 383
}

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

388
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
389 390 391 392
}

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

Camil Staps's avatar
Camil Staps committed
395 396
	code_offset = (size_t) pgrm.code;
	data_offset = (size_t) pgrm.data;
397

398
	for(i=0; i<pgrm.code_reloc_size; ++i) {
399 400
		struct relocation *relocation_p;

Camil Staps's avatar
Camil Staps committed
401
		relocation_p=&pgrm.code_relocations[i];
402
		if ((relocation_p->relocation_label->label_offset & 1)==0)
Camil Staps's avatar
Camil Staps committed
403
			*(int32_t*)&pgrm.code[relocation_p->relocation_offset] += code_offset;
404
		else
Camil Staps's avatar
Camil Staps committed
405
			*(int32_t*)&pgrm.code[relocation_p->relocation_offset] += data_offset;
406 407
	}

408
	for(i=0; i<pgrm.data_reloc_size; ++i) {
409 410
		struct relocation *relocation_p;

Camil Staps's avatar
Camil Staps committed
411
		relocation_p=&pgrm.data_relocations[i];
412
		if ((relocation_p->relocation_label->label_offset & 1)==0)
Camil Staps's avatar
Camil Staps committed
413
			*(int32_t*)&pgrm.data[relocation_p->relocation_offset] += code_offset;
414
		else
Camil Staps's avatar
Camil Staps committed
415
			*(int32_t*)&pgrm.data[relocation_p->relocation_offset] += data_offset;
416 417 418
	}
}

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

423
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
424 425 426
	store_code_label_value(label_name,0);
}

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

431
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
432 433 434
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
435
void add_instruction_label_offset_label(int16_t i,char *label_name1,uint32_t offset,char *label_name2) {
436 437 438
	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);

439
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
440 441 442 443
	store_code_label_value(label_name1,offset);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
444
void add_instruction_label_offset_w(uint16_t i,char *label_name,uint32_t offset,int32_t n1) {
445 446 447
	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);

448
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
449
	store_code_label_value(label_name,offset);
450
	store_code_elem(2, n1);
451 452
}

Camil Staps's avatar
Camil Staps committed
453
void add_instruction_label_offset_w_label(uint16_t i,char *label_name1,uint32_t offset,int32_t n1,char *label_name2) {
454 455 456
	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);

457
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
458
	store_code_label_value(label_name1,offset);
459
	store_code_elem(2, n1);
460 461 462 463
	store_code_label_value(label_name2,0);
}

void add_instruction_label_offset_label_label_offset_label
Camil Staps's avatar
Camil Staps committed
464
	(int16_t i,char *label_name1,uint32_t offset1,char *label_name2,char *label_name3,uint32_t offset2,char *label_name4) {
465 466 467 468
	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);

469
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
470 471 472 473 474 475
	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
476
void add_instruction_label_w_w(int16_t i,char *label_name,int32_t n1,int32_t n2) {
477 478 479
	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);

480
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
481
	store_code_label_value(label_name,0);
482 483
	store_code_elem(2, n1);
	store_code_elem(2, n2);
484 485
}

Camil Staps's avatar
Camil Staps committed
486
void add_instruction_c(int16_t i,char n) {
487 488 489 490 491 492 493
	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);
}

494 495 496 497 498 499 500 501 502
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
503
void add_instruction_w(int16_t i,int32_t n) {
504 505 506
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),(int)n);

507 508 509 510
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n);
}

511
void add_instruction_w_i(int16_t i,int32_t n1,int64_t n2) {
512
	if (list_code || i>max_implemented_instruction_n)
513
		printf("%d\t%s %d %d\n",pgrm.code_size,instruction_name (i),(int)n1,(int)n2);
514

515
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
516
	store_code_elem(2, n1);
Camil Staps's avatar
Camil Staps committed
517
	store_code_elem(8, n2);
518 519
}

Camil Staps's avatar
Camil Staps committed
520
void add_instruction_w_label(int16_t i,int32_t n,char *label_name) {
521 522 523
	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);

524 525 526 527 528
	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
529
void add_instruction_w_label_offset(int16_t i,int32_t n,char *label_name,uint32_t offset) {
530 531 532
	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);

533
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
534
	store_code_elem(2, n);
535 536 537
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
538
void add_instruction_w_label_offset_label(int16_t i,int32_t n,char *label_name1,uint32_t offset,char *label_name2) {
539 540 541
	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);

542
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
543
	store_code_elem(2, n);
544 545 546 547
	store_code_label_value(label_name1,offset);
	store_code_label_value(label_name2,0);
}

Camil Staps's avatar
Camil Staps committed
548
void add_instruction_w_label_w(int16_t i,int32_t n1,char *label_name,int32_t n2) {
549 550 551
	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);

552
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
553
	store_code_elem(2, n1);
554
	store_code_label_value(label_name,0);
555
	store_code_elem(2, n2);
556 557 558
}

void add_instruction_w_label_offset_label_label_offset_label
Camil Staps's avatar
Camil Staps committed
559
	(int16_t i,int32_t n1,char *label_name1,uint32_t offset1,char *label_name2,char *label_name3,uint32_t offset2,char *label_name4) {
560 561 562 563
	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);

564
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
565
	store_code_elem(2, n1);
566 567 568 569 570 571
	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
572
void add_instruction_w_label_offset_w(int16_t i,int32_t n1,char *label_name,uint32_t offset,int32_t n2) {
573 574 575
	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);

576
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
577
	store_code_elem(2, n1);
578
	store_code_label_value(label_name,offset);
579
	store_code_elem(2, n2);
580 581
}

Camil Staps's avatar
Camil Staps committed
582
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) {
583 584 585
	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);

586
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
587
	store_code_elem(2, n1);
588
	store_code_label_value(label_name,offset);
589 590
	store_code_elem(2, n2);
	store_code_elem(2, n3);
591 592
}

Camil Staps's avatar
Camil Staps committed
593
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) {
594 595 596
	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);

597
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
598
	store_code_elem(2, n1);
599
	store_code_label_value(label_name,offset);
600 601 602
	store_code_elem(2, n2);
	store_code_elem(2, n3);
	store_code_elem(2, n4);
603 604
}

Camil Staps's avatar
Camil Staps committed
605
void add_instruction_w_c(int16_t i,int32_t n1,char n2) {
606 607 608 609 610 611 612 613
	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
614
void add_instruction_w_w(int16_t i,int32_t n1,int32_t n2) {
615 616
	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
617

618
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
619 620
	store_code_elem(2, n1);
	store_code_elem(2, n2);
621 622
}

623
void add_instruction_i_w(int16_t i,int64_t n1,int32_t n2) {
624 625
	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
626

627 628 629 630 631
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(8, n1);
	store_code_elem(2, n2);
}

632 633 634 635 636 637 638 639 640
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
641
void add_instruction_w_c_label(int16_t i,int32_t n1,char n2,char *label_name) {
642 643 644 645 646 647 648 649 650
	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
651
void add_instruction_w_w_label(int16_t i,int32_t n1,int32_t n2,char *label_name) {
652 653
	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);
654 655 656 657

	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
	store_code_elem(2, n1);
	store_code_elem(2, n2);
658
	store_code_label_value(label_name,0);
659 660
}

661
void add_instruction_w_i_label(int16_t i,int32_t n1,int64_t n2,char *label_name) {
662 663 664
	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);

665
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
666
	store_code_elem(2, n1);
Camil Staps's avatar
Camil Staps committed
667
	store_code_elem(8, n2);
668 669 670
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
671
void add_instruction_w_w_label_offset(int32_t i,int32_t n1,int32_t n2,char *label_name,uint32_t offset) {
672 673 674
	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);

675
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
676 677
	store_code_elem(2, n1);
	store_code_elem(2, n2);
678 679 680
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
681
void add_instruction_w_w_label_w(int16_t i,int32_t n1,int32_t n2,char *label_name,int32_t n3) {
682 683 684
	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);

685
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
686 687
	store_code_elem(2, n1);
	store_code_elem(2, n2);
688
	store_code_label_value(label_name,0);
689
	store_code_elem(2, n3);
690 691
}

Camil Staps's avatar
Camil Staps committed
692
void add_instruction_w_c_label_c_label(int16_t i,int32_t n1,char n2,char *label_name1,char n3,char *label_name2) {
693 694 695 696 697 698 699 700 701 702 703
	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
704
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) {
705 706 707
	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);

708
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
709 710
	store_code_elem(2, n1);
	store_code_elem(2, n2);
711
	store_code_label_value(label_name1,0);
712
	store_code_elem(2, n3);
713 714 715
	store_code_label_value(label_name2,0);
}

716
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) {
717 718 719 720 721 722 723 724 725 726 727
	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
728
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) {
729 730 731
	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);

732
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
733 734
	store_code_elem(2, n1);
	store_code_elem(2, n2);
735
	store_code_label_value(label_name,offset);
736
	store_code_elem(2, n3);
737 738
}

Camil Staps's avatar
Camil Staps committed
739
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) {
740 741 742
	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);

743
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
744 745
	store_code_elem(2, n1);
	store_code_elem(2, n2);
746
	store_code_label_value(label_name,0);
747 748
	store_code_elem(2, n3);
	store_code_elem(2, n4);
749 750
}

Camil Staps's avatar
Camil Staps committed
751
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) {
752 753 754
	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);

755
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
756 757
	store_code_elem(2, n1);
	store_code_elem(2, n2);
758
	store_code_label_value(label_name,offset);
759 760
	store_code_elem(2, n3);
	store_code_elem(2, n4);
761 762
}

Camil Staps's avatar
Camil Staps committed
763
void add_instruction_w_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3) {
764 765 766
	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);

767
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
768 769 770
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
771 772
}

Camil Staps's avatar
Camil Staps committed
773
void add_instruction_w_w_w_label(int16_t i,int32_t n1,int32_t n2,int32_t n3,char *label_name) {
774 775 776
	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);

777
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
778 779 780
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
781 782 783
	store_code_label_value(label_name,0);
}

Camil Staps's avatar
Camil Staps committed
784
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) {
785 786 787
	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);

788
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
789 790 791
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
792 793 794
	store_code_label_value(label_name,offset);
}

Camil Staps's avatar
Camil Staps committed
795
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) {
796 797 798
	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);

799
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
800 801 802
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
803
	store_code_label_value(label_name,0);
804
	store_code_elem(2, n4);
805 806
}

Camil Staps's avatar
Camil Staps committed
807
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) {
808 809 810
	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);

811
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
812 813 814
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
815
	store_code_label_value(label_name,offset);
816
	store_code_elem(2, n4);
817 818
}

Camil Staps's avatar
Camil Staps committed
819
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) {
820 821 822
	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);

823
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
824 825 826
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
827
	store_code_label_value(label_name,0);
828 829
	store_code_elem(2, n4);
	store_code_elem(2, n5);
830 831
}

Camil Staps's avatar
Camil Staps committed
832
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) {
833 834 835
	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);

836
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
837 838 839
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
840
	store_code_label_value(label_name,offset);
841 842
	store_code_elem(2, n4);
	store_code_elem(2, n5);
843 844
}

Camil Staps's avatar
Camil Staps committed
845
void add_instruction_w_w_w_w(int16_t i,int32_t n1,int32_t n2,int32_t n3,int32_t n4) {
846 847 848
	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);

849
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
850 851 852 853
	store_code_elem(2, n1);
	store_code_elem(2, n2);
	store_code_elem(2, n3);
	store_code_elem(2, n4);
854 855
}

Camil Staps's avatar
Camil Staps committed
856
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) {
857 858 859
	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);

860
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
861 862 863 864 865
	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);
866 867
}

868
void add_instruction_i(int16_t i,int64_t n) {
869
	if (list_code || i>max_implemented_instruction_n)
870
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),(int)n);
871

872
	store_code_elem(BYTEWIDTH_INSTRUCTION, i);
Camil Staps's avatar
Camil Staps committed
873
	store_code_elem(8, n);
874 875
}

Camil Staps's avatar
Camil Staps committed
876
void add_instruction_r(int16_t i,double r) {
877 878 879 880 881 882 883
	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)));
}

Camil Staps's avatar
Camil Staps committed
884 885 886 887 888 889 890 891 892
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
893
void add_instruction_internal_label(int16_t i,struct label *label) {
894 895 896
	if (list_code || i>max_implemented_instruction_n)
		printf("%d\t%s %d\n",pgrm.code_size,instruction_name (i),label->label_offset);