Commit e916d8de authored by Victor Yacovlev's avatar Victor Yacovlev

LLVM: Fixed unicode function names handling via GNU AS

parent ca28befc
......@@ -322,7 +322,7 @@ QByteArray LLVMCodeGeneratorPlugin::runExternalToolsToGenerateExecutable(const Q
static const QString LD = bundledToolchainPath + "\\ld.exe";
#else
static const QString LLC = "llc";
static const QString AS = "clang"; // GNU AS does not support Unicode names, so use CLang
static const QString AS = "as"; // GNU AS does not support Unicode names, so use CLang
static const QString LD = "clang"; // libstdc++ might have several names in Linux, use CLang to find it
#endif
......
......@@ -270,8 +270,8 @@ void LLVMGenerator::createMainFunction(const AST::AlgorithmPtr &entryPoint)
if (entryPoint) {
const QString entryPointQName = "__kumir_function_" + entryPoint->header.name;
const CString entryPointName =
CString(entryPointQName.toUtf8().constData());
const CString entryPointName = NameTranslator::screenUtf8Name(entryPointQName);
Q_ASSERT(entryPointName.length() > 0);
llvm::Function * entryPointFunc = currentModule_->getFunction(entryPointName);
......@@ -406,7 +406,7 @@ void LLVMGenerator::addFunction(const AST::AlgorithmPtr kfunc, bool createBody)
const QString actualName = "__kumir_function_" + kfunc->header.name;
// Use UTF-8 names to prevent unambiguous linkage between files
CString name = CString(actualName.toUtf8().data());
CString name = NameTranslator::screenUtf8Name(actualName);
size_t largsCount = 0u;
......@@ -1870,8 +1870,9 @@ llvm::Value * LLVMGenerator::createFunctionCall(llvm::IRBuilder<> &builder, cons
if (alg->header.implType == AST::AlgorhitmCompiled) {
builder.CreateCall(kumirCheckCallStack_);
funcName = CString("__kumir_function_") +
CString(alg->header.name.toUtf8().constData());
funcName = NameTranslator::screenUtf8Name(
"__kumir_function_" + alg->header.name
);
func = currentModule_->getFunction(funcName);
Q_ASSERT(func);
}
......@@ -1880,9 +1881,9 @@ llvm::Value * LLVMGenerator::createFunctionCall(llvm::IRBuilder<> &builder, cons
alg->header.external.moduleName.endsWith(".kod") )
)
{
funcName = CString(alg->header.name.toUtf8().constData());
funcName = CString("__kumir_function_") +
CString(alg->header.name.toUtf8().constData());
funcName = NameTranslator::screenUtf8Name(
"__kumir_function_" + alg->header.name
);
func = currentModule_->getFunction(funcName);
Q_ASSERT(func);
}
......
......@@ -82,6 +82,22 @@ NameTranslator::Namespace& NameTranslator::ns()
return l_.back();
}
CString NameTranslator::screenUtf8Name(const QString &x)
{
CString result;
for (int i=0; i<x.length(); i++) {
const QChar source = x.at(i);
if (0 == source.toLatin1()) {
QString code = "\\" + QString::number(source.unicode(), 16);
result.append(code.toStdString());
}
else {
result.push_back(source.toLatin1());
}
}
return result;
}
QString NameTranslator::suggestName(const QString &x)
{
QString result;
......
......@@ -21,6 +21,7 @@ public:
CString addGlobal(const QString &name);
CString find(const QString & name) const;
static QString suggestName(const QString &x);
static CString screenUtf8Name(const QString &x);
private:
typedef struct {
QString sName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment