annotate ir/ir.cpp @ 1499:df11cdec45a2

Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324. The idea is to separate the notion of const from 'this variable can always be replaced with its initializer' in the frontend. To do that, I introduced Declaration::isSameAsInitializer, which is overridden in VarDeclaration to return false for constants that have a struct literal initializer. So {{{ const S s = S(5); void foo() { auto ps = &s; } // is no longer replaced by void foo() { auto ps = &(S(5)); } }}} To make taking the address of a struct constant with a struct-initializer outside of function scope possible, I made sure that AddrExp::optimize doesn't try to run the argument's optimization with WANTinterpret - that'd again replace the constant with a struct literal temporary.
author Christian Kamm <kamm incasoftware de>
date Sun, 14 Jun 2009 19:49:58 +0200
parents 2a687353c84d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1150
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
1 #include "llvm/Target/TargetData.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
2
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
3 #include "gen/irstate.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
4 #include "gen/tollvm.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
5 #include "gen/functions.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
6
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
7 #include "ir/ir.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
8 #include "ir/irfunction.h"
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
9
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
10
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
11 unsigned GetTypeAlignment(Ir* ir, Type* t)
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
12 {
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
13 return gTargetData->getABITypeAlignment(DtoType(t));
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
14 }
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
15
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
16 Ir::Ir()
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
17 : irs(NULL)
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
18 {
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
19 }
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
20
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
21 void Ir::addFunctionBody(IrFunction * f)
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
22 {
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
23 functionbodies.push_back(f);
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
24 }
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
25
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
26 void Ir::emitFunctionBodies()
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
27 {
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
28 while (!functionbodies.empty())
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
29 {
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
30 IrFunction* irf = functionbodies.front();
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
31 functionbodies.pop_front();
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
32 DtoDefineFunction(irf->decl);
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
33 }
2a687353c84d Added missing new files.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
34 }