diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs index 7b4d1780ccd69..c762d43919d87 100644 --- a/src/librustc/back/write.rs +++ b/src/librustc/back/write.rs @@ -12,6 +12,7 @@ use back::lto; use back::link::{get_cc_prog, remove}; use driver::driver::{CrateTranslation, ModuleTranslation, OutputFilenames}; use driver::config::{NoDebugInfo, Passes, SomePasses, AllPasses}; +use driver::config::{AsmDefault, AsmIntel, AsmAtt}; use driver::session::Session; use driver::config; use llvm; @@ -34,7 +35,6 @@ use std::sync::{Arc, Mutex}; use std::task::TaskBuilder; use libc::{c_uint, c_int, c_void}; - #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] pub enum OutputType { OutputTypeBitcode, @@ -957,6 +957,13 @@ unsafe fn configure_llvm(sess: &Session) { add("rustc"); // fake program name if vectorize_loop { add("-vectorize-loops"); } if vectorize_slp { add("-vectorize-slp"); } + + match sess.opts.syntax { + AsmIntel => add("-x86-asm-syntax=intel"), + AsmAtt => add("-x86-asm-syntax=att"), + AsmDefault => {} + } + if sess.time_llvm_passes() { add("-time-passes"); } if sess.print_llvm_passes() { add("-debug-pass=Structure"); } diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index 9ce012502446d..b454680bff813 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -62,6 +62,13 @@ pub enum DebugInfoLevel { FullDebugInfo, } +#[deriving(Clone, PartialEq)] +pub enum AsmSyntax { + AsmDefault, + AsmAtt, + AsmIntel, +} + #[deriving(Clone)] pub struct Options { // The crate config requested for the session, which may be combined @@ -101,7 +108,10 @@ pub struct Options { /// An optional name to use as the crate for std during std injection, /// written `extern crate std = "name"`. Default to "std". Used by /// out-of-tree drivers. - pub alt_std_name: Option + pub alt_std_name: Option, + // Syntax to use when emitting asm + pub syntax: AsmSyntax, + } /// Some reasonable defaults @@ -130,6 +140,7 @@ pub fn basic_options() -> Options { externs: HashMap::new(), crate_name: None, alt_std_name: None, + syntax: AsmDefault, } } @@ -623,6 +634,10 @@ pub fn optgroups() -> Vec { auto = colorize, if output goes to a tty (default); always = always colorize output; never = never colorize output", "auto|always|never"), + optopt("", "asm-syntax", "Configure syntax to use for asm: + default = use the default syntax for the platform; + att = use at&t syntax if available; + intel = use intel syntax if available", "default|att|intel"), optmulti("", "extern", "Specify where an external rust library is located", "NAME=PATH"), ) @@ -796,6 +811,20 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } }; + let syntax = match matches.opt_str("asm-syntax").as_ref().map(|s| s.as_slice()) { + Some("default") => AsmDefault, + Some("att") => AsmAtt, + Some("intel") => AsmIntel, + + None => AsmDefault, + + Some(arg) => { + early_error(format!("argument for --asm-syntax must be default, att \ + or intel (instead was `{}`)", + arg).as_slice()) + } + }; + let mut externs = HashMap::new(); for arg in matches.opt_strs("extern").iter() { let mut parts = arg.as_slice().splitn(1, '='); @@ -839,7 +868,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { color: color, externs: externs, crate_name: crate_name, - alt_std_name: None + alt_std_name: None, + syntax: syntax, } }