parse_abc.c 35.1 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1
#include <inttypes.h>
2
#include "parse_abc.h"
3

Camil Staps's avatar
Camil Staps committed
4
#include <stdio.h>
5
#include <stdlib.h>
Camil Staps's avatar
Camil Staps committed
6
#include <string.h>
Camil Staps's avatar
Camil Staps committed
7
#include <ctype.h>
Erin van der Veen's avatar
Erin van der Veen committed
8

9
#include "bcgen_instructions.h"
10
#include "settings.h"
11
#include "util.h"
Camil Staps's avatar
Camil Staps committed
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 66 67 68 69

void warning_i (char *error_string,int integer) {
	fprintf(stderr, error_string, integer);
}

#define MAX_STRING_LENGTH 200

typedef char STRING [MAX_STRING_LENGTH+1];

static unsigned char alpha_num_table[257];

static void initialize_alpha_num_table()
{
	int i;
	static unsigned char extra_alpha_nums[]="@#$%^&*-+/=<>\\_~.?\'\"|`!:{};";

	for (i=0; i<257; ++i)
		alpha_num_table[i]=0;

	for (i='a'; i<='z'; ++i)
		alpha_num_table[i+1]=1;
	for (i='A'; i<='Z'; ++i)
		alpha_num_table[1+i]=1;
	for (i='0'; i<='9'; ++i)
		alpha_num_table[1+i]=1;
	for (i=0; i<sizeof (extra_alpha_nums)-1; ++i)
		alpha_num_table[1+extra_alpha_nums[i]]=1;
}

#define is_alpha_num_character(c) (alpha_num_table[(c)+1])
#define is_digit_character(c) ((unsigned)((c)-'0')<(unsigned)10)
#define is_hexdigit_character(c) ((unsigned)((c)-'0')<(unsigned)10 || (unsigned)((c | 0x20)-'a')<(unsigned)6)
#define is_octdigit_character(c) ((unsigned)((c)-'0')<(unsigned)8)
#define append_char(c) if (length<MAX_STRING_LENGTH) {label_string[length] = (c); ++length; };

void init_parser(void) {
	initialize_alpha_num_table();
}

static char *current_line;
static char last_char;
static uint32_t line_number;

static char next_character() {
	return *current_line++;
}

static int skip_spaces_and_tabs (void)
{
	if (last_char==' ' || last_char=='\t'){
		do
			last_char=next_character();
		while (last_char==' ' || last_char=='\t');
		return 1;
	} else
		return 0;
}

Camil Staps's avatar
Camil Staps committed
70 71 72
static void parse_label (char *label_string);
void parse_line(char* line, unsigned int line_nr) {
	char *end, *token;
Camil Staps's avatar
Camil Staps committed
73

Camil Staps's avatar
Camil Staps committed
74
	line_number = line_nr;
Camil Staps's avatar
Camil Staps committed
75

Camil Staps's avatar
Camil Staps committed
76 77 78 79
	end = line;
	while (isspace(*end))
		end++;

80
	if ((end != line && *(end-1) == '\n') || *end == '|') {
81 82
		return;
	} else if (end == line && line[0] != '.' && line[0] != '|') {
Camil Staps's avatar
Camil Staps committed
83 84 85 86 87 88 89 90
		char s[MAX_STRING_LENGTH];
		strsep(&end, " \r\n\t");
		current_line = line;
		last_char = next_character();
		parse_label(s);
		code_label(s);
	} else if ((token = strsep(&end, " \r\n\t")) != NULL) {
		instruction* i = instruction_lookup(token);
91 92 93 94
		if (i == NULL) {
			fprintf(stderr, "Unknown instruction '%s' at line %d.\n", token, line_nr);
			exit(1);
		} else {
Camil Staps's avatar
Camil Staps committed
95 96 97 98 99
			current_line = end;
			last_char = next_character();
			skip_spaces_and_tabs();
			i->parse_function(i);
		}
100 101 102
	} else {
		fprintf(stderr, "Parse error at line %d.\n", line_nr);
		exit(1);
Camil Staps's avatar
Camil Staps committed
103
	}
Camil Staps's avatar
Camil Staps committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
}

static int try_parse_label (char *label_string)
{
	int length;

	length=0;
	if (is_alpha_num_character (last_char))
		do {
			switch (last_char){
				case '.':
					append_char ('_');
					append_char ('P');
					break;
				case '_':
					append_char ('_');
					append_char ('_');
					break;
				case '*':
					append_char ('_');
					append_char ('M');
					break;
				case '-':
					append_char ('_');
					append_char ('S');
					break;
				case '+':
					append_char ('_');
					append_char ('A');
					break;
				case '=':
					append_char ('_');
					append_char ('E');
					break;
				case '~':
					append_char ('_');
					append_char ('T');
					break;
				case '<':
					append_char ('_');
					append_char ('L');
					break;
				case '>':
					append_char ('_');
					append_char ('G');
					break;
				case '/':
					append_char ('_');
					append_char ('D');
					break;
				case '?':
					append_char ('_');
					append_char ('Q');
					break;
				case '#':
					append_char ('_');
					append_char ('H');
					break;
				case ':':
					append_char ('_');
					append_char ('C');
					break;
				case '$':
					append_char ('_');
					append_char ('N');
					append_char ('D');
					break;
				case '^':
					append_char ('_');
					append_char ('N');
					append_char ('C');
					break;
				case '@':
					append_char ('_');
					append_char ('N');
					append_char ('T');
					break;
				case '&':
					append_char ('_');
					append_char ('N');
					append_char ('A');
					break;
				case '%':
					append_char ('_');
					append_char ('N');
					append_char ('P');
					break;
				case '\'':
					append_char ('_');
					append_char ('N');
					append_char ('S');
					break;
				case '\"':
					append_char ('_');
					append_char ('N');
					append_char ('Q');
					break;
				case '|':
					append_char ('_');
					append_char ('O');
					break;
				case '\\':
					append_char ('_');
					append_char ('N');
					append_char ('B');
					break;
				case '`':
					append_char ('_');
					append_char ('B');
					break;
				case '!':
					append_char ('_');
					append_char ('N');
					append_char ('E');
					break;
				case ';':
					append_char ('_');
					append_char ('I');
					break;
				default:
					append_char (last_char);
			}
			last_char=next_character();
		} while (is_alpha_num_character (last_char));

	label_string[length]='\0';

	if (length==0)
		return 0;
	if (length==MAX_STRING_LENGTH)
		warning_i("Label too long, extra characters ignored at line %d\n",line_number);
	return 1;
}

#define is_newline(c) ((c)=='\n' || (c)=='\r')

static void abc_parser_error_i(char *message, int i) {
	fprintf(stderr,message,i);
	exit(-1);
}

245
static int parse_integer (int64_t *integer_p)
Camil Staps's avatar
Camil Staps committed
246
{
247
	int64_t integer;
Camil Staps's avatar
Camil Staps committed
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
	int minus_sign;

	minus_sign=0;
	if (last_char=='+' || last_char=='-'){
		if (last_char=='-')
			minus_sign=!minus_sign;
		last_char=next_character();
	}

	if (!is_digit_character (last_char))
		abc_parser_error_i ("Integer expected at line %d\n",line_number);

	integer=last_char-'0';
	last_char=next_character();

	while (is_digit_character (last_char)){
		integer*=10;
		integer+=last_char-'0';
		last_char=next_character();
	}

	skip_spaces_and_tabs();

	if (minus_sign)
		integer=-integer;
	*integer_p=integer;

	return 1;
}

static int parse_string_character (char *c_p)
{
	if (last_char!='\\'){
		if (last_char==EOF)
			return 0;
		*c_p=last_char;
		last_char=next_character();
	} else {
		last_char=next_character();
		if (last_char>='0' && last_char<='7'){
			int c=last_char-'0';
			last_char=next_character();
			if (last_char>='0' && last_char<='7'){
				c=(c<<3)+(last_char-'0');
				last_char=next_character();
				if (last_char>='0' && last_char<='7'){
					c=(c<<3)+(last_char-'0');
					last_char=next_character();
				}
			}
			*c_p=c;
		} else {
			switch (last_char){
				case 'b':	*c_p='\b';	break;
				case 'f':	*c_p='\f';	break;
#if (defined (M68000) && !defined (SUN)) || defined (__MWERKS__) || defined (__MRC__) || defined (POWER)
				case 'n':	*c_p='\xd';	break;
				case 'r':	*c_p='\xa';	break;
#else
				case 'n':	*c_p='\n';	break;
				case 'r':	*c_p='\r';	break;
#endif
				case 't':	*c_p='\t';	break;
				case EOF:	return 0;
				default:	*c_p=last_char;
			}
			last_char=next_character();
		}
	}
	return 1;
}

static int parse_string (char *string,int *string_length_p)
{
	int length;

	if (last_char!='"')
		abc_parser_error_i ("String expected at line %d",line_number);

	last_char=next_character();

	length=0;

	while (last_char!='"'){
		char c;

		if (!parse_string_character (&c))
			abc_parser_error_i ("Error in string at line %d\n",line_number);

		if (length<MAX_STRING_LENGTH)
			string[length++]=c;
	}

	if (length==MAX_STRING_LENGTH)
		warning_i("String too long, extra characters ignored at line %d\n",line_number);

	last_char=next_character();

	string[length]='\0';
	*string_length_p=length;

	skip_spaces_and_tabs();

	return 1;
}

static int parse_descriptor_string (char *string,int *string_length_p)
{
	int length;

	if (last_char!='"')
		abc_parser_error_i ("String expected at line %d",line_number);

	last_char=next_character();

	length=0;

	while (last_char!='"'){
		char c;

		if (last_char==EOF)
			abc_parser_error_i ("Error in string at line %d\n",line_number);

		c=last_char;
		last_char=next_character();

		if (length<MAX_STRING_LENGTH)
			string[length++]=c;
	}

	if (length==MAX_STRING_LENGTH)
		warning_i("String too long, extra characters ignored at line %d\n",line_number);

	last_char=next_character();

	string[length]='\0';
	*string_length_p=length;

	skip_spaces_and_tabs();

	return 1;
}

static void parse_label (char *label_string)
{
	if (!try_parse_label (label_string))
		abc_parser_error_i ("Label expected at line %d\n",line_number);
	skip_spaces_and_tabs();
}

static int try_parse_label_without_conversion (char *label_string)
{
	int length;

	length=0;
	if (is_alpha_num_character (last_char))
		do {
			append_char (last_char);
			last_char=next_character();
		} while (is_alpha_num_character (last_char));

	label_string[length]='\0';

	if (length==0)
		return 0;
	if (length==MAX_STRING_LENGTH)
		warning_i("Label too long, extra characters ignored at line %d\n",line_number);
	return 1;
}

static void parse_label_without_conversion (char *label_string)
{
	if (!try_parse_label_without_conversion (label_string))
		abc_parser_error_i ("Label expected at line %d\n",line_number);
	skip_spaces_and_tabs();
}

static int try_parse_record_field_types (char *label_string)
{
	int length;

	length=0;
	if (is_alpha_num_character (last_char) || last_char==',' || last_char=='(' || last_char==')')
		do {
			append_char (last_char);
			last_char=next_character();
		} while (is_alpha_num_character (last_char) || last_char==',' || last_char=='(' || last_char==')');

	label_string[length]='\0';

	if (length==0)
		return 0;
	if (length==MAX_STRING_LENGTH)
		warning_i("Label too long, extra characters ignored at line %d\n",line_number);
	return 1;
}

static void parse_record_field_types (char *label_string)
{
	if (!try_parse_record_field_types (label_string))
		abc_parser_error_i ("Record field types expected at line %d\n",line_number);
	skip_spaces_and_tabs();
}

452
static int parse_unsigned_integer (int64_t *integer_p)
Camil Staps's avatar
Camil Staps committed
453
{
454
	int64_t integer;
Camil Staps's avatar
Camil Staps committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647

	if (!is_digit_character (last_char))
		abc_parser_error_i ("Integer expected at line %d\n",line_number);

	integer=last_char-'0';
	last_char=next_character();

	while (is_digit_character (last_char)){
		integer*=10;
		integer+=last_char-'0';
		last_char=next_character();
	}

	skip_spaces_and_tabs();

	*integer_p=integer;

	return 1;
}

static int parse_clean_integer (CleanInt *integer_p)
{
	CleanInt integer;
	int minus_sign;

	minus_sign=0;
	if (last_char=='+' || last_char=='-'){
		if (last_char=='-')
			minus_sign=!minus_sign;
		last_char=next_character();
	}

	if (!is_digit_character (last_char))
		abc_parser_error_i ("Integer expected at line %d\n",line_number);

	integer=last_char-'0';
	last_char=next_character();

	if (last_char=='x' && integer==0){
		last_char=next_character();
		if (!is_hexdigit_character (last_char))
			abc_parser_error_i ("Integer expected at line %d\n",line_number);
		do {
			integer<<=4;
			integer+= last_char<='9' ? last_char-'0' : (last_char | 0x20)-('a'-10);
			last_char=next_character();
		} while (is_hexdigit_character (last_char));
	} else if (last_char=='o' && integer==0){
		last_char=next_character();
		if (!is_octdigit_character (last_char))
			abc_parser_error_i ("Integer expected at line %d\n",line_number);
		do {
			integer<<=3;
			integer+= last_char-'0';
			last_char=next_character();
		} while (is_octdigit_character (last_char));
	} else {
		while (is_digit_character (last_char)){
			integer*=10;
			integer+=last_char-'0';
			last_char=next_character();
		}
	}

	skip_spaces_and_tabs();

	if (minus_sign)
		integer=-integer;
	*integer_p=integer;

	return 1;
}

static int parse_boolean (int *boolean_p)
{
	if (last_char=='F'){
		if ((last_char=next_character())=='A' && (last_char=next_character())=='L' &&
				(last_char=next_character())=='S' && (last_char=next_character())=='E'){
			last_char=next_character();
			skip_spaces_and_tabs();
			*boolean_p=0;
			return 1;
		}
	} else if (last_char=='T'){
		if ((last_char=next_character())=='R' && (last_char=next_character())=='U' &&
				(last_char=next_character())=='E'){
			last_char=next_character();
			skip_spaces_and_tabs();
			*boolean_p=1;
			return 1;
		}
	}
	abc_parser_error_i ("Boolean expected at line %d\n",line_number);
	return 0;
}

static int parse_character (unsigned char *character_p)
{
	if (last_char!='\'')
		abc_parser_error_i ("Character expected at line %d\n",line_number);

	last_char=next_character();

	if (!parse_string_character ((char*)character_p))
		abc_parser_error_i ("Error in character at line %d\n",line_number);

	if (last_char!='\'')
		abc_parser_error_i ("Character not terminated at line %d\n",line_number);

	last_char=next_character();

	skip_spaces_and_tabs();

	return 1;
}

static char *resize_string (char *string,int length,int max_length)
{
	if (length==MAX_STRING_LENGTH){
		char *new_string;
		int i;

		new_string=safe_malloc(max_length);

		for (i=0; i<length; ++i)
			new_string[i]=string[i];

		return new_string;
	} else {
		string=safe_realloc (string,max_length);

		return string;
	}
}

static int parse_0_or_1 (int *integer_p)
{
	int integer;

	if (!(last_char=='0' || last_char=='1'))
		abc_parser_error_i ("0 or 1 expected at line %d\n",line_number);

	integer=last_char-'0';

	last_char=next_character();
	skip_spaces_and_tabs();

	*integer_p=integer;

	return 1;
}

