Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: add --asm-syntax flag #17835

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/librustc/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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"); }

Expand Down
34 changes: 32 additions & 2 deletions src/librustc/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>
pub alt_std_name: Option<String>,
// Syntax to use when emitting asm
pub syntax: AsmSyntax,

}

/// Some reasonable defaults
Expand Down Expand Up @@ -130,6 +140,7 @@ pub fn basic_options() -> Options {
externs: HashMap::new(),
crate_name: None,
alt_std_name: None,
syntax: AsmDefault,
}
}

Expand Down Expand Up @@ -623,6 +634,10 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
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"),
)
Expand Down Expand Up @@ -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, '=');
Expand Down Expand Up @@ -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,
}
}

Expand Down