代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/pin-gcc-client 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 001eb22fb00d2240235def0a4d3923f325eba8ad Mon Sep 17 00:00:00 2001
From: d00573793 <dingguangya1@huawei.com>
Date: Mon, 6 Mar 2023 22:05:28 +0800
Subject: [PATCH 6/6] [Pin-gcc-client] Add GetDeclType
diff --git a/include/PluginAPI/BasicPluginOpsAPI.h b/include/PluginAPI/BasicPluginOpsAPI.h
index bb1e0b2..22da8df 100644
--- a/include/PluginAPI/BasicPluginOpsAPI.h
+++ b/include/PluginAPI/BasicPluginOpsAPI.h
@@ -64,6 +64,7 @@ public:
virtual vector<LocalDeclOp> GetDecls(uint64_t funcID) = 0;
virtual vector<DeclBaseOp> GetFuncDecls(uint64_t funcID) = 0;
virtual vector<FieldDeclOp> GetFields(uint64_t declID) = 0;
+ virtual PluginIR::PluginTypeBase GetDeclType(uint64_t declID) = 0;
virtual DeclBaseOp BuildDecl(IDefineCode, string, PluginTypeBase) = 0;
virtual mlir::Value MakeNode(IDefineCode) = 0;
diff --git a/include/PluginAPI/PluginClientAPI.h b/include/PluginAPI/PluginClientAPI.h
index 9b845a8..26ef71d 100644
--- a/include/PluginAPI/PluginClientAPI.h
+++ b/include/PluginAPI/PluginClientAPI.h
@@ -56,6 +56,7 @@ public:
vector<LocalDeclOp> GetDecls(uint64_t funcID) override;
vector<DeclBaseOp> GetFuncDecls(uint64_t funcID) override;
vector<FieldDeclOp> GetFields(uint64_t declID) override;
+ PluginIR::PluginTypeBase GetDeclType(uint64_t declID) override;
DeclBaseOp BuildDecl(IDefineCode, string, PluginTypeBase) override;
mlir::Value MakeNode(IDefineCode) override;
diff --git a/include/Translate/GimpleToPluginOps.h b/include/Translate/GimpleToPluginOps.h
index 0565b01..1332219 100644
--- a/include/Translate/GimpleToPluginOps.h
+++ b/include/Translate/GimpleToPluginOps.h
@@ -73,6 +73,7 @@ public:
vector<mlir::Plugin::LocalDeclOp> GetAllDecls(uint64_t);
vector<mlir::Plugin::DeclBaseOp> GetFuncDecls(uint64_t);
vector<FieldDeclOp> GetFields(uint64_t);
+ PluginIR::PluginTypeBase GetDeclType(uint64_t);
mlir::Plugin::DeclBaseOp BuildDecl(IDefineCode, string, PluginTypeBase);
mlir::Value MakeNode(IDefineCode);
diff --git a/lib/PluginAPI/PluginClientAPI.cpp b/lib/PluginAPI/PluginClientAPI.cpp
index 0ee062b..95e9ab3 100644
--- a/lib/PluginAPI/PluginClientAPI.cpp
+++ b/lib/PluginAPI/PluginClientAPI.cpp
@@ -117,6 +117,11 @@ vector<FieldDeclOp> PluginClientAPI::GetFields(uint64_t declID)
return gimpleConversion.GetFields(declID);
}
+PluginIR::PluginTypeBase PluginClientAPI::GetDeclType(uint64_t declID)
+{
+ return gimpleConversion.GetDeclType(declID);
+}
+
mlir::Value PluginClientAPI::MakeNode(IDefineCode code)
{
return gimpleConversion.MakeNode(code);
diff --git a/lib/PluginClient/PluginClient.cpp b/lib/PluginClient/PluginClient.cpp
index 83e8642..c354d7e 100644
--- a/lib/PluginClient/PluginClient.cpp
+++ b/lib/PluginClient/PluginClient.cpp
@@ -268,6 +268,19 @@ void GetBuildDeclResult(PluginClient *client, Json::Value& root, string& result)
client->ReceiveSendMsg("DeclOpResult", result);
}
+void GetDeclTypeResult(PluginClient *client, Json::Value& root, string& result)
+{
+ mlir::MLIRContext context;
+ context.getOrLoadDialect<PluginDialect>();
+ PluginAPI::PluginClientAPI clientAPI(context);
+ std::string declIdKey = "declId";
+ uint64_t declID = atol(root[declIdKey].asString().c_str());
+ PluginIR::PluginTypeBase retType = clientAPI.GetDeclType(declID);
+ PluginJson json = client->GetJson();
+ result = json.TypeJsonSerialize(retType).toStyledString();
+ client->ReceiveSendMsg("PluginTypeResult", result);
+}
+
void SetDeclNameResult(PluginClient *client, Json::Value& root, string& result)
{
/// Json格式
@@ -1266,6 +1279,7 @@ std::map<string, GetResultFunc> g_getResultFunc = {
{"GetFuncDecls", GetFuncDeclsResult},
{"GetFields", GetFieldsResult},
{"BuildDecl", GetBuildDeclResult},
+ {"GetDeclType", GetDeclTypeResult},
{"MakeNode", GetMakeNodeResult},
{"SetDeclName", SetDeclNameResult},
{"SetDeclType", SetDeclTypeResult},
diff --git a/lib/PluginClient/PluginInputCheck.cpp b/lib/PluginClient/PluginInputCheck.cpp
index 4d17e0a..36ebd8c 100755
--- a/lib/PluginClient/PluginInputCheck.cpp
+++ b/lib/PluginClient/PluginInputCheck.cpp
@@ -47,7 +47,7 @@ bool PluginInputCheck::ReadConfigfile(Json::Value& root)
}
if (!reader.parse(ifs, root)) {
- printf("parse %s fail! check the file format!\n", configFilePath.c_str());
+ fprintf(stderr, "parse %s fail! check the file format!\n", configFilePath.c_str());
ifs.close();
return false;
}
diff --git a/lib/PluginClient/PluginJson.cpp b/lib/PluginClient/PluginJson.cpp
index 76f13a7..be0ee8d 100755
--- a/lib/PluginClient/PluginJson.cpp
+++ b/lib/PluginClient/PluginJson.cpp
@@ -209,7 +209,6 @@ void PluginJson::CGnodeOpJsonSerialize(CGnodeOp& cgnode, string& out)
root["attributes"]["definition"] = "0";
}
root["attributes"]["symbolName"] = cgnode.symbolNameAttr().getValue().str().c_str();
- fprintf(stderr, "dgy client cgnode json %s\n", root.toStyledString().c_str());
out = root.toStyledString();
}
diff --git a/lib/PluginClient/PluginLog.cpp b/lib/PluginClient/PluginLog.cpp
index 6cdf7af..7ace548 100644
--- a/lib/PluginClient/PluginLog.cpp
+++ b/lib/PluginClient/PluginLog.cpp
@@ -46,14 +46,14 @@ static void GetLogFileName(string& fileName)
{
time_t nowTime = time(nullptr);
if (nowTime == -1) {
- printf("%s fail\n", __func__);
+ fprintf(stderr, "%s fail\n", __func__);
}
struct tm *t = localtime(&nowTime);
char buf[100];
int ret = sprintf(buf, "/tmp/pin_client%d_%4d%02d%02d_%02d_%02d_%02d.log", getpid(),
t->tm_year + BASE_DATE, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
if (ret < 0) {
- printf("%s sprintf fail\n", __func__);
+ fprintf(stderr, "%s sprintf fail\n", __func__);
}
fileName = buf;
}
@@ -100,14 +100,14 @@ static void LogWrite(const char *tag, const char *msg)
{
time_t nowTime = time(nullptr);
if (nowTime == -1) {
- printf("%s fail\n", __func__);
+ fprintf(stderr, "%s fail\n", __func__);
}
struct tm *t = localtime(&nowTime);
char buf[30];
int ret = sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d ", t->tm_year + BASE_DATE, t->tm_mon + 1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
if (ret < 0) {
- printf("%s sprintf fail\n", __func__);
+ fprintf(stderr, "%s sprintf fail\n", __func__);
}
string stag = tag;
string smsg = msg;
@@ -123,12 +123,12 @@ void LogPrint(LogPriority priority, const char *tag, const char *fmt, ...)
va_start(ap, fmt);
int ret = vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
if (ret < 0) {
- printf("%s vsnprintf fail\n", __func__);
+ fprintf(stderr, "%s vsnprintf fail\n", __func__);
}
va_end(ap);
if (priority <= g_priority) {
- printf("%s%s", tag, buf);
+ fprintf(stderr, "%s%s", tag, buf);
}
g_mutex.lock();
diff --git a/lib/Translate/GimpleToPluginOps.cpp b/lib/Translate/GimpleToPluginOps.cpp
index d1b3298..930b430 100644
--- a/lib/Translate/GimpleToPluginOps.cpp
+++ b/lib/Translate/GimpleToPluginOps.cpp
@@ -93,7 +93,7 @@ static IComparisonCode TranslateCmpCode(enum tree_code ccode)
case NE_EXPR:
return IComparisonCode::ne;
default:
- printf("tcc_comparison: %d not suppoted!\n", ccode);
+ fprintf(stderr, "tcc_comparison: %d not suppoted!\n", ccode);
break;
}
return IComparisonCode::UNDEF;
@@ -117,7 +117,7 @@ static enum tree_code TranslateCmpCodeToTreeCode(IComparisonCode iCode)
case IComparisonCode::ne:
return NE_EXPR;
default:
- printf("tcc_comparison not suppoted!\n");
+ fprintf(stderr, "tcc_comparison not suppoted!\n");
break;
}
// FIXME.
@@ -320,8 +320,6 @@ CGnodeOp GimpleToPluginOps::BuildCGnodeOp(uint64_t id)
{
cgraph_node *node;
node = reinterpret_cast<cgraph_node *>(id);
- fprintf(stderr, "dgy client BuildCGnodeOp id : %lld\n", id);
- fprintf(stderr, "dgy client BuildCGnodeOp node name is : %s/%d\n", node->name(), node->order);
mlir::StringRef symbolName(node->name());
bool definition = false;
if (node->definition)
@@ -338,8 +336,6 @@ vector<uint64_t> GimpleToPluginOps::GetCGnodeIDs()
vector<uint64_t> cgnodeIDs;
FOR_EACH_FUNCTION (node) {
int64_t id = reinterpret_cast<int64_t>(reinterpret_cast<void*>(node));
- fprintf(stderr, "dgy client GetCGnodeIDs id : %lld\n", id);
- fprintf(stderr, "dgy client GetCGnodeIDs node name is : %s/%d\n", node->name(), node->order);
cgnodeIDs.push_back(id);
}
return cgnodeIDs;
@@ -506,6 +502,14 @@ vector<FieldDeclOp> GimpleToPluginOps::GetFields(uint64_t declID)
return fields;
}
+PluginIR::PluginTypeBase GimpleToPluginOps::GetDeclType(uint64_t declID)
+{
+ tree decl = reinterpret_cast<tree>(declID);
+ tree type = TREE_TYPE(decl);
+ PluginIR::PluginTypeBase retType = typeTranslator.translateType(reinterpret_cast<uintptr_t>(reinterpret_cast<void*>(type)));
+ return retType;
+}
+
DeclBaseOp GimpleToPluginOps::BuildDecl(IDefineCode code, string name, PluginTypeBase type)
{
tree newtype = make_node(RECORD_TYPE);
@@ -581,8 +585,8 @@ void GimpleToPluginOps::LayoutDecl(uint64_t declId)
{
tree decl = reinterpret_cast<tree>(declId);
layout_decl (decl, 0);
- debug_tree(decl);
- debug_tree(TREE_TYPE(decl));
+ // debug_tree(decl);
+ // debug_tree(TREE_TYPE(decl));
}
void GimpleToPluginOps::SetDeclChain(uint64_t newfieldId, uint64_t fieldId)
@@ -900,19 +904,19 @@ Operation *GimpleToPluginOps::BuildOperation(uint64_t id)
break;
}
case GIMPLE_TRY: {
- printf("try stmt \n");
+ fprintf(stderr, "try stmt \n");
TryOp tryOp = BuildTryOp(id);
ret = tryOp.getOperation();
break;
}
case GIMPLE_CATCH: {
- printf("catch stmt \n");
+ fprintf(stderr, "catch stmt \n");
CatchOp catchOp = BuildCatchOp(id);
ret = catchOp.getOperation();
break;
}
case GIMPLE_BIND: {
- printf("bind stmt \n");
+ fprintf(stderr, "bind stmt \n");
BindOp bindOp = BuildBindOp(id);
ret = bindOp.getOperation();
break;
@@ -1078,7 +1082,7 @@ uint64_t GimpleToPluginOps::CreateGassign(uint64_t blockId, IExprCode iCode,
} else if (vargs.size() == 4) {
ret = gimple_build_assign(vargs[0], TranslateExprCodeToTreeCode(iCode), vargs[1], vargs[2], vargs[3]);
} else {
- printf("ERROR size: %ld.\n", vargs.size());
+ fprintf(stderr, "ERROR size: %ld.\n", vargs.size());
}
basic_block bb = reinterpret_cast<basic_block>(blockId);
if (bb != nullptr) {
@@ -1288,7 +1292,7 @@ EHMntOp GimpleToPluginOps::BuildEHMntOp(uint64_t gehmntId)
uint64_t fndecladdr = reinterpret_cast<uint64_t>(
reinterpret_cast<void*>(gimple_eh_must_not_throw_fndecl(stmt)));
Value fndecl = TreeToValue(fndecladdr);
- printf("build --------------------------------------\n");
+ fprintf(stderr, "build --------------------------------------\n");
EHMntOp ret = builder.create<EHMntOp>(
builder.getUnknownLoc(), gehmntId, fndecl);
return ret;
@@ -1718,7 +1722,7 @@ bool GimpleToPluginOps::ProcessGimpleStmt(intptr_t bbPtr, Region& rg)
gimple *stmt = gsi_stmt (si);
uint64_t id = reinterpret_cast<uint64_t>(reinterpret_cast<void*>(stmt));
if (BuildOperation(id) == nullptr) {
- printf("ERROR: BuildOperation!");
+ fprintf(stderr, "ERROR: BuildOperation!");
}
if(gimple_code(stmt) == GIMPLE_COND || gimple_code(stmt) == GIMPLE_SWITCH
|| gimple_code(stmt) == GIMPLE_TRANSACTION || gimple_code(stmt) == GIMPLE_RESX ||
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。