1# RUN: llvm-mc -triple i386-linux-gnu %s | FileCheck %s
2
3# Checking that the '%' was evaluated as a string first
4# In a fail scenario: The asmprint will print: addl $%(1+4), %eax
5
6# CHECK:  addl $5, %eax
7.altmacro
8.macro percent_expr arg
9    addl $\arg, %eax
10.endm
11
12percent_expr %(1+4)
13
14
15# Checking that the second '%' acts as modulo operator
16# The altmacro percent '%' must be located before the first argument
17# If a percent is located in the middle of the estimated argument without any
18# '%' in the beginning , error will be generated.
19# The second percent '%' after the first altmacro percent '%' is a regular operator.
20
21# CHECK:  addl $1, %eax
22.macro inner_percent arg
23    addl $\arg, %eax
24.endm
25
26inner_percent %(1%4)
27
28
29# Checking for nested macro
30# The first argument use is for the calling function and the second use is for the evaluation.
31
32# CHECK:  addl    $1, %eax
33.macro macro_call_0 number
34    addl $\number, %eax
35.endm
36
37.macro macro_call_1 number
38    macro_call_\number %(\number + 1)
39.endm
40
41macro_call_1 %(1-1)
42
43
44# Checking the ability to pass a number of arguments.
45# The arguments can be separated by ',' or not.
46
47# CHECK: label013:
48# CHECK:  addl $0, %eax
49# CHECK:  addl $1, %eax
50# CHECK:  addl $3, %eax
51
52# CHECK: label014:
53# CHECK:  addl $0, %eax
54# CHECK:  addl $1, %eax
55# CHECK:  addl $4, %eax
56
57.macro multi_args_macro arg1 arg2 arg3
58    label\arg1\arg2\arg3:
59	addl $\arg1, %eax
60	addl $\arg2, %eax
61	addl $\arg3, %eax
62.endm
63
64multi_args_macro %(1+4-5) 1 %2+1
65multi_args_macro %(1+4-5),1,%4%10
66