xref: /llvm-project/llvm/test/tools/llvm-ml/macro.asm (revision a4e964a2821905728b866fb64784fbea1f67ccc1)
18fee2ee9SEric Astor; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
28fee2ee9SEric Astor
38fee2ee9SEric Astor.data
48fee2ee9SEric Astor
58fee2ee9SEric Astorx1 DWORD ?
68fee2ee9SEric Astorx2 DWORD ?
78fee2ee9SEric Astorxa1 DWORD ?
88fee2ee9SEric Astor
98fee2ee9SEric Astor.code
108fee2ee9SEric Astor
11*a4e964a2SEric AstorSubstitutionMacro macro a1:req, a2:=<7>
128fee2ee9SEric Astor  mov eax, a1
138fee2ee9SEric Astor  mov eax, a1&
148fee2ee9SEric Astor  mov eax, &a1
158fee2ee9SEric Astor  mov eax, &a1&
168fee2ee9SEric Astor
178fee2ee9SEric Astor  mov eax, xa1
188fee2ee9SEric Astor  mov eax, x&a1
198fee2ee9SEric Astor  mov eax, x&a1&
208fee2ee9SEric Astor
218fee2ee9SEric Astor  mov eax, a2
228fee2ee9SEric Astor  mov eax, a2&
238fee2ee9SEric Astor  mov eax, &a2
248fee2ee9SEric Astor  mov eax, &a2&
258fee2ee9SEric Astorendm
268fee2ee9SEric Astor
278fee2ee9SEric Astorsubstitution_test_with_default PROC
288fee2ee9SEric Astor; CHECK-LABEL: substitution_test_with_default:
298fee2ee9SEric Astor
30*a4e964a2SEric Astor  SubstitutionMacro 1
318fee2ee9SEric Astor; CHECK: mov eax, 1
328fee2ee9SEric Astor; CHECK-NEXT: mov eax, 1
338fee2ee9SEric Astor; CHECK-NEXT: mov eax, 1
348fee2ee9SEric Astor; CHECK-NEXT: mov eax, 1
358fee2ee9SEric Astor; CHECK: mov eax, dword ptr [rip + xa1]
368fee2ee9SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x1]
378fee2ee9SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x1]
388fee2ee9SEric Astor; CHECK: mov eax, 7
398fee2ee9SEric Astor; CHECK-NEXT: mov eax, 7
408fee2ee9SEric Astor; CHECK-NEXT: mov eax, 7
418fee2ee9SEric Astor; CHECK-NEXT: mov eax, 7
428fee2ee9SEric Astor
438fee2ee9SEric Astor  ret
448fee2ee9SEric Astorsubstitution_test_with_default ENDP
458fee2ee9SEric Astor
468fee2ee9SEric Astorsubstitution_test_with_value PROC
478fee2ee9SEric Astor; CHECK-LABEL: substitution_test_with_value:
488fee2ee9SEric Astor
49*a4e964a2SEric Astor  SubstitutionMacro 2, 8
508fee2ee9SEric Astor; CHECK: mov eax, 2
518fee2ee9SEric Astor; CHECK-NEXT: mov eax, 2
528fee2ee9SEric Astor; CHECK-NEXT: mov eax, 2
538fee2ee9SEric Astor; CHECK-NEXT: mov eax, 2
548fee2ee9SEric Astor; CHECK: mov eax, dword ptr [rip + xa1]
558fee2ee9SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
568fee2ee9SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
578fee2ee9SEric Astor; CHECK: mov eax, 8
588fee2ee9SEric Astor; CHECK-NEXT: mov eax, 8
598fee2ee9SEric Astor; CHECK-NEXT: mov eax, 8
608fee2ee9SEric Astor; CHECK-NEXT: mov eax, 8
618fee2ee9SEric Astor
628fee2ee9SEric Astor  ret
638fee2ee9SEric Astorsubstitution_test_with_value ENDP
648fee2ee9SEric Astor
65*a4e964a2SEric Astorsubstitution_test_lowercase PROC
66*a4e964a2SEric Astor; CHECK-LABEL: substitution_test_lowercase:
67*a4e964a2SEric Astor
68*a4e964a2SEric Astor  substitutionmacro 2, 8
69*a4e964a2SEric Astor; CHECK: mov eax, 2
70*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
71*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
72*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
73*a4e964a2SEric Astor; CHECK: mov eax, dword ptr [rip + xa1]
74*a4e964a2SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
75*a4e964a2SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
76*a4e964a2SEric Astor; CHECK: mov eax, 8
77*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
78*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
79*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
80*a4e964a2SEric Astor
81*a4e964a2SEric Astor  ret
82*a4e964a2SEric Astorsubstitution_test_lowercase ENDP
83*a4e964a2SEric Astor
84*a4e964a2SEric Astorsubstitution_test_uppercase PROC
85*a4e964a2SEric Astor; CHECK-LABEL: substitution_test_uppercase:
86*a4e964a2SEric Astor
87*a4e964a2SEric Astor  SUBSTITUTIONMACRO 2, 8
88*a4e964a2SEric Astor; CHECK: mov eax, 2
89*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
90*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
91*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 2
92*a4e964a2SEric Astor; CHECK: mov eax, dword ptr [rip + xa1]
93*a4e964a2SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
94*a4e964a2SEric Astor; CHECK-NEXT: mov eax, dword ptr [rip + x2]
95*a4e964a2SEric Astor; CHECK: mov eax, 8
96*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
97*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
98*a4e964a2SEric Astor; CHECK-NEXT: mov eax, 8
99*a4e964a2SEric Astor
100*a4e964a2SEric Astor  ret
101*a4e964a2SEric Astorsubstitution_test_uppercase ENDP
102*a4e964a2SEric Astor
103*a4e964a2SEric AstorAmbiguousSubstitutionMacro MACRO x, y
1048fee2ee9SEric Astor  x&y BYTE 0
1058fee2ee9SEric AstorENDM
1068fee2ee9SEric Astor
1078fee2ee9SEric Astorambiguous_substitution_test PROC
1088fee2ee9SEric Astor; CHECK-LABEL: ambiguous_substitution_test:
1098fee2ee9SEric Astor
1108fee2ee9SEric Astor; should expand to ab BYTE 0
111*a4e964a2SEric Astor  AmbiguousSubstitutionMacro a, b
1128fee2ee9SEric Astor
1138fee2ee9SEric Astor; CHECK: ab:
1148fee2ee9SEric Astor; CHECK-NOT: ay:
1158fee2ee9SEric Astor; CHECK-NOT: xb:
1168fee2ee9SEric Astor; CHECK-NOT: xy:
1178fee2ee9SEric Astorambiguous_substitution_test ENDP
1188fee2ee9SEric Astor
119*a4e964a2SEric AstorAmbiguousSubstitutionInStringMacro MACRO x, y
1208fee2ee9SEric Astor  BYTE "x&y"
1218fee2ee9SEric AstorENDM
1228fee2ee9SEric Astor
1238fee2ee9SEric Astorambiguous_substitution_in_string_test PROC
1248fee2ee9SEric Astor; CHECK-LABEL: ambiguous_substitution_in_string_test:
1258fee2ee9SEric Astor
1268fee2ee9SEric Astor; should expand to BYTE "5y"
127*a4e964a2SEric Astor  AmbiguousSubstitutionInStringMacro 5, 7
1288fee2ee9SEric Astor
1298fee2ee9SEric Astor; CHECK: .byte 53
1308fee2ee9SEric Astor; CHECK-NEXT: .byte 121
1318fee2ee9SEric Astor; CHECK-NOT: .byte
1328fee2ee9SEric Astorambiguous_substitution_in_string_test ENDP
1338fee2ee9SEric Astor
134*a4e964a2SEric AstorOptionalParameterMacro MACRO a1:req, a2
1358fee2ee9SEric Astor  mov eax, a1
1368fee2ee9SEric AstorIFNB <a2>
1378fee2ee9SEric Astor  mov eax, a2
1388fee2ee9SEric AstorENDIF
1398fee2ee9SEric Astor  ret
1408fee2ee9SEric AstorENDM
1418fee2ee9SEric Astor
1428fee2ee9SEric Astoroptional_parameter_test PROC
1438fee2ee9SEric Astor; CHECK-LABEL: optional_parameter_test:
1448fee2ee9SEric Astor
145*a4e964a2SEric Astor  OptionalParameterMacro 4
1468fee2ee9SEric Astor; CHECK: mov eax, 4
1478fee2ee9SEric Astor; CHECK: ret
1488fee2ee9SEric Astor
149*a4e964a2SEric Astor  OptionalParameterMacro 5, 9
1508fee2ee9SEric Astor; CHECK: mov eax, 5
1518fee2ee9SEric Astor; CHECK: mov eax, 9
1528fee2ee9SEric Astor; CHECK: ret
1538fee2ee9SEric Astoroptional_parameter_test ENDP
1548fee2ee9SEric Astor
155*a4e964a2SEric AstorLocalSymbolMacro MACRO
1568fee2ee9SEric Astor  LOCAL a
1578fee2ee9SEric Astora: ret
1588fee2ee9SEric Astor   jmp a
1598fee2ee9SEric AstorENDM
1608fee2ee9SEric Astor
1618fee2ee9SEric Astorlocal_symbol_test PROC
1628fee2ee9SEric Astor; CHECK-LABEL: local_symbol_test:
1638fee2ee9SEric Astor
164*a4e964a2SEric Astor  LocalSymbolMacro
1658fee2ee9SEric Astor; CHECK: "??0000":
1668fee2ee9SEric Astor; CHECK-NEXT: ret
1678fee2ee9SEric Astor; CHECK-NEXT: jmp "??0000"
1688fee2ee9SEric Astor
169*a4e964a2SEric Astor  LocalSymbolMacro
1708fee2ee9SEric Astor; CHECK: "??0001":
1718fee2ee9SEric Astor; CHECK-NEXT: ret
1728fee2ee9SEric Astor; CHECK-NEXT: jmp "??0001"
1738fee2ee9SEric Astorlocal_symbol_test ENDP
1748fee2ee9SEric Astor
175*a4e964a2SEric AstorPURGE AmbiguousSubstitutionMacro, LocalSymbolMacro,
176*a4e964a2SEric Astor      OptionalParameterMacro
1778fee2ee9SEric Astor
1788fee2ee9SEric Astor; Redefinition
179*a4e964a2SEric AstorLocalSymbolMacro MACRO
1808fee2ee9SEric Astor  LOCAL b
1818fee2ee9SEric Astorb: xor eax, eax
1828fee2ee9SEric Astor   jmp b
1838fee2ee9SEric AstorENDM
1848fee2ee9SEric Astor
1858fee2ee9SEric Astorpurge_test PROC
1868fee2ee9SEric Astor; CHECK-LABEL: purge_test:
1878fee2ee9SEric Astor
188*a4e964a2SEric Astor  LocalSymbolMacro
1898fee2ee9SEric Astor; CHECK: "??0002":
1908fee2ee9SEric Astor; CHECK-NEXT: xor eax, eax
1918fee2ee9SEric Astor; CHECK-NEXT: jmp "??0002"
1928fee2ee9SEric Astorpurge_test ENDP
1938fee2ee9SEric Astor
1948fee2ee9SEric AstorEND
195