llvm.org GIT mirror llvm / 519212b
Let the integrated assembler understand .exitm, PR20426. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213876 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 6 years ago
2 changed file(s) with 104 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
9191 /// The location where parsing should resume upon instantiation completion.
9292 SMLoc ExitLoc;
9393
94 /// The depth of TheCondStack at the start of the instantiation.
95 size_t CondStackDepth;
96
9497 public:
95 MacroInstantiation(SMLoc IL, int EB, SMLoc EL, MemoryBuffer *I);
98 MacroInstantiation(SMLoc IL, int EB, SMLoc EL, MemoryBuffer *I,
99 size_t CondStackDepth);
96100 };
97101
98102 struct ParseStatementInfo {
350354 DK_CFI_REMEMBER_STATE, DK_CFI_RESTORE_STATE, DK_CFI_SAME_VALUE,
351355 DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
352356 DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
353 DK_MACROS_ON, DK_MACROS_OFF, DK_MACRO, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
357 DK_MACROS_ON, DK_MACROS_OFF,
358 DK_MACRO, DK_EXITM, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
354359 DK_SLEB128, DK_ULEB128,
355360 DK_ERR, DK_ERROR, DK_WARNING,
356361 DK_END
402407
403408 // macro directives
404409 bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
410 bool parseDirectiveExitMacro(StringRef Directive);
405411 bool parseDirectiveEndMacro(StringRef Directive);
406412 bool parseDirectiveMacro(SMLoc DirectiveLoc);
407413 bool parseDirectiveMacrosOnOff(StringRef Directive);
15401546 return parseDirectiveMacrosOnOff(IDVal);
15411547 case DK_MACRO:
15421548 return parseDirectiveMacro(IDLoc);
1549 case DK_EXITM:
1550 return parseDirectiveExitMacro(IDVal);
15431551 case DK_ENDM:
15441552 case DK_ENDMACRO:
15451553 return parseDirectiveEndMacro(IDVal);
18571865 }
18581866
18591867 MacroInstantiation::MacroInstantiation(SMLoc IL, int EB, SMLoc EL,
1860 MemoryBuffer *I)
1861 : Instantiation(I), InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL) {}
1868 MemoryBuffer *I, size_t CondStackDepth)
1869 : Instantiation(I), InstantiationLoc(IL), ExitBuffer(EB), ExitLoc(EL),
1870 CondStackDepth(CondStackDepth) {}
18621871
18631872 static bool isOperator(AsmToken::TokenKind kind) {
18641873 switch (kind) {
21212130
21222131 // Create the macro instantiation object and add to the current macro
21232132 // instantiation stack.
2124 MacroInstantiation *MI = new MacroInstantiation(
2125 NameLoc, CurBuffer, getTok().getLoc(), Instantiation);
2133 MacroInstantiation *MI =
2134 new MacroInstantiation(NameLoc, CurBuffer, getTok().getLoc(),
2135 Instantiation, TheCondStack.size());
21262136 ActiveMacros.push_back(MI);
21272137
21282138 // Jump to the macro instantiation and prime the lexer.
34683478 Warning(DirectiveLoc, "macro defined with named parameters which are not "
34693479 "used in macro body, possible positional parameter "
34703480 "found in body which will have no effect");
3481 }
3482
3483 /// parseDirectiveExitMacro
3484 /// ::= .exitm
3485 bool AsmParser::parseDirectiveExitMacro(StringRef Directive) {
3486 if (getLexer().isNot(AsmToken::EndOfStatement))
3487 return TokError("unexpected token in '" + Directive + "' directive");
3488
3489 if (!isInsideMacroInstantiation())
3490 return TokError("unexpected '" + Directive + "' in file, "
3491 "no current macro definition");
3492
3493 // Exit all conditionals that are active in the current macro.
3494 while (TheCondStack.size() != ActiveMacros.back()->CondStackDepth) {
3495 TheCondState = TheCondStack.back();
3496 TheCondStack.pop_back();
3497 }
3498
3499 handleMacroExit();
3500 return false;
34713501 }
34723502
34733503 /// parseDirectiveEndMacro
42254255 DirectiveKindMap[".macros_on"] = DK_MACROS_ON;
42264256 DirectiveKindMap[".macros_off"] = DK_MACROS_OFF;
42274257 DirectiveKindMap[".macro"] = DK_MACRO;
4258 DirectiveKindMap[".exitm"] = DK_EXITM;
42284259 DirectiveKindMap[".endm"] = DK_ENDM;
42294260 DirectiveKindMap[".endmacro"] = DK_ENDMACRO;
42304261 DirectiveKindMap[".purgem"] = DK_PURGEM;
42854316
42864317 // Create the macro instantiation object and add to the current macro
42874318 // instantiation stack.
4288 MacroInstantiation *MI = new MacroInstantiation(
4289 DirectiveLoc, CurBuffer, getTok().getLoc(), Instantiation);
4319 MacroInstantiation *MI =
4320 new MacroInstantiation(DirectiveLoc, CurBuffer, getTok().getLoc(),
4321 Instantiation, TheCondStack.size());
42904322 ActiveMacros.push_back(MI);
42914323
42924324 // Jump to the macro instantiation and prime the lexer.
0 // RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
1
2 // .exitm is encountered in a normal macro expansion
3 .macro REP
4 .rept 3
5 .long 0
6 .exitm
7 .endr
8 .endm
9 REP
10 // Only the output from the first rept expansion should make it through:
11 // CHECK: .long 0
12 // CHECK-NOT: .long 0
13
14 // .exitm is in a true branch
15 .macro A
16 .if 1
17 .long 1
18 .exitm
19 .endif
20 .long 1
21 .endm
22 A
23 // CHECK: .long 1
24 // CHECK-NOT: .long 1
25
26 // .exitm is in a false branch
27 .macro B
28 .if 1
29 .long 2
30 .else
31 .exitm
32 .endif
33 .long 2
34 .endm
35 B
36 // CHECK: .long 2
37 // CHECK: .long 2
38
39
40 // .exitm is in a false branch that is encountered prior to the true branch
41 .macro C
42 .if 0
43 .exitm
44 .else
45 .long 3
46 .endif
47 .long 3
48 .endm
49 C
50 // CHECK: .long 3
51 // CHECK: .long 3
52
53 // .exitm is in a macro that's expanded in a conditional block.
54 .macro D
55 .long 4
56 .exitm
57 .long 4
58 .endm
59 .if 1
60 D
61 .endif
62 // CHECK: .long 4
63 // CHECK-NOT: .long 4