Skip to content

Commit a72f067

Browse files
authored
Merge pull request #596 from scratchcpp/llvm_operators
LLVM: Implement operators
2 parents f2e0457 + 4d9f6fa commit a72f067

File tree

12 files changed

+1647
-102
lines changed

12 files changed

+1647
-102
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class LIBSCRATCHCPP_EXPORT Compiler
2929
Void,
3030
Number,
3131
Bool,
32-
String
32+
String,
33+
Unknown
3334
};
3435

3536
Compiler(IEngine *engine, Target *target);
@@ -47,6 +48,15 @@ class LIBSCRATCHCPP_EXPORT Compiler
4748
void addListContents(List *list);
4849
void addInput(const std::string &name);
4950

51+
void createAdd();
52+
void createSub();
53+
void createMul();
54+
void createDiv();
55+
56+
void createCmpEQ();
57+
void createCmpGT();
58+
void createCmpLT();
59+
5060
void moveToIf(std::shared_ptr<Block> substack);
5161
void moveToIfElse(std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
5262
void moveToRepeatLoop(std::shared_ptr<Block> substack);

src/dev/engine/compiler.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,48 @@ void Compiler::addInput(const std::string &name)
102102
addInput(impl->block->inputAt(impl->block->findInput(name)).get());
103103
}
104104

105+
/*! Creates an add instruction from the last 2 values. */
106+
void Compiler::createAdd()
107+
{
108+
impl->builder->createAdd();
109+
}
110+
111+
/*! Creates a subtract instruction from the last 2 values. */
112+
void Compiler::createSub()
113+
{
114+
impl->builder->createSub();
115+
}
116+
117+
/*! Creates a multiply instruction from the last 2 values. */
118+
void Compiler::createMul()
119+
{
120+
impl->builder->createMul();
121+
}
122+
123+
/*! Creates a divide instruction from the last 2 values. */
124+
void Compiler::createDiv()
125+
{
126+
impl->builder->createDiv();
127+
}
128+
129+
/*! Creates an equality comparison instruction using the last 2 values. */
130+
void Compiler::createCmpEQ()
131+
{
132+
impl->builder->createCmpEQ();
133+
}
134+
135+
/*! Creates a greater than comparison instruction using the last 2 values. */
136+
void Compiler::createCmpGT()
137+
{
138+
impl->builder->createCmpGT();
139+
}
140+
141+
/*! Creates a lower than comparison instruction using the last 2 values. */
142+
void Compiler::createCmpLT()
143+
{
144+
impl->builder->createCmpLT();
145+
}
146+
105147
/*! Jumps to the given if substack. */
106148
void Compiler::moveToIf(std::shared_ptr<Block> substack)
107149
{

src/dev/engine/internal/icodebuilder.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ class ICodeBuilder
2424
virtual void addVariableValue(Variable *variable) = 0;
2525
virtual void addListContents(List *list) = 0;
2626

27+
virtual void createAdd() = 0;
28+
virtual void createSub() = 0;
29+
virtual void createMul() = 0;
30+
virtual void createDiv() = 0;
31+
32+
virtual void createCmpEQ() = 0;
33+
virtual void createCmpGT() = 0;
34+
virtual void createCmpLT() = 0;
35+
36+
virtual void createAnd() = 0;
37+
virtual void createOr() = 0;
38+
virtual void createNot() = 0;
39+
2740
virtual void beginIfStatement() = 0;
2841
virtual void beginElseBranch() = 0;
2942
virtual void endIf() = 0;

0 commit comments

Comments
 (0)