[pure-lang-svn] SF.net SVN: pure-lang:[481] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-13 09:06:07
|
Revision: 481 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=481&view=rev Author: agraef Date: 2008-08-13 09:06:17 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Add support for single precision 'float' arguments and return values to the C interface. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/interpreter.cc Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-13 01:45:47 UTC (rev 480) +++ pure/trunk/ChangeLog 2008-08-13 09:06:17 UTC (rev 481) @@ -1,5 +1,9 @@ 2008-08-13 Albert Graef <Dr....@t-...> + * interpreter.cc (declare_extern, named_type, type_name): Add + support for single precision 'float' arguments and return values + to the C interface. Reported by Eddie Rucker. + * examples/signal.pure: Add signal processing example. * runtime.cc (pure_catch, pure_invoke): Collecting temporary Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-13 01:45:47 UTC (rev 480) +++ pure/trunk/interpreter.cc 2008-08-13 09:06:17 UTC (rev 481) @@ -2567,6 +2567,8 @@ return Type::Int32Ty; else if (name == "long") return Type::Int64Ty; + else if (name == "float") + return Type::FloatTy; else if (name == "double") return Type::DoubleTy; else if (name == "char*") @@ -2606,6 +2608,8 @@ return "int"; else if (type == Type::Int64Ty) return "long"; + else if (type == Type::FloatTy) + return "float"; else if (type == Type::DoubleTy) return "double"; else if (type == CharPtrTy) @@ -2872,6 +2876,18 @@ phi->addIncoming(intv, intbb); phi->addIncoming(mpzv, mpzbb); unboxed[i] = phi; + } else if (argt[i] == Type::FloatTy) { + BasicBlock *okbb = BasicBlock::Create("ok"); + Value *idx[2] = { Zero, Zero }; + Value *tagv = b.CreateLoad(b.CreateGEP(x, idx, idx+2), "tag"); + b.CreateCondBr + (b.CreateICmpEQ(tagv, SInt(EXPR::DBL), "cmp"), okbb, failedbb); + f->getBasicBlockList().push_back(okbb); + b.SetInsertPoint(okbb); + Value *pv = b.CreateBitCast(x, DblExprPtrTy, "dblexpr"); + idx[1] = ValFldIndex; + Value *dv = b.CreateLoad(b.CreateGEP(pv, idx, idx+2), "dblval"); + unboxed[i] = b.CreateFPTrunc(dv, Type::FloatTy); } else if (argt[i] == Type::DoubleTy) { BasicBlock *okbb = BasicBlock::Create("ok"); Value *idx[2] = { Zero, Zero }; @@ -2897,6 +2913,7 @@ } else if (argt[i] == PointerType::get(Type::Int16Ty, 0) || argt[i] == PointerType::get(Type::Int32Ty, 0) || argt[i] == PointerType::get(Type::Int64Ty, 0) || + argt[i] == PointerType::get(Type::FloatTy, 0) || argt[i] == PointerType::get(Type::DoubleTy, 0)) { BasicBlock *okbb = BasicBlock::Create("ok"); Value *idx[2] = { Zero, Zero }; @@ -2977,6 +2994,9 @@ u = b.CreateCall(module->getFunction("pure_int"), u); else if (type == Type::Int64Ty) u = b.CreateCall(module->getFunction("pure_long"), u); + else if (type == Type::FloatTy) + u = b.CreateCall(module->getFunction("pure_double"), + b.CreateFPExt(u, Type::DoubleTy)); else if (type == Type::DoubleTy) u = b.CreateCall(module->getFunction("pure_double"), u); else if (type == CharPtrTy) @@ -2984,6 +3004,7 @@ else if (type == PointerType::get(Type::Int16Ty, 0) || type == PointerType::get(Type::Int32Ty, 0) || type == PointerType::get(Type::Int64Ty, 0) || + type == PointerType::get(Type::FloatTy, 0) || type == PointerType::get(Type::DoubleTy, 0)) u = b.CreateCall(module->getFunction("pure_pointer"), b.CreateBitCast(u, VoidPtrTy)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |