blob: 7a7978788d9b7a5022ae9ca394c2908675eb5b85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* ========================================
Copyright (C) 2024-2025 Amlal El Mahrouss, licensed under the Apache 2.0 license
======================================== */
#pragma once
#include <CompilerKit/AST.h>
#include <CompilerKit/CodeGenerator.h>
#include <CompilerKit/Detail/Config.h>
#include <CompilerKit/ErrorID.h>
#include <ThirdParty/Dialogs/Dialogs.h>
#include <iostream>
#define kZero64Section ".zero64"
#define kCode64Section ".code64"
#define kData64Section ".data64"
#define kZero128Section ".zero128"
#define kCode128Section ".code128"
#define kData128Section ".data128"
#define kBlank "\e[0;30m"
#define kRed "\e[0;31m"
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
#define kStdOut (std::cout << kRed << "drv: " << kWhite)
#define kStdErr (std::cerr << kYellow << "drv: " << kWhite)
#define kStdEndl std::endl
#define kPrintF kStdOut
#define kPrintErr kStdErr
inline static UInt32 kErrorLimit = 10;
inline static UInt32 kAcceptableErrors = 0;
inline static bool kVerbose = false;
inline static bool kOutputAsBinary = false;
namespace CompilerKit::Detail {
/// @brief Blob structure
struct Blob final {
std::vector<Char> mBlob{}; // PEF code/bss/data blob.
UIntPtr mOffset{0UL}; // the offset of the PEF container header...
explicit operator bool() { return mBlob.empty() && mOffset > 0UL; }
};
inline void print_error(STLString reason, STLString file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
kStdErr << reason << kBlank << std::endl;
if (kAcceptableErrors > kErrorLimit) std::exit(NECTI_EXEC_ERROR);
++kAcceptableErrors;
}
inline void print_warning(STLString reason, STLString file) noexcept {
if (reason[0] == '\n') reason.erase(0, 1);
kStdOut << kYellow << reason << kBlank << std::endl;
}
/// @internal
/// @brief Handler for SIGSEGV signal.
inline void drvi_crash_handler(std::int32_t id) {
CompilerKit::STLString verbose_header = "LIBCOMPILER CRASH REPORT - ";
verbose_header += kDistVersion;
verbose_header += " - ";
verbose_header += CompilerKit::current_date();
for (auto& ch : verbose_header) {
std::cout << '=';
}
std::cout << std::endl;
std::cout << verbose_header << std::endl;
for (auto& ch : verbose_header) {
std::cout << '=';
}
std::cout << std::endl;
kStdOut << "DATE: " << CompilerKit::current_date() << std::endl;
kStdOut << "VERSION: " << kDistVersion << std::endl;
kStdOut << "ERRNO: " << errno << std::endl;
kStdOut << "ERRNO(STRING): " << strerror(errno) << std::endl;
switch (id) {
case SIGSEGV: {
kStdOut << "SIGNAL: Segmentation Fault." << kBlank << std::endl;
break;
}
case SIGABRT: {
kStdOut << "SIGNAL: Aborted." << kBlank << std::endl;
break;
}
}
std::cout << kWhite;
for (auto& ch : verbose_header) {
std::cout << '=';
}
std::cout << std::endl;
std::cout << verbose_header << std::endl;
for (auto& ch : verbose_header) {
std::cout << '=';
}
std::cout << std::endl;
std::exit(NECTI_EXEC_ERROR);
}
} // namespace CompilerKit::Detail
|