Skip to content

Commit 17a8f87

Browse files
committed
Remove old compiler from LLVM builds
1 parent b68c38b commit 17a8f87

File tree

16 files changed

+92
-6
lines changed

16 files changed

+92
-6
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ target_sources(scratchcpp
4646
include/scratchcpp/field.h
4747
include/scratchcpp/script.h
4848
include/scratchcpp/broadcast.h
49-
include/scratchcpp/compiler.h
5049
include/scratchcpp/virtualmachine.h
5150
include/scratchcpp/blockprototype.h
5251
include/scratchcpp/block.h
@@ -68,6 +67,11 @@ target_sources(scratchcpp
6867

6968
if (LIBSCRATCHCPP_USE_LLVM)
7069
target_compile_definitions(scratchcpp PUBLIC USE_LLVM)
70+
else()
71+
target_sources(scratchcpp
72+
PUBLIC
73+
include/scratchcpp/compiler.h
74+
)
7175
endif()
7276

7377
include(FetchContent)

include/scratchcpp/block.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
2525
Block(const std::string &id, const std::string &opcode);
2626
Block(const Block &) = delete;
2727

28+
#ifndef USE_LLVM
2829
void compile(Compiler *compiler);
30+
#endif
2931

3032
const std::string &opcode() const;
3133

@@ -73,11 +75,13 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
7375
void setTarget(Target *newTarget);
7476
Target *target() const;
7577

78+
#ifndef USE_LLVM
7679
BlockComp compileFunction() const;
7780
void setCompileFunction(BlockComp newCompileFunction);
7881

7982
BlockComp hatPredicateCompileFunction() const;
8083
void setHatPredicateCompileFunction(HatPredicateCompileFunc newHatPredicateCompileFunction);
84+
#endif // USE_LLVM
8185

8286
bool mutationHasNext() const;
8387
void setMutationHasNext(bool newMutationHasNext);

include/scratchcpp/global.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ namespace libscratchcpp
2424
{
2525

2626
class VirtualMachine;
27+
#ifndef USE_LLVM
2728
class Compiler;
29+
#endif
2830
class Block;
2931
class Value;
3032

@@ -35,12 +37,14 @@ class Value;
3537
*/
3638
using BlockFunc = unsigned int (*)(VirtualMachine *vm);
3739

40+
#ifndef USE_LLVM
3841
/*!
3942
* \typedef BlockComp
4043
*
4144
* BlockComp is a function pointer for functions which are used to compile blocks to bytecode.
4245
*/
4346
using BlockComp = void (*)(Compiler *);
47+
#endif // USE_LLVM
4448

4549
/*!
4650
* \typedef MonitorNameFunc
@@ -56,12 +60,14 @@ using MonitorNameFunc = const std::string &(*)(Block *);
5660
*/
5761
using MonitorChangeFunc = void (*)(Block *, const Value &newValue);
5862

63+
#ifndef USE_LLVM
5964
/*!
6065
* \typedef HatPredicateCompileFunc
6166
*
6267
* HatPredicateCompileFunc is a function pointer for functions which are used to compile edge-activated hat predicates to bytecode.
6368
*/
6469
using HatPredicateCompileFunc = void (*)(Compiler *vm);
70+
#endif // USE_LLVM
6571

6672
} // namespace libscratchcpp
6773

include/scratchcpp/iengine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class LIBSCRATCHCPP_EXPORT IEngine
225225
/*! Returns the list of block functions. */
226226
virtual const std::vector<BlockFunc> &blockFunctions() const = 0;
227227

228+
#ifndef USE_LLVM
228229
/*!
229230
* Call this from IExtension#registerBlocks() to add a compile function to a block section.
230231
* \see <a href="extensions.html">Extensions</a>
@@ -237,6 +238,7 @@ class LIBSCRATCHCPP_EXPORT IEngine
237238
* \see <a href="extensions.html">Extensions</a>
238239
*/
239240
virtual void addHatPredicateCompileFunction(IExtension *extension, const std::string &opcode, HatPredicateCompileFunc f) = 0;
241+
#endif // USE_LLVM
240242

241243
/*!
242244
* Call this from IExtension#registerBlocks() to add a monitor name function to a block section.
@@ -356,11 +358,13 @@ class LIBSCRATCHCPP_EXPORT IEngine
356358
/*! Sets the list of monitors. */
357359
virtual void setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors) = 0;
358360

361+
#ifndef USE_LLVM
359362
/*! Creates a monitor for the given variable if it's missing and returns it. */
360363
virtual Monitor *createVariableMonitor(std::shared_ptr<Variable> var, const std::string &opcode, const std::string &varFieldName, int varFieldId, BlockComp compileFunction) = 0;
361364

362365
/*! Creates a monitor for the given list if it's missing and returns it. */
363366
virtual Monitor *createListMonitor(std::shared_ptr<List> list, const std::string &opcode, const std::string &listFieldName, int listFieldId, BlockComp compileFunction) = 0;
367+
#endif // USE_LLVM
364368

365369
/*! Emits when a monitor is added. */
366370
virtual sigslot::signal<Monitor *> &monitorAdded() = 0;

include/scratchcpp/inputvalue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace libscratchcpp
1111
{
1212

1313
class Block;
14+
#ifndef USE_LLVM
1415
class Compiler;
16+
#endif
1517
class Entity;
1618
class InputValuePrivate;
1719

@@ -35,7 +37,9 @@ class LIBSCRATCHCPP_EXPORT InputValue
3537

3638
InputValue(Type type = Type::Number);
3739

40+
#ifndef USE_LLVM
3841
void compile(Compiler *compiler);
42+
#endif
3943

4044
Type type() const;
4145
void setType(Type newType);

src/engine/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ target_sources(scratchcpp
33
virtualmachine.cpp
44
virtualmachine_p.cpp
55
virtualmachine_p.h
6-
compiler.cpp
7-
compiler_p.cpp
8-
compiler_p.h
96
script.cpp
107
script_p.cpp
118
script_p.h
@@ -23,3 +20,12 @@ target_sources(scratchcpp
2320
internal/randomgenerator.cpp
2421
internal/irandomgenerator.h
2522
)
23+
24+
if(NOT LIBSCRATCHCPP_USE_LLVM)
25+
target_sources(scratchcpp
26+
PRIVATE
27+
compiler.cpp
28+
compiler_p.cpp
29+
compiler_p.h
30+
)
31+
endif()

src/engine/internal/engine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include <scratchcpp/stage.h>
88
#include <scratchcpp/textbubble.h>
99
#include <scratchcpp/broadcast.h>
10+
#ifndef USE_LLVM
1011
#include <scratchcpp/compiler.h>
12+
#endif
1113
#include <scratchcpp/input.h>
1214
#include <scratchcpp/inputvalue.h>
1315
#include <scratchcpp/field.h>
@@ -105,6 +107,7 @@ void Engine::clear()
105107
// Resolves ID references and sets pointers of entities.
106108
void Engine::resolveIds()
107109
{
110+
#ifndef USE_LLVM
108111
for (auto target : m_targets) {
109112
std::cout << "Processing target " << target->name() << "..." << std::endl;
110113
const auto &blocks = target->blocks();
@@ -256,10 +259,12 @@ void Engine::resolveIds()
256259
block->updateInputMap();
257260
block->updateFieldMap();
258261
}
262+
#endif // USE_LLVM
259263
}
260264

261265
void Engine::compile()
262266
{
267+
#ifndef USE_LLVM
263268
// Resolve entities by ID
264269
resolveIds();
265270

@@ -317,6 +322,7 @@ void Engine::compile()
317322

318323
for (auto monitor : m_monitors)
319324
compileMonitor(monitor);
325+
#endif // USE_LLVM
320326
}
321327

322328
void Engine::start()
@@ -945,6 +951,7 @@ const std::vector<BlockFunc> &Engine::blockFunctions() const
945951
return m_functions;
946952
}
947953

954+
#ifndef USE_LLVM
948955
void Engine::addCompileFunction(IExtension *extension, const std::string &opcode, BlockComp f)
949956
{
950957
if (m_compileFunctions.find(extension) == m_compileFunctions.cend())
@@ -960,6 +967,7 @@ void Engine::addHatPredicateCompileFunction(IExtension *extension, const std::st
960967

961968
m_hatPredicateCompileFunctions[extension][opcode] = f;
962969
}
970+
#endif // USE_LLVM
963971

964972
void Engine::addMonitorNameFunction(IExtension *extension, const std::string &opcode, MonitorNameFunc f)
965973
{
@@ -979,10 +987,12 @@ void Engine::addMonitorChangeFunction(IExtension *extension, const std::string &
979987

980988
void Engine::addHatBlock(IExtension *extension, const std::string &opcode)
981989
{
990+
#ifndef USE_LLVM
982991
if (m_compileFunctions.find(extension) == m_compileFunctions.cend())
983992
m_compileFunctions[extension] = {};
984993

985994
m_compileFunctions[extension][opcode] = [](Compiler *compiler) {};
995+
#endif
986996
}
987997

988998
void Engine::addInput(IExtension *extension, const std::string &name, int id)
@@ -1362,6 +1372,7 @@ void Engine::setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitor
13621372
}
13631373
}
13641374

1375+
#ifndef USE_LLVM
13651376
Monitor *Engine::createVariableMonitor(std::shared_ptr<Variable> var, const std::string &opcode, const std::string &varFieldName, int varFieldId, BlockComp compileFunction)
13661377
{
13671378
if (var->monitor())
@@ -1398,6 +1409,7 @@ Monitor *Engine::createListMonitor(std::shared_ptr<List> list, const std::string
13981409
return monitor.get();
13991410
}
14001411
}
1412+
#endif // USE_LLVM
14011413

14021414
sigslot::signal<Monitor *> &Engine::monitorAdded()
14031415
{
@@ -1722,8 +1734,10 @@ const std::unordered_set<std::string> &Engine::unsupportedBlocks() const
17221734

17231735
void Engine::clearExtensionData()
17241736
{
1737+
#ifndef USE_LLVM
17251738
m_compileFunctions.clear();
17261739
m_hatPredicateCompileFunctions.clear();
1740+
#endif
17271741
m_monitorNameFunctions.clear();
17281742
m_monitorChangeFunctions.clear();
17291743
m_inputs.clear();
@@ -1733,16 +1747,19 @@ void Engine::clearExtensionData()
17331747

17341748
IExtension *Engine::blockExtension(const std::string &opcode) const
17351749
{
1750+
#ifndef USE_LLVM
17361751
for (const auto &[ext, data] : m_compileFunctions) {
17371752
auto it = data.find(opcode);
17381753

17391754
if (it != data.cend())
17401755
return ext;
17411756
}
1757+
#endif // USE_LLVM
17421758

17431759
return nullptr;
17441760
}
17451761

1762+
#ifndef USE_LLVM
17461763
BlockComp Engine::resolveBlockCompileFunc(IExtension *extension, const std::string &opcode) const
17471764
{
17481765
if (!extension)
@@ -1776,6 +1793,7 @@ HatPredicateCompileFunc Engine::resolveHatPredicateCompileFunc(IExtension *exten
17761793

17771794
return nullptr;
17781795
}
1796+
#endif // USE_LLVM
17791797

17801798
MonitorNameFunc Engine::resolveMonitorNameFunc(IExtension *extension, const std::string &opcode) const
17811799
{
@@ -1864,6 +1882,7 @@ int Engine::resolveFieldValue(IExtension *extension, const std::string &value) c
18641882

18651883
void Engine::compileMonitor(std::shared_ptr<Monitor> monitor)
18661884
{
1885+
#ifndef USE_LLVM
18671886
Target *target = monitor->sprite() ? static_cast<Target *>(monitor->sprite()) : stage();
18681887
Compiler compiler(this, target);
18691888
auto block = monitor->block();
@@ -1909,6 +1928,7 @@ void Engine::compileMonitor(std::shared_ptr<Monitor> monitor)
19091928

19101929
for (const std::string &opcode : unsupportedBlocks)
19111930
m_unsupportedBlocks.insert(opcode);
1931+
#endif // USE_LLVM
19121932
}
19131933

19141934
void Engine::finalize()

src/engine/internal/engine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ class Engine : public IEngine
105105
unsigned int functionIndex(BlockFunc f) override;
106106
const std::vector<BlockFunc> &blockFunctions() const override;
107107

108+
#ifndef USE_LLVM
108109
void addCompileFunction(IExtension *extension, const std::string &opcode, BlockComp f) override;
109110
void addHatPredicateCompileFunction(IExtension *extension, const std::string &opcode, HatPredicateCompileFunc f) override;
111+
#endif
110112
void addMonitorNameFunction(IExtension *extension, const std::string &opcode, MonitorNameFunc f) override;
111113
void addMonitorChangeFunction(IExtension *extension, const std::string &opcode, MonitorChangeFunc f) override;
112114
void addHatBlock(IExtension *extension, const std::string &opcode) override;
@@ -145,8 +147,10 @@ class Engine : public IEngine
145147

146148
const std::vector<std::shared_ptr<Monitor>> &monitors() const override;
147149
void setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors) override;
150+
#ifndef USE_LLVM
148151
Monitor *createVariableMonitor(std::shared_ptr<Variable> var, const std::string &opcode, const std::string &varFieldName, int varFieldId, BlockComp compileFunction) override;
149152
Monitor *createListMonitor(std::shared_ptr<List> list, const std::string &opcode, const std::string &listFieldName, int listFieldId, BlockComp compileFunction) override;
153+
#endif
150154
sigslot::signal<Monitor *> &monitorAdded() override;
151155
sigslot::signal<Monitor *, IMonitorHandler *> &monitorRemoved() override;
152156

@@ -190,8 +194,10 @@ class Engine : public IEngine
190194

191195
void clearExtensionData();
192196
IExtension *blockExtension(const std::string &opcode) const;
197+
#ifndef USE_LLVM
193198
BlockComp resolveBlockCompileFunc(IExtension *extension, const std::string &opcode) const;
194199
HatPredicateCompileFunc resolveHatPredicateCompileFunc(IExtension *extension, const std::string &opcode) const;
200+
#endif
195201
MonitorNameFunc resolveMonitorNameFunc(IExtension *extension, const std::string &opcode) const;
196202
MonitorChangeFunc resolveMonitorChangeFunc(IExtension *extension, const std::string &opcode) const;
197203
int resolveInput(IExtension *extension, const std::string &name) const;
@@ -253,8 +259,10 @@ class Engine : public IEngine
253259
std::recursive_mutex m_eventLoopMutex;
254260
std::string m_userAgent;
255261

262+
#ifndef USE_LLVM
256263
std::unordered_map<IExtension *, std::unordered_map<std::string, BlockComp>> m_compileFunctions;
257264
std::unordered_map<IExtension *, std::unordered_map<std::string, HatPredicateCompileFunc>> m_hatPredicateCompileFunctions;
265+
#endif
258266
std::unordered_map<IExtension *, std::unordered_map<std::string, MonitorNameFunc>> m_monitorNameFunctions;
259267
std::unordered_map<IExtension *, std::unordered_map<std::string, MonitorChangeFunc>> m_monitorChangeFunctions;
260268
std::unordered_map<IExtension *, std::unordered_map<std::string, int>> m_inputs;

src/scratch/block.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ Block::Block(const std::string &id, const std::string &opcode) :
1717
{
1818
}
1919

20+
#ifndef USE_LLVM
2021
/*! Calls the compile function. */
2122
void Block::compile(Compiler *compiler)
2223
{
2324
if (impl->compileFunction)
2425
return impl->compileFunction(compiler);
2526
}
27+
#endif // USE_LLVM
2628

2729
/*! Returns the opcode. */
2830
const std::string &Block::opcode() const
2931
{
3032
return impl->opcode;
3133
}
3234

35+
#ifndef USE_LLVM
3336
/*! Returns the compile function. \see <a href="blockSections.html">Block sections</a> */
3437
BlockComp Block::compileFunction() const
3538
{
@@ -59,6 +62,7 @@ void Block::setHatPredicateCompileFunction(HatPredicateCompileFunc newHatPredica
5962

6063
impl->hatPredicateCompileFunction = newHatPredicateCompileFunction;
6164
}
65+
#endif // USE_LLVM
6266

6367
/*! Returns true if the block can have a block following it. */
6468
bool Block::mutationHasNext() const

src/scratch/block_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ struct BlockPrivate
2222
BlockPrivate(const BlockPrivate &) = delete;
2323

2424
std::string opcode;
25+
#ifndef USE_LLVM
2526
BlockComp compileFunction = nullptr;
2627
HatPredicateCompileFunc hatPredicateCompileFunction = nullptr;
28+
#endif
2729
std::shared_ptr<Block> next = nullptr;
2830
std::string nextId;
2931
std::shared_ptr<Block> parent = nullptr;

0 commit comments

Comments
 (0)