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