| 1 | module c |
| 2 | |
| 3 | import os |
| 4 | import v.ast |
| 5 | import v.checker |
| 6 | import v.parser |
| 7 | import v.pref |
| 8 | |
| 9 | fn generate_freestanding_output(main_src string) string { |
| 10 | mut table := ast.new_table() |
| 11 | mut pref_ := pref.new_preferences() |
| 12 | pref_.is_bare = true |
| 13 | builtin_src := 'module builtin\n\nasm amd64 {\n\t.globl _start\n\t_start:\n\tret\n}\n' |
| 14 | mut builtin_file := parser.parse_text(builtin_src, os.join_path('/virtual', 'vlib', 'builtin', |
| 15 | 'linux_bare', 'linux_syscalls.v'), mut table, .skip_comments, pref_) |
| 16 | mut main_file := parser.parse_text(main_src, os.join_path('/virtual', 'main.v'), mut table, |
| 17 | .skip_comments, pref_) |
| 18 | mut chk := checker.new_checker(table, pref_) |
| 19 | chk.check(mut builtin_file) |
| 20 | chk.check(mut main_file) |
| 21 | result := gen([builtin_file, main_file], mut table, pref_) |
| 22 | return result.res_builder.bytestr() |
| 23 | } |
| 24 | |
| 25 | fn test_freestanding_c_output_does_not_redeclare_size_t() { |
| 26 | generated := generate_freestanding_output('module main\n\nfn main() {}\n') |
| 27 | assert generated.contains('<stddef.h>') |
| 28 | assert !generated.contains('typedef long unsigned int size_t;') |
| 29 | } |
| 30 | |