Debian Codegraph @

test cases/common/118 llvm ir and assembly/meson.build

raw
1 project('llvm-ir', 'c', 'cpp')
2
3 if meson.backend() == 'xcode'
4 error('MESON_SKIP_TEST: asm not supported with the Xcode backend. Patches welcome.')
5 endif
6
7 cpu = host_machine.cpu_family()
8 supported_cpus = ['arm', 'aarch64', 'x86', 'x86_64']
9
10 foreach lang : ['c', 'cpp']
11 cc = meson.get_compiler(lang)
12 cc_id = cc.get_id()
13 ## Build a trivial executable with mixed LLVM IR source
14 if cc_id == 'clang'
15 e = executable('square_ir_' + lang, 'square.ll', 'main.' + lang)
16 test('test IR square' + lang, e)
17 endif
18 ## Build a trivial executable with mixed assembly source
19 # This also helps test whether cc.symbols_have_underscore_prefix() is working
20 # properly. This is done by assembling some assembly into an object that will
21 # provide the unsigned_squared() symbol to main.c/cpp. This requires the
22 # C symbol mangling to be known in advance.
23 if cc.symbols_have_underscore_prefix()
24 uscore_args = ['-DMESON_TEST__UNDERSCORE_SYMBOL']
25 message('underscore is prefixed')
26 else
27 uscore_args = []
28 message('underscore is NOT prefixed')
29 endif
30 square_base = 'square-' + cpu
31 square_impl = square_base + '.S'
32 # MSVC cannot directly compile assembly files, so we pass it through the
33 # cl.exe pre-processor first and then assemble it with ml.exe or armasm.exe
34 # assembler. Then we can link it into the executable.
35 if cc.get_argument_syntax() == 'msvc'
36 cl = cc.cmd_array()
37 if cpu == 'x86'
38 asmcmd = 'ml'
39 elif cpu == 'x86_64'
40 asmcmd = 'ml64'
41 elif cpu == 'aarch64'
42 asmcmd = 'armasm64'
43 elif cpu == 'arm'
44 asmcmd = 'armasm'
45 else
46 error('Unsupported cpu family: "' + cpu + '"')
47 endif
48 ml = find_program(asmcmd, required: false)
49 if not ml.found()
50 error('MESON_SKIP_TEST: Microsoft assembler (ml/armasm) not found')
51 endif
52 # Preprocess file (ml doesn't support pre-processing)
53 # Force the input to be C (/Tc) because ICL otherwise assumes it's an object (.obj) file
54 preproc_name = lang + square_base + '.i'
55 square_preproc = custom_target(lang + square_impl + 'preproc',
56 input : square_impl,
57 output : preproc_name,
58 command : [cl, '/nologo', '/EP', '/P', '/Fi' + preproc_name, '/Tc', '@INPUT@'] + uscore_args)
59 # Use assembled object file instead of the original .S assembly source
60 if asmcmd.startswith('armasm')
61 square_impl = custom_target(lang + square_impl,
62 input : square_preproc,
63 output : lang + square_base + '.obj',
64 command : [ml, '-nologo', '-o', '@OUTPUT@', '@INPUT@'])
65 else
66 square_impl = custom_target(lang + square_impl,
67 input : square_preproc,
68 output : lang + square_base + '.obj',
69 command : [ml, '/nologo', '/safeseh', '/Fo', '@OUTPUT@', '/c', '@INPUT@'])
70 endif
71 endif
72 if supported_cpus.contains(cpu)
73 e = executable('square_asm_' + lang, square_impl, 'main.' + lang,
74 c_args : uscore_args, cpp_args : uscore_args)
75 test('test ASM square' + lang, e)
76 elif cc_id != 'clang'
77 error('MESON_SKIP_TEST: Unsupported cpu: "' + cpu + '", and LLVM not found')
78 endif
79 endforeach