Exemple #1
0
void lexerr(MachineResult *result, ParserData *parser_data)
{
	// output to console
	fprintf (stderr, "%-8s%s on line %d: \"%s\"\n", "LEXERR", attribute_to_str(result->token->attribute), result->line_no, result->lexeme);

	// listing file
	if (parser_data->listing != NULL)
		fprintf (parser_data->listing, "%-8s%-30s%s\n", "LEXERR", attribute_to_str(result->token->attribute), result->lexeme);

	parser_data->result |= PARSER_RESULT_LEXERR;
}
Exemple #2
0
static void dump_attributes(attribute *da, dump *ctx)
{
	for(; da; da = da->next){
		dump_desc_colour_newline(ctx, "attribute",
				da, &da->where,
				maybe_colour(ctx->fout, col_desc), 0);

		dump_printf_indent(ctx, 0, " %s\n", attribute_to_str(da));
	}
}
Exemple #3
0
void print_type(type *ref, decl *d)
{
	char buf[TYPE_STATIC_BUFSIZ];

	fprintf(cc1_out, "%s",
			type_to_str_r_spel(buf, ref, d ? d->spel : NULL));

	if(ref->type == type_attr){
		attribute *da;
		for(da = ref->bits.attr; da; da = da->next){
			fprintf(cc1_out, " __attribute__((%s))",
					attribute_to_str(da));
		}
	}
}
Exemple #4
0
static void print_attribute(attribute *da)
{
	for(; da; da = da->next){
		idt_printf("__attribute__((%s))\n", attribute_to_str(da));

		gen_str_indent++;
		switch(da->type){
			case attr_section:
				idt_printf("section \"%s\"\n", da->bits.section);
				break;
			case attr_nonnull:
			{
				unsigned long l = da->bits.nonnull_args;

				idt_printf("nonnull: ");
				if(l == ~0UL){
					fprintf(cc1_out, "all");
				}else{
					const char *sep = "";
					int i;

					for(i = 0; i <= 32; i++)
						if(l & (1 << i)){
							fprintf(cc1_out, "%s%d", sep, i);
							sep = ", ";
						}
				}

				fputc('\n', cc1_out);
				break;
			}

			default:
				break;
		}
		gen_str_indent--;
	}
}
Exemple #5
0
MachineResult *get_next_token(ParserData *parser_data, int options)
{
	// remember where we were last by saving source file pointer
	static FILE *s;

	// save current line
	static char l[MAX_LINE_LENGTH_1];
	static char *f;
	static int i = 0;

	// options for things like NOP
	static int o = 0;
	static MachineResult *r;

	if (o & TOKEN_OPTION_NOP && r != NULL) {
		 o = options;
		return r;
	}

	// grab another line
	if (s != parser_data->source || f - l > MAX_LINE_LENGTH || *f == 0)
	{
		s = parser_data->source;

		char *line = get_next_line(parser_data->source);

		strcpy(l, line);
		f = l;
		i++;

		// output line to listing file
		if (parser_data->listing != NULL)
			fprintf (parser_data->listing, "%-8d%s\n", i, line);
	}

	MachineResult result = machine_omega(f, parser_data->reserved_words, parser_data->symbol_table);

	// do not increment line counter for eof
	if (result.token->type == TOKEN_EOF) i--;

	result.line_no = i;

	MachineResult *resultPtr = (MachineResult *)malloc(sizeof(MachineResult));
	memcpy(resultPtr, &result, sizeof(MachineResult));

	// advance our internal pointer
	f = result.f;

	if (resultPtr->token->type == TOKEN_WHITESPACE)
		return get_next_token(parser_data, options);

	// write token to tokens file
	if (parser_data->tokens != NULL) {
		fprintf (parser_data->tokens, "%-10d%-20s%-20s%-6d(%s)\n", i, resultPtr->lexeme, token_type_to_str(resultPtr->token->type), resultPtr->token->attribute, attribute_to_str(resultPtr->token->attribute));
	}

	// handle lexical errors
	if (resultPtr->token->type == TOKEN_LEXERR) {
		// output errors to listing file
		if (!(options & TOKEN_OPTION_SQUASH_ERRS))
			lexerr(resultPtr, parser_data);

		// do not return lexerr tokens
		return get_next_token(parser_data, options);
	}

	// check for a nop
	if (options & TOKEN_OPTION_NOP)
		r = resultPtr;

	o = options;

	return resultPtr;
}