Mercurial > projects > ldc
annotate gen/asmstmt.cpp @ 534:7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 24 Aug 2008 16:22:58 +0200 |
parents | 672eb4893b55 |
children | 2fe2d4518618 |
rev | line source |
---|---|
304 | 1 // Taken from GDC source tree. Original by David Friedman. |
2 // Released under the Artistic License found in dmd/artistic.txt | |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
3 |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
4 #include "gen/llvm.h" |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
5 #include "llvm/InlineAsm.h" |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
6 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
7 //#include "d-gcc-includes.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
8 //#include "total.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
9 #include "dmd/statement.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
10 #include "dmd/scope.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
11 #include "dmd/declaration.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
12 #include "dmd/dsymbol.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
13 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
14 #include <cassert> |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
15 #include <deque> |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
16 #include <iostream> |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
17 #include <sstream> |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
18 #include <cstring> |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
19 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
20 //#include "d-lang.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
21 //#include "d-codegen.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
22 |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
23 #include "gen/irstate.h" |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
24 #include "gen/dvalue.h" |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
25 #include "gen/tollvm.h" |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
26 #include "gen/logger.h" |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
27 #include "gen/todebug.h" |
302 | 28 #include "gen/llvmhelpers.h" |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
29 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
30 typedef enum { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
31 Arg_Integer, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
32 Arg_Pointer, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
33 Arg_Memory, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
34 Arg_FrameRelative, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
35 Arg_LocalSize, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
36 Arg_Dollar |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
37 } AsmArgType; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
38 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
39 typedef enum { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
40 Mode_Input, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
41 Mode_Output, |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
42 Mode_Update |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
43 } AsmArgMode; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
44 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
45 struct AsmArg { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
46 AsmArgType type; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
47 Expression * expr; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
48 AsmArgMode mode; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
49 AsmArg(AsmArgType type, Expression * expr, AsmArgMode mode) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
50 this->type = type; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
51 this->expr = expr; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
52 this->mode = mode; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
53 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
54 }; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
55 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
56 struct AsmCode { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
57 char * insnTemplate; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
58 unsigned insnTemplateLen; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
59 Array args; // of AsmArg |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
60 unsigned moreRegs; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
61 unsigned dollarLabel; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
62 int clobbersMemory; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
63 AsmCode() { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
64 insnTemplate = NULL; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
65 insnTemplateLen = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
66 moreRegs = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
67 dollarLabel = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
68 clobbersMemory = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
69 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
70 }; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
71 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
72 AsmStatement::AsmStatement(Loc loc, Token *tokens) : |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
73 Statement(loc) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
74 { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
75 this->tokens = tokens; // Do I need to copy these? |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
76 asmcode = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
77 asmalign = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
78 refparam = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
79 naked = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
80 regs = 0; |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
81 |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
82 isBranchToLabel = NULL; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
83 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
84 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
85 Statement *AsmStatement::syntaxCopy() |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
86 { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
87 // copy tokens? copy 'code'? |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
88 AsmStatement * a_s = new AsmStatement(loc,tokens); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
89 a_s->asmcode = asmcode; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
90 a_s->refparam = refparam; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
91 a_s->naked = naked; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
92 a_s->regs = a_s->regs; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
93 return a_s; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
94 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
95 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
96 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
97 { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
98 bool sep = 0, nsep = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
99 buf->writestring("asm { "); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
100 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
101 for (Token * t = tokens; t; t = t->next) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
102 switch (t->value) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
103 case TOKlparen: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
104 case TOKrparen: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
105 case TOKlbracket: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
106 case TOKrbracket: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
107 case TOKcolon: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
108 case TOKsemicolon: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
109 case TOKcomma: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
110 case TOKstring: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
111 case TOKcharv: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
112 case TOKwcharv: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
113 case TOKdcharv: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
114 nsep = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
115 break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
116 default: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
117 nsep = 1; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
118 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
119 if (sep + nsep == 2) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
120 buf->writeByte(' '); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
121 sep = nsep; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
122 buf->writestring(t->toChars()); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
123 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
124 buf->writestring("; }"); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
125 buf->writenl(); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
126 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
127 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
128 int AsmStatement::comeFrom() |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
129 { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
130 return FALSE; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
131 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
132 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
133 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
134 #include "d-asm-i386.h" |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
135 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
136 bool d_have_inline_asm() { return true; } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
137 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
138 Statement *AsmStatement::semantic(Scope *sc) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
139 { |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
140 bool err = false; |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
141 if (global.params.cpu != ARCHx86) |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
142 { |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
143 error("inline asm is not supported for the \"%s\" architecture", global.params.llvmArch); |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
144 err = true; |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
145 } |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
146 if (!global.params.useInlineAsm) |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
147 { |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
148 error("inline asm is not allowed when the -noasm switch is used"); |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
149 err = true; |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
150 } |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
151 if (err) |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
152 fatal(); |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
153 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
154 sc->func->inlineAsm = 1; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
155 sc->func->inlineStatus = ILSno; // %% not sure |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
156 // %% need to set DECL_UNINLINABLE too? |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
157 sc->func->hasReturnExp = 1; // %% DMD does this, apparently... |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
158 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
159 // empty statement -- still do the above things because they might be expected? |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
160 if (! tokens) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
161 return this; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
162 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
163 AsmProcessor ap(sc, this); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
164 ap.run(); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
165 return this; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
166 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
167 |
336 | 168 int AsmStatement::blockExit() |
169 { | |
170 //printf("AsmStatement::blockExit(%p)\n", this); | |
171 return BEfallthru | BEreturn | BEgoto | BEhalt; | |
172 } | |
173 | |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
174 void |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
175 AsmStatement::toIR(IRState * irs) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
176 { |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
177 Logger::println("AsmStatement::toIR(): %s", loc.toChars()); |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
178 LOG_SCOPE; |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
179 |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
180 // get asm block |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
181 IRAsmBlock* asmblock = irs->asmBlock; |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
182 assert(asmblock); |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
183 |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
184 // debug info |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
185 if (global.params.symdebug) |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
186 DtoDwarfStopPoint(loc.linnum); |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
187 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
188 if (! asmcode) |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
189 return; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
190 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
191 static std::string i_cns = "i"; |
231
61aa721a6b7f
[svn r247] fixed accessing global symbols from inline asm.
lindquist
parents:
229
diff
changeset
|
192 static std::string p_cns = "i"; |
222
251548c1035d
[svn r238] use *m for memory input constraints and pass in their address
ChristianK
parents:
221
diff
changeset
|
193 static std::string m_cns = "*m"; |
221
68687d8c3e9a
[svn r237] some inline asm output now seems to work, see tangotests/asm2.d
lindquist
parents:
220
diff
changeset
|
194 static std::string mw_cns = "=*m"; |
223
5ffca623b5df
[svn r239] also use indirect modifier for update constraints
ChristianK
parents:
222
diff
changeset
|
195 static std::string mrw_cns = "+*m"; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
196 static std::string memory_name = "memory"; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
197 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
198 AsmCode * code = (AsmCode *) asmcode; |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
199 std::deque<LLValue*> input_values; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
200 std::deque<std::string> input_constraints; |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
201 std::deque<LLValue*> output_values; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
202 std::deque<std::string> output_constraints; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
203 std::deque<std::string> clobbers; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
204 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
205 // FIXME |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
206 #define HOST_WIDE_INT long |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
207 HOST_WIDE_INT var_frame_offset; // "frame_offset" is a macro |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
208 bool clobbers_mem = code->clobbersMemory; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
209 int input_idx = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
210 int n_outputs = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
211 int arg_map[10]; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
212 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
213 assert(code->args.dim <= 10); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
214 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
215 for (unsigned i = 0; i < code->args.dim; i++) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
216 AsmArg * arg = (AsmArg *) code->args.data[i]; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
217 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
218 bool is_input = true; |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
219 LLValue* arg_val = 0; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
220 std::string cns; |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
221 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
222 switch (arg->type) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
223 case Arg_Integer: |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
224 arg_val = arg->expr->toElem(irs)->getRVal(); |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
225 do_integer: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
226 cns = i_cns; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
227 break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
228 case Arg_Pointer: |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
229 assert(arg->expr->op == TOKvar); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
230 arg_val = arg->expr->toElem(irs)->getRVal(); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
231 cns = p_cns; |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
232 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
233 break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
234 case Arg_Memory: |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
235 arg_val = arg->expr->toElem(irs)->getRVal(); |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
236 |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
237 switch (arg->mode) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
238 case Mode_Input: cns = m_cns; break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
239 case Mode_Output: cns = mw_cns; is_input = false; break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
240 case Mode_Update: cns = mrw_cns; is_input = false; break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
241 default: assert(0); break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
242 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
243 break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
244 case Arg_FrameRelative: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
245 // FIXME |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
246 std::cout << "asm fixme Arg_FrameRelative" << std::endl; |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
247 assert(0); |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
248 /* if (arg->expr->op == TOKvar) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
249 arg_val = ((VarExp *) arg->expr)->var->toSymbol()->Stree; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
250 else |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
251 assert(0);*/ |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
252 if ( getFrameRelativeValue(arg_val, & var_frame_offset) ) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
253 // arg_val = irs->integerConstant(var_frame_offset); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
254 cns = i_cns; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
255 } else { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
256 this->error("%s", "argument not frame relative"); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
257 return; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
258 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
259 if (arg->mode != Mode_Input) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
260 clobbers_mem = true; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
261 break; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
262 case Arg_LocalSize: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
263 // FIXME |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
264 std::cout << "asm fixme Arg_LocalSize" << std::endl; |
229
cac3d27ae481
[svn r245] initial support for labels in inline asm, broken :/
lindquist
parents:
227
diff
changeset
|
265 assert(0); |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
266 /* var_frame_offset = cfun->x_frame_offset; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
267 if (var_frame_offset < 0) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
268 var_frame_offset = - var_frame_offset; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
269 arg_val = irs->integerConstant( var_frame_offset );*/ |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
270 goto do_integer; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
271 default: |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
272 assert(0); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
273 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
274 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
275 if (is_input) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
276 arg_map[i] = --input_idx; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
277 //inputs.cons(tree_cons(NULL_TREE, cns, NULL_TREE), arg_val); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
278 input_values.push_back(arg_val); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
279 input_constraints.push_back(cns); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
280 } else { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
281 arg_map[i] = n_outputs++; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
282 //outputs.cons(tree_cons(NULL_TREE, cns, NULL_TREE), arg_val); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
283 output_values.push_back(arg_val); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
284 output_constraints.push_back(cns); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
285 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
286 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
287 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
288 // Telling GCC that callee-saved registers are clobbered makes it preserve |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
289 // those registers. This changes the stack from what a naked function |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
290 // expects. |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
291 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
292 // FIXME |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
293 // if (! irs->func->naked) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
294 for (int i = 0; i < 32; i++) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
295 if (regs & (1 << i)) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
296 //clobbers.cons(NULL_TREE, regInfo[i].gccName); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
297 clobbers.push_back(regInfo[i].gccName); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
298 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
299 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
300 for (int i = 0; i < 32; i++) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
301 if (code->moreRegs & (1 << (i-32))) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
302 //clobbers.cons(NULL_TREE, regInfo[i].gccName); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
303 clobbers.push_back(regInfo[i].gccName); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
304 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
305 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
306 if (clobbers_mem) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
307 clobbers.push_back(memory_name); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
308 //clobbers.cons(NULL_TREE, memory_name); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
309 // } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
310 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
311 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
312 // Remap argument numbers |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
313 for (unsigned i = 0; i < code->args.dim; i++) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
314 if (arg_map[i] < 0) |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
315 arg_map[i] = -arg_map[i] - 1 + n_outputs; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
316 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
317 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
318 bool pct = false; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
319 char * p = code->insnTemplate; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
320 char * q = p + code->insnTemplateLen; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
321 //printf("start: %.*s\n", code->insnTemplateLen, code->insnTemplate); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
322 while (p < q) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
323 if (pct) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
324 if (*p >= '0' && *p <= '9') { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
325 // %% doesn't check against nargs |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
326 *p = '0' + arg_map[*p - '0']; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
327 pct = false; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
328 } else if (*p == '$') { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
329 pct = false; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
330 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
331 //assert(*p == '%');// could be 'a', etc. so forget it.. |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
332 } else if (*p == '$') |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
333 pct = true; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
334 ++p; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
335 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
336 |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
234
diff
changeset
|
337 Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate); |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
338 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
339 std::string insnt(code->insnTemplate, code->insnTemplateLen); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
340 |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
341 // rewrite GCC-style constraints to LLVM-style constraints |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
342 std::string llvmOutConstraints; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
343 std::string llvmInConstraints; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
344 int n = 0; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
345 typedef std::deque<std::string>::iterator it; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
346 for(it i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i, ++n) { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
347 // rewrite update constraint to in and out constraints |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
348 if((*i)[0] == '+') { |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
349 (*i)[0] = '='; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
350 std::string input_constraint; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
351 std::stringstream ss; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
352 ss << n; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
353 ss >> input_constraint; |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
354 //FIXME: I think multiple inout constraints will mess up the order! |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
355 input_constraints.push_front(input_constraint); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
356 input_values.push_front(output_values[n]); |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
357 } |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
358 llvmOutConstraints += *i; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
359 llvmOutConstraints += ","; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
360 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
361 for(it i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) { |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
362 llvmInConstraints += *i; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
363 llvmInConstraints += ","; |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
364 } |
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
365 |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
366 std::string clobstr; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
367 for(it i = clobbers.begin(), e = clobbers.end(); i != e; ++i) { |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
368 clobstr = "~{" + *i + "},"; |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
369 asmblock->clobs.insert(clobstr); |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
370 } |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
371 |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
372 // excessive commas are removed later... |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
373 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
374 // push asm statement |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
375 IRAsmStmt* asmStmt = new IRAsmStmt; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
376 asmStmt->code = insnt; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
377 asmStmt->out_c = llvmOutConstraints; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
378 asmStmt->in_c = llvmInConstraints; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
379 asmStmt->out.insert(asmStmt->out.begin(), output_values.begin(), output_values.end()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
380 asmStmt->in.insert(asmStmt->in.begin(), input_values.begin(), input_values.end()); |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
381 asmStmt->isBranchToLabel = isBranchToLabel; |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
382 asmblock->s.push_back(asmStmt); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
383 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
384 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
385 ////////////////////////////////////////////////////////////////////////////// |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
386 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
387 AsmBlockStatement::AsmBlockStatement(Loc loc, Statements* s) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
388 : CompoundStatement(loc, s) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
389 { |
309 | 390 enclosinghandler = NULL; |
356
44daf304421c
[svn r377] The previous check was too strict, it completely disallowed gotos within finally blocks. This reenables them as long as they don't cross a finally boundary.
ChristianK
parents:
336
diff
changeset
|
391 tf = NULL; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
392 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
393 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
394 // rewrite argument indices to the block scope indices |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
395 static void remap_outargs(std::string& insnt, size_t nargs, size_t& idx) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
396 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
397 static const std::string digits[10] = |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
398 { |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
399 "0","1","2","3","4", |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
400 "5","6","7","8","9" |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
401 }; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
402 assert(nargs <= 10); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
403 |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
404 static const std::string prefix("<<out"); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
405 static const std::string suffix(">>"); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
406 std::string argnum; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
407 std::string needle; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
408 char buf[10]; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
409 for (unsigned i = 0; i < nargs; i++) { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
410 needle = prefix + digits[i] + suffix; |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
411 size_t pos = insnt.find(needle); |
303 | 412 if(std::string::npos != pos) |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
413 sprintf(buf, "%u", idx++); |
302 | 414 while(std::string::npos != (pos = insnt.find(needle))) |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
415 insnt.replace(pos, needle.size(), buf); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
416 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
417 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
418 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
419 // rewrite argument indices to the block scope indices |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
420 static void remap_inargs(std::string& insnt, size_t nargs, size_t& idx) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
421 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
422 static const std::string digits[10] = |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
423 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
424 "0","1","2","3","4", |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
425 "5","6","7","8","9" |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
426 }; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
427 assert(nargs <= 10); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
428 |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
429 static const std::string prefix("<<in"); |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
233
diff
changeset
|
430 static const std::string suffix(">>"); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
431 std::string argnum; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
432 std::string needle; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
433 char buf[10]; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
434 for (unsigned i = 0; i < nargs; i++) { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
435 needle = prefix + digits[i] + suffix; |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
436 size_t pos = insnt.find(needle); |
303 | 437 if(std::string::npos != pos) |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
438 sprintf(buf, "%u", idx++); |
302 | 439 while(std::string::npos != (pos = insnt.find(needle))) |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
440 insnt.replace(pos, needle.size(), buf); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
441 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
442 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
443 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
444 void AsmBlockStatement::toIR(IRState* p) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
445 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
446 Logger::println("AsmBlockStatement::toIR(): %s", loc.toChars()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
447 LOG_SCOPE; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
448 Logger::println("BEGIN ASM"); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
449 |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
450 // create asm block structure |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
451 assert(!p->asmBlock); |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
452 IRAsmBlock* asmblock = new IRAsmBlock; |
239
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
453 assert(asmblock); |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
454 p->asmBlock = asmblock; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
455 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
456 // do asm statements |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
457 for (int i=0; i<statements->dim; i++) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
458 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
459 Statement* s = (Statement*)statements->data[i]; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
460 if (s) { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
461 s->toIR(p); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
462 } |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
463 } |
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
219
diff
changeset
|
464 |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
465 // build forwarder for in-asm branches to external labels |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
466 // this additional asm code sets the __llvm_jump_target variable |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
467 // to a unique value that will identify the jump target in |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
468 // a post-asm switch |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
469 |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
470 // maps each goto destination to its special value |
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
471 std::map<Identifier*, int> gotoToVal; |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
472 |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
473 // location of the special value determining the goto label |
302 | 474 // will be set if post-asm dispatcher block is needed |
475 llvm::AllocaInst* jump_target; | |
301
f42a1090e895
[svn r322] More asm-to-outside jumping work. Unfinished.
ChristianK
parents:
300
diff
changeset
|
476 |
302 | 477 { |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
478 FuncDeclaration* fd = gIR->func()->decl; |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
479 char* fdmangle = fd->mangle(); |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
480 |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
481 // we use a simple static counter to make sure the new end labels are unique |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
482 static size_t uniqueLabelsId = 0; |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
483 std::ostringstream asmGotoEndLabel; |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
484 asmGotoEndLabel << "." << fdmangle << "__llvm_asm_end" << uniqueLabelsId++; |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
485 |
302 | 486 // initialize the setter statement we're going to build |
487 IRAsmStmt* outSetterStmt = new IRAsmStmt; | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
488 std::string asmGotoEnd = "jmp "+asmGotoEndLabel.str()+" ; "; |
302 | 489 std::ostringstream code; |
490 code << asmGotoEnd; | |
491 | |
492 int n_goto = 1; | |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
493 |
302 | 494 size_t n = asmblock->s.size(); |
495 for(size_t i=0; i<n; ++i) | |
496 { | |
497 IRAsmStmt* a = asmblock->s[i]; | |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
498 |
302 | 499 // skip non-branch statements |
500 if(!a->isBranchToLabel) | |
501 continue; | |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
502 |
302 | 503 // if internal, no special handling is necessary, skip |
504 std::vector<Identifier*>::const_iterator it, end; | |
505 end = asmblock->internalLabels.end(); | |
506 bool skip = false; | |
507 for(it = asmblock->internalLabels.begin(); it != end; ++it) | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
508 if((*it)->equals(a->isBranchToLabel)) |
302 | 509 skip = true; |
510 if(skip) | |
511 continue; | |
512 | |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
513 // if we already set things up for this branch target, skip |
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
514 if(gotoToVal.find(a->isBranchToLabel) != gotoToVal.end()) |
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
515 continue; |
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
516 |
302 | 517 // record that the jump needs to be handled in the post-asm dispatcher |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
518 gotoToVal[a->isBranchToLabel] = n_goto; |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
519 |
302 | 520 // provide an in-asm target for the branch and set value |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
521 Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string); |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
522 code << fdmangle << '_' << a->isBranchToLabel->string << ": ; "; |
302 | 523 code << "movl $<<in" << n_goto << ">>, $<<out0>> ; "; |
524 //FIXME: Store the value -> label mapping somewhere, so it can be referenced later | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
525 outSetterStmt->in.push_back(DtoConstUint(n_goto)); |
302 | 526 outSetterStmt->in_c += "i,"; |
527 code << asmGotoEnd; | |
528 | |
529 ++n_goto; | |
530 } | |
531 if(code.str() != asmGotoEnd) | |
532 { | |
533 // finalize code | |
534 outSetterStmt->code = code.str(); | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
535 outSetterStmt->code += asmGotoEndLabel.str()+": ; "; |
302 | 536 |
537 // create storage for and initialize the temporary | |
479
672eb4893b55
Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents:
356
diff
changeset
|
538 jump_target = DtoAlloca(LLType::Int32Ty, "__llvm_jump_target"); |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
304
diff
changeset
|
539 gIR->ir->CreateStore(DtoConstUint(0), jump_target); |
302 | 540 // setup variable for output from asm |
541 outSetterStmt->out_c = "=*m,"; | |
542 outSetterStmt->out.push_back(jump_target); | |
543 | |
544 asmblock->s.push_back(outSetterStmt); | |
545 } | |
546 else | |
547 delete outSetterStmt; | |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
548 } |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
549 |
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
550 |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
551 // build asm block |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
552 std::vector<LLValue*> outargs; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
553 std::vector<LLValue*> inargs; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
554 std::vector<const LLType*> outtypes; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
555 std::vector<const LLType*> intypes; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
556 std::string out_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
557 std::string in_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
558 std::string clobbers; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
559 std::string code; |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
560 size_t asmIdx = 0; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
561 |
302 | 562 size_t n = asmblock->s.size(); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
563 for (size_t i=0; i<n; ++i) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
564 { |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
565 IRAsmStmt* a = asmblock->s[i]; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
566 assert(a); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
567 size_t onn = a->out.size(); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
568 for (size_t j=0; j<onn; ++j) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
569 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
570 outargs.push_back(a->out[j]); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
571 outtypes.push_back(a->out[j]->getType()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
572 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
573 if (!a->out_c.empty()) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
574 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
575 out_c += a->out_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
576 } |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
577 remap_outargs(a->code, onn+a->in.size(), asmIdx); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
578 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
579 for (size_t i=0; i<n; ++i) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
580 { |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
581 IRAsmStmt* a = asmblock->s[i]; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
582 assert(a); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
583 size_t inn = a->in.size(); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
584 for (size_t j=0; j<inn; ++j) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
585 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
586 inargs.push_back(a->in[j]); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
587 intypes.push_back(a->in[j]->getType()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
588 } |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
589 if (!a->in_c.empty()) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
590 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
591 in_c += a->in_c; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
592 } |
300
7b1040c76dd2
[svn r321] Fix bug in argument remapping functions.
ChristianK
parents:
299
diff
changeset
|
593 remap_inargs(a->code, inn+a->out.size(), asmIdx); |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
594 if (!code.empty()) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
595 code += " ; "; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
596 code += a->code; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
597 } |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
598 asmblock->s.clear(); |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
599 |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
600 // append inputs |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
601 out_c += in_c; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
602 |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
603 // append clobbers |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
604 typedef std::set<std::string>::iterator clobs_it; |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
605 for (clobs_it i=asmblock->clobs.begin(); i!=asmblock->clobs.end(); ++i) |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
606 { |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
607 out_c += *i; |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
608 } |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
609 |
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
610 // remove excessive comma |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
611 if (!out_c.empty()) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
612 out_c.resize(out_c.size()-1); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
613 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
614 Logger::println("code = \"%s\"", code.c_str()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
615 Logger::println("constraints = \"%s\"", out_c.c_str()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
616 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
617 std::vector<const LLType*> types; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
618 types.insert(types.end(), outtypes.begin(), outtypes.end()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
619 types.insert(types.end(), intypes.begin(), intypes.end()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
620 llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, types, false); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
621 Logger::cout() << "function type = " << *fty << '\n'; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
622 llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
623 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
624 std::vector<LLValue*> args; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
625 args.insert(args.end(), outargs.begin(), outargs.end()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
626 args.insert(args.end(), inargs.begin(), inargs.end()); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
627 llvm::CallInst* call = p->ir->CreateCall(ia, args.begin(), args.end(), ""); |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
628 |
233
76ee1bbe487e
[svn r249] Changed inline asm clobbers to a set instead of a list so we don't get duplicate clobbers.
lindquist
parents:
232
diff
changeset
|
629 p->asmBlock = NULL; |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
630 Logger::println("END ASM"); |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
631 |
302 | 632 // if asm contained external branches, emit goto forwarder code |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
633 if(!gotoToVal.empty()) |
302 | 634 { |
635 assert(jump_target); | |
636 | |
637 // make new blocks | |
638 llvm::BasicBlock* oldend = gIR->scopeend(); | |
639 llvm::BasicBlock* bb = llvm::BasicBlock::Create("afterasmgotoforwarder", p->topfunc(), oldend); | |
640 | |
641 llvm::LoadInst* val = p->ir->CreateLoad(jump_target, "__llvm_jump_target_value"); | |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
642 llvm::SwitchInst* sw = p->ir->CreateSwitch(val, bb, gotoToVal.size()); |
302 | 643 |
644 // add all cases | |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
645 std::map<Identifier*, int>::iterator it, end = gotoToVal.end(); |
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
646 for(it = gotoToVal.begin(); it != end; ++it) |
302 | 647 { |
648 llvm::BasicBlock* casebb = llvm::BasicBlock::Create("case", p->topfunc(), bb); | |
312
553f844ae5b9
[svn r333] Fix inline asm bug with multiple branches to the same label.
ChristianK
parents:
309
diff
changeset
|
649 sw->addCase(llvm::ConstantInt::get(llvm::IntegerType::get(32), it->second), casebb); |
302 | 650 |
651 p->scope() = IRScope(casebb,bb); | |
356
44daf304421c
[svn r377] The previous check was too strict, it completely disallowed gotos within finally blocks. This reenables them as long as they don't cross a finally boundary.
ChristianK
parents:
336
diff
changeset
|
652 DtoGoto(&loc, it->first, enclosinghandler, tf); |
302 | 653 } |
654 | |
655 p->scope() = IRScope(bb,oldend); | |
656 } | |
219
761c8352f494
[svn r235] rough port of GDC's inline assembler code, unfinished
ChristianK
parents:
diff
changeset
|
657 } |
232
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
658 |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
659 // the whole idea of this statement is to avoid the flattening |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
660 Statements* AsmBlockStatement::flatten(Scope* sc) |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
661 { |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
662 return NULL; |
092468448d25
[svn r248] Fixed: labels in inline asm block now work for the normal case.
lindquist
parents:
231
diff
changeset
|
663 } |
239
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
664 |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
665 Statement *AsmBlockStatement::syntaxCopy() |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
666 { |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
667 Statements *a = new Statements(); |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
668 a->setDim(statements->dim); |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
669 for (size_t i = 0; i < statements->dim; i++) |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
670 { |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
671 Statement *s = (Statement *)statements->data[i]; |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
672 if (s) |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
673 s = s->syntaxCopy(); |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
674 a->data[i] = s; |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
675 } |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
676 AsmBlockStatement *cs = new AsmBlockStatement(loc, a); |
fa691b1c0498
[svn r256] AsmBlockStatement was still being flattened in some cases.
lindquist
parents:
237
diff
changeset
|
677 return cs; |
299
df8a7b8d5929
[svn r320] Begun work on branches out of asm blocks. Unfinished.
ChristianK
parents:
239
diff
changeset
|
678 } |
302 | 679 |
680 // necessary for in-asm branches | |
681 Statement *AsmBlockStatement::semantic(Scope *sc) | |
682 { | |
309 | 683 enclosinghandler = sc->tfOfTry; |
356
44daf304421c
[svn r377] The previous check was too strict, it completely disallowed gotos within finally blocks. This reenables them as long as they don't cross a finally boundary.
ChristianK
parents:
336
diff
changeset
|
684 tf = sc->tf; |
302 | 685 |
686 return CompoundStatement::semantic(sc); | |
687 } |