#include #include #include "gtest/gtest.h" #include "game/runtime.h" #include "goalc/listener/Listener.h" #include "goalc/compiler/Compiler.h" TEST(CompilerAndRuntime, ConstructCompiler) { Compiler compiler; } // TODO -move these into another file? TEST(CompilerAndRuntime, InlineIsInline) { Compiler compiler; auto code = compiler.get_goos().reader.read_from_file({"goal_src", "test", "test-declare-inline.gc"}); auto compiled = compiler.compile_object_file("test-code", code, true); EXPECT_EQ(compiled->functions().size(), 2); auto& ir = compiled->top_level_function().code(); bool got_mult = false; for (auto& x : ir) { EXPECT_EQ(dynamic_cast(x.get()), nullptr); auto as_im = dynamic_cast(x.get()); if (as_im) { EXPECT_EQ(as_im->get_kind(), IntegerMathKind::IMUL_32); got_mult = true; } } EXPECT_TRUE(got_mult); } TEST(CompilerAndRuntime, AllowInline) { Compiler compiler; auto code = compiler.get_goos().reader.read_from_file({"goal_src", "test", "test-inline-call.gc"}); auto compiled = compiler.compile_object_file("test-code", code, true); EXPECT_EQ(compiled->functions().size(), 2); auto& ir = compiled->top_level_function().code(); int got_mult = 0; int got_call = 0; for (auto& x : ir) { if (dynamic_cast(x.get())) { got_call++; } auto as_im = dynamic_cast(x.get()); if (as_im && as_im->get_kind() == IntegerMathKind::IMUL_32) { got_mult++; } } EXPECT_EQ(got_mult, 1); EXPECT_EQ(got_call, 1); }