From 18b71a78314505b4dd3816f9662709860aafaf4c Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 12 Mar 2013 01:02:58 -0700 Subject: [PATCH] Add alignstack option for inline asm. --- src/librustc/middle/trans/build.rs | 11 +++++++++-- src/librustc/middle/trans/expr.rs | 7 +++---- src/libsyntax/ast.rs | 4 ++-- src/libsyntax/ext/asm.rs | 5 ++++- src/libsyntax/print/pprust.rs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 2e6b0c5f782..50a7669a1be 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -873,12 +873,19 @@ pub fn add_comment(bcx: block, text: &str) { } 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 { 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 v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile, False, dia); + let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile, + alignstack, dia); Call(cx, v, ~[]) } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 0539dadca8e..c163183bfc8 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -691,14 +691,13 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, ast::expr_assign_op(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 // be passing since the constraints for in/outputs aren't included do str::as_c_str(*asm) |a| { do str::as_c_str(*cons) |c| { - let v = if volatile { lib::llvm::True } - else { lib::llvm::False }; - InlineAsmCall(bcx, a, c, v, lib::llvm::AD_ATT); + InlineAsmCall(bcx, a, c, volatile, alignstack, + lib::llvm::AD_ATT); } } return bcx; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7b4b382393f..b22018c4c76 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -601,8 +601,8 @@ pub enum expr_ { expr_ret(Option<@expr>), expr_log(log_level, @expr, @expr), - /* asm, clobbers + constraints, volatile */ - expr_inline_asm(@~str, @~str, bool), + /* asm, clobbers + constraints, volatile, align stack */ + expr_inline_asm(@~str, @~str, bool, bool), expr_mac(mac), diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 3f1aea59ab5..8051a67d8fd 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -52,6 +52,7 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) let mut inputs = ~[]; let mut cons = ~""; let mut volatile = false; + let mut alignstack = false; let mut state = Asm; loop outer: { @@ -115,6 +116,8 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) if option == ~"volatile" { volatile = true; + } else if option == ~"alignstack" { + alignstack = true; } 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 { 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 }) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6b1a72b92ff..92883123782 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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 { word(s.s, ~"__volatile__ asm!"); } else {