Exemple #1
0
void SourceMapGenerator::setDebugLoc(const llvm::DebugLoc& debugLoc)
{
	if(!sourceMap)
		return;
	if(!lineStart)
	{
		//TODO: Support multi-segment
	}
	else
	{
		// Start a new line
		MDNode* file = debugLoc.getScope(Ctx);
		assert(file->getNumOperands()>=2);
		MDNode* fileNamePath = cast<MDNode>(file->getOperand(1));
		assert(fileNamePath->getNumOperands()==2);
		MDString* fileNameString = cast<MDString>(fileNamePath->getOperand(0));

		auto fileMapIt = fileMap.find(fileNameString);
		if (fileMapIt == fileMap.end())
			fileMapIt = fileMap.insert(std::make_pair(fileNameString, fileMap.size())).first;
		uint32_t currentFile = fileMapIt->second;
		uint32_t currentLine = debugLoc.getLine() - 1;
		uint32_t currentColoumn = debugLoc.getCol();
		// Starting coloumn in the generated code
		writeBase64VLQInt(0);
		// Other fields are encoded as difference from the previous one in the file
		// We can use the last value directly because it is initialized as 0
		// File index
		writeBase64VLQInt(currentFile - lastFile);
		// Line index
		writeBase64VLQInt(currentLine - lastLine);
		// Coloumn index
		writeBase64VLQInt(currentColoumn - lastColoumn);
		lastFile = currentFile;
		lastLine = currentLine;
		lastColoumn = currentColoumn;
	}
	lineStart = false;
}
// @brief Lexicographic order on (line, col) of our debug locations.
static bool operator<(const llvm::DebugLoc &LHS, const llvm::DebugLoc &RHS) {
  return LHS.getLine() < RHS.getLine() ||
         (LHS.getLine() == RHS.getLine() && LHS.getCol() < RHS.getCol());
}