Skip to content

Commit d8ab47e

Browse files
committed
Properly handle input operands for inline asm.
1 parent 6d078db commit d8ab47e

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

src/librustc/middle/trans/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ pub fn add_comment(bcx: block, text: &str) {
873873
}
874874
875875
pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
876+
inputs: &[ValueRef],
876877
volatile: bool, alignstack: bool,
877878
dia: AsmDialect) -> ValueRef {
878879
unsafe {
@@ -883,11 +884,15 @@ pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
883884
let alignstack = if alignstack { lib::llvm::True }
884885
else { lib::llvm::False };
885886
886-
let llfty = T_fn(~[], T_void());
887+
let argtys = do inputs.map |v| {
888+
io::println(fmt!("ARG TYPE: %?", val_str(cx.ccx().tn, *v)));
889+
val_ty(*v)
890+
};
891+
let llfty = T_fn(argtys, T_void());
887892
let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile,
888893
alignstack, dia as c_uint);
889894
890-
Call(cx, v, ~[])
895+
Call(cx, v, inputs)
891896
}
892897
}
893898

src/librustc/middle/trans/expr.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,51 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
558558
return trans_rvalue_stmt_unadjusted(bcx, a);
559559
}
560560
ast::expr_inline_asm(asm, ref ins, ref outs,
561-
cons, volatile, alignstack) => {
562-
// XXX: cons doesn't actual contain ALL the stuff we should
563-
// be passing since the constraints for in/outputs aren't included
561+
clobs, volatile, alignstack) => {
562+
let mut constraints = ~[];
563+
let mut cleanups = ~[];
564+
565+
// TODO: Handle outputs
566+
567+
let inputs = do ins.map |&(c, in)| {
568+
569+
constraints.push(copy *c);
570+
571+
let inty = ty::arg {
572+
mode: ast::expl(ast::by_val),
573+
ty: expr_ty(bcx, in)
574+
};
575+
576+
577+
unpack_result!(bcx, {
578+
callee::trans_arg_expr(bcx, inty, in, &mut cleanups,
579+
None, callee::DontAutorefArg)
580+
})
581+
582+
};
583+
584+
for cleanups.each |c| {
585+
revoke_clean(bcx, *c);
586+
}
587+
588+
let mut constraints = str::connect(constraints, ",");
589+
590+
// Add the clobbers
591+
if *clobs != ~"" {
592+
if constraints == ~"" {
593+
constraints += *clobs;
594+
} else {
595+
constraints += ~"," + *clobs;
596+
}
597+
} else {
598+
constraints += *clobs;
599+
}
600+
601+
io::println(fmt!("Inputs: %?\nConstraints: %?\n", ins, constraints));
602+
564603
do str::as_c_str(*asm) |a| {
565-
do str::as_c_str(*cons) |c| {
566-
InlineAsmCall(bcx, a, c, volatile, alignstack,
604+
do str::as_c_str(constraints) |c| {
605+
InlineAsmCall(bcx, a, c, inputs, volatile, alignstack,
567606
lib::llvm::AD_ATT);
568607
}
569608
}

0 commit comments

Comments
 (0)