Add alignstack option for inline asm.

This commit is contained in:
Luqman Aden 2013-03-12 01:02:58 -07:00
parent 7f500ab4c1
commit 18b71a7831
5 changed files with 19 additions and 10 deletions

View File

@ -873,12 +873,19 @@ pub fn add_comment(bcx: block, text: &str) {
} }
pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char, pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
volatile: lib::llvm::Bool, dia: AsmDialect) -> ValueRef { volatile: bool, alignstack: bool,
dia: AsmDialect) -> ValueRef {
unsafe { unsafe {
count_insn(cx, "inlineasm"); count_insn(cx, "inlineasm");
let volatile = if volatile { lib::llvm::True }
else { lib::llvm::False };
let alignstack = if alignstack { lib::llvm::True }
else { lib::llvm::False };
let llfty = T_fn(~[], T_void()); let llfty = T_fn(~[], T_void());
let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile, False, dia); let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile,
alignstack, dia);
Call(cx, v, ~[]) Call(cx, v, ~[])
} }

View File

@ -691,14 +691,13 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast::expr_assign_op(op, dst, src) => { ast::expr_assign_op(op, dst, src) => {
return trans_assign_op(bcx, expr, op, dst, src); return trans_assign_op(bcx, expr, op, dst, src);
} }
ast::expr_inline_asm(asm, cons, volatile) => { ast::expr_inline_asm(asm, cons, volatile, alignstack) => {
// XXX: cons doesn't actual contain ALL the stuff we should // XXX: cons doesn't actual contain ALL the stuff we should
// be passing since the constraints for in/outputs aren't included // be passing since the constraints for in/outputs aren't included
do str::as_c_str(*asm) |a| { do str::as_c_str(*asm) |a| {
do str::as_c_str(*cons) |c| { do str::as_c_str(*cons) |c| {
let v = if volatile { lib::llvm::True } InlineAsmCall(bcx, a, c, volatile, alignstack,
else { lib::llvm::False }; lib::llvm::AD_ATT);
InlineAsmCall(bcx, a, c, v, lib::llvm::AD_ATT);
} }
} }
return bcx; return bcx;

View File

@ -601,8 +601,8 @@ pub enum expr_ {
expr_ret(Option<@expr>), expr_ret(Option<@expr>),
expr_log(log_level, @expr, @expr), expr_log(log_level, @expr, @expr),
/* asm, clobbers + constraints, volatile */ /* asm, clobbers + constraints, volatile, align stack */
expr_inline_asm(@~str, @~str, bool), expr_inline_asm(@~str, @~str, bool, bool),
expr_mac(mac), expr_mac(mac),

View File

@ -52,6 +52,7 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
let mut inputs = ~[]; let mut inputs = ~[];
let mut cons = ~""; let mut cons = ~"";
let mut volatile = false; let mut volatile = false;
let mut alignstack = false;
let mut state = Asm; let mut state = Asm;
loop outer: { loop outer: {
@ -115,6 +116,8 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
if option == ~"volatile" { if option == ~"volatile" {
volatile = true; volatile = true;
} else if option == ~"alignstack" {
alignstack = true;
} }
if *p.token == token::COMMA { if *p.token == token::COMMA {
@ -153,7 +156,7 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree])
MRExpr(@ast::expr { MRExpr(@ast::expr {
id: cx.next_id(), id: cx.next_id(),
callee_id: cx.next_id(), callee_id: cx.next_id(),
node: ast::expr_inline_asm(@asm, @cons, volatile), node: ast::expr_inline_asm(@asm, @cons, volatile, alignstack),
span: sp span: sp
}) })
} }

View File

@ -1398,7 +1398,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
} }
} }
} }
ast::expr_inline_asm(a, c, v) => { ast::expr_inline_asm(a, c, v, _) => {
if v { if v {
word(s.s, ~"__volatile__ asm!"); word(s.s, ~"__volatile__ asm!");
} else { } else {