summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-09 17:43:30 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-09 17:43:30 +0100
commit587943f7e6510078e789155c0c364709c22f4316 (patch)
treeb4406176c141beea5170693c7872a58f2c035836
parentb65c80c1b076e574aca27f84035c464efe50e92f (diff)
[CHORE] Patches for assembler and PTX support.nectar-gpu-improvements-and-bjam
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--include/CompilerKit/Detail/Config.h4
-rw-r--r--share/bjam/nectar-ptx.jam (renamed from share/bjam/nectar.jam)4
-rw-r--r--snippets/test_snippets/inner.nc7
-rw-r--r--src/CompilerKit/ck-osx.json2
-rw-r--r--src/CompilerKit/ck-posix.json2
-rw-r--r--src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp45
-rw-r--r--src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp2
7 files changed, 36 insertions, 30 deletions
diff --git a/include/CompilerKit/Detail/Config.h b/include/CompilerKit/Detail/Config.h
index eeb653d..651904e 100644
--- a/include/CompilerKit/Detail/Config.h
+++ b/include/CompilerKit/Detail/Config.h
@@ -17,8 +17,8 @@
namespace CompilerKit {
inline static constexpr int kBaseYear = 1900;
- using STLString = std::string;
- using RopeString = ocl::tproc::crope;
+using STLString = std::string;
+using RopeString = ocl::tproc::crope;
inline STLString current_date() noexcept {
auto time_data = time(nullptr);
diff --git a/share/bjam/nectar.jam b/share/bjam/nectar-ptx.jam
index 0ce91c6..bacc607 100644
--- a/share/bjam/nectar.jam
+++ b/share/bjam/nectar-ptx.jam
@@ -4,6 +4,8 @@
# Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License
#
+# Supports the Nectar compiler for PTX.
+
import toolset ;
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
@@ -13,3 +15,5 @@ if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
feature.extend toolset : ptx-necdrv ;
+
+
diff --git a/snippets/test_snippets/inner.nc b/snippets/test_snippets/inner.nc
index 5d90b41..3004ea7 100644
--- a/snippets/test_snippets/inner.nc
+++ b/snippets/test_snippets/inner.nc
@@ -1,11 +1,6 @@
-extern exit;
let main()
{
let foo := 42;
-
- const ret_stub():
- foo := 0x10;
- exit(foo);
- return 0x0;
+ return foo;
}
diff --git a/src/CompilerKit/ck-osx.json b/src/CompilerKit/ck-osx.json
index 3aabdcd..de3d082 100644
--- a/src/CompilerKit/ck-osx.json
+++ b/src/CompilerKit/ck-osx.json
@@ -23,5 +23,5 @@
"CK_USE_MACHO_LINKER=1",
"kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)"
],
- "description": "CompilerKit for OSX. CK is the framework behind Nectar."
+ "description": "CompilerKit for OS X. The CompilerKit is the framework behind Nectar."
}
diff --git a/src/CompilerKit/ck-posix.json b/src/CompilerKit/ck-posix.json
index e67072b..69c6777 100644
--- a/src/CompilerKit/ck-posix.json
+++ b/src/CompilerKit/ck-posix.json
@@ -22,6 +22,6 @@
"CK_POSIX=1",
"kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)"
],
- "description": "CompilerKit for POSIX. CompilerKit is the framework behind Nectar."
+ "description": "CompilerKit for POSIX. The CompilerKit is the framework behind Nectar."
}
diff --git a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp
index 6ee1313..db433cb 100644
--- a/src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp
+++ b/src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp
@@ -902,8 +902,9 @@ bool CompilerKit::EncoderAMD64::WriteNumber8(const std::size_t& pos, std::string
bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerKit::STLString file) {
if (CompilerKit::ast_find_needle(line, "public_segment ")) return true;
-
- struct RegMapAMD64 {
+ if (CompilerKit::ast_find_needle(line, "extern_segment ")) return true;
+
+ struct RegMapAMD64 final {
CompilerKit::STLString fName;
i64_byte_t fModRM;
};
@@ -1132,7 +1133,9 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK
std::vector<RegMapAMD64> currentRegList;
- for (auto& reg : kRegisterList) {
+ currentRegList.reserve(3);
+
+ for (auto reg : kRegisterList) {
std::string registerName;
if (bits == 32)
@@ -1211,9 +1214,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK
kAppBytes.emplace_back(0x31);
}
- if (onlyOneReg) {
+ if (onlyOneReg && currentRegList.size() > 0) {
auto num = GetNumber32(line, ",");
-
auto modrm = (0x3 << 6 | currentRegList[0].fModRM);
kAppBytes.emplace_back(0xC7); // prefixed before placing the modrm and then the number.
@@ -1229,17 +1231,20 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK
break;
}
- if (currentRegList[1].fName[0] == 'r' && currentRegList[0].fName[0] == 'e') {
- CompilerKit::Detail::print_error("Invalid combination of operands and registers.",
- "CompilerKit");
- throw std::runtime_error("comb_op_reg");
- }
-
- if (currentRegList[0].fName[0] == 'r' && currentRegList[1].fName[0] == 'e') {
- CompilerKit::Detail::print_error("Invalid combination of operands and registers.",
- "CompilerKit");
- throw std::runtime_error("comb_op_reg");
- }
+
+ if (currentRegList.size() > 0) {
+ if (currentRegList[1].fName[0] == 'r' && currentRegList[0].fName[0] == 'e') {
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.",
+ "CompilerKit");
+ throw std::runtime_error("comb_op_reg");
+ }
+
+ if (currentRegList[0].fName[0] == 'r' && currentRegList[1].fName[0] == 'e') {
+ CompilerKit::Detail::print_error("Invalid combination of operands and registers.",
+ "CompilerKit");
+ throw std::runtime_error("comb_op_reg");
+ }
+ }
if (bits == 16) {
if (currentRegList[0].fName[0] == 'r' || currentRegList[0].fName[0] == 'e') {
@@ -1286,8 +1291,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK
}
// Register lookup table
- struct RegInfo {
- const char* name;
+ struct RegInfo final {
+ CompilerKit::STLString name;
i64_byte_t code;
};
@@ -1537,8 +1542,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(CompilerKit::STLString line, CompilerK
}
// Register lookup table
- struct RegInfo {
- const char* name;
+ struct RegInfo final {
+ CompilerKit::STLString name;
i64_byte_t code;
};
diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp b/src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp
index b6961c2..800433d 100644
--- a/src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp
+++ b/src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp
@@ -3,6 +3,8 @@
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/ne-foss-org/nectar
+/// @note This frontend is based on Nectar's AMD64 frontend.
+
/// BUGS: 0
///////////////////////