Skip to content

Commit a2bff34

Browse files
committed
Add initial C++ transpiler classes
1 parent 26063a9 commit a2bff34

14 files changed

Lines changed: 690 additions & 2 deletions

‎src/engine/internal/codegen/codebuilderfactory.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "llvm/llvmcodebuilder.h"
77
#include "llvm/llvmcompilercontext.h"
88
#elif defined(CODEGEN_BACKEND_CPP)
9+
#include "cpp/cppcodebuilder.h"
10+
#include "cpp/cppcompilercontext.h"
911
#endif
1012

1113
using namespace libscratchcpp;
@@ -23,7 +25,8 @@ std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(CompilerContext *ctx, B
2325
assert(dynamic_cast<LLVMCompilerContext *>(ctx));
2426
return std::make_shared<LLVMCodeBuilder>(static_cast<LLVMCompilerContext *>(ctx), procedurePrototype, codeType);
2527
#elif defined(CODEGEN_BACKEND_CPP)
26-
return nullptr;
28+
assert(dynamic_cast<CppCompilerContext *>(ctx));
29+
return std::make_shared<CppCodeBuilder>(static_cast<CppCompilerContext *>(ctx), procedurePrototype, codeType);
2730
#endif
2831
}
2932

@@ -33,6 +36,7 @@ std::shared_ptr<CompilerContext> CodeBuilderFactory::createCtx(IEngine *engine,
3336
auto ptr = std::make_shared<LLVMCompilerContext>(engine, target, unsafeConstants);
3437
return ptr;
3538
#elif defined(CODEGEN_BACKEND_CPP)
36-
return nullptr;
39+
auto ptr = std::make_shared<CppCompilerContext>(engine, target, unsafeConstants);
40+
return ptr;
3741
#endif
3842
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
target_sources(scratchcpp
22
PRIVATE
3+
cppcompilercontext.cpp
4+
cppcompilercontext.h
5+
cppexecutablecode.cpp
6+
cppexecutablecode.h
7+
cppexecutioncontext.cpp
8+
cppexecutioncontext.h
9+
cppinstruction.h
10+
cppinstructionlist.h
11+
cppvalue.h
12+
cppconstant.h
13+
cppcodebuilder.cpp
14+
cppcodebuilder.h
315
)
Lines changed: 336 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,336 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "cppcodebuilder.h"
4+
5+
using namespace libscratchcpp;
6+
7+
CppCodeBuilder::CppCodeBuilder(CppCompilerContext *ctx, BlockPrototype *procedurePrototype, Compiler::CodeType codeType) :
8+
m_ctx(ctx),
9+
m_procedurePrototype(procedurePrototype),
10+
m_codeType(codeType)
11+
{
12+
}
13+
14+
std::shared_ptr<ExecutableCode> CppCodeBuilder::build()
15+
{
16+
return nullptr;
17+
}
18+
19+
CompilerValue *CppCodeBuilder::addFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
20+
{
21+
return nullptr;
22+
}
23+
24+
CompilerValue *CppCodeBuilder::addTargetFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
25+
{
26+
return nullptr;
27+
}
28+
29+
CompilerValue *CppCodeBuilder::addFunctionCallWithCtx(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
30+
{
31+
return nullptr;
32+
}
33+
34+
CompilerConstant *CppCodeBuilder::addConstValue(const Value &value)
35+
{
36+
return nullptr;
37+
}
38+
39+
CompilerValue *CppCodeBuilder::addStringChar(CompilerValue *string, CompilerValue *index)
40+
{
41+
return nullptr;
42+
}
43+
44+
CompilerValue *CppCodeBuilder::addStringLength(CompilerValue *string)
45+
{
46+
return nullptr;
47+
}
48+
49+
CompilerValue *CppCodeBuilder::addLoopIndex()
50+
{
51+
return nullptr;
52+
}
53+
54+
CompilerValue *CppCodeBuilder::addLocalVariableValue(CompilerLocalVariable *variable)
55+
{
56+
return nullptr;
57+
}
58+
59+
CompilerValue *CppCodeBuilder::addVariableValue(Variable *variable)
60+
{
61+
return nullptr;
62+
}
63+
64+
CompilerValue *CppCodeBuilder::addListContents(List *list)
65+
{
66+
return nullptr;
67+
}
68+
69+
CompilerValue *CppCodeBuilder::addListItem(List *list, CompilerValue *index)
70+
{
71+
return nullptr;
72+
}
73+
74+
CompilerValue *CppCodeBuilder::addListItemIndex(List *list, CompilerValue *item)
75+
{
76+
return nullptr;
77+
}
78+
79+
CompilerValue *CppCodeBuilder::addListContains(List *list, CompilerValue *item)
80+
{
81+
return nullptr;
82+
}
83+
84+
CompilerValue *CppCodeBuilder::addListSize(List *list)
85+
{
86+
return nullptr;
87+
}
88+
89+
CompilerValue *CppCodeBuilder::addProcedureArgument(const std::string &name)
90+
{
91+
return nullptr;
92+
}
93+
94+
CompilerValue *CppCodeBuilder::createAdd(CompilerValue *operand1, CompilerValue *operand2)
95+
{
96+
return nullptr;
97+
}
98+
99+
CompilerValue *CppCodeBuilder::createSub(CompilerValue *operand1, CompilerValue *operand2)
100+
{
101+
return nullptr;
102+
}
103+
104+
CompilerValue *CppCodeBuilder::createMul(CompilerValue *operand1, CompilerValue *operand2)
105+
{
106+
return nullptr;
107+
}
108+
109+
CompilerValue *CppCodeBuilder::createDiv(CompilerValue *operand1, CompilerValue *operand2)
110+
{
111+
return nullptr;
112+
}
113+
114+
CompilerValue *CppCodeBuilder::createRandom(CompilerValue *from, CompilerValue *to)
115+
{
116+
return nullptr;
117+
}
118+
119+
CompilerValue *CppCodeBuilder::createRandomInt(CompilerValue *from, CompilerValue *to)
120+
{
121+
return nullptr;
122+
}
123+
124+
CompilerValue *CppCodeBuilder::createCmpEQ(CompilerValue *operand1, CompilerValue *operand2)
125+
{
126+
return nullptr;
127+
}
128+
129+
CompilerValue *CppCodeBuilder::createCmpGT(CompilerValue *operand1, CompilerValue *operand2)
130+
{
131+
return nullptr;
132+
}
133+
134+
CompilerValue *CppCodeBuilder::createCmpLT(CompilerValue *operand1, CompilerValue *operand2)
135+
{
136+
return nullptr;
137+
}
138+
139+
CompilerValue *CppCodeBuilder::createStrCmpEQ(CompilerValue *string1, CompilerValue *string2, bool caseSensitive)
140+
{
141+
return nullptr;
142+
}
143+
144+
CompilerValue *CppCodeBuilder::createAnd(CompilerValue *operand1, CompilerValue *operand2)
145+
{
146+
return nullptr;
147+
}
148+
149+
CompilerValue *CppCodeBuilder::createOr(CompilerValue *operand1, CompilerValue *operand2)
150+
{
151+
return nullptr;
152+
}
153+
154+
CompilerValue *CppCodeBuilder::createNot(CompilerValue *operand)
155+
{
156+
return nullptr;
157+
}
158+
159+
CompilerValue *CppCodeBuilder::createMod(CompilerValue *num1, CompilerValue *num2)
160+
{
161+
return nullptr;
162+
}
163+
164+
CompilerValue *CppCodeBuilder::createRound(CompilerValue *num)
165+
{
166+
return nullptr;
167+
}
168+
169+
CompilerValue *CppCodeBuilder::createAbs(CompilerValue *num)
170+
{
171+
return nullptr;
172+
}
173+
174+
CompilerValue *CppCodeBuilder::createFloor(CompilerValue *num)
175+
{
176+
return nullptr;
177+
}
178+
179+
CompilerValue *CppCodeBuilder::createCeil(CompilerValue *num)
180+
{
181+
return nullptr;
182+
}
183+
184+
CompilerValue *CppCodeBuilder::createSqrt(CompilerValue *num)
185+
{
186+
return nullptr;
187+
}
188+
189+
CompilerValue *CppCodeBuilder::createSin(CompilerValue *num)
190+
{
191+
return nullptr;
192+
}
193+
194+
CompilerValue *CppCodeBuilder::createCos(CompilerValue *num)
195+
{
196+
return nullptr;
197+
}
198+
199+
CompilerValue *CppCodeBuilder::createTan(CompilerValue *num)
200+
{
201+
return nullptr;
202+
}
203+
204+
CompilerValue *CppCodeBuilder::createAsin(CompilerValue *num)
205+
{
206+
return nullptr;
207+
}
208+
209+
CompilerValue *CppCodeBuilder::createAcos(CompilerValue *num)
210+
{
211+
return nullptr;
212+
}
213+
214+
CompilerValue *CppCodeBuilder::createAtan(CompilerValue *num)
215+
{
216+
return nullptr;
217+
}
218+
219+
CompilerValue *CppCodeBuilder::createLn(CompilerValue *num)
220+
{
221+
return nullptr;
222+
}
223+
224+
CompilerValue *CppCodeBuilder::createLog10(CompilerValue *num)
225+
{
226+
return nullptr;
227+
}
228+
229+
CompilerValue *CppCodeBuilder::createExp(CompilerValue *num)
230+
{
231+
return nullptr;
232+
}
233+
234+
CompilerValue *CppCodeBuilder::createExp10(CompilerValue *num)
235+
{
236+
return nullptr;
237+
}
238+
239+
CompilerValue *CppCodeBuilder::createStringConcat(CompilerValue *string1, CompilerValue *string2)
240+
{
241+
return nullptr;
242+
}
243+
244+
CompilerValue *CppCodeBuilder::createSelect(CompilerValue *cond, CompilerValue *trueValue, CompilerValue *falseValue, Compiler::StaticType valueType)
245+
{
246+
return nullptr;
247+
}
248+
249+
CompilerLocalVariable *CppCodeBuilder::createLocalVariable(Compiler::StaticType type)
250+
{
251+
return nullptr;
252+
}
253+
254+
void CppCodeBuilder::createLocalVariableWrite(CompilerLocalVariable *variable, CompilerValue *value)
255+
{
256+
}
257+
258+
void CppCodeBuilder::createVariableWrite(Variable *variable, CompilerValue *value)
259+
{
260+
}
261+
262+
void CppCodeBuilder::createListClear(List *list)
263+
{
264+
}
265+
266+
void CppCodeBuilder::createListRemove(List *list, CompilerValue *index)
267+
{
268+
}
269+
270+
void CppCodeBuilder::createListAppend(List *list, CompilerValue *item)
271+
{
272+
}
273+
274+
void CppCodeBuilder::createListInsert(List *list, CompilerValue *index, CompilerValue *item)
275+
{
276+
}
277+
278+
void CppCodeBuilder::createListReplace(List *list, CompilerValue *index, CompilerValue *item)
279+
{
280+
}
281+
282+
void CppCodeBuilder::beginIfStatement(CompilerValue *cond)
283+
{
284+
}
285+
286+
void CppCodeBuilder::beginElseBranch()
287+
{
288+
}
289+
290+
void CppCodeBuilder::endIf()
291+
{
292+
}
293+
294+
void CppCodeBuilder::beginRepeatLoop(CompilerValue *count)
295+
{
296+
}
297+
298+
void CppCodeBuilder::beginWhileLoop(CompilerValue *cond)
299+
{
300+
}
301+
302+
void CppCodeBuilder::beginRepeatUntilLoop(CompilerValue *cond)
303+
{
304+
}
305+
306+
void CppCodeBuilder::beginLoopCondition()
307+
{
308+
}
309+
310+
void CppCodeBuilder::endLoop()
311+
{
312+
}
313+
314+
void CppCodeBuilder::yield()
315+
{
316+
}
317+
318+
void CppCodeBuilder::createStop()
319+
{
320+
}
321+
322+
void CppCodeBuilder::createThreadStop()
323+
{
324+
}
325+
326+
void CppCodeBuilder::invalidateTarget()
327+
{
328+
}
329+
330+
void CppCodeBuilder::createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args)
331+
{
332+
}
333+
334+
void CppCodeBuilder::createPrint(CompilerValue *string)
335+
{
336+
}

0 commit comments

Comments
 (0)