aboutsummaryrefslogtreecommitdiff
path: root/test cases/common/126 llvm ir and assembly/meson.build
blob: 97cce18b6a7b2c5dd7d49c979a1e541f372cd635 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
project('llvm-ir', 'c', 'cpp')

foreach lang : ['c', 'cpp']
  cc = meson.get_compiler(lang)
  cc_id = cc.get_id()
  ## Build a trivial executale with mixed LLVM IR source
  if cc_id == 'clang'
    e = executable('square_ir_' + lang, 'square.ll', 'main.' + lang)
    test('test IR square' + lang, e)
  endif
  ## Build a trivial executable with mixed assembly source
  # This also helps test whether cc.symbols_have_underscore_prefix() is working
  # properly. This is done by assembling some assembly into an object that will
  # provide the unsigned_squared() symbol to main.c/cpp. This requires the
  # C symbol mangling to be known in advance.
  if cc.symbols_have_underscore_prefix()
    uscore_args = ['-DMESON_TEST__UNDERSCORE_SYMBOL']
    message('underscore is prefixed')
  else
    uscore_args = []
    message('underscore is NOT prefixed')
  endif
  cpu = host_machine.cpu_family()
  square_base = 'square-' + cpu
  square_impl = square_base + '.S'
  # MSVC cannot directly compile assembly files, so we pass it through the
  # cl.exe pre-processor first and then assemble it with the ml.exe assembler.
  # Then we can link it into the executable.
  if cc_id == 'msvc'
    cl = find_program('cl')
    if cpu == 'x86'
      ml = find_program('ml')
    elif cpu == 'x86_64'
      ml = find_program('ml64')
    else
      error('Unsupported cpu family: "' + cpu + '"')
    endif
    # Preprocess file (ml doesn't support pre-processing)
    preproc_name = lang + square_base + '.i'
    square_preproc = custom_target(lang + square_impl + 'preproc',
        input : square_impl,
        output : preproc_name,
        command : [cl, '/EP', '/P', '/Fi' + preproc_name, '@INPUT@'] + uscore_args)
    # Use assembled object file instead of the original .S assembly source
    square_impl = custom_target(lang + square_impl,
        input : square_preproc,
        output : lang + square_base + '.obj',
        command : [ml, '/Fo', '@OUTPUT@', '/c', '@INPUT@'])

  endif
  e = executable('square_asm_' + lang, square_impl, 'main.' + lang,
      c_args : uscore_args, cpp_args : uscore_args)
  test('test ASM square' + lang, e)
endforeach