Exemple #1
0
bool options_parse_assembler(options_state_t *s)
{
	const char *full_option = s->argv[s->i];
	if (full_option[0] != '-')
		return false;

	const char *arg;
	if (accept_prefix(s, "-Wa,", true, &arg)) {
		driver_add_flag(&asflags_obst, "%s", full_option);
	} else if ((arg = spaced_arg("Xassembler", s)) != NULL) {
		driver_add_flag(&asflags_obst, "-Xassembler");
		driver_add_flag(&asflags_obst, arg);
	} else {
		return false;
	}
	return true;
}
Exemple #2
0
bool options_parse_early_target(options_state_t *s)
{
	const char *full_option = s->argv[s->i];
	if (full_option[0] != '-')
		return false;
	const char *option = &full_option[1];

	const char *arg;
	if (simple_arg("pthread", s)) {
		/* set flags for the preprocessor */
		driver_add_flag(&cppflags_obst, "-D_REENTRANT");
		/* set flags for the linker */
		driver_add_flag(&ldflags_obst, "-lpthread");
	} else if ((arg = spaced_arg("target", s)) != NULL) {
		if (!parse_target_triple(arg))
			s->argument_errors = true;
		/* remove argument so we do not parse it again in later phases */
		s->argv[s->i-1] = NULL;
	} else if ((arg = equals_arg("-target", s)) != NULL) {
		if (!parse_target_triple(arg))
			s->argument_errors = true;
	} else if (simple_arg("m64", s) || simple_arg("m32", s)
	        || simple_arg("m16", s)) {
		driver_add_flag(&cppflags_obst, full_option);
		driver_add_flag(&asflags_obst, full_option);
		driver_add_flag(&ldflags_obst, full_option);
		target_size_override = atoi(option+1);
	} else {
		bool truth_value;
		const char *fopt;
		if ((fopt = f_no_arg(&truth_value, s)) != NULL) {
			if (f_yesno_arg("-fprofile-generate", s)) {
				profile_generate = truth_value;
			} else if (f_yesno_arg("-fprofile-use", s)) {
				profile_use = truth_value;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	/* Remove argument so we do not parse it again in later phases */
	return true;
}
Exemple #3
0
bool options_parse_linker(options_state_t *s)
{
	const char *full_option = s->argv[s->i];
	if (full_option[0] != '-')
		return false;

	const char *arg;
	if ((arg = prefix_arg("l", s)) != NULL) {
		driver_add_flag(&ldflags_obst, "-l%s", arg);
	} else if ((arg = prefix_arg("L", s)) != NULL) {
		driver_add_flag(&ldflags_obst, "-L%s", arg);
	} else if (simple_arg("static", s)
	        || simple_arg("no-pie", s)
	        || simple_arg("nodefaultlibs", s)
	        || simple_arg("nostartfiles", s)
	        || simple_arg("nostdlib", s)
	        || simple_arg("pie", s)
	        || simple_arg("rdynamic", s)
	        || simple_arg("s", s)
	        || simple_arg("shared", s)
	        || simple_arg("shared-libgcc", s)
	        || simple_arg("static-libgcc", s)
	        || simple_arg("symbolic", s)
	        || accept_prefix(s, "-Wl,", true, &arg)) {
	    driver_add_flag(&ldflags_obst, full_option);
	} else if ((arg = spaced_arg("Xlinker", s)) != NULL) {
		driver_add_flag(&ldflags_obst, "-Xlinker");
		driver_add_flag(&ldflags_obst, arg);
	} else if (simple_arg("pg", s)) {
		set_target_option("gprof");
		driver_add_flag(&ldflags_obst, "-pg");
	} else if ((arg = equals_arg("print-file-name", s)) != NULL) {
		print_file_name_file = arg;
		s->action = action_print_file_name;
	} else {
		return false;
	}
	return true;
}
Exemple #4
0
static bool pass_options_to_firm_be(void)
{
#ifdef NO_DEFAULT_VERIFY
    set_target_option("verify=off");
#endif

	if (profile_generate) {
		driver_add_flag(&ldflags_obst, "-lfirmprof");
		set_target_option("profilegenerate");
	}
	if (profile_use) {
		set_target_option("profileuse");
	}
	if (target.set_use_frame_pointer) {
		set_target_option(target.use_frame_pointer ? "omitfp=no" : "omitfp");
	}

	if (target.set_pic) {
		if (target.pic && !ir_target_supports_pic()) {
			errorf(NULL,
			       "Position independent code (PIC) not supported by target");
			exit(EXIT_FAILURE);
		}

		set_target_option(target.pic ? "pic=1" : "pic=0");
	}
	if (target.set_noplt)
		set_target_option(target.pic_noplt ? "noplt=1" : "noplt=0");

	/* pass options to firm backend (this happens delayed because we first
	 * had to decide which backend is actually used) */
	bool res = true;
	for (codegen_option_t *option = codegen_options; option != NULL;
	     option = option->next) {
		/* pass option along to firm backend (except the ones already filtered
		 * out like -m32, -m64) */
		if (!ir_target_option(option->option)) {
			errorf(NULL, "Unknown codegen option '-m%s'", option->option);
			res = false;
			continue;
		}

		/* hack to emulate the behaviour of some gcc spec files which filter
		 * flags to pass to cpp/ld/as */
		static char const *const pass_to_cpp_and_ld[] = {
			"soft-float"
		};
		for (size_t i = 0; i < ARRAY_SIZE(pass_to_cpp_and_ld); ++i) {
			if (streq(pass_to_cpp_and_ld[i], option->option)) {
				char buf[64];
				snprintf(buf, sizeof(buf), "-m%s", option->option);
				driver_add_flag(&cppflags_obst, buf);
				driver_add_flag(&asflags_obst, buf);
				driver_add_flag(&ldflags_obst, buf);
				break;
			}
		}
	}

	return res;
}
Exemple #5
0
bool options_parse_diagnostics(options_state_t *s)
{
	const char *full_option = s->argv[s->i];
	if (full_option[0] != '-')
		return false;
	const char *option = &full_option[1];

	if (simple_arg("w", s)) {
		driver_add_flag(&cppflags_obst, "-w");
		disable_all_warnings();
	} else if (simple_arg("pedantic", s)) {
		dialect.strict = true;
		set_warning_opt("pedantic");
		set_warning_opt("error=return-type");
	} else if (simple_arg("pedantic-errors", s)) {
		dialect.strict = true;
		set_warning_opt("error=pedantic");
		set_warning_opt("error=return-type");
	} else if (option[0] == 'W') {
		if (simple_arg("Winit-self", s)) {
			/* ignored (same as gcc does) */
		} else if (simple_arg("Wformat-y2k", s)
		        || simple_arg("Wformat-security", s)
		        || simple_arg("Wold-style-declaration", s)
		        || simple_arg("Wtype-limits", s)) {
			/* ignore (gcc compatibility) */
		} else if (option[1] != '\0' && option[2] == ',') {
			/* this is not a warning option */
			return false;
		} else {
			set_warning_opt(&option[1]);
		}
	} else if (option[0] == 'f') {
		const char *arg;

		if ((arg = equals_arg("fmessage-length", s)) != NULL) {
			(void)arg;
			/* not supported yet */
		} else {
			bool truth_value;
			const char *fopt;
			if ((fopt = f_no_arg(&truth_value, s)) != NULL) {
				if (f_yesno_arg("-fdiagnostics-show-option", s)) {
					diagnostics_show_option = truth_value;
				} else if (f_yesno_arg("-fshow-column", s)) {
					show_column = truth_value;
				} else if (f_yesno_arg("-fcolor-diagnostics", s)
				        || f_yesno_arg("-fdiagnostics-color", s)) {
					diagnostic_enable_color(truth_value
						? (colorterm != 0 ? colorterm : 8)
						: 0);
				} else {
					return false;
				}
			} else {
				return false;
			}
		}
	} else {
		return false;
	}
	return true;
}
Exemple #6
0
bool options_parse_preprocessor(options_state_t *s)
{
	const char *full_option = s->argv[s->i];
	if (full_option[0] != '-')
		return false;
	const char *option = &full_option[1];

	const char *arg;
	bool is_MD = false;
	if ((arg = prefix_arg("I", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-I%s", arg);
		append_include_path(&bracket_searchpath, arg, false);
	} else if ((arg = prefix_arg("D", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-D%s", arg);
		record_cmdline_define(true, arg);
	} else if ((arg = prefix_arg("U", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-U%s", arg);
		record_cmdline_define(false, arg);
	} else if (simple_arg("MMD", s) || (is_MD = simple_arg("MD", s))) {
		construct_dep_target = true;
		include_system_headers_in_dependencies = is_MD;
		driver_add_flag(&cppflags_obst, "-%s", option);
	} else if (simple_arg("MP", s)) {
		print_phony_targets = true;
		driver_add_flag(&cppflags_obst, "-%s", option);
	} else if ((arg = prefix_arg("MF", s)) != NULL) {
		dependency_file = arg;
		goto add_arg_opt;
	} else if ((arg = prefix_arg("MT", s)) != NULL) {
		dependency_target = arg;
		dont_escape_target = true;
		goto add_arg_opt;
	} else if ((arg = prefix_arg("MQ", s)) != NULL) {
		dependency_target = arg;
		dont_escape_target = false;
add_arg_opt:
		driver_add_flag(&cppflags_obst, "-%s", option);
		driver_add_flag(&cppflags_obst, "%s", arg);
	} else if ((arg = prefix_arg("include", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-include");
		driver_add_flag(&cppflags_obst, "%s", arg);
	} else if ((arg = prefix_arg("idirafter", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-idirafter");
		driver_add_flag(&cppflags_obst, "%s", arg);
		append_include_path(&after_searchpath, arg, false);
	} else if ((arg = prefix_arg("isystem", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-isystem");
		driver_add_flag(&cppflags_obst, "%s", arg);
		append_include_path(&system_searchpath, arg, false);
	} else if ((arg = prefix_arg("iquote", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-iquote");
		driver_add_flag(&cppflags_obst, "%s", arg);
		append_include_path(&quote_searchpath, arg, false);
	} else if (simple_arg("nostdinc", s)) {
		driver_no_stdinc = true;
		driver_add_flag(&cppflags_obst, "-%s", option);
	} else if ((arg = equals_arg("finput-charset", s)) != NULL) {
		input_decoder = input_get_decoder(arg);
		if (input_decoder == NULL) {
			errorf(NULL, "input encoding \"%s\" not supported", arg);
		}
	} else if ((arg = spaced_arg("Xpreprocessor", s)) != NULL) {
		driver_add_flag(&cppflags_obst, "-Xpreprocessor");
		driver_add_flag(&cppflags_obst, arg);
	} else if (accept_prefix(s, "-Wp,", true, &arg)) {
		driver_add_flag(&cppflags_obst, "%s", full_option);
	} else if (simple_arg("integrated-cpp", s)) {
		driver_use_integrated_preprocessor = true;
	} else if (simple_arg("no-integrated-cpp", s)) {
		driver_use_integrated_preprocessor = false;
	} else if (simple_arg("trigraphs", s)) {
		/* pass these through to the preprocessor */
		driver_add_flag(&cppflags_obst, "-%s", option);
	} else if (simple_arg("fdollars-in-identifiers", s)) {
		no_dollar_in_symbol = false;
	} else if (simple_arg("fno-dollars-in-identifiers", s)) {
		no_dollar_in_symbol = true;
	} else {
		return false;
	}
	return true;
}
Exemple #7
0
static bool pass_options_to_firm_be(void)
{
	switch (target.object_format) {
	case OBJECT_FORMAT_ELF:     set_be_option("objectformat=elf");    break;
	case OBJECT_FORMAT_MACH_O:  set_be_option("objectformat=mach-o"); break;
	case OBJECT_FORMAT_PE_COFF: set_be_option("objectformat=coff");   break;
	}

	if (profile_generate) {
		driver_add_flag(&ldflags_obst, "-lfirmprof");
		set_be_option("profilegenerate");
	}
	if (profile_use) {
		set_be_option("profileuse");
	}
	bool res = true;
	const char *pic_option;
	if (target.pic_mode > 0) {
		/* Select correct PIC mode */
		if (target.object_format == OBJECT_FORMAT_MACH_O) {
			pic_option = "pic=mach-o";
		} else {
			pic_option = target.pic_no_plt ? "pic=elf-noplt"
			                               : "pic=elf";
		}
	} else {
		pic_option = "pic=none";
	}
	set_be_option(pic_option);

	/* pass options to firm backend (this happens delayed because we first
	 * had to decide which backend is actually used) */
	for (codegen_option_t *option = codegen_options; option != NULL;
	     option = option->next) {
		char        buf[256];
		const char *opt = option->option;
		/* pass option along to firm backend (except the -m32, -m64 stuff) */
		snprintf(buf, sizeof(buf), "%s-%s", target.firm_isa, opt);
		if (be_parse_arg(buf) == 0) {
			errorf(NULL, "Unknown codegen option '-m%s'", opt);
			res = false;
			continue;
		}

		/* hack to emulate the behaviour of some gcc spec files which filter
		 * flags to pass to cpp/ld/as */
		static char const *const pass_to_cpp_and_ld[] = {
			"soft-float"
		};
		for (size_t i = 0; i < ARRAY_SIZE(pass_to_cpp_and_ld); ++i) {
			if (streq(pass_to_cpp_and_ld[i], option->option)) {
				snprintf(buf, sizeof(buf), "-m%s", option->option);
				driver_add_flag(&cppflags_obst, buf);
				driver_add_flag(&asflags_obst, buf);
				driver_add_flag(&ldflags_obst, buf);
				break;
			}
		}
	}

	/* We can initialize the backend at this point and call be_get_backend_param() */
	if (target.pic_mode > 0 && !be_get_backend_param()->pic_supported) {
		errorf(NULL, "Selected backend '%s' does not support position independent code (PIC)",
			   target.firm_isa);
		res = false;
	}

	return res;
}