static char *parse_string2 (char *string,int *string_length_p)
{
	int length,max_length;

	if (last_char!='"')
		abc_parser_error_i ("String expected at line %d",line_number);

	last_char=next_character();

	length=0;
	max_length=MAX_STRING_LENGTH;

	while (last_char!='"'){
		char c;

		if (!parse_string_character (&c))
			abc_parser_error_i ("Error in string at line %d\n",line_number);

		if (length<max_length)
			string[length++]=c;
		else {
			max_length=max_length<<1;
			string=resize_string (string,length,max_length);
			string[length++]=c;
		}
	}

	last_char=next_character();

	if (length>=max_length){
		++max_length;
		string=resize_string (string,length,max_length);
	}
	string[length]='\0';
	*string_length_p=length;

	skip_spaces_and_tabs();

	return string;
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
static int parse_hex_real (double *real_p)
{
	int s1,s2;
	unsigned int i1,i2;

	last_char=next_character();
	if (!is_hexdigit_character (last_char))
		abc_parser_error_i ("Hex digit expected in real at line %d\n",line_number);

	while (last_char=='0')
		last_char=next_character();

	i1=0;
	s1=0;
	while (s1<7){
		if (!is_hexdigit_character (last_char)){
			*real_p=(double)i1;
			return 1;
		}
		i1<<=4;
		i1+=last_char<='9' ? last_char-'0' : (last_char | 0x20)-('a'-10);
		++s1;
		last_char=next_character();
	}

	i2=0;
	s2=0;
	while (s2<7){
		if (!is_hexdigit_character (last_char)){
			double r;

			r=(double)i1;
			while (s2>=0){
				r*=16.0;
				--s2;
			}
			*real_p=r+(double)i2;
			return 1;
		}
		i2<<=4;
		i2+=last_char<='9' ? last_char-'0' : (last_char | 0x20)-('a'-10);
		++s2;
		last_char=next_character();
	}

	{
	int extra_non_zero_char;
	double p,r1;
	char char14;

	p=1.0;

	r1=(double)i1*(double)0x10000000;

	char14=last_char;
	if (i1<0x2000000){
		if (!is_hexdigit_character (last_char)){
			*real_p=r1+(double)i2;
			return 1;
		}
		p*=16.0;
		last_char=next_character();
	}

	while (last_char=='0'){
		p*=16.0;
		last_char=next_character();
	}

	extra_non_zero_char=0;
	if (is_hexdigit_character (last_char)){
		extra_non_zero_char=1;
		do {
			p*=16.0;
			last_char=next_character();
		} while (is_hexdigit_character (last_char));
	}

	/* round to 53 bits */
	if (i1<0x2000000){
		if (char14>'8' || (char14=='8' && !(extra_non_zero_char==0 && (i2 & 1)==0)))
			++i2;
	} else if (i1<0x4000000){
		if ((i2 & 1)!=0 && !(extra_non_zero_char==0 && (i2 & 2)==0))
			i2 += 2;
		i2 &= -2;
	} else if (i1<0x8000000){
		if ((i2 & 2)>2 || ((i2 & 2)==2 && !(extra_non_zero_char==0 && (i2 & 4)==0)))
			i2 += 4;
		i2 &= -4;
	} else {
		if ((i2 & 4)>4 || ((i2 & 4)==4 && !(extra_non_zero_char==0 && (i2 & 8)==0)))
			i2 += 8;
		i2 &= -8;
	}

	*real_p=(r1+(double)i2)*p;
	return 1;
	}
}

static int parse_real (double *real_p)
{
	unsigned int real_string_length=0;
	char real_string[64];

	if (last_char=='+' || last_char=='-'){
		if (last_char=='-')
			real_string[real_string_length++]='-';
		last_char=next_character();
	}

	if (last_char=='0'){
761
		real_string[real_string_length++]='0';
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
		last_char=next_character();

		if (last_char=='x'){
			int r;

			r=parse_hex_real (real_p);

			if (real_string[0]=='-')
				*real_p = - *real_p;

			skip_spaces_and_tabs();

			return r;
		}

		while (is_digit_character (last_char)) {
			real_string[real_string_length++]=last_char;
			last_char=next_character();
		}
	} else if (!is_digit_character(last_char)) {
		abc_parser_error_i ("Digit expected in real at line %d\n",line_number);
		return 0;
	} else {
		do {
			real_string[real_string_length++]=last_char;
			last_char=next_character();
		} while (is_digit_character(last_char));
	}

	if (last_char=='.'){
		real_string[real_string_length++]=last_char;
		last_char=next_character();

		if (!is_digit_character(last_char)) {
			abc_parser_error_i ("Digit expected in real at line %d\n",line_number);
			return 0;
		} else {
			do {
				real_string[real_string_length++]=last_char;
				last_char=next_character();
			} while (is_digit_character(last_char));
		}
	} else if (last_char!='e' && last_char!='E')
		abc_parser_error_i ("'.' or 'E' expected in real at line %d\n",line_number);

	if (last_char=='e' || last_char=='E'){
		real_string[real_string_length++]=last_char;
		last_char=next_character();

		if (last_char=='+' || last_char=='-'){
			if (last_char=='-')
				real_string[real_string_length++]='-';
			last_char=next_character();
		}

		if (!is_digit_character(last_char)) {
			abc_parser_error_i ("Digit expected in real at line %d\n",line_number);
			return 0;
		} else {
			do {
				real_string[real_string_length++]=last_char;
				last_char=next_character();
			} while (is_digit_character(last_char));
		}
	}

	if (real_string_length==MAX_STRING_LENGTH)
		abc_parser_error_i ("Real denotation too long at line %d\n",line_number);

	real_string[real_string_length]='\0';

	skip_spaces_and_tabs();

	*real_p=atof (real_string);

	return 1;
}

840
int parse_instruction (instruction *instruction)
Camil Staps's avatar
Camil Staps committed
841
{
842 843 844 845
	instruction->code_function();
	return 1;
}

846
int parse_instruction_a (instruction *instruction)
Camil Staps's avatar
Camil Staps committed
847 848
{
	STRING a;
849

Camil Staps's avatar
Camil Staps committed
850 851
	parse_label (a);
	instruction->code_function (a);
852 853 854
	return 1;
}

855
int parse_instruction_a_n (instruction *instruction)
Camil Staps's avatar
Camil Staps committed
856
{
857
	STRING a;
858
	int64_t n;
Camil Staps's avatar
Camil Staps committed
859

860 861 862
	parse_label (a);
	if (!parse_unsigned_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
863
	instruction->code_function (a,(int)n);
864 865 866
	return 1;
}

867
int parse_instruction_a_n_a (instruction *instruction)
868 869
{
	STRING a1,a2;
870
	int64_t n1;
Camil Staps's avatar
Camil Staps committed
871

872 873 874 875
	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	parse_label (a2);
Camil Staps's avatar
Camil Staps committed
876
	instruction->code_function (a1,(int)n1,a2);
877 878 879
	return 1;
}

880
int parse_instruction_a_n_a_a_n_a (instruction *instruction)
881 882
{
	STRING a1,a2,a3,a4;
883
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
884

885 886 887 888 889 890 891 892
	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	parse_label (a2);
	parse_label (a3);
	if (!parse_unsigned_integer (&n2))
		return 0;
	parse_label (a4);
Camil Staps's avatar
Camil Staps committed
893
	instruction->code_function (a1,(int)n1,a2,a3,(int)n2,a4);
894 895 896
	return 1;
}

897
int parse_instruction_a_n_a_n (instruction *instruction)
898 899
{
	STRING a1,a2;
900
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
901

902 903 904 905 906 907
	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	parse_label (a2);
	if (!parse_unsigned_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
908
	instruction->code_function (a1,(int)n1,a2,(int)n2);
909 910 911
	return 1;
}

912
int parse_instruction_a_n_n (instruction *instruction)
913 914
{
	STRING a;
915
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
916

917 918 919
	parse_label (a);
	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
920
	instruction->code_function (a,(int)n1,(int)n2);
921 922 923
	return 1;
}

924
int parse_instruction_a_n_n_a (instruction *instruction)
925 926
{
	STRING a1,a2;
927
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
928

929 930 931 932 933 934
	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	if (!parse_integer (&n2))
		return 0;
	parse_label (a2);
Camil Staps's avatar
Camil Staps committed
935
	instruction->code_function (a1,(int)n1,(int)n2,a2);
936 937 938
	return 1;
}

939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
int parse_instruction_a_n_n_a_n (instruction *instruction)
{
	STRING a1,a2;
	int64_t n1,n2,n3;

	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	if (!parse_integer (&n2))
		return 0;
	parse_label (a2);
	if (!parse_integer (&n3))
		return 0;
	instruction->code_function (a1,(int)n1,(int)n2,a2,(int)n3);
	return 1;
}

956
int parse_instruction_a_n_n_n (instruction *instruction)
957 958
{
	STRING a;
959
	int64_t n1,n2,n3;
Camil Staps's avatar
Camil Staps committed
960

961 962 963
	parse_label (a);
	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) || !parse_unsigned_integer (&n3))
		return 0;
Camil Staps's avatar
Camil Staps committed
964
	instruction->code_function (a,(int)n1,(int)n2,(int)n3);
965 966 967
	return 1;
}

Camil Staps's avatar
Camil Staps committed
968
static void parse_bit_string (char *s_p)
969 970 971 972 973 974 975 976
{
	if (last_char!='0' && last_char!='1'){
		abc_parser_error_i ("0 or 1 expected at line %d\n",line_number);
		*s_p='\0';
	}

	do {
		*s_p++=last_char;
Camil Staps's avatar
Camil Staps committed
977
		last_char=next_character();
978 979 980 981 982
	} while (last_char=='0' || last_char=='1');

	*s_p='\0';
}

983
int parse_instruction_a_n_n_b (instruction *instruction)
984 985
{
	STRING a1,a2;
986
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
987

988 989 990 991 992
	parse_label (a1);
	if (!parse_unsigned_integer (&n1))
		return 0;
	if (!parse_unsigned_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
993

994
	parse_bit_string (a2);
Camil Staps's avatar
Camil Staps committed
995

996
	skip_spaces_and_tabs();
Camil Staps's avatar
Camil Staps committed
997 998

	instruction->code_function (a1,(int)n1,(int)n2,a2);
999 1000 1001
	return 1;
}

1002
int parse_instruction_a_n_n_n_b (instruction *instruction)
1003 1004
{
	STRING a1,a2;
1005
	int64_t n1,n2,n3;
Camil Staps's avatar
Camil Staps committed
1006

1007 1008 1009 1010 1011 1012 1013
	parse_label (a1);
	if (!parse_unsigned_integer (&n1))
		return 0;
	if (!parse_unsigned_integer (&n2))
		return 0;
	if (!parse_unsigned_integer (&n3))
		return 0;
Camil Staps's avatar
Camil Staps committed
1014

1015
	parse_bit_string (a2);
Camil Staps's avatar
Camil Staps committed
1016

1017
	skip_spaces_and_tabs();
Camil Staps's avatar
Camil Staps committed
1018 1019

	instruction->code_function (a1,(int)n1,(int)n2,(int)n3,a2);
1020 1021 1022
	return 1;
}

1023
int parse_instruction_a_n_n_n_n (instruction *instruction)
1024 1025
{
	STRING a1;
1026
	int64_t n1,n2,n3,n4;
Camil Staps's avatar
Camil Staps committed
1027

1028
	parse_label (a1);
Camil Staps's avatar
Camil Staps committed
1029
	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1030 1031
		!parse_unsigned_integer (&n3) || !parse_unsigned_integer (&n4))
		return 0;
Camil Staps's avatar
Camil Staps committed
1032
	instruction->code_function (a1,(int)n1,(int)n2,(int)n3,(int)n4);
1033 1034 1035
	return 1;
}

1036
int parse_instruction_a_n_n_n_n_n (instruction *instruction)
1037 1038
{
	STRING a1;
1039
	int64_t n1,n2,n3,n4,n5;
Camil Staps's avatar
Camil Staps committed
1040

1041
	parse_label (a1);
Camil Staps's avatar
Camil Staps committed
1042
	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1043 1044 1045
		!parse_unsigned_integer (&n3) || !parse_unsigned_integer (&n4) ||
		!parse_unsigned_integer (&n5))
		return 0;
Camil Staps's avatar
Camil Staps committed
1046
	instruction->code_function (a1,(int)n1,(int)n2,(int)n3,(int)n4,(int)n5);
1047 1048 1049
	return 1;
}

