From 1809214995380469b2d45c982963bd5378aa42f5 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sat, 28 Mar 2009 07:24:53 +0100 Subject: [PATCH] Added support for single D type register return from __asm. --- dmd/attrib.c | 9 ++------- gen/naked.cpp | 7 ++++--- runtime/import/ldc/llvmasm.di | 6 ++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dmd/attrib.c b/dmd/attrib.c index 161f868a..4dda95e8 100644 --- a/dmd/attrib.c +++ b/dmd/attrib.c @@ -1130,9 +1130,9 @@ void PragmaDeclaration::semantic(Scope *sc) case LLVMinline_asm: if (TemplateDeclaration* td = s->isTemplateDeclaration()) { - if (td->parameters->dim != 0) + if (td->parameters->dim > 1) { - error("the '%s' pragma template must have exactly zero template parameters", ident->toChars()); + error("the '%s' pragma template must have exactly zero or one template parameters", ident->toChars()); fatal(); } else if (!td->onemember) @@ -1140,11 +1140,6 @@ void PragmaDeclaration::semantic(Scope *sc) error("the '%s' pragma template must have exactly one member", ident->toChars()); fatal(); } - else if (td->overnext || td->overroot) - { - error("the '%s' pragma template must not be overloaded", ident->toChars()); - fatal(); - } td->llvmInternal = llvm_internal; } else diff --git a/gen/naked.cpp b/gen/naked.cpp index af1140d1..aee7a243 100644 --- a/gen/naked.cpp +++ b/gen/naked.cpp @@ -376,7 +376,8 @@ DValue * DtoInlineAsmExpr(Loc loc, FuncDeclaration * fd, Expressions * arguments } // build asm function type - llvm::FunctionType* FT = llvm::FunctionType::get(llvm::Type::VoidTy, argtypes, false); + const llvm::Type* ret_type = DtoType(fd->type->nextOf()); + llvm::FunctionType* FT = llvm::FunctionType::get(ret_type, argtypes, false); // build asm call bool sideeffect = true; @@ -384,8 +385,8 @@ DValue * DtoInlineAsmExpr(Loc loc, FuncDeclaration * fd, Expressions * arguments llvm::Value* v = gIR->ir->CreateCall(ia, args.begin(), args.end(), ""); - // return NULL for now - return NULL; + // return call as im value + return new DImValue(fd->type->nextOf(), v); } diff --git a/runtime/import/ldc/llvmasm.di b/runtime/import/ldc/llvmasm.di index 2aa035d5..daab45c4 100644 --- a/runtime/import/ldc/llvmasm.di +++ b/runtime/import/ldc/llvmasm.di @@ -5,3 +5,9 @@ template __asm() { void __asm(char[] asmcode, char[] constraints, ...); } + +pragma(llvm_inline_asm) +template __asm(T) +{ + T __asm(char[] asmcode, char[] constraints, ...); +}