annotate gen/naked.cpp @ 983:6e68054cfc20

Fix out-ouf-source build for runtime as well. To build out-of-source, follow these steps: # [[Insert LLVM build instructions here]] mkdir my_build_dir cd my_build_dir svn co http://svn.dsource.org/projects/tango/trunk tango ccmake <PATH_TO_SOURCE> # (Regular ccmake stuff, press 'c' a few times followed by 'g') make make runtime # add `PWD`/bin to PATH closes #213
author Frits van Bommel <fvbommel wxs.nl>
date Thu, 19 Feb 2009 11:01:34 +0100
parents 7e669954db7d
children 2667e3a145be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
1 #include "gen/llvm.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
2
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
3 #include "expression.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
4 #include "statement.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
5 #include "declaration.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
6
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
7 #include <cassert>
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
8
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
9 #include "gen/logger.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
10 #include "gen/irstate.h"
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
11 #include "gen/llvmhelpers.h"
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
12 #include "gen/tollvm.h"
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
13
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
14 //////////////////////////////////////////////////////////////////////////////////////////
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
15
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
16 void Statement::toNakedIR(IRState *p)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
17 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
18 error("not allowed in naked function");
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
19 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
20
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
21 //////////////////////////////////////////////////////////////////////////////////////////
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
22
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
23 void CompoundStatement::toNakedIR(IRState *p)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
24 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
25 Logger::println("CompoundStatement::toNakedIR(): %s", loc.toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
26 LOG_SCOPE;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
27
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
28 if (statements)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
29 for (unsigned i = 0; i < statements->dim; i++)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
30 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
31 Statement* s = (Statement*)statements->data[i];
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
32 if (s) s->toNakedIR(p);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
33 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
34 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
35
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
36 //////////////////////////////////////////////////////////////////////////////////////////
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
37
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
38 void ExpStatement::toNakedIR(IRState *p)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
39 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
40 Logger::println("ExpStatement::toNakedIR(): %s", loc.toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
41 LOG_SCOPE;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
42
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
43 // only expstmt supported in declarations
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
44 if (exp->op != TOKdeclaration)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
45 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
46 Statement::toNakedIR(p);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
47 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
48 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
49
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
50 DeclarationExp* d = (DeclarationExp*)exp;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
51 VarDeclaration* vd = d->declaration->isVarDeclaration();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
52 FuncDeclaration* fd = d->declaration->isFuncDeclaration();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
53 EnumDeclaration* ed = d->declaration->isEnumDeclaration();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
54
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
55 // and only static variable/function declaration
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
56 // no locals or nested stuffies!
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
57 if (!vd && !fd && !ed)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
58 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
59 Statement::toNakedIR(p);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
60 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
61 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
62 else if (vd && !vd->isDataseg())
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
63 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
64 error("non-static variable '%s' not allowed in naked function", vd->toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
65 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
66 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
67 else if (fd && !fd->isStatic())
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
68 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
69 error("non-static nested function '%s' not allowed in naked function", fd->toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
70 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
71 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
72 // enum decls should always be safe
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
73
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
74 // make sure the symbols gets processed
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
75 d->declaration->toObjFile(0);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
76 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
77
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
78 //////////////////////////////////////////////////////////////////////////////////////////
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
79
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
80 void LabelStatement::toNakedIR(IRState *p)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
81 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
82 Logger::println("LabelStatement::toNakedIR(): %s", loc.toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
83 LOG_SCOPE;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
84
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
85 p->nakedAsm << p->func()->decl->mangle() << "_" << ident->toChars() << ":";
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
86
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
87 if (statement)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
88 statement->toNakedIR(p);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
89 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
90
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
91 //////////////////////////////////////////////////////////////////////////////////////////
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
92
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
93 void DtoDefineNakedFunction(FuncDeclaration* fd)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
94 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
95 Logger::println("DtoDefineNakedFunction(%s)", fd->mangle());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
96 LOG_SCOPE;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
97
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
98 assert(fd->ir.irFunc);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
99 gIR->functions.push_back(fd->ir.irFunc);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
100
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
101 // we need to do special processing on the body, since we only want
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
102 // to allow actual inline asm blocks to reach the final asm output
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
103
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
104 std::ostringstream& asmstr = gIR->nakedAsm;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
105
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
106 // build function header
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
107
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
108 // FIXME: could we perhaps use llvm asmwriter to give us these details ?
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
109
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
110 const char* mangle = fd->mangle();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
111 std::ostringstream tmpstr;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
112
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
113 // osx is different
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
114 // also mangling has an extra underscore prefixed
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
115 if (global.params.os == OSMacOSX)
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
116 {
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
117 std::string section = "text";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
118 bool weak = false;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
119 if (DtoIsTemplateInstance(fd))
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
120 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
121 tmpstr << "section\t__TEXT,__textcoal_nt,coalesced,pure_instructions";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
122 section = tmpstr.str();
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
123 weak = true;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
124 }
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
125 asmstr << "\t." << section << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
126 asmstr << "\t.align\t4,0x90" << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
127 asmstr << "\t.globl\t_" << mangle << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
128 if (weak)
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
129 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
130 asmstr << "\t.weak_definition\t_" << mangle << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
131 }
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
132 asmstr << "_" << mangle << ":" << std::endl;
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
133 }
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
134 // this works on linux x86 32 and 64 bit
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
135 // assume it works everywhere else as well for now
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
136 else
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
137 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
138 const char* linkage = "globl";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
139 std::string section = "text";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
140 if (DtoIsTemplateInstance(fd))
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
141 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
142 linkage = "weak";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
143 tmpstr << "section\t.gnu.linkonce.t." << mangle << ",\"ax\",@progbits";
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
144 section = tmpstr.str();
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
145 }
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
146 asmstr << "\t." << section << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
147 asmstr << "\t.align\t16" << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
148 asmstr << "\t." << linkage << "\t" << mangle << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
149 asmstr << "\t.type\t" << mangle << ",@function" << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
150 asmstr << mangle << ":" << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
151 }
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
152
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
153 // emit body
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
154 fd->fbody->toNakedIR(gIR);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
155
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
156 // emit size after body
923
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
157 // llvm does this on linux, but not on osx
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
158 if (global.params.os != OSMacOSX)
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
159 {
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
160 asmstr << "\t.size\t" << mangle << ", .-" << mangle << std::endl << std::endl;
9bab304ed531 Added support for naked asm on OSX. (hopefully!)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 920
diff changeset
161 }
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
162
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
163 gIR->module->appendModuleInlineAsm(asmstr.str());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
164 asmstr.str("");
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
165
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
166 gIR->functions.pop_back();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
diff changeset
167 }
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
168
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
169 //////////////////////////////////////////////////////////////////////////////////////////
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
170
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
171 static LLValue* x86_64_cfloatRetFixup(IRBuilderHelper b, LLValue* orig) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
172 assert(orig->getType() == LLType::DoubleTy);
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
173 LLType* retty = LLStructType::get(LLType::DoubleTy, NULL);
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
174 LLValue* undef = llvm::UndefValue::get(retty);
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
175 return b->CreateInsertValue(undef, orig, 0, "asm.ret");
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
176 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
177
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
178 void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
179 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
180 Logger::println("emitABIReturnAsmStmt(%s)", fdecl->mangle());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
181 LOG_SCOPE;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
182
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
183 IRAsmStmt* as = new IRAsmStmt;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
184
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
185 const LLType* llretTy = DtoType(fdecl->type->nextOf());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
186 asmblock->retty = llretTy;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
187 asmblock->retn = 1;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
188
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
189 // x86
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
190 if (global.params.cpu == ARCHx86)
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
191 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
192 LINK l = fdecl->linkage;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
193 assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
194
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
195 Type* rt = fdecl->type->nextOf()->toBasetype();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
196 if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
197 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
198 if (rt->size() == 8) {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
199 as->out_c = "=A,";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
200 } else {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
201 as->out_c = "={ax},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
202 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
203 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
204 else if (rt->isfloating())
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
205 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
206 if (rt->iscomplex()) {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
207 as->out_c = "={st},={st(1)},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
208 asmblock->retn = 2;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
209 } else {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
210 as->out_c = "={st},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
211 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
212 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
213 else if (rt->ty == Tarray || rt->ty == Tdelegate)
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
214 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
215 as->out_c = "={ax},={dx},";
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
216 asmblock->retn = 2;
954
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
217 #if 0
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
218 // this is to show how to allocate a temporary for the return value
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
219 // in case the appropriate multi register constraint isn't supported.
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
220 // this way abi return from inline asm can still be emulated.
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
221
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
222 // generate asm
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
223 as->out_c = "=*m,=*m,";
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
224 LLValue* tmp = DtoAlloca(llretTy, ".tmp_asm_ret");
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
225 as->out.push_back( tmp );
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
226 as->out.push_back( DtoGEPi(tmp, 0,1) );
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
227 as->code = "movd %eax, $<<out0>>" "\n\t" "mov %edx, $<<out1>>";
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
228
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
229 // fix asmblock
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
230 asmblock->retn = 0;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
231 asmblock->retemu = true;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
232 asmblock->asmBlock->abiret = tmp;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
233
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
234 // add "ret" stmt
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
235 asmblock->s.push_back(as);
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
236
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
237 // done, we don't want anything pushed in the front of the block
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
238 return;
e048e36bc155 Added support for using a temporary to implement emulated ABI return from inline asm, could be easier to use, but I think this will do. It's so extremely target dependent in any case that doing a completely generic approach seems hard.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 949
diff changeset
239 #endif
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
240 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
241 else
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
242 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
243 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
244 fatal();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
245 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
246 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
247
959
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
248 // x86_64
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
249 else if (global.params.cpu == ARCHx86_64)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
250 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
251 LINK l = fdecl->linkage;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
252 /* TODO: Check if this works with extern(Windows), completely untested.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
253 * In particular, returning cdouble may not work with
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
254 * extern(Windows) since according to X86CallingConv.td it
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
255 * doesn't allow XMM1 to be used.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
256 * (So is extern(C), but that should be fine as the calling convention
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
257 * is identical to that of extern(D))
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
258 */
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
259 assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
260
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
261 Type* rt = fdecl->type->nextOf()->toBasetype();
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
262 if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
263 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
264 as->out_c = "={ax},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
265 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
266 else if (rt->isfloating())
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
267 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
268 if (rt == Type::tcomplex80) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
269 // On x87 stack, re=st, im=st(1)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
270 as->out_c = "={st},={st(1)},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
271 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
272 } else if (rt == Type::tfloat80 || rt == Type::timaginary80) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
273 // On x87 stack
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
274 as->out_c = "={st},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
275 } else if (l != LINKd && rt == Type::tcomplex32) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
276 // LLVM and GCC disagree on how to return {float, float}.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
277 // For compatibility, use the GCC/LLVM-GCC way for extern(C/Windows)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
278 // extern(C) cfloat -> %xmm0 (extract two floats)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
279 #if 0
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
280 // Disabled because "regular" extern(C) functions aren't
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
281 // ABI-compatible with GCC yet.
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
282 // TODO: enable when "extern(C) cfloat foo();" compiles to "declare { double } @foo();"
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
283 as->out_c = "={xmm0},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
284 asmblock->retty = LLStructType::get(LLType::DoubleTy, NULL);;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
285 asmblock->retfixup = &x86_64_cfloatRetFixup;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
286 #else
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
287 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
288 fatal();
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
289 #endif
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
290 } else if (rt->iscomplex()) {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
291 // cdouble and extern(D) cfloat -> re=%xmm0, im=%xmm1
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
292 as->out_c = "={xmm0},={xmm1},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
293 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
294 } else {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
295 // Plain float/double/ifloat/idouble
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
296 as->out_c = "={xmm0},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
297 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
298 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
299 else if (rt->ty == Tarray || rt->ty == Tdelegate)
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
300 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
301 as->out_c = "={ax},={dx},";
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
302 asmblock->retn = 2;
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
303 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
304 else
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
305 {
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
306 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
307 fatal();
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
308 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
309 }
7e669954db7d Implement implicit return after inline asm on x86_64
Frits van Bommel <fvbommel wxs.nl>
parents: 954
diff changeset
310
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
311 // unsupported
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
312 else
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
313 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
314 error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple);
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
315 fatal();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
316 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
317
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
318 // return values always go in the front
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
319 asmblock->s.push_front(as);
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 923
diff changeset
320 }