@@ -207,11 +207,17 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
207
207
}
208
208
if (Done) break ;
209
209
210
+ bool HasCurlyBraces = false ;
211
+ if (*LastEmitted == ' {' ) { // ${variable}
212
+ ++LastEmitted; // Consume '{' character.
213
+ HasCurlyBraces = true ;
214
+ }
215
+
210
216
// If we have ${:foo}, then this is not a real operand reference, it is a
211
217
// "magic" string reference, just like in .td files. Arrange to call
212
218
// PrintSpecial.
213
- if (LastEmitted[ 0 ] == ' { ' && LastEmitted[1 ] == ' :' ) {
214
- LastEmitted += 2 ;
219
+ if (HasCurlyBraces && LastEmitted[0 ] == ' :' ) {
220
+ ++LastEmitted ;
215
221
const char *StrStart = LastEmitted;
216
222
const char *StrEnd = strchr (StrStart, ' }' );
217
223
if (!StrEnd)
@@ -238,6 +244,27 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
238
244
report_fatal_error (" Invalid $ operand number in inline asm string: '" +
239
245
Twine (AsmStr) + " '" );
240
246
247
+ char Modifier[2 ] = { 0 , 0 };
248
+
249
+ if (HasCurlyBraces) {
250
+ // If we have curly braces, check for a modifier character. This
251
+ // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
252
+ if (*LastEmitted == ' :' ) {
253
+ ++LastEmitted; // Consume ':' character.
254
+ if (*LastEmitted == 0 )
255
+ report_fatal_error (" Bad ${:} expression in inline asm string: '" +
256
+ Twine (AsmStr) + " '" );
257
+
258
+ Modifier[0 ] = *LastEmitted;
259
+ ++LastEmitted; // Consume modifier character.
260
+ }
261
+
262
+ if (*LastEmitted != ' }' )
263
+ report_fatal_error (" Bad ${} expression in inline asm string: '" +
264
+ Twine (AsmStr) + " '" );
265
+ ++LastEmitted; // Consume '}' character.
266
+ }
267
+
241
268
// Okay, we finally have a value number. Ask the target to print this
242
269
// operand!
243
270
unsigned OpNo = InlineAsm::MIOp_FirstOperand;
@@ -262,9 +289,11 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
262
289
++OpNo; // Skip over the ID number.
263
290
264
291
if (InlineAsm::isMemKind (OpFlags)) {
265
- Error = AP->PrintAsmMemoryOperand (MI, OpNo, /* Modifier*/ nullptr , OS);
292
+ Error = AP->PrintAsmMemoryOperand (
293
+ MI, OpNo, Modifier[0 ] ? Modifier : nullptr , OS);
266
294
} else {
267
- Error = AP->PrintAsmOperand (MI, OpNo, /* Modifier*/ nullptr , OS);
295
+ Error = AP->PrintAsmOperand (MI, OpNo,
296
+ Modifier[0 ] ? Modifier : nullptr , OS);
268
297
}
269
298
}
270
299
if (Error) {
0 commit comments