1050
int parse_instruction_b (instruction *instruction)
1051 1052
{
	int b;
Camil Staps's avatar
Camil Staps committed
1053

1054 1055
	if (!parse_boolean (&b))
		return 0;
Camil Staps's avatar
Camil Staps committed
1056
	instruction->code_function (b);
1057 1058 1059
	return 1;
}

1060
int parse_instruction_b_n (instruction *instruction)
1061 1062
{
	int b;
1063
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1064

1065 1066
	if (!parse_boolean (&b) || !parse_unsigned_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1067
	instruction->code_function (b,(int)n);
1068 1069 1070
	return 1;
}

1071
int parse_instruction_c (instruction *instruction)
1072 1073
{
	unsigned char c;
Camil Staps's avatar
Camil Staps committed
1074

1075 1076
	if (!parse_character (&c))
		return 0;
Camil Staps's avatar
Camil Staps committed
1077
	instruction->code_function (c);
1078 1079 1080
	return 1;
}

1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
int parse_instruction_c_a (instruction *instruction)
{
	unsigned char c;
	STRING a;

	if (!parse_character (&c))
		return 0;
	parse_label (a);
	instruction->code_function (c,a);
	return 1;
}

1093
int parse_instruction_c_c_n_a_a (instruction *instruction)
1094 1095
{
	unsigned char c1,c2;
1096
	int64_t n;
1097
	STRING a1,a2;
Camil Staps's avatar
Camil Staps committed
1098

1099 1100 1101 1102
	if (!parse_character (&c1) || !parse_character (&c2) || !parse_unsigned_integer (&n))
		return 0;
	parse_label (a1);
	parse_label (a2);
Camil Staps's avatar
Camil Staps committed
1103
	instruction->code_function (c1,c2,(int)n,a1,a2);
1104 1105 1106
	return 1;
}

1107
int parse_instruction_c_n (instruction *instruction)
1108 1109
{
	unsigned char c;
1110
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1111

1112 1113
	if (!parse_character (&c) || !parse_unsigned_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1114
	instruction->code_function (c,(int)n);
1115 1116 1117
	return 1;
}

1118
int parse_instruction_c_n_a (instruction *instruction)
1119 1120
{
	unsigned char c;
1121
	int64_t n;
1122
	STRING a;
Camil Staps's avatar
Camil Staps committed
1123

1124 1125 1126
	if (!parse_character (&c) || !parse_unsigned_integer (&n))
		return 0;
	parse_label (a);
Camil Staps's avatar
Camil Staps committed
1127
	instruction->code_function (c,(int)n,a);
1128 1129 1130
	return 1;
}

1131
int parse_instruction_i (instruction *instruction)
1132 1133
{
	CleanInt i;
Camil Staps's avatar
Camil Staps committed
1134

1135 1136
	if (!parse_clean_integer (&i))
		return 0;
Camil Staps's avatar
Camil Staps committed
1137
	instruction->code_function (i);
1138 1139 1140
	return 1;
}

1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
int parse_instruction_i_a (instruction *instruction)
{
	CleanInt i;
	STRING a;

	if (!parse_clean_integer (&i))
		return 0;
	parse_label (a);
	instruction->code_function (i,a);
	return 1;
}

1153
int parse_instruction_i_i_n_a_a (instruction *instruction)
1154 1155
{
	CleanInt i1,i2;
1156
	int64_t n;
1157 1158 1159 1160 1161 1162
	STRING a1,a2;

	if (!parse_clean_integer (&i1) || !parse_clean_integer (&i2) || !parse_unsigned_integer (&n))
		return 0;
	parse_label (a1);
	parse_label (a2);
Camil Staps's avatar
Camil Staps committed
1163
	instruction->code_function (i1,i2,(int)n,a1,a2);
1164 1165 1166
	return 1;
}

1167
int parse_instruction_i_n (instruction *instruction)
1168 1169
{
	CleanInt i;
1170
	int64_t n;
1171 1172 1173

	if (!parse_clean_integer (&i) || !parse_unsigned_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1174
	instruction->code_function (i,(int)n);
1175 1176 1177
	return 1;
}

1178
int parse_instruction_i_n_a (instruction *instruction)
1179 1180
{
	CleanInt i;
1181
	int64_t n;
1182 1183 1184 1185 1186
	STRING a;

	if (!parse_clean_integer (&i) || !parse_unsigned_integer (&n))
		return 0;
	parse_label (a);
Camil Staps's avatar
Camil Staps committed
1187
	instruction->code_function (i,(int)n,a);
1188 1189 1190
	return 1;
}

1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
int parse_instruction_r (instruction *instruction)
{
	double r;

	if (!parse_real (&r))
		return 0;
	instruction->code_function (r);
	return 1;
}

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
int parse_instruction_r_n (instruction *instruction)
{
	double r;
	int64_t n;

	if (!parse_real (&r) || !parse_unsigned_integer (&n))
		return 0;
	instruction->code_function (r,(int)n);
	return 1;
}

1212
int parse_instruction_l (instruction *instruction)
1213 1214
{
	STRING a;
Camil Staps's avatar
Camil Staps committed
1215

1216
	parse_label_without_conversion (a);
Camil Staps's avatar
Camil Staps committed
1217
	instruction->code_function (a);
1218 1219 1220
	return 1;
}

1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
int parse_instruction_l_s (instruction *instruction)
{
	STRING l1,s1;
	int l;

	parse_label_without_conversion (l1);
	if (!parse_string (s1,&l))
		return 0;

	instruction->code_function (l1,s1,l);
	return 1;
}

1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
int parse_instruction_l_a_s (instruction *instruction)
{
	STRING l1,l2,s1;
	int l;

	parse_label_without_conversion (l1);
	parse_label (l2);
	if (!parse_string (s1,&l))
		return 0;

	instruction->code_function (l1,l2,s1,l);
	return 1;
}

1248
int parse_instruction_n (instruction *instruction)
1249
{
1250
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1251

1252 1253
	if (!parse_unsigned_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1254 1255

	instruction->code_function ((int)n);
1256 1257 1258
	return 1;
}

1259
int parse_instruction_n_a (instruction *instruction)
1260 1261
{
	STRING a;
1262
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1263

1264 1265 1266
	if (!parse_unsigned_integer (&n))
		return 0;
	parse_label (a);
Camil Staps's avatar
Camil Staps committed
1267
	instruction->code_function ((int)n,a);
1268 1269 1270
	return 1;
}

1271
int parse_instruction_n_a_n_a_a_n_a (instruction *instruction)
1272 1273
{
	STRING a1,a2,a3,a4;
1274
	int64_t n0,n1,n2;
Camil Staps's avatar
Camil Staps committed
1275

1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
	if (!parse_unsigned_integer (&n0))
		return 0;
	parse_label (a1);
	if (!parse_integer (&n1))
		return 0;
	parse_label (a2);
	parse_label (a3);
	if (!parse_unsigned_integer (&n2))
		return 0;
	parse_label (a4);
Camil Staps's avatar
Camil Staps committed
1286
	instruction->code_function ((int)n0,a1,(int)n1,a2,a3,(int)n2,a4);
1287 1288 1289
	return 1;
}

1290
int parse_instruction_n_b (instruction *instruction)
1291 1292
{
	int b;
1293
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1294

1295 1296
	if (!parse_unsigned_integer (&n) || !parse_boolean (&b))
		return 0;
Camil Staps's avatar
Camil Staps committed
1297
	instruction->code_function ((int)n,b);
1298 1299 1300
	return 1;
}

1301
int parse_instruction_n_n (instruction *instruction)
1302
{
1303
	int64_t n1,n2;
Camil Staps's avatar
Camil Staps committed
1304

1305 1306
	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
1307
	instruction->code_function ((int)n1,(int)n2);
1308 1309 1310
	return 1;
}

1311
int parse_instruction_n_n_n (instruction *instruction)
1312
{
1313
	int64_t n1,n2,n3;
Camil Staps's avatar
Camil Staps committed
1314 1315

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1316 1317
		!parse_unsigned_integer (&n3))
		return 0;
Camil Staps's avatar
Camil Staps committed
1318
	instruction->code_function ((int)n1,(int)n2,(int)n3);
1319 1320 1321
	return 1;
}

1322
int parse_instruction_n_n_n_n (instruction *instruction)
1323
{
1324
	int64_t n1,n2,n3,n4;
Camil Staps's avatar
Camil Staps committed
1325 1326

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1327 1328
		!parse_unsigned_integer (&n3) || !parse_unsigned_integer (&n4))
		return 0;
Camil Staps's avatar
Camil Staps committed
1329
	instruction->code_function ((int)n1,(int)n2,(int)n3,(int)n4);
1330 1331 1332
	return 1;
}

1333
int parse_instruction_n_n_n_n_n (instruction *instruction)
1334
{
1335
	int64_t n1,n2,n3,n4,n5;
Camil Staps's avatar
Camil Staps committed
1336 1337

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1338 1339 1340
		!parse_unsigned_integer (&n3) || !parse_unsigned_integer (&n4) ||
		!parse_unsigned_integer (&n5))
		return 0;
Camil Staps's avatar
Camil Staps committed
1341
	instruction->code_function ((int)n1,(int)n2,(int)n3,(int)n4,(int)n5);
1342 1343 1344
	return 1;
}

1345
int parse_instruction_n_n_n_n_n_n_n (instruction *instruction)
1346
{
1347
	int64_t n1,n2,n3,n4,n5,n6,n7;
Camil Staps's avatar
Camil Staps committed
1348 1349

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2) ||
1350 1351 1352 1353
		!parse_unsigned_integer (&n3) || !parse_unsigned_integer (&n4) ||
		!parse_unsigned_integer (&n5) || !parse_unsigned_integer (&n6) ||
		!parse_unsigned_integer (&n7))
		return 0;
