aboutsummaryrefslogtreecommitdiff
path: root/tests/test_hello_world.py
blob: 03773921c1dfc609f70d4efb17259b75d067c365 (plain)
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
import unittest

from crowbar_reference_compiler import build_ast, build_ssa, parse_header, parse_implementation, scan


class TestHelloWorld(unittest.TestCase):
    def test_ssa(self):
        code = r"""
//include "stdio.hro";

int32 main() {
    printf("Hello, world!\n");
    return 0;
}
"""
        tokens = scan(code)
        parse_tree = parse_implementation(tokens)
        ast = build_ast(parse_tree, [])
        actual_ssa = build_ssa(ast)
        expected_ssa = r"""
data $data0 = { b "Hello, world!\n", b 0 }

export function w $main() {
@start
    %t0 =l copy $data0
    call $printf(l %t0, ...)
    %t1 =w copy 0
    ret %t1
}
""".strip()
        self.assertEqual(expected_ssa, actual_ssa)


if __name__ == '__main__':
    unittest.main()