1
Fork 0

Properly handle input operands for inline asm.

This commit is contained in:
Luqman Aden 2013-03-13 00:32:23 -07:00 committed by Luqman Aden
parent 6d078db952
commit d8ab47e7f9
2 changed files with 51 additions and 7 deletions

View file

@ -873,6 +873,7 @@ pub fn add_comment(bcx: block, text: &str) {
}
pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
inputs: &[ValueRef],
volatile: bool, alignstack: bool,
dia: AsmDialect) -> ValueRef {
unsafe {
@ -883,11 +884,15 @@ pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
let alignstack = if alignstack { lib::llvm::True }
else { lib::llvm::False };
let llfty = T_fn(~[], T_void());
let argtys = do inputs.map |v| {
io::println(fmt!("ARG TYPE: %?", val_str(cx.ccx().tn, *v)));
val_ty(*v)
};
let llfty = T_fn(argtys, T_void());
let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile,
alignstack, dia as c_uint);
Call(cx, v, ~[])
Call(cx, v, inputs)
}
}

View file

@ -558,12 +558,51 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
return trans_rvalue_stmt_unadjusted(bcx, a);
}
ast::expr_inline_asm(asm, ref ins, ref outs,
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
clobs, volatile, alignstack) => {
let mut constraints = ~[];
let mut cleanups = ~[];
// TODO: Handle outputs
let inputs = do ins.map |&(c, in)| {
constraints.push(copy *c);
let inty = ty::arg {
mode: ast::expl(ast::by_val),
ty: expr_ty(bcx, in)
};
unpack_result!(bcx, {
callee::trans_arg_expr(bcx, inty, in, &mut cleanups,
None, callee::DontAutorefArg)
})
};
for cleanups.each |c| {
revoke_clean(bcx, *c);
}
let mut constraints = str::connect(constraints, ",");
// Add the clobbers
if *clobs != ~"" {
if constraints == ~"" {
constraints += *clobs;
} else {
constraints += ~"," + *clobs;
}
} else {
constraints += *clobs;
}
io::println(fmt!("Inputs: %?\nConstraints: %?\n", ins, constraints));
do str::as_c_str(*asm) |a| {
do str::as_c_str(*cons) |c| {
InlineAsmCall(bcx, a, c, volatile, alignstack,
do str::as_c_str(constraints) |c| {
InlineAsmCall(bcx, a, c, inputs, volatile, alignstack,
lib::llvm::AD_ATT);
}
}