summaryrefslogtreecommitdiff
path: root/lib/MC/MCParser
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2011-11-01 22:27:22 +0000
committerKevin Enderby <enderby@apple.com>2011-11-01 22:27:22 +0000
commit613b7576896fbd03fe495f4ee27b404f81386774 (patch)
tree2650c11c10a570a3683afe918366e5c93b246529 /lib/MC/MCParser
parent60cb643f7561e5be7a3b5fe705535e96de72cbf5 (diff)
downloadllvm-613b7576896fbd03fe495f4ee27b404f81386774.tar.gz
llvm-613b7576896fbd03fe495f4ee27b404f81386774.tar.bz2
llvm-613b7576896fbd03fe495f4ee27b404f81386774.tar.xz
First part of support for generating dwarf for assembly source files with the
-g flag. In this part we generate the .file for the source being assembled and the .loc's for the assembled instructions. The next part will be to generate the dwarf Compile Unit DIE and a dwarf subprogram DIE for each non-temporary label. Once the next part is done test cases will be added. rdar://9275556 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCParser')
-rw-r--r--lib/MC/MCParser/AsmParser.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index d7ee1c4ca3..990fd17f59 100644
--- a/lib/MC/MCParser/AsmParser.cpp
+++ b/lib/MC/MCParser/AsmParser.cpp
@@ -464,6 +464,14 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
HadError = false;
AsmCond StartingCondState = TheCondState;
+ // If we are generating dwarf for assembly source files save the initial text
+ // section and generate a .file directive.
+ if (getContext().getGenDwarfForAssembly()) {
+ getContext().setGenDwarfSection(getStreamer().getCurrentSection());
+ getStreamer().EmitDwarfFileDirective(getContext().nextGenDwarfFileNumber(),
+ StringRef(), SrcMgr.getMemoryBuffer(CurBuffer)->getBufferIdentifier());
+ }
+
// While we have input, parse each statement.
while (Lexer.isNot(AsmToken::Eof)) {
if (!ParseStatement()) continue;
@@ -1211,6 +1219,18 @@ bool AsmParser::ParseStatement() {
PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str());
}
+ // If we are generating dwarf for assembly source files and the current
+ // section is the initial text section then generate a .loc directive for
+ // the instruction.
+ if (!HadError && getContext().getGenDwarfForAssembly() &&
+ getContext().getGenDwarfSection() == getStreamer().getCurrentSection() ) {
+ getStreamer().EmitDwarfLocDirective(getContext().getGenDwarfFileNumber(),
+ SrcMgr.FindLineNumber(IDLoc, CurBuffer),
+ 0, DWARF2_LINE_DEFAULT_IS_STMT ?
+ DWARF2_FLAG_IS_STMT : 0, 0, 0,
+ StringRef());
+ }
+
// If parsing succeeded, match the instruction.
if (!HadError)
HadError = getTargetParser().MatchAndEmitInstruction(IDLoc, ParsedOperands,
@@ -2342,6 +2362,10 @@ bool GenericAsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) {
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.file' directive");
+ if (getContext().getGenDwarfForAssembly() == true)
+ Error(DirectiveLoc, "input can't have .file dwarf directives when -g is "
+ "used to generate dwarf debug info for assembly code");
+
if (FileNumber == -1)
getStreamer().EmitFileDirective(Filename);
else {