aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/client.cpp107
-rw-r--r--core/salis.c45
-rw-r--r--core/server.c24
3 files changed, 102 insertions, 74 deletions
diff --git a/core/client.cpp b/core/client.cpp
index 2ca419a..d541129 100644
--- a/core/client.cpp
+++ b/core/client.cpp
@@ -1,26 +1,25 @@
-// [SECTION] Includes
-// [SECTION] Defines
-// [SECTION] Status enum
-// [SECTION] String comparator declaration
-// [SECTION] Trace declarations
-// [SECTION] Plot declarations
-// [SECTION] Plots
-// [SECTION] Heatmap colormap
-// [SECTION] Global variables
-// [SECTION] String comparator definition
-// [SECTION] Trace (base) definition
-// [SECTION] TraceNamed definition
-// [SECTION] TraceHeatmap definition
-// [SECTION] Plot (base) definition
-// [SECTION] PlotLines definition
-// [SECTION] PlotStacked definition
-// [SECTION] PlotHeatmap definition
-// [SECTION] Data functions
-// [SECTION] GUI functions
-// [SECTION] Main functions
+// index
+// [section] includes
+// [section] macros & enums
+// [section] string comparator declaration
+// [section] trace declarations
+// [section] plot declarations
+// [section] plots
+// [section] global variables
+// [section] string comparator definition
+// [section] Trace (base) definition
+// [section] TraceNamed definition
+// [section] TraceHeatmap definition
+// [section] Plot (base) definition
+// [section] PlotLines definition
+// [section] PlotStacked definition
+// [section] PlotHeatmap definition
+// [section] data functions
+// [section] gui functions
+// [section] main functions
// ----------------------------------------------------------------------------
-// [SECTION] Includes
+// [section] includes
// ----------------------------------------------------------------------------
#include <arpa/inet.h>
#include <GL/glu.h>
@@ -41,7 +40,7 @@
#include "logger.c"
// ----------------------------------------------------------------------------
-// [SECTION] Defines
+// [section] macros & enums
// ----------------------------------------------------------------------------
#define COLOR_BLACK ImVec4(0.f, 0.f, 0.f, 1.f)
#define FONT_SIZE 12.f
@@ -75,9 +74,6 @@
#define DEFVAL_HM_LEFT 0l
#define DEFVAL_HM_PIXEL_COUNT 0x400l // must equal HM_PIXEL_COUNT in server.c
-// ----------------------------------------------------------------------------
-// [SECTION] Status enum
-// ----------------------------------------------------------------------------
enum Status {
STATUS_STOPPED,
STATUS_RUNNING,
@@ -86,14 +82,14 @@ enum Status {
};
// ----------------------------------------------------------------------------
-// [SECTION] String comparator declaration
+// [section] string comparator declaration
// ----------------------------------------------------------------------------
struct StringComparator {
bool operator()(const char *a, const char *b) const;
};
// ----------------------------------------------------------------------------
-// [SECTION] Trace declarations
+// [section] trace declarations
// ----------------------------------------------------------------------------
template <class T>
struct Trace : public std::vector<T> {
@@ -134,7 +130,7 @@ struct TraceHeatmap : public TraceNamed<T> {
};
// ----------------------------------------------------------------------------
-// [SECTION] Plot declarations
+// [section] plot declarations
// ----------------------------------------------------------------------------
typedef int (*AxisFormatter)(double value, char *buff, int size, void *data);
@@ -201,7 +197,7 @@ private:
};
// ----------------------------------------------------------------------------
-// [SECTION] Plots
+// [section] plots
// ----------------------------------------------------------------------------
#include "plots.cpp"
@@ -282,23 +278,7 @@ std::array g_core_plots_heatmaps = std::to_array<PlotHeatmap>({
});
// ----------------------------------------------------------------------------
-// [SECTION] Heatmap colormap
-// ----------------------------------------------------------------------------
-std::array g_hm_colormap = std::to_array<ImVec4>({
- {0.000f, 0.000f, 0.016f, 1.f},
- {0.106f, 0.047f, 0.255f, 1.f},
- {0.290f, 0.047f, 0.420f, 1.f},
- {0.471f, 0.110f, 0.427f, 1.f},
- {0.647f, 0.173f, 0.376f, 1.f},
- {0.812f, 0.267f, 0.275f, 1.f},
- {0.929f, 0.412f, 0.145f, 1.f},
- {0.984f, 0.608f, 0.024f, 1.f},
- {0.969f, 0.820f, 0.239f, 1.f},
- {0.988f, 1.000f, 0.643f, 1.f},
-});
-
-// ----------------------------------------------------------------------------
-// [SECTION] Global variables
+// [section] global variables
// ----------------------------------------------------------------------------
GLFWwindow *g_window;
ImGuiIO *g_imgui_io;
@@ -355,17 +335,30 @@ std::vector<Plot *> g_plots;
Trace<double> g_x_axis_double;
Trace<double> g_zero_trace;
+std::array g_hm_colormap = std::to_array<ImVec4>({
+ {0.000f, 0.000f, 0.016f, 1.f},
+ {0.106f, 0.047f, 0.255f, 1.f},
+ {0.290f, 0.047f, 0.420f, 1.f},
+ {0.471f, 0.110f, 0.427f, 1.f},
+ {0.647f, 0.173f, 0.376f, 1.f},
+ {0.812f, 0.267f, 0.275f, 1.f},
+ {0.929f, 0.412f, 0.145f, 1.f},
+ {0.984f, 0.608f, 0.024f, 1.f},
+ {0.969f, 0.820f, 0.239f, 1.f},
+ {0.988f, 1.000f, 0.643f, 1.f},
+});
+
PFNGLCOPYIMAGESUBDATAPROC glCopyImageSubData;
// ----------------------------------------------------------------------------
-// [SECTION] String comparator definition
+// [section] string comparator definition
// ----------------------------------------------------------------------------
bool StringComparator::operator()(const char *a, const char *b) const {
return strcmp(a, b) < 0;
}
// ----------------------------------------------------------------------------
-// [SECTION] Trace (base) definition
+// [section] Trace (base) definition
// ----------------------------------------------------------------------------
template <class T>
Trace<T>::Trace() : std::vector<T>() {}
@@ -430,7 +423,7 @@ void Trace<T>::trim_spec(int64_t multiplier) {
}
// ----------------------------------------------------------------------------
-// [SECTION] TraceNamed definition
+// [section] TraceNamed definition
// ----------------------------------------------------------------------------
template <class T>
TraceNamed<T>::TraceNamed(const char *name, const char *label) : m_name(name), m_label(label) {}
@@ -446,7 +439,7 @@ const char *TraceNamed<T>::get_label() const {
}
// ----------------------------------------------------------------------------
-// [SECTION] TraceHeatmap definition
+// [section] TraceHeatmap definition
// ----------------------------------------------------------------------------
template <class T>
TraceHeatmap<T>::TraceHeatmap(const char *name, const char *name_fmt) : TraceNamed<T>(name, name_fmt) {}
@@ -469,7 +462,7 @@ void TraceHeatmap<T>::validate() const {
#endif
// ----------------------------------------------------------------------------
-// [SECTION] Plot (base) definition
+// [section] Plot (base) definition
// ----------------------------------------------------------------------------
Plot::Plot(const char *name, const char *section) : m_visible(true), m_name(name), m_section(section) {}
@@ -531,7 +524,7 @@ void Plot::render_post(const ImVec2 &frame_size) {
}
// ----------------------------------------------------------------------------
-// [SECTION] PlotLines definition
+// [section] PlotLines definition
// ----------------------------------------------------------------------------
PlotLines::PlotLines(const char *name, const char *section, std::vector<const char *> trace_keys) : Plot(name, section), m_trace_keys(trace_keys) {}
@@ -549,7 +542,7 @@ void PlotLines::render_internal(const ImVec2 &frame_size) {
}
// ----------------------------------------------------------------------------
-// [SECTION] PlotStacked definition
+// [section] PlotStacked definition
// ----------------------------------------------------------------------------
PlotStacked::PlotStacked(const char *name, const char *section, std::vector<const char *> trace_keys) : Plot(name, section), m_trace_keys(trace_keys), m_trace_states(trace_keys.size(), true), m_trace_totals(), m_trace_normals(trace_keys.size()), m_needs_reset(true) {}
@@ -651,7 +644,7 @@ void PlotStacked::render_internal(const ImVec2 &frame_size) {
}
// ----------------------------------------------------------------------------
-// [SECTION] PlotHeatmap definition
+// [section] PlotHeatmap definition
// ----------------------------------------------------------------------------
PlotHeatmap::PlotHeatmap(const char *name, const char *section, const char *trace_key) : Plot(name, section), m_trace_key(trace_key), m_tex_scale_pow(-1.f), m_tex_scale_high(0.f), m_tex_rendered_last(0), m_rows_rendered(0), m_tex_id(0), m_tex_render(), m_needs_reset(true) {}
@@ -797,7 +790,7 @@ void PlotHeatmap::render_post(const ImVec2 &frame_size) {
}
// ----------------------------------------------------------------------------
-// [SECTION] Data functions
+// [section] data functions
// ----------------------------------------------------------------------------
int64_t data_max_hm_pixel_pow(void) {
return (int64_t)floor(log2((double)(MVEC_SIZE - g_hm_left) / (double)g_hm_pixel_count));
@@ -987,7 +980,7 @@ void data_stop_fetching(void) {
}
// ----------------------------------------------------------------------------
-// [SECTION] GUI functions
+// [section] gui functions
// ----------------------------------------------------------------------------
void gui_render_data_input(const char *label, int64_t *target) {
assert(target);
@@ -1276,7 +1269,7 @@ void gui_render(void) {
}
// ----------------------------------------------------------------------------
-// [SECTION] Main functions
+// [section] main functions
// ----------------------------------------------------------------------------
void app_sig_handler(int signo) {
(void)signo;
diff --git a/core/salis.c b/core/salis.c
index 3740f3c..9f9a3d0 100644
--- a/core/salis.c
+++ b/core/salis.c
@@ -1,3 +1,19 @@
+// index
+// [section] includes
+// [section] macros & enums
+// [section] structs
+// [section] globals
+// [section] architecture forward declarations
+// [section] memory vector functions
+// [section] mutator functions
+// [section] process functions
+// [section] core functions
+// [section] salis functions
+// [section] architecture & ui includes
+
+// ----------------------------------------------------------------------------
+// [section] includes
+// ----------------------------------------------------------------------------
#include <assert.h>
#include <sqlite3.h>
#include <stdbool.h>
@@ -12,6 +28,9 @@
#include "compress.c"
#include "sql.c"
+// ----------------------------------------------------------------------------
+// [section] macros & enums
+// ----------------------------------------------------------------------------
#define INST_CAP 0x80
#define INST_MASK 0x7f
#define IPC_FLAG 0x80
@@ -24,6 +43,9 @@
EVENT_ARRAY(core, 2, bev) /* birth events array */
#define EVENT_ARRAYS_COUNT 3
+// ----------------------------------------------------------------------------
+// [section] structs
+// ----------------------------------------------------------------------------
struct Proc {
#define PROC_FIELD(type, name) type name;
PROC_FIELDS
@@ -71,7 +93,9 @@ struct Core {
uint8_t tgap[THREAD_GAP];
};
-// Globals
+// ----------------------------------------------------------------------------
+// [section] globals
+// ----------------------------------------------------------------------------
struct Core g_cores[CORES];
uint64_t g_steps;
uint64_t g_syncs;
@@ -84,7 +108,9 @@ char g_asav_pbuf[AUTOSAVE_NAME_LEN];
thrd_t g_eva_thrds[CORES][EVENT_ARRAYS_COUNT];
struct DeflateParams g_eva_deflate_params[CORES][EVENT_ARRAYS_COUNT];
-// Each architecture must define these functions
+// ----------------------------------------------------------------------------
+// [section] architecture forward declarations
+// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW)
void arch_core_init(struct Core *core);
#endif
@@ -122,7 +148,7 @@ void arch_push_data_header(void);
void arch_push_data_line(void);
// ----------------------------------------------------------------------------
-// Memory vector functions
+// [section] memory vector functions
// ----------------------------------------------------------------------------
#if defined(MVEC_LOOP)
uint64_t mvec_loop(uint64_t addr) {
@@ -282,7 +308,7 @@ uint64_t mvec_get_owner(const struct Core *core, uint64_t addr) {
}
// ----------------------------------------------------------------------------
-// Mutator functions
+// [section] mutator functions
// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW)
uint64_t muta_smix(uint64_t *seed) {
@@ -333,7 +359,7 @@ void muta_cosmic_ray(struct Core *core) {
}
// ----------------------------------------------------------------------------
-// Process functions
+// [section] process functions
// ----------------------------------------------------------------------------
void proc_new(struct Core *core, const struct Proc *proc) {
assert(core);
@@ -402,7 +428,7 @@ struct Proc *proc_fetch(struct Core *core, uint64_t pix) {
}
// ----------------------------------------------------------------------------
-// Core functions
+// [section] core functions
// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW) || defined(COMMAND_LOAD)
void core_save(FILE *f, const struct Core *core) {
@@ -621,7 +647,7 @@ void core_step(struct Core *core) {
}
// ----------------------------------------------------------------------------
-// Main salis functions
+// [section] salis functions
// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW) || defined(COMMAND_LOAD)
void salis_save(const char *path) {
@@ -1071,13 +1097,10 @@ void salis_free(void) {
}
// ----------------------------------------------------------------------------
-// Architecture
+// [section] architecture & ui includes
// ----------------------------------------------------------------------------
#include "arch.c"
-// ----------------------------------------------------------------------------
-// UI
-// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW) || defined(COMMAND_LOAD)
#include "ui.c"
#endif
diff --git a/core/server.c b/core/server.c
index 82b6da5..9a06825 100644
--- a/core/server.c
+++ b/core/server.c
@@ -1,3 +1,15 @@
+// index
+// [section] includes
+// [section] macros
+// [section] structs
+// [section] globals
+// [section] event array render function
+// [section] sql callbacks
+// [section] main functions
+
+// ----------------------------------------------------------------------------
+// [section] includes
+// ----------------------------------------------------------------------------
#include <arpa/inet.h>
#include <assert.h>
#include <json-c/json.h>
@@ -12,14 +24,14 @@
#include "sql.c"
// ----------------------------------------------------------------------------
-// Defines
+// [section] macros
// ----------------------------------------------------------------------------
#define BACKLOG 10
#define EVA_SIZE (sizeof(uint64_t) * MVEC_SIZE)
#define MAX_HM_PIXEL_COUNT 0x400 // must equal DEFVAL_HM_PIXEL_COUNT in client.cpp
// ----------------------------------------------------------------------------
-// Declarations
+// [section] structs
// ----------------------------------------------------------------------------
struct Socket {
int fd;
@@ -43,13 +55,13 @@ struct RenderContext {
};
// ----------------------------------------------------------------------------
-// Globals
+// [section] globals
// ----------------------------------------------------------------------------
struct json_object *g_response_header;
size_t g_blob_count;
// ----------------------------------------------------------------------------
-// Event array render function
+// [section] event array render function
// ----------------------------------------------------------------------------
int eva_render(void *data) {
assert(data);
@@ -101,7 +113,7 @@ int eva_render(void *data) {
}
// ----------------------------------------------------------------------------
-// SQL callbacks
+// [section] sql callbacks
// ----------------------------------------------------------------------------
void sql_callback_add_column_name(sqlite3_stmt *sql_stmt, void *data) {
assert(sql_stmt);
@@ -168,7 +180,7 @@ void sql_callback_add_data(sqlite3_stmt *sql_stmt, void *data) {
}
// ----------------------------------------------------------------------------
-// Main functions
+// [section] main functions
// ----------------------------------------------------------------------------
void sig_handler(int signo) {
(void)signo;