Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/dvalue.cpp

Revision 1180:f5729209a1d4, 1.9 kB (checked in by Frits van Bommel <fvbommel wxs.nl>, 3 years ago)

Remove some redundancy from the DValue hierarchy: all subclasses had a 'type'
field and identical implementations of virtual function getType().
Move these to DValue itself, and make getType() non-virtual.

Line 
1 #include "gen/llvm.h"
2
3 #include "gen/tollvm.h"
4 #include "gen/irstate.h"
5 #include "gen/logger.h"
6 #include "gen/dvalue.h"
7 #include "gen/llvmhelpers.h"
8
9 #include "declaration.h"
10
11 /////////////////////////////////////////////////////////////////////////////////////////////////
12 /////////////////////////////////////////////////////////////////////////////////////////////////
13
14 DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue)
15 : DValue(t), var(vd), val(llvmValue)
16 {}
17
18 DVarValue::DVarValue(Type* t, LLValue* llvmValue)
19 : DValue(t), var(0), val(llvmValue)
20 {}
21
22 LLValue* DVarValue::getLVal()
23 {
24     assert(val);
25     return val;
26 }
27
28 LLValue* DVarValue::getRVal()
29 {
30     assert(val);
31     Type* bt = type->toBasetype();
32     if (DtoIsPassedByRef(bt))
33         return val;
34     return DtoLoad(val);
35 }
36
37 /////////////////////////////////////////////////////////////////////////////////////////////////
38 /////////////////////////////////////////////////////////////////////////////////////////////////
39
40 LLValue* DSliceValue::getRVal()
41 {
42     assert(len);
43     assert(ptr);
44     return DtoAggrPair(len, ptr);
45 }
46
47 /////////////////////////////////////////////////////////////////////////////////////////////////
48 /////////////////////////////////////////////////////////////////////////////////////////////////
49
50 DFuncValue::DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt)
51 : DValue(fd->type), func(fd), val(v), vthis(vt)
52 {}
53
54 LLValue* DFuncValue::getRVal()
55 {
56     assert(val);
57     return val;
58 }
59
60 /////////////////////////////////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////////////////////////////////
62
63 LLValue* DConstValue::getRVal()
64 {
65     assert(c);
66     return c;
67 }
68
69 /////////////////////////////////////////////////////////////////////////////////////////////////
70 /////////////////////////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.