2017-04-19 8 views
0

llvm 패스 중에 디렉토리와 파일 이름을 추출해야합니다. 현재 버전의 llvm은 getFilename 및 getDirectory를 DebugLoc에서 DebugInfoMetadata로 이동했습니다. DebugLoc 헤더에서 클래스 멤버 getFilename을 직접 찾을 수 없습니다. 어떻게하면 명령에서 소스 코드 파일 이름 및 디렉토리로 이동합니까?LLVM 명령어에서 파일 이름과 디렉토리를 얻는 방법은 무엇입니까?

http://llvm.org/docs/doxygen/html/classllvm_1_1DebugLoc.html

또한 도움이 될 수 있습니다 인쇄 기능이 있지만 그것은 단지 LLVM :: raw_ostream을 취하고 표준 : : 문자열로 리디렉션 할 수 없습니다.

void print (raw_ostream &OS) const prints source location /path/to/file.exe:line:col @[inlined at]

아래 코드는

const DebugLoc &location = an_instruction_iter->getDebugLoc() StringRef File = location->getFilename() // Gives an error

은 --- 솔루션은 내가 몇 분 전에 알아 낸 오류 ----

const DebugLoc &location = i_iter->getDebugLoc(); const DILocation *test =location.get(); test->getFilename();

답변

1

을주는 것입니다 1)

std::string dbgInfo; 
llvm::raw_string_ostream rso(dbgInfo); 
location->print(rso); 
std::sting dbgStr = rso.str() 

2)

auto *Scope = cast<DIScope>(location->getScope()); 
std::string fileName = Scope->getFilename(); 
+0

두 번째 솔루션은 작동합니다. 첫 번째 해결책은 오류를 낸다 ' 'print'에 대한 호출에 일치하는 멤버 함수가 없다. location-> print (stream); ' –

+0

@QuentinMayo 나는 대답을 업데이트했다. – hailinzeng