Camil Staps's avatar
Camil Staps committed
1354
	instruction->code_function ((int)n1,(int)n2,(int)n3,(int)n4,(int)n5,(int)n6,(int)n7);
1355 1356 1357
	return 1;
}

1358
int parse_instruction_on (instruction *instruction)
1359
{
1360
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1361

1362 1363 1364 1365 1366
	if (!is_digit_character (last_char))
		n=-1;
	else
		if (!parse_unsigned_integer (&n))
			return 0;
Camil Staps's avatar
Camil Staps committed
1367 1368

	instruction->code_function ((int)n);
1369 1370 1371
	return 1;
}

1372
int parse_instruction_s (instruction *instruction)
1373 1374 1375
{
	STRING s;
	int length;
Camil Staps's avatar
Camil Staps committed
1376

1377 1378
	if (!parse_string (s,&length))
		return 0;
Camil Staps's avatar
Camil Staps committed
1379
	instruction->code_function (s,length);
1380 1381 1382
	return 1;
}

1383
int parse_instruction_s2 (instruction *instruction)
1384 1385 1386 1387 1388 1389 1390
{
	STRING s;
	int length;
	char *string;

	string=parse_string2 (s,&length);

Camil Staps's avatar
Camil Staps committed
1391 1392
	instruction->code_function (string,length);

1393 1394 1395 1396 1397 1398
	if (string!=s)
		free (string);

	return 1;
}

