From 0c9ac1c8766d9836258f4ab1c1dbc4be29b9ea54 Mon Sep 17 00:00:00 2001 From: abdussamedulutas Date: Sun, 11 Jan 2026 21:34:23 +0300 Subject: [PATCH] =?UTF-8?q?GNU=20Lightning=20=C3=BCzerinde=20=C3=A7al?= =?UTF-8?q?=C4=B1=C5=9F=C4=B1ld=C4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/c_cpp_properties.json | 3 +- .vscode/tasks.json | 46 ++++++++++----- Parsing.cpp | 104 ++++++++++++++++++++++++++-------- Parsing1.cpp | 34 +++++++++++ 4 files changed, 147 insertions(+), 40 deletions(-) create mode 100644 Parsing1.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index c2098a2..f8f443e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,7 +3,8 @@ { "name": "linux-gcc-x64", "includePath": [ - "${workspaceFolder}/**" + "${workspaceFolder}/**", + "${workspaceFolder}/lightning/include" ], "compilerPath": "/usr/bin/gcc", "cStandard": "${default}", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7f4b69d..f401567 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,16 +1,32 @@ { - "version": "2.0.0", - "tasks": [ - { - "label": "build saqut", - "type": "shell", - "command": "g++", - "args": ["-g", "-O0", "Parsing.cpp", "-o", "saqut"], - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": ["$gcc"] - } - ] -} + "version": "2.0.0", + "tasks": [ + { + "type": "cppbuild", + "label": "build saqut", + "command": "/usr/bin/g++", + "args": [ + "-g", // Debug sembolleri açık kalsın + "-O0", // Debug sırasında optimizasyonu kapat (kodun satırları karışmasın) + "./Parsing.cpp", + "${workspaceFolder}/lightning/lib/.libs/liblightning.a", + "-I${workspaceFolder}/lightning/include", + "-D_GNU_SOURCE", + "-ldl", + "-o", + "saqut" // Çıktı ismi sabit olsun (saqut) + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "saQut için özel JIT derleme görevi" + } + ] +} \ No newline at end of file diff --git a/Parsing.cpp b/Parsing.cpp index 298fccd..d8dd422 100644 --- a/Parsing.cpp +++ b/Parsing.cpp @@ -1,34 +1,90 @@ +extern "C" { + #include "lightning.h" +} #include #include -#include -#include -#include -#include "./core/Tokenizer.cpp" -#include "./core/Parser/Parser.cpp" -#include "./core/IR/IR.cpp" +#include +#include +#include -int main() -{ - std::ifstream dosyaOku("source.sqt", std::ios::in | std::ios::binary); - std::string icerik; +extern "C" int saqut_print(int value) { + return value + 1; +} - if (dosyaOku.is_open()) { - std::stringstream buffer; - buffer << dosyaOku.rdbuf(); // Dosya içeriğini buffer'a boşalt - icerik = buffer.str(); - dosyaOku.close(); +int main() { + init_jit("saqut"); + jit_state_t *_jit = jit_new_state(); + + jit_prolog(); + + jit_movi(JIT_V0, 0); // sum = 0 (V0 kayıtçısı sum olsun) + jit_movi(JIT_V1, 1); // a = 1 (V1 kayıtçısı a olsun) + + jit_node_t *loop_start = jit_label(); + + // sum += a (Kayıtçıdan kayıtçıya toplama - Işık hızında) + jit_addr(JIT_V0, JIT_V0, JIT_V1); + + // a++ + jit_addi(JIT_V1, JIT_V1, 1); + // a++ + jit_addi(JIT_V1, JIT_V1, 1); + // a++ + jit_addi(JIT_V1, JIT_V1, 1); + // a++ + jit_addi(JIT_V1, JIT_V1, 1); + + // a < 15000 kontrolü + jit_movi(JIT_R1, 15000); + jit_node_t *if_node = jit_bltr(JIT_V1, JIT_R1); // a < 15000 ise loop_start'a zıpla + jit_patch_at(if_node, loop_start); + + jit_movr(JIT_R0, JIT_V0); // sonucu döndür + jit_retr(JIT_R0); + jit_epilog(); + + // --- ÇALIŞTIRMA VE KAYDETME --- + jit_realize(); + + jit_word_t size; + void* final_code = jit_emit(); + jit_get_code(&size); + + void (*func)() = (void (*)())final_code; + + std::cout << "--- saQut Programı Başlıyor ---" << std::endl; + if (final_code) { + auto start = std::chrono::high_resolution_clock::now(); + func(); + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << "Süre: " << elapsed.count() << " mikrosaniye." << std::endl; } - Tokenizer tokenizer; - Parser parser; - CodeGenerator codeGenerator; - - auto tokens = tokenizer.scan(icerik); - ASTNode * ast = parser.parse(tokens); - - codeGenerator.parse(ast); - codeGenerator.IROpDatas; + if (final_code) { + volatile int prevent_optimization = 0; + auto start = std::chrono::high_resolution_clock::now(); + int sum = 0; + for(int a = 0; a < 15000; a++) { + sum += saqut_print(a); + } + prevent_optimization = sum; + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << "Süre: " << elapsed.count() << " mikrosaniye." << prevent_optimization << std::endl; + } + + std::cout << "--- saQut Programı Bitti ---" << std::endl; + + std::cout << "Kod üretildi. Boyut: " << static_cast(size) << " bayt." << std::endl; + + std::ofstream outfile("calc.bin", std::ios::binary); + outfile.write(reinterpret_cast(final_code), size); + outfile.close(); + + jit_destroy_state(); + finish_jit(); return 0; } \ No newline at end of file diff --git a/Parsing1.cpp b/Parsing1.cpp new file mode 100644 index 0000000..298fccd --- /dev/null +++ b/Parsing1.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include "./core/Tokenizer.cpp" +#include "./core/Parser/Parser.cpp" +#include "./core/IR/IR.cpp" + +int main() +{ + std::ifstream dosyaOku("source.sqt", std::ios::in | std::ios::binary); + std::string icerik; + + if (dosyaOku.is_open()) { + std::stringstream buffer; + buffer << dosyaOku.rdbuf(); // Dosya içeriğini buffer'a boşalt + icerik = buffer.str(); + dosyaOku.close(); + } + + Tokenizer tokenizer; + Parser parser; + CodeGenerator codeGenerator; + + auto tokens = tokenizer.scan(icerik); + ASTNode * ast = parser.parse(tokens); + + codeGenerator.parse(ast); + + codeGenerator.IROpDatas; + + return 0; +} \ No newline at end of file