Skip to content

Commit eb463c0

Browse files
committed
Compiler: Add methods for comparison operators
1 parent 379a12e commit eb463c0

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

include/scratchcpp/dev/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class LIBSCRATCHCPP_EXPORT Compiler
5353
void createMul();
5454
void createDiv();
5555

56+
void createCmpEQ();
57+
void createCmpGT();
58+
void createCmpLT();
59+
5660
void moveToIf(std::shared_ptr<Block> substack);
5761
void moveToIfElse(std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
5862
void moveToRepeatLoop(std::shared_ptr<Block> substack);

src/dev/engine/compiler.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ void Compiler::createDiv()
126126
impl->builder->createDiv();
127127
}
128128

129+
void Compiler::createCmpEQ()
130+
{
131+
impl->builder->createCmpEQ();
132+
}
133+
134+
void Compiler::createCmpGT()
135+
{
136+
impl->builder->createCmpGT();
137+
}
138+
139+
void Compiler::createCmpLT()
140+
{
141+
impl->builder->createCmpLT();
142+
}
143+
129144
/*! Jumps to the given if substack. */
130145
void Compiler::moveToIf(std::shared_ptr<Block> substack)
131146
{

test/dev/compiler/compiler_test.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,45 @@ TEST_F(CompilerTest, CreateDiv)
271271
compile(compiler, block);
272272
}
273273

274+
TEST_F(CompilerTest, CreateCmpEQ)
275+
{
276+
Compiler compiler(&m_engine, &m_target);
277+
auto block = std::make_shared<Block>("", "");
278+
279+
block->setCompileFunction([](Compiler *compiler) {
280+
EXPECT_CALL(*m_builder, createCmpEQ);
281+
compiler->createCmpEQ();
282+
});
283+
284+
compile(compiler, block);
285+
}
286+
287+
TEST_F(CompilerTest, CreateCmpGT)
288+
{
289+
Compiler compiler(&m_engine, &m_target);
290+
auto block = std::make_shared<Block>("", "");
291+
292+
block->setCompileFunction([](Compiler *compiler) {
293+
EXPECT_CALL(*m_builder, createCmpGT);
294+
compiler->createCmpGT();
295+
});
296+
297+
compile(compiler, block);
298+
}
299+
300+
TEST_F(CompilerTest, CreateCmpLT)
301+
{
302+
Compiler compiler(&m_engine, &m_target);
303+
auto block = std::make_shared<Block>("", "");
304+
305+
block->setCompileFunction([](Compiler *compiler) {
306+
EXPECT_CALL(*m_builder, createCmpLT);
307+
compiler->createCmpLT();
308+
});
309+
310+
compile(compiler, block);
311+
}
312+
274313
TEST_F(CompilerTest, MoveToIf)
275314
{
276315
Compiler compiler(&m_engine, &m_target);

0 commit comments

Comments
 (0)