2020-11-19 04:38:25 +08:00
|
|
|
//===------- SourceInfo.h - Target independent OpenMP target RTL -- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Methods used to describe source information in target regions
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _SOURCE_INFO_H_
|
|
|
|
#define _SOURCE_INFO_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
static const bool OS_WINDOWS = true;
|
|
|
|
#else
|
|
|
|
static const bool OS_WINDOWS = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// Type alias for source location information for variable mappings with
|
|
|
|
/// data layout ";name;filename;row;col;;\0" from clang.
|
|
|
|
using map_var_info_t = void *;
|
|
|
|
|
2020-11-20 00:56:59 +08:00
|
|
|
/// The ident structure that describes a source location from kmp.h. with
|
|
|
|
/// source location string data as ";filename;function;line;column;;\0".
|
|
|
|
struct ident_t {
|
|
|
|
// Ident_t flags described in kmp.h.
|
|
|
|
int32_t reserved_1;
|
|
|
|
int32_t flags;
|
|
|
|
int32_t reserved_2;
|
|
|
|
int32_t reserved_3;
|
|
|
|
char const *psource;
|
|
|
|
};
|
|
|
|
|
2020-11-19 04:38:25 +08:00
|
|
|
/// Struct to hold source individual location information.
|
|
|
|
class SourceInfo {
|
|
|
|
/// Underlying string copy of the original source information.
|
2020-11-20 00:56:59 +08:00
|
|
|
const std::string sourceStr;
|
|
|
|
|
|
|
|
/// Location fields extracted from the source information string.
|
|
|
|
const std::string name;
|
|
|
|
const std::string filename;
|
|
|
|
const int32_t line;
|
|
|
|
const int32_t column;
|
2020-11-19 04:38:25 +08:00
|
|
|
|
2020-11-20 00:56:59 +08:00
|
|
|
std::string initStr(const void *name) {
|
2020-11-19 04:38:25 +08:00
|
|
|
if (!name)
|
|
|
|
return ";unknown;unknown;0;0;;";
|
|
|
|
else
|
|
|
|
return std::string(reinterpret_cast<const char *>(name));
|
|
|
|
}
|
|
|
|
|
2020-12-19 04:14:44 +08:00
|
|
|
std::string initStr(const ident_t *loc) {
|
|
|
|
if (!loc)
|
|
|
|
return ";unknown;unknown;0;0;;";
|
|
|
|
else
|
|
|
|
return std::string(reinterpret_cast<const char *>(loc->psource));
|
|
|
|
}
|
|
|
|
|
2020-11-19 04:38:25 +08:00
|
|
|
/// Get n-th substring in an expression separated by ;.
|
2020-11-20 00:56:59 +08:00
|
|
|
std::string getSubstring(const int n) const {
|
|
|
|
std::size_t begin = sourceStr.find(';');
|
|
|
|
std::size_t end = sourceStr.find(';', begin + 1);
|
2020-11-19 04:38:25 +08:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
begin = end;
|
2020-11-20 00:56:59 +08:00
|
|
|
end = sourceStr.find(';', begin + 1);
|
2020-11-19 04:38:25 +08:00
|
|
|
}
|
2020-11-20 00:56:59 +08:00
|
|
|
return sourceStr.substr(begin + 1, end - begin - 1);
|
2020-11-19 04:38:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Get the filename from a full path.
|
2020-11-20 00:56:59 +08:00
|
|
|
std::string removePath(const std::string &path) const {
|
2020-11-19 04:38:25 +08:00
|
|
|
std::size_t pos = (OS_WINDOWS) ? path.rfind('\\') : path.rfind('/');
|
|
|
|
return path.substr(pos + 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2020-11-20 00:56:59 +08:00
|
|
|
SourceInfo(const ident_t *loc)
|
2020-12-19 04:14:44 +08:00
|
|
|
: sourceStr(initStr(loc)), name(getSubstring(1)),
|
2020-11-20 00:56:59 +08:00
|
|
|
filename(removePath(getSubstring(0))), line(std::stoi(getSubstring(2))),
|
|
|
|
column(std::stoi(getSubstring(3))) {}
|
|
|
|
|
2020-11-19 04:38:25 +08:00
|
|
|
SourceInfo(const map_var_info_t name)
|
2020-11-20 00:56:59 +08:00
|
|
|
: sourceStr(initStr(name)), name(getSubstring(0)),
|
2020-11-19 04:38:25 +08:00
|
|
|
filename(removePath(getSubstring(1))), line(std::stoi(getSubstring(2))),
|
|
|
|
column(std::stoi(getSubstring(3))) {}
|
|
|
|
|
2020-11-20 00:56:59 +08:00
|
|
|
const char *getName() const { return name.c_str(); }
|
|
|
|
const char *getFilename() const { return filename.c_str(); }
|
|
|
|
int32_t getLine() const { return line; }
|
|
|
|
int32_t getColumn() const { return column; }
|
|
|
|
bool isAvailible() const { return (line || column); }
|
2020-11-19 04:38:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Standalone function for getting the variable name of a mapping.
|
|
|
|
static inline std::string getNameFromMapping(const map_var_info_t name) {
|
|
|
|
if (!name)
|
|
|
|
return "unknown";
|
|
|
|
|
|
|
|
const std::string name_str(reinterpret_cast<const char *>(name));
|
|
|
|
std::size_t begin = name_str.find(';');
|
|
|
|
std::size_t end = name_str.find(';', begin + 1);
|
|
|
|
return name_str.substr(begin + 1, end - begin - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|