-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLLVMGenerator_tests.cpp
More file actions
64 lines (53 loc) · 1.63 KB
/
Copy pathLLVMGenerator_tests.cpp
File metadata and controls
64 lines (53 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "core.hpp"
#include "gtest/gtest.h"
import py.lexer;
import py.runtime;
import py.ast;
// After the import: these name module-owned types.
#include "LLVMGenerator.hpp"
#include "LLVMProgram.hpp"
namespace {
std::shared_ptr<Program> generate_llvm_module(std::string_view program)
{
auto lexer = Lexer::create(std::string(program), "_llvm_backend_tests_.py");
parser::Parser p{ lexer };
ASSERT(p.parse().is_ok());
auto module = as<ast::Module>(p.module());
ASSERT(module);
return codegen::LLVMGenerator::compile(module, {}, compiler::OptimizationLevel::None);
}
}// namespace
TEST(LLVMBackend, CompilesTypeAnnotatedFunction)
{
constexpr std::string_view program =
"def add(a: int, b: int) -> int:\n"
" result = a + b\n"
" return result\n";
auto llvm_module = generate_llvm_module(program);
ASSERT_TRUE(llvm_module);
}
// TEST(LLVMBackend, CompilesTypeAnnotatedFunction)
// {
// constexpr std::string_view program =
// "def add(a: int, b: int) -> int:\n"
// " result = a + b\n"
// " return result\n"
// "print(add(1, 2))\n";
// auto llvm_module = generate_llvm_module(program);
// ASSERT_TRUE(llvm_module);
// const auto &func =
// std::static_pointer_cast<codegen::LLVMFunction>(llvm_module->as_pyfunction("add"));
// const auto &llvm_func = func->impl();
// }
// TEST(LLVMBackend, CompilesTypeAnnotatedFibonacci)
// {
// constexpr std::string_view program =
// "def fibo(n: int) -> int:\n"
// " if n == 0:\n"
// " return 0\n"
// " elif n == 1:\n"
// " return 1\n"
// " return fibo(n-1) + fibo(n-2)\n";
// auto llvm_module = generate_llvm_module(program);
// ASSERT_TRUE(llvm_module);
// }