diff options
| -rw-r--r-- | example/example_06_nectar_gpu/Jamfile.v2 | 14 | ||||
| -rw-r--r-- | example/example_06_nectar_gpu/example.nc | 10 | ||||
| -rw-r--r-- | include/CompilerKit/Detail/Config.h | 4 | ||||
| -rw-r--r-- | share/bjam/nectar-ptx.jam | 19 | ||||
| -rw-r--r-- | snippets/test_snippets/inner.nc | 7 | ||||
| -rw-r--r-- | src/CompilerKit/ck-osx.json | 2 | ||||
| -rw-r--r-- | src/CompilerKit/ck-posix.json | 2 | ||||
| -rw-r--r-- | src/CompilerKit/src/Assemblers/Assembler+AMD64.cpp | 45 | ||||
| -rw-r--r-- | src/CompilerKit/src/Compilers/NectarCompiler+PTX.cpp | 2 | ||||
| -rw-r--r-- | test/.keep (renamed from example/example_05_asm_gpu/.keep) | 0 |
10 files changed, 67 insertions, 38 deletions
diff --git a/example/example_06_nectar_gpu/Jamfile.v2 b/example/example_06_nectar_gpu/Jamfile.v2 new file mode 100644 index 0000000..87f2328 --- /dev/null +++ b/example/example_06_nectar_gpu/Jamfile.v2 @@ -0,0 +1,14 @@ +# +# File: Jamfile.v2 +# Author: Amlal El Mahrouss, +# Copyright 2026, Amlal El Mahrouss, Licensed under the Boost Software License +# + +project gpu_example +: default-build debug +: <toolset>ptx-necdrv +; + +exe example.o + : example.nc ; + diff --git a/example/example_06_nectar_gpu/example.nc b/example/example_06_nectar_gpu/example.nc index 34db3f9..5c9760b 100644 --- a/example/example_06_nectar_gpu/example.nc +++ b/example/example_06_nectar_gpu/example.nc @@ -1,11 +1,5 @@ -extern palloc; - const main() { - let type := 0; - let sz := 0; - let align := 0; - - const ptr := palloc(type, sz, align); - return 0; + const dummy := 0x10; + return dummy; } 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-ptx.jam b/share/bjam/nectar-ptx.jam new file mode 100644 index 0000000..bacc607 --- /dev/null +++ b/share/bjam/nectar-ptx.jam @@ -0,0 +1,19 @@ +# +# File: nectar.jam +# Author: Amlal El Mahrouss, +# 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 ] ] +{ + .debug-configuration = true ; +} + +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 /////////////////////// diff --git a/example/example_05_asm_gpu/.keep b/test/.keep index e69de29..e69de29 100644 --- a/example/example_05_asm_gpu/.keep +++ b/test/.keep |
