diff --git a/Examples/Project/stdio.rf b/Examples/Project/stdio.rf new file mode 100644 index 00000000..3dae6375 --- /dev/null +++ b/Examples/Project/stdio.rf @@ -0,0 +1,9 @@ +{ + "type": "CStatic", + "count": 1, + "components": { + "CNamespace": { + "0": "stdio" + } + } +} \ No newline at end of file diff --git a/Libs/Backends/MIR/Compiler/Include/MIRBackendModule.h b/Libs/Backends/MIR/Compiler/Include/MIRBackendModule.h index d5559832..93e858b3 100644 --- a/Libs/Backends/MIR/Compiler/Include/MIRBackendModule.h +++ b/Libs/Backends/MIR/Compiler/Include/MIRBackendModule.h @@ -31,5 +31,7 @@ namespace rift } void Build(Compiler& compiler) override; + + void PrintBuildFinish(Compiler& compiler) const; }; } // namespace rift diff --git a/Libs/Backends/MIR/Compiler/Src/C2MIR.cpp b/Libs/Backends/MIR/Compiler/Src/C2MIR.cpp index d9368dcf..d754ef4e 100644 --- a/Libs/Backends/MIR/Compiler/Src/C2MIR.cpp +++ b/Libs/Backends/MIR/Compiler/Src/C2MIR.cpp @@ -83,16 +83,15 @@ namespace rift::MIR const CMIRModule& module) { auto getCode = [](void* data) -> p::i32 { - auto* codeLeft = static_cast(data); - if (codeLeft->size() > -1) + const char*& codeLeft = *static_cast(data); + if (*codeLeft == '\0') { - *codeLeft = Strings::RemoveFromStart(*codeLeft, 1); - return *codeLeft->data(); + return EOF; } - return EOF; + return *(codeLeft++); }; - StringView code = module.code; + const char* code = module.code.data(); if (!c2mir_compile(ctx, &options, getCode, &code, name.Data(), nullptr)) { compiler.Error("C to MIR compilation failed"); diff --git a/Libs/Backends/MIR/Compiler/Src/MIRBackendModule.cpp b/Libs/Backends/MIR/Compiler/Src/MIRBackendModule.cpp index 06c2876d..e94e17c5 100644 --- a/Libs/Backends/MIR/Compiler/Src/MIRBackendModule.cpp +++ b/Libs/Backends/MIR/Compiler/Src/MIRBackendModule.cpp @@ -236,6 +236,7 @@ namespace rift if (compiler.HasErrors()) { + PrintBuildFinish(compiler); return; } @@ -260,6 +261,17 @@ namespace rift } MIR_load_module(ctx, module); } + + if (!mainFunc) + { + compiler.Error("Main function not found in MIR generated code."); + } + } + + if (compiler.HasErrors()) + { + PrintBuildFinish(compiler); + return; } OpenSTDLibs(); @@ -283,24 +295,29 @@ namespace rift p::DateTime startTime = p::DateTime::Now(); p::i32 resultCode = entry(); // Run! + MIR_gen_finish(ctx); + if (compiler.config.verbose) { p::Info(" execution -- {:.3f}s\n", (p::DateTime::Now() - startTime).GetTotalSeconds()); p::Info("exit code: {}\n", resultCode); } - MIR_gen_finish(ctx); + PrintBuildFinish(compiler); + + CloseSTDLibs(); + MIR_finish(ctx); + } + void MIRBackend::PrintBuildFinish(Compiler& compiler) const + { if (!compiler.HasErrors()) { p::Info("Build complete."); } else { - p::Info("Build failed: {} errors", compiler.GetErrors().Size()); + p::Error("Build failed: {} errors", compiler.GetErrors().Size()); } - - CloseSTDLibs(); - MIR_finish(ctx); } } // namespace rift \ No newline at end of file diff --git a/Tools/mir/test/test.c b/Tools/mir/test/test.c index b38f78ff..4b09ba1f 100644 --- a/Tools/mir/test/test.c +++ b/Tools/mir/test/test.c @@ -1,10 +1,38 @@ -#include +// Struct Declarations -void main() +// Function Declarations + +// Struct Declarations +typedef struct TestStruct TestStruct; + +// Struct Declarations +typedef struct Welcome Welcome; +typedef struct TestClass TestClass; + +// Function Declarations +void Project_Main_Main(); +void Project_Welcome_Print(long long in1, long long in2); + +// Struct Definitions +struct TestStruct +{}; + +// Struct Definitions +struct Welcome +{}; +struct TestClass +{}; + +// Function Definitions +void Project_Main_Main() +{ + printf("hola"); +} +void Project_Welcome_Print(long long in1, long long in2) {} + +int main() { - bool a = true; - int q = sizeof(int); - int nn = 2433; - printf("%i", q + nn); + Project_Main_Main(); + return 0; }