-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathEduCfrontTest5.expect
More file actions
147 lines (117 loc) · 2.92 KB
/
EduCfrontTest5.expect
File metadata and controls
147 lines (117 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*************************************************************************************
* NOTE: This an educational hand-rolled transformation. Things can be incorrect or *
* buggy. *
*************************************************************************************/
void __cxa_start(void);
void __cxa_atexit(void);
typedef int (*__vptp)();
struct __mptr
{
short d;
short i;
__vptp f;
};
extern struct __mptr* __vtbl_array[];
typedef struct WithDefaultCtor
{
char __dummy;
} WithDefaultCtor;
inline WithDefaultCtor * Constructor_WithDefaultCtor(WithDefaultCtor * __this)
{
return __this;
}
typedef struct Type
{
char __dummy;
} Type;
inline Type * Constructor_Type(Type * __this, int)
{
return __this;
}
inline void Destructor_Type(Type * __this)
{
}
typedef struct Base
{
__mptr * __vptrBase;
Type mY;
} Base;
inline void Destructor_Base(Base * __this)
{
__this->__vptrBase = __vtbl_array[0];
}
inline Base * Constructor_Base(Base * __this)
{
__this->__vptrBase = __vtbl_array[0];
Constructor_Type(&__this->mY, 5);
return __this;
}
typedef struct BaseSecond
{
__mptr * __vptrBaseSecond;
Type mX;
} BaseSecond;
inline void Destructor_BaseSecond(BaseSecond * __this)
{
__this->__vptrBaseSecond = __vtbl_array[1];
}
inline BaseSecond * Constructor_BaseSecond(BaseSecond * __this)
{
__this->__vptrBaseSecond = __vtbl_array[1];
Constructor_Type(&__this->mX, 5);
return __this;
}
typedef struct Derived
{
__mptr * __vptrBase;
Type mY;
__mptr * __vptrBaseSecond;
Type mX;
double mD;
WithDefaultCtor mWd;
} Derived;
inline void Destructor_Derived(Derived * __this)
{
__this->mD = 7;
Destructor_BaseSecond((BaseSecond *)__this);
Destructor_Base((Base *)__this);
}
inline Derived * Constructor_Derived(Derived * __this)
{
Constructor_Base((Base *)__this);
Constructor_BaseSecond((BaseSecond *)__this);
__this->__vptrBase = __vtbl_array[2];
__this->__vptrBaseSecond = __vtbl_array[3];
Constructor_WithDefaultCtor(&__this->mWd);
return __this;
}
Derived d;
int __main(int argc, const char ** argv)
{
int x = 7;
++x;
return 0;
/* x // lifetime ends here */
}
int main(int argc, const char ** argv)
{
__cxa_start();
int ret = __main(argc, argv);
__cxa_atexit();
return ret;
/* ret // lifetime ends here */
(*((void (*)(Derived *))((&d)->__vptrBase[0]).f))((((Derived *)(char *)(&d)) + ((&d)->__vptrBase[0]).d));
}
__mptr __vtbl_Base[1] = {0, 0, (__vptp)Destructor_Base};
__mptr __vtbl_BaseSecond[1] = {0, 0, (__vptp)Destructor_BaseSecond};
__mptr __vtbl_DerivedBase[1] = {0, 0, (__vptp)Destructor_Derived};
__mptr __vtbl_DerivedBaseSecond[1] = {-16, 0, (__vptp)Destructor_Derived};
__mptr * __vtbl_array[4] = {__vtbl_Base, __vtbl_BaseSecond, __vtbl_DerivedBase, __vtbl_DerivedBaseSecond};
void __cxa_start(void)
{
Constructor_Derived(&d);
}
void __cxa_atexit(void)
{
Destructor_Derived(&d);
}