mirror of
https://github.com/open-goal/jak-project
synced 2026-06-21 00:31:41 -04:00
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
#include <thread>
|
|
#include <chrono>
|
|
|
|
#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<IR_FunctionCall*>(x.get()), nullptr);
|
|
auto as_im = dynamic_cast<IR_IntegerMath*>(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<IR_FunctionCall*>(x.get())) {
|
|
got_call++;
|
|
}
|
|
auto as_im = dynamic_cast<IR_IntegerMath*>(x.get());
|
|
if (as_im && as_im->get_kind() == IntegerMathKind::IMUL_32) {
|
|
got_mult++;
|
|
}
|
|
}
|
|
EXPECT_EQ(got_mult, 1);
|
|
EXPECT_EQ(got_call, 1);
|
|
}
|
|
|