commit 80c5c4891b1d821b49dacb0a9677ed98f60c63a3
parent dc99e28ea8f9a5c217e2cb9ccebf63c3953f6384
Author: kyle <kyle@getaddrinfo.net>
Date: Sat, 2 Apr 2016 14:57:22 -0600
gl: prefix some files
Diffstat:
6 files changed, 309 insertions(+), 309 deletions(-)
diff --git a/src/Jamfile b/src/Jamfile
@@ -6,8 +6,8 @@ INSTRUMENT_SRCS =
instrument_ast_visitor.cc ;
CITRUN_SRCS =
- main.cc
- runtime_process.cc
+ gl_main.cc
+ gl_runtime_conn.cc
af_unix.cc
view.cc
demo-atlas.cc
diff --git a/src/gl_main.cc b/src/gl_main.cc
@@ -0,0 +1,209 @@
+#include <err.h>
+
+#include <iostream>
+#include <vector>
+
+#include "af_unix.h"
+#include "gl_runtime_conn.h"
+#include "view.h"
+
+#include "demo-buffer.h"
+#include "demo-font.h"
+
+
+class window {
+public:
+ window(int argc, char *argv[]);
+ void start();
+
+ static void idle_step();
+ static void print_fps(int);
+ static void next_frame(View *);
+
+ static FT_Library ft_library;
+ static FT_Face ft_face;
+
+ static demo_font_t *font;
+ static demo_buffer_t *buffer;
+
+ static View *static_vu;
+ static af_unix socket;
+ static std::vector<drawable*> drawables;
+private:
+ static void display();
+ static void reshape_func(int, int);
+ static void keyboard_func(unsigned char, int, int);
+ static void special_func(int, int, int);
+ static void mouse_func(int, int, int, int);
+ static void motion_func(int, int);
+
+ demo_glstate_t *st;
+};
+
+std::vector<drawable*> window::drawables;
+af_unix window::socket;
+View *window::static_vu;
+
+FT_Library window::ft_library;
+FT_Face window::ft_face;
+
+demo_font_t *window::font;
+demo_buffer_t *window::buffer;
+
+window::window(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(1600, 1200);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
+ int window = glutCreateWindow("Source Code Visualizer");
+ glutReshapeFunc(reshape_func);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(keyboard_func);
+ glutSpecialFunc(special_func);
+ glutMouseFunc(mouse_func);
+ glutMotionFunc(motion_func);
+
+ GLenum glew_status = glewInit();
+ if (GLEW_OK != glew_status)
+ errx(1, "%s", glewGetErrorString(glew_status));
+ if (!glewIsSupported("GL_VERSION_2_0"))
+ errx(1, "No support for OpenGL 2.0 found");
+
+ st = demo_glstate_create();
+ buffer = demo_buffer_create();
+
+ static_vu = new View(st, buffer);
+ static_vu->print_help();
+
+ FT_Init_FreeType(&ft_library);
+
+#if defined(__OpenBSD__)
+ const char *font_path = "/usr/X11R6/lib/X11/fonts/TTF/DejaVuSansMono.ttf";
+#elif defined(__APPLE__)
+ const char *font_path = "/Library/Fonts/Andale Mono.ttf";
+#elif defined(__gnu_linux__)
+ // Assuming Debian here
+ const char *font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf";
+#endif
+ ft_face = NULL;
+ FT_New_Face(ft_library, font_path, /* face_index */ 0, &ft_face);
+
+ font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
+
+ static_vu->setup();
+
+ // This creates the socket with SOCK_NONBLOCK
+ socket.set_listen();
+
+ static_vu->toggle_animation();
+}
+
+void
+window::reshape_func(int width, int height)
+{
+ static_vu->reshape_func(width, height);
+}
+
+void
+window::keyboard_func(unsigned char key, int x, int y)
+{
+ static_vu->keyboard_func(key, x, y);
+}
+
+void
+window::special_func(int key, int x, int y)
+{
+ static_vu->special_func(key, x, y);
+}
+
+void
+window::mouse_func(int button, int state, int x, int y)
+{
+ static_vu->mouse_func(button, state, x, y);
+}
+
+void
+window::motion_func(int x, int y)
+{
+ static_vu->motion_func(x, y);
+}
+
+void
+window::start()
+{
+ glutMainLoop();
+}
+
+void
+window::display(void)
+{
+ static_vu->display();
+}
+
+
+/* Return current time in milli-seconds */
+static long
+current_time(void)
+{
+ return glutGet(GLUT_ELAPSED_TIME);
+}
+
+void
+window::next_frame(View *vu)
+{
+ af_unix *temp_socket = window::socket.accept();
+ if (temp_socket)
+ window::drawables.push_back(new RuntimeProcess(temp_socket, buffer, font));
+
+ for (auto &i : window::drawables)
+ i->idle();
+
+ glutPostRedisplay ();
+}
+
+void
+window::idle_step(void)
+{
+ View *vu = static_vu;
+ if (vu->animate) {
+ next_frame (vu);
+ }
+ else
+ glutIdleFunc(NULL);
+}
+
+void
+window::print_fps(int ms)
+{
+ View *vu = static_vu;
+ if (vu->animate) {
+ glutTimerFunc (ms, print_fps, ms);
+ long t = current_time ();
+ LOGI ("%gfps\n", vu->num_frames * 1000. / (t - vu->fps_start_time));
+ vu->num_frames = 0;
+ vu->fps_start_time = t;
+ } else
+ vu->has_fps_timer = false;
+}
+
+void
+start_animation()
+{
+ View *vu = window::static_vu;
+ vu->num_frames = 0;
+ vu->last_frame_time = vu->fps_start_time = current_time();
+ glutIdleFunc(window::idle_step);
+ if (!vu->has_fps_timer) {
+ vu->has_fps_timer = true;
+ glutTimerFunc (5000, window::print_fps, 5000);
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ window glut_window(argc, argv);
+ glut_window.start();
+
+ return 0;
+}
diff --git a/src/gl_runtime_conn.cc b/src/gl_runtime_conn.cc
@@ -0,0 +1,98 @@
+#include <err.h>
+
+#include <cassert>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+
+#include "gl_runtime_conn.h"
+
+RuntimeProcess::RuntimeProcess(af_unix *sock, demo_buffer_t *buf, demo_font_t *f) :
+ socket(sock),
+ buffer(buf),
+ font(f)
+{
+ uint64_t num_tus;
+ socket->read_all(num_tus);
+ translation_units.resize(num_tus);
+
+ assert(sizeof(pid_t) == 4);
+ socket->read_all((uint8_t *)&process_id, 4);
+ socket->read_all((uint8_t *)&parent_process_id, 4);
+ socket->read_all((uint8_t *)&process_group, 4);
+
+ std::stringstream ss;
+ ss << "Translation Units: " << num_tus << std::endl;
+ ss << "Process ID: " << process_id << std::endl;
+ ss << "Parent Process ID: " << parent_process_id << std::endl;
+ ss << "Process Group: " << process_group << std::endl;
+
+ glyphy_point_t top_left = { 0, 0 };
+ demo_buffer_move_to(buffer, &top_left);
+ demo_buffer_add_text(buffer, ss.str().c_str(), font, 1);
+
+ for (auto ¤t_unit : translation_units) {
+ top_left.y = 4;
+
+ uint64_t file_name_sz;
+ socket->read_all(file_name_sz);
+
+ current_unit.file_name.resize(file_name_sz);
+ socket->read_all((uint8_t *)¤t_unit.file_name[0], file_name_sz);
+
+ read_file(current_unit.file_name, top_left);
+ top_left.x += 50;
+
+ socket->read_all((uint8_t *)¤t_unit.num_lines, 4);
+ current_unit.execution_counts.resize(current_unit.num_lines);
+
+ socket->read_all((uint8_t *)¤t_unit.inst_sites, 4);
+ }
+
+ demo_font_print_stats(font);
+}
+
+void
+RuntimeProcess::read_file(std::string file_name, glyphy_point_t top_left)
+{
+ std::string line;
+ std::ifstream file_stream(file_name);
+
+ if (file_stream.is_open() == 0)
+ errx(1, "ifstream.open()");
+
+ while (std::getline(file_stream, line)) {
+ size_t tab_pos = 0;
+ // Find and replace replace all tabs with spaces
+ while ((tab_pos = line.find('\t')) != std::string::npos) {
+ int rem = tab_pos % 8;
+ line.erase(tab_pos, 1);
+ line.insert(tab_pos, std::string(8 - rem, ' '));
+ }
+
+ demo_buffer_move_to(buffer, &top_left);
+ demo_buffer_add_text(buffer, line.c_str(), font, 1);
+ ++top_left.y;
+ }
+
+ file_stream.close();
+}
+
+void
+RuntimeProcess::draw()
+{
+}
+
+void
+RuntimeProcess::idle()
+{
+ for (auto &trans_unit : translation_units) {
+ size_t bytes_total = trans_unit.num_lines * sizeof(uint64_t);
+ assert(socket->read_all((uint8_t *)&trans_unit.execution_counts[0], bytes_total) == bytes_total);
+ }
+
+ // Send response back
+ uint8_t msg_type = 1;
+ assert(socket->write_all(&msg_type, 1) == 1);
+}
diff --git a/src/runtime_process.h b/src/gl_runtime_conn.h
diff --git a/src/main.cc b/src/main.cc
@@ -1,209 +0,0 @@
-#include <err.h>
-
-#include <iostream>
-#include <vector>
-
-#include "af_unix.h"
-#include "runtime_process.h"
-#include "view.h"
-
-#include "demo-buffer.h"
-#include "demo-font.h"
-
-
-class window {
-public:
- window(int argc, char *argv[]);
- void start();
-
- static void idle_step();
- static void print_fps(int);
- static void next_frame(View *);
-
- static FT_Library ft_library;
- static FT_Face ft_face;
-
- static demo_font_t *font;
- static demo_buffer_t *buffer;
-
- static View *static_vu;
- static af_unix socket;
- static std::vector<drawable*> drawables;
-private:
- static void display();
- static void reshape_func(int, int);
- static void keyboard_func(unsigned char, int, int);
- static void special_func(int, int, int);
- static void mouse_func(int, int, int, int);
- static void motion_func(int, int);
-
- demo_glstate_t *st;
-};
-
-std::vector<drawable*> window::drawables;
-af_unix window::socket;
-View *window::static_vu;
-
-FT_Library window::ft_library;
-FT_Face window::ft_face;
-
-demo_font_t *window::font;
-demo_buffer_t *window::buffer;
-
-window::window(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(1600, 1200);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- int window = glutCreateWindow("Source Code Visualizer");
- glutReshapeFunc(reshape_func);
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard_func);
- glutSpecialFunc(special_func);
- glutMouseFunc(mouse_func);
- glutMotionFunc(motion_func);
-
- GLenum glew_status = glewInit();
- if (GLEW_OK != glew_status)
- errx(1, "%s", glewGetErrorString(glew_status));
- if (!glewIsSupported("GL_VERSION_2_0"))
- errx(1, "No support for OpenGL 2.0 found");
-
- st = demo_glstate_create();
- buffer = demo_buffer_create();
-
- static_vu = new View(st, buffer);
- static_vu->print_help();
-
- FT_Init_FreeType(&ft_library);
-
-#if defined(__OpenBSD__)
- const char *font_path = "/usr/X11R6/lib/X11/fonts/TTF/DejaVuSansMono.ttf";
-#elif defined(__APPLE__)
- const char *font_path = "/Library/Fonts/Andale Mono.ttf";
-#elif defined(__gnu_linux__)
- // Assuming Debian here
- const char *font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf";
-#endif
- ft_face = NULL;
- FT_New_Face(ft_library, font_path, /* face_index */ 0, &ft_face);
-
- font = demo_font_create(ft_face, demo_glstate_get_atlas(st));
-
- static_vu->setup();
-
- // This creates the socket with SOCK_NONBLOCK
- socket.set_listen();
-
- static_vu->toggle_animation();
-}
-
-void
-window::reshape_func(int width, int height)
-{
- static_vu->reshape_func(width, height);
-}
-
-void
-window::keyboard_func(unsigned char key, int x, int y)
-{
- static_vu->keyboard_func(key, x, y);
-}
-
-void
-window::special_func(int key, int x, int y)
-{
- static_vu->special_func(key, x, y);
-}
-
-void
-window::mouse_func(int button, int state, int x, int y)
-{
- static_vu->mouse_func(button, state, x, y);
-}
-
-void
-window::motion_func(int x, int y)
-{
- static_vu->motion_func(x, y);
-}
-
-void
-window::start()
-{
- glutMainLoop();
-}
-
-void
-window::display(void)
-{
- static_vu->display();
-}
-
-
-/* Return current time in milli-seconds */
-static long
-current_time(void)
-{
- return glutGet(GLUT_ELAPSED_TIME);
-}
-
-void
-window::next_frame(View *vu)
-{
- af_unix *temp_socket = window::socket.accept();
- if (temp_socket)
- window::drawables.push_back(new RuntimeProcess(temp_socket, buffer, font));
-
- for (auto &i : window::drawables)
- i->idle();
-
- glutPostRedisplay ();
-}
-
-void
-window::idle_step(void)
-{
- View *vu = static_vu;
- if (vu->animate) {
- next_frame (vu);
- }
- else
- glutIdleFunc(NULL);
-}
-
-void
-window::print_fps(int ms)
-{
- View *vu = static_vu;
- if (vu->animate) {
- glutTimerFunc (ms, print_fps, ms);
- long t = current_time ();
- LOGI ("%gfps\n", vu->num_frames * 1000. / (t - vu->fps_start_time));
- vu->num_frames = 0;
- vu->fps_start_time = t;
- } else
- vu->has_fps_timer = false;
-}
-
-void
-start_animation()
-{
- View *vu = window::static_vu;
- vu->num_frames = 0;
- vu->last_frame_time = vu->fps_start_time = current_time();
- glutIdleFunc(window::idle_step);
- if (!vu->has_fps_timer) {
- vu->has_fps_timer = true;
- glutTimerFunc (5000, window::print_fps, 5000);
- }
-}
-
-int
-main(int argc, char *argv[])
-{
- window glut_window(argc, argv);
- glut_window.start();
-
- return 0;
-}
diff --git a/src/runtime_process.cc b/src/runtime_process.cc
@@ -1,98 +0,0 @@
-#include <err.h>
-
-#include <cassert>
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <vector>
-
-#include "runtime_process.h"
-
-RuntimeProcess::RuntimeProcess(af_unix *sock, demo_buffer_t *buf, demo_font_t *f) :
- socket(sock),
- buffer(buf),
- font(f)
-{
- uint64_t num_tus;
- socket->read_all(num_tus);
- translation_units.resize(num_tus);
-
- assert(sizeof(pid_t) == 4);
- socket->read_all((uint8_t *)&process_id, 4);
- socket->read_all((uint8_t *)&parent_process_id, 4);
- socket->read_all((uint8_t *)&process_group, 4);
-
- std::stringstream ss;
- ss << "Translation Units: " << num_tus << std::endl;
- ss << "Process ID: " << process_id << std::endl;
- ss << "Parent Process ID: " << parent_process_id << std::endl;
- ss << "Process Group: " << process_group << std::endl;
-
- glyphy_point_t top_left = { 0, 0 };
- demo_buffer_move_to(buffer, &top_left);
- demo_buffer_add_text(buffer, ss.str().c_str(), font, 1);
-
- for (auto ¤t_unit : translation_units) {
- top_left.y = 4;
-
- uint64_t file_name_sz;
- socket->read_all(file_name_sz);
-
- current_unit.file_name.resize(file_name_sz);
- socket->read_all((uint8_t *)¤t_unit.file_name[0], file_name_sz);
-
- read_file(current_unit.file_name, top_left);
- top_left.x += 50;
-
- socket->read_all((uint8_t *)¤t_unit.num_lines, 4);
- current_unit.execution_counts.resize(current_unit.num_lines);
-
- socket->read_all((uint8_t *)¤t_unit.inst_sites, 4);
- }
-
- demo_font_print_stats(font);
-}
-
-void
-RuntimeProcess::read_file(std::string file_name, glyphy_point_t top_left)
-{
- std::string line;
- std::ifstream file_stream(file_name);
-
- if (file_stream.is_open() == 0)
- errx(1, "ifstream.open()");
-
- while (std::getline(file_stream, line)) {
- size_t tab_pos = 0;
- // Find and replace replace all tabs with spaces
- while ((tab_pos = line.find('\t')) != std::string::npos) {
- int rem = tab_pos % 8;
- line.erase(tab_pos, 1);
- line.insert(tab_pos, std::string(8 - rem, ' '));
- }
-
- demo_buffer_move_to(buffer, &top_left);
- demo_buffer_add_text(buffer, line.c_str(), font, 1);
- ++top_left.y;
- }
-
- file_stream.close();
-}
-
-void
-RuntimeProcess::draw()
-{
-}
-
-void
-RuntimeProcess::idle()
-{
- for (auto &trans_unit : translation_units) {
- size_t bytes_total = trans_unit.num_lines * sizeof(uint64_t);
- assert(socket->read_all((uint8_t *)&trans_unit.execution_counts[0], bytes_total) == bytes_total);
- }
-
- // Send response back
- uint8_t msg_type = 1;
- assert(socket->write_all(&msg_type, 1) == 1);
-}