summaryrefslogtreecommitdiffhomepage
path: root/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp')
-rw-r--r--src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp
index 4b7fa5f..5d15a77 100644
--- a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp
+++ b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp
@@ -231,18 +231,17 @@ class CompilerFrontendNectarPTX final CK_COMPILER_FRONTEND {
static CompilerFrontendNectarPTX* kFrontend = nullptr;
-static constexpr const char* kPtxRetReg = "%rd0";
-static constexpr const char* kPtxTmpRegA = "%rd1";
-static constexpr const char* kPtxTmpRegB = "%rd2";
-static constexpr const char* kPtxThisReg = "%rd3";
-static constexpr const char* kPtxPredReg = "%p1";
+static constexpr const char* kPtxRetReg = "%rd0";
+static constexpr const char* kPtxTmpRegA = "%rd1";
+static constexpr const char* kPtxTmpRegB = "%rd2";
+static constexpr const char* kPtxThisReg = "%rd3";
+static constexpr const char* kPtxPredReg = "%p1";
static std::vector<CompilerKit::STLString> kRegisterList = {
- "%rd16", "%rd17", "%rd18", "%rd19", "%rd20", "%rd21", "%rd22", "%rd23",
- "%rd24", "%rd25", "%rd26", "%rd27", "%rd28", "%rd29", "%rd30", "%rd31",
- "%rd32", "%rd33", "%rd34", "%rd35", "%rd36", "%rd37", "%rd38", "%rd39",
- "%rd40", "%rd41", "%rd42", "%rd43", "%rd44", "%rd45", "%rd46", "%rd47",
- "%rd48", "%rd49", "%rd50", "%rd51", "%rd52", "%rd53", "%rd54", "%rd55",
+ "%rd16", "%rd17", "%rd18", "%rd19", "%rd20", "%rd21", "%rd22", "%rd23", "%rd24", "%rd25",
+ "%rd26", "%rd27", "%rd28", "%rd29", "%rd30", "%rd31", "%rd32", "%rd33", "%rd34", "%rd35",
+ "%rd36", "%rd37", "%rd38", "%rd39", "%rd40", "%rd41", "%rd42", "%rd43", "%rd44", "%rd45",
+ "%rd46", "%rd47", "%rd48", "%rd49", "%rd50", "%rd51", "%rd52", "%rd53", "%rd54", "%rd55",
"%rd56", "%rd57", "%rd58", "%rd59", "%rd60", "%rd61", "%rd62", "%rd63",
};
@@ -273,7 +272,7 @@ static std::vector<std::pair<CompilerKit::STLString, std::uintptr_t>> kOriginMap
/////////////////////////////////////////////////////////////////////////////////////////
static auto nectar_get_impl_member(const CompilerKit::STLString& class_name,
- const CompilerKit::STLString& member_name) {
+ const CompilerKit::STLString& member_name) -> CompilerStructMap {
// Find or create struct map entry
for (auto& sm : kContext.fStructMapVector) {
if (sm.fName == class_name) {
@@ -281,7 +280,7 @@ static auto nectar_get_impl_member(const CompilerKit::STLString& class_name,
}
}
- return CompilerStructMap{};
+ return {};
}
CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
@@ -289,7 +288,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree;
CompilerKit::STLString syntax_rem_buffer;
- if (text.empty()) return syntax_tree;
+ if (!NectarCheckFrontend(text)) return syntax_tree;
std::size_t index{};
std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list;
@@ -406,7 +405,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
CompilerKit::STLString{kPtxPredReg} + ", " +
CompilerKit::STLString{kPtxTmpRegA} + ", " +
CompilerKit::STLString{kPtxTmpRegB} + ";\n";
- syntax_tree.fUserValue += "@"+ CompilerKit::STLString{kPtxPredReg} + " bra __ret_" +
+ syntax_tree.fUserValue += "@" + CompilerKit::STLString{kPtxPredReg} + " bra __ret_" +
std::to_string(kOrigin) + "_" + kCurrentIfSymbol + ";\n";
kCurrentIfSymbol = std::to_string(kOrigin) + "_" + kCurrentIfSymbol;
@@ -575,8 +574,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
case CompilerKit::KeywordKind::kKeywordKindNew: {
if (auto pos = syntax_tree.fUserValue.find(keyword.first.fKeywordName);
pos != CompilerKit::STLString::npos) {
- syntax_tree.fUserValue.replace(pos, keyword.first.fKeywordName.size(),
- "__operator_new");
+ syntax_tree.fUserValue.replace(pos, keyword.first.fKeywordName.size(), "__operator_new");
}
continue;
@@ -645,9 +643,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
}
if (!nectar_get_variable_ref(nameVar).empty())
- syntax_tree.fUserValue +=
- "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " +
- nectar_get_variable_ref(nameVar) + ";\n";
+ syntax_tree.fUserValue += "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " +
+ nectar_get_variable_ref(nameVar) + ";\n";
if (CompilerKit::KeywordKind::kKeywordKindFunctionAccess != keyword.first.fKeywordKind)
method = valueOfVar.erase(valueOfVar.find("("));
@@ -676,8 +673,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
}
}
- if (!arg.empty())
- buf += "mov.u64 %rd" + std::to_string(index) + ", " + val + ";\n";
+ if (!arg.empty()) buf += "mov.u64 %rd" + std::to_string(index) + ", " + val + ";\n";
arg.clear();
++index;
@@ -694,7 +690,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
syntax_tree.fUserValue += "call.uni ";
syntax_tree.fUserValue +=
(keyword.first.fKeywordName.ends_with('>') ? nectar_get_variable_ref(nameVar)
- : nectar_get_variable_ref(nameVar)) +
+ : nectar_get_variable_ref(nameVar)) +
method + ";\n";
} else {
auto res = buf;
@@ -854,9 +850,8 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile(
kExternalSymbols.insert(mangled + valueOfVar);
syntax_tree.fUserValue += "call " + mangled + valueOfVar + ";\n";
- syntax_tree.fUserValue +=
- instr + nectar_get_variable_ref(varName) + ", " +
- CompilerKit::STLString{kPtxRetReg} + ";\n";
+ syntax_tree.fUserValue += instr + nectar_get_variable_ref(varName) + ", " +
+ CompilerKit::STLString{kPtxRetReg} + ";\n";
}
break;
@@ -1432,7 +1427,7 @@ static CompilerKit::STLString nectar_generate_constructor_call(
nectar_pop_scope();
CompilerKit::STLString code;
- auto objReg = nectar_allocate_register(obj_name);
+ auto objReg = nectar_allocate_register(obj_name);
if (!objReg.empty()) {
code += "mov.u64 " + CompilerKit::STLString{kPtxThisReg} + ", " + objReg + ";\n";
}
@@ -1467,8 +1462,8 @@ static CompilerKit::STLString nectar_generate_destructor_call(
static void nectar_process_function_parameters(const std::vector<CompilerKit::STLString>& args) {
for (size_t i = 0; i < args.size(); ++i) {
VariableInfo param;
- param.fName = "arg" + std::to_string(i);
- param.fLocation = VarLocation::kRegister;
+ param.fName = "arg" + std::to_string(i);
+ param.fLocation = VarLocation::kRegister;
if (i < kRegisterConventionCallList.size()) {
param.fRegister = kRegisterConventionCallList[i];
} else {