1399
int parse_instruction_s2_n_a (instruction *instruction)
1400 1401 1402 1403
{
	STRING s1,s2;
	int length;
	char *string;
1404
	int64_t n;
Camil Staps's avatar
Camil Staps committed
1405

1406 1407 1408 1409 1410
	string=parse_string2 (s1,&length);
	if (!parse_unsigned_integer (&n))
		return 0;
	parse_label (s2);

Camil Staps's avatar
Camil Staps committed
1411 1412
	instruction->code_function (string,length,(int)n,s2);

1413 1414 1415 1416 1417 1418
	if (string!=s1)
		free (string);

	return 1;
}

1419
int parse_directive (instruction *instruction)
1420
{
Camil Staps's avatar
Camil Staps committed
1421
	instruction->code_function();
1422 1423 1424
	return 1;
}

1425
int parse_directive_a (instruction *instruction)
1426
{
1427
	int64_t n;
1428 1429 1430 1431
	STRING s;

	if (!parse_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1432

1433
	parse_label (s);
Camil Staps's avatar
Camil Staps committed
1434
	instruction->code_function ((int)n,s);
1435 1436 1437 1438

	return 1;
}

1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
int parse_directive_ai (instruction *instruction)
{
	int64_t n;
	STRING s1,s2;

	if (!parse_integer (&n))
		return 0;

	parse_label (s1);
	parse_label (s2);
	instruction->code_function ((int)n,s1,s2);

	return 1;
}

1454
int parse_directive_depend (instruction *instruction)
1455 1456 1457
{
	STRING a;
	int l;
Camil Staps's avatar
Camil Staps committed
1458

1459 1460 1461 1462 1463 1464 1465
	if (!parse_string (a,&l))
		return 0;

	 /* skip optional last modification time */
	if (last_char=='"'){
		STRING t;
		int tl;
Camil Staps's avatar
Camil Staps committed
1466

1467 1468 1469
		parse_string (t,&tl);
	}

Camil Staps's avatar
Camil Staps committed
1470
	instruction->code_function (a,l);
1471 1472 1473

#if 0
	while (last_char==','){
Camil Staps's avatar
Camil Staps committed
1474
		last_char=next_character();
1475 1476 1477
		skip_spaces_and_tabs();
		if (!parse_string (a,&l))
			return 0;
Camil Staps's avatar
Camil Staps committed
1478
		instruction->code_function (a,l);
1479 1480 1481 1482 1483 1484
	}
#endif

	return 1;
}

1485
int parse_directive_desc (instruction *instruction)
1486 1487 1488
{
	STRING a1,a2,a3,s;
	int l;
1489 1490
	int64_t n;
	int64_t f;
1491 1492 1493 1494 1495 1496 1497

	parse_label (a1);
	parse_label (a2);
	parse_label (a3);

	if (!parse_unsigned_integer (&n) || !parse_unsigned_integer (&f) || !parse_descriptor_string (s,&l))
		return 0;
Camil Staps's avatar
Camil Staps committed
1498
	instruction->code_function (a1,a2,a3,(int)n,(int)f,s,l);
1499 1500 1501
	return 1;
}

1502
int parse_directive_desc0 (instruction *instruction)
1503 1504 1505
{
	STRING a1,s;
	int l;
1506
	int64_t n;
1507 1508 1509 1510 1511

	parse_label (a1);

	if (!parse_unsigned_integer (&n) || !parse_descriptor_string (s,&l))
		return 0;
Camil Staps's avatar
Camil Staps committed
1512
	instruction->code_function (a1,(int)n,s,l);
1513 1514 1515
	return 1;
}

1516
int parse_directive_descn (instruction *instruction)
1517 1518 1519
{
	STRING a1,a2,s;
	int l;
1520
	int64_t n;
1521 1522 1523 1524 1525 1526
	int f;

	parse_label (a1);
	parse_label (a2);
	if (!parse_unsigned_integer (&n) || !parse_0_or_1 (&f) || !parse_descriptor_string (s,&l))
		return 0;
Camil Staps's avatar
Camil Staps committed
1527
	instruction->code_function (a1,a2,(int)n,f,s,l);
1528 1529 1530
	return 1;
}

1531
int parse_directive_implab (instruction *instruction)
1532 1533
{
	STRING s;
Camil Staps's avatar
Camil Staps committed
1534

1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
	parse_label (s);
	skip_spaces_and_tabs();

	if (!is_newline (last_char)){
		STRING s2;

		parse_label (s2);
		code_implab_node_entry (s,s2);
	} else
		code_implab (s);

	return 1;
}

1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
int parse_directive_implib_impobj (instruction *instruction)
{
	STRING s;
	int l;

	if (!parse_string (s,&l))
		return 0;

	skip_spaces_and_tabs();
	return 1;
}

1561
int parse_directive_labels (instruction *instruction)
1562 1563
{
	STRING s;
Camil Staps's avatar
Camil Staps committed
1564

1565
	parse_label (s);
Camil Staps's avatar
Camil Staps committed
1566
	instruction->code_function (s);
1567
	skip_spaces_and_tabs();
Camil Staps's avatar
Camil Staps committed
1568

1569 1570 1571 1572 1573 1574
	while (!is_newline (last_char)){
		if (!try_parse_label (s)){
			abc_parser_error_i ("Label expected at line %d\n",line_number);
			return 0;
		}
		skip_spaces_and_tabs();
Camil Staps's avatar
Camil Staps committed
1575
		instruction->code_function (s);
1576 1577 1578 1579 1580 1581
		skip_spaces_and_tabs();
	}

	return 1;
}

1582
int parse_directive_module (instruction *instruction)
1583 1584 1585 1586 1587 1588 1589
{
	STRING a,s;
	int l;

	parse_label (a);
	if (!parse_string (s,&l))
		return 0;
Camil Staps's avatar
Camil Staps committed
1590

1591 1592 1593 1594
	 /* skip optional last modification time */
	if (last_char=='"'){
		STRING t;
		int tl;
Camil Staps's avatar
Camil Staps committed
1595

1596 1597 1598
		parse_string (t,&tl);
	}

Camil Staps's avatar
Camil Staps committed
1599
	instruction->code_function (a,s,l);
1600 1601 1602
	return 1;
}

1603
int parse_directive_n (instruction *instruction)
1604
{
1605
	int64_t n;
1606 1607 1608 1609
	STRING s;

	if (!parse_integer (&n))
		return 0;
Camil Staps's avatar
Camil Staps committed
1610

1611 1612 1613 1614 1615 1616 1617 1618
	parse_label (s);

	skip_spaces_and_tabs();

	if (!is_newline (last_char)){
		STRING s2;

		parse_label (s2);
Camil Staps's avatar
Camil Staps committed
1619
		instruction->code_function ((int)n,s,s2);
1620
	} else
Camil Staps's avatar
Camil Staps committed
1621
		instruction->code_function ((int)n,s,NULL);
1622 1623 1624 1625

	return 1;
}

1626
int parse_directive_nu (instruction *instruction)
1627
{
1628
	int64_t n1,n2;
1629 1630 1631 1632
	STRING s;

	if (!parse_integer (&n1) || !parse_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
1633

1634 1635 1636 1637 1638 1639 1640 1641
	parse_label (s);

	skip_spaces_and_tabs();

	if (!is_newline (last_char)){
		STRING s2;

		parse_label (s2);
Camil Staps's avatar
Camil Staps committed
1642
		instruction->code_function ((int)n1,(int)n2,s,s2);
1643
	} else
Camil Staps's avatar
Camil Staps committed
1644
		instruction->code_function ((int)n1,(int)n2,s,NULL);
1645 1646 1647 1648

	return 1;
}

1649
int parse_directive_n_l (instruction *instruction)
1650
{
1651
	int64_t n;
1652 1653 1654 1655 1656 1657 1658
	STRING s;

	if (!parse_unsigned_integer (&n))
		return 0;

	/* parse the options string as a label */
	parse_label (s);
Camil Staps's avatar
Camil Staps committed
1659 1660

	instruction->code_function ((int)n,(char *)s);
1661 1662 1663
	return 1;
}

1664 1665
int parse_directive_n_n_n (instruction *instruction)
{
1666
	int64_t n1,n2,n3;
1667 1668 1669 1670 1671 1672 1673 1674 1675

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2)
	||  !parse_unsigned_integer (&n3))
		return 0;

	instruction->code_function ((int)n1,(int)n2,(int)n3);
	return 1;
}

1676 1677 1678 1679
#define SMALL_VECTOR_SIZE 32
#define LOG_SMALL_VECTOR_SIZE 5
#define MASK_SMALL_VECTOR_SIZE 31

1680
int parse_directive_n_n_t (instruction *instruction)
1681
{
1682
	int64_t n1,n2;
1683
	int i;
1684 1685
	static uint64_t small_vector;
	uint64_t *vector_p;
1686 1687 1688 1689
	int vector_size=0;

	if (!parse_unsigned_integer (&n1) || !parse_unsigned_integer (&n2))
		return 0;
Camil Staps's avatar
Camil Staps committed
1690

1691 1692 1693 1694
	vector_size=n2;
	if (vector_size+1<=SMALL_VECTOR_SIZE)
		vector_p=&small_vector;
	else
1695
		vector_p=(uint64_t*)safe_malloc(((vector_size+1+SMALL_VECTOR_SIZE-1)>>LOG_SMALL_VECTOR_SIZE) * sizeof (uint64_t));
Camil Staps's avatar
Camil Staps committed
1696

1697 1698 1699 1700 1701 1702 1703 1704
	i=0;
	while (i!=n2){
		switch (last_char){
			case 'i':	case 'I':
			case 'b':	case 'B':
			case 'c':	case 'C':
			case 'p':	case 'P':
				vector_p[i>>LOG_SMALL_VECTOR_SIZE] &= ~ (1<< (i & MASK_SMALL_VECTOR_SIZE));
Camil Staps's avatar
Camil Staps committed
1705
				i+=1;
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
				break;
			case 'f':	case 'F':
				vector_p[i>>LOG_SMALL_VECTOR_SIZE] &= ~ (1<< (i & MASK_SMALL_VECTOR_SIZE));
				i+=1;
				vector_p[i>>LOG_SMALL_VECTOR_SIZE] &= ~ (1<< (i & MASK_SMALL_VECTOR_SIZE));
				i+=1;
				break;
			case 'r':	case 'R':
				vector_p[i>>LOG_SMALL_VECTOR_SIZE] |= (1<< (i & MASK_SMALL_VECTOR_SIZE));
				i+=1;
				break;
			default:
1718 1719
				fprintf(stderr,"B, C, F, I, P or R expected instead of '%c' (0x%02x) at line %d\n",last_char,last_char,line_number);
				exit(1);
1720
		}
Camil Staps's avatar
Camil Staps committed
1721
		last_char=next_character();
1722 1723
		skip_spaces_and_tabs();
	}
Camil Staps's avatar
Camil Staps committed
1724 1725

	instruction->code_function ((int)n1,(int)n2,v