summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <mparisi@stevens.edu>2020-09-19 21:10:20 -0400
committerMax <mparisi@stevens.edu>2020-09-19 21:10:20 -0400
commit0d2092ae1cefc010e372ecdc151f5c276e74b8ca (patch)
treeb229313f22609401134de8cf93dd32184890ccc6
parent083b3797477dac8665a2bc95685668f6f9207bf5 (diff)
Update calcrom so that it shows data split completion rate as well
-rw-r--r--.travis/calcrom/calcrom.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/.travis/calcrom/calcrom.cpp b/.travis/calcrom/calcrom.cpp
index b9e9e3f..9df4ed1 100644
--- a/.travis/calcrom/calcrom.cpp
+++ b/.travis/calcrom/calcrom.cpp
@@ -2,6 +2,7 @@
* CALCROM.CPP
* © PikalaxALT 2020
* © red031000 2020
+ * © mparisi20 2020
*
* Simple C++ executable to measure the completion rate of Pokémon Battle Revolution
* reverse engineering (decompilation).
@@ -27,6 +28,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
+#include <regex>
#include <elf.h>
#include <glob.h>
#include <string.h>
@@ -99,7 +101,11 @@ void analyze(string basedir, string version) {
// data _____|_____
// text |
unsigned sizes[2][2] = {{0, 0}, {0, 0}};
- unsigned split_code_sizes[2] = {0, 0};
+ // Accumulate asm sizes
+ // split unsplit
+ // data _____|________
+ // text |
+ unsigned split_sizes[2][2] = {{0, 0}, {0, 0}};
char * shstrtab = NULL;
size_t shstrsz = 0;
stringstream builddir;
@@ -113,7 +119,8 @@ void analyze(string basedir, string version) {
string ext = fname_s.substr(fname_s.rfind('.'), 4);
bool is_asm = ext == ".s";
string fileroot = fname_s.substr(fname_s.rfind('/') + 1);
- bool is_unsplit = (is_asm && fileroot.rfind("text_", 0) == 0);
+ string unsplit_regex("(init|extab|extabindex|text|ctors|dtors|rodata|data|sdata|sdata2)(_[^.]*)?[.]s");
+ bool is_unsplit = is_asm && regex_match(fileroot, regex(unsplit_regex));
fname_s = fname_s.replace(fname_s.find(basedir), basedir.length(), basebuilddir.str());
fname_s = fname_s.replace(fname_s.rfind('.'), 4, ".o");
@@ -155,14 +162,15 @@ void analyze(string basedir, string version) {
for (Elf32_Shdr & hdr : shdr) {
string shname = shstrtab + hdr.sh_name;
bool is_text = (shname == ".text" || shname == ".init");
- bool is_data = (shname == ".data" || shname == ".dtors" || shname == ".ctors" || shname == ".sdata" || shname == ".sdata2");
+ bool is_data = (shname == ".data" || shname == ".dtors" || shname == ".ctors" ||
+ shname == ".sdata" || shname == ".sdata2" || shname == ".rodata");
size_t size = hdr.sh_size + (hdr.sh_size & 3 ? 4 - (hdr.sh_size & 3) : 0);
if (is_text || is_data)
{
sizes[is_text][is_asm] += size;
- if (is_text && is_asm)
+ if (is_asm)
{
- split_code_sizes[is_unsplit] += size;
+ split_sizes[is_text][is_unsplit] += size;
}
}
}
@@ -175,15 +183,15 @@ void analyze(string basedir, string version) {
double total_text_d = total_text;
double src_text_d = sizes[1][0];
double asm_text_d = sizes[1][1];
- double split_asm_text_d = split_code_sizes[0];
- double unsplit_asm_text_d = split_code_sizes[1];
+ double split_asm_text_d = split_sizes[1][0];
+ double unsplit_asm_text_d = split_sizes[1][1];
cout << " " << total_text << " total bytes of code" << endl;
cout << " " << sizes[1][0] << " bytes of code in src (" << (src_text_d / total_text_d * 100.0) << "%)" << endl;
cout << " " << sizes[1][1] << " bytes of code in asm (" << (asm_text_d / total_text_d * 100.0) << "%)" << endl;
if (sizes[1][1] > 0) {
- cout << " " << split_code_sizes[0] << " bytes of asm code in split files (" << (split_asm_text_d / asm_text_d * 100.0) << "%)" << endl;
- cout << " " << split_code_sizes[1] << " bytes of asm code in unsplit files (" << (unsplit_asm_text_d / asm_text_d * 100.0) << "%)" << endl;
+ cout << " " << split_sizes[1][0] << " bytes of asm code in split files (" << (split_asm_text_d / asm_text_d * 100.0) << "%)" << endl;
+ cout << " " << split_sizes[1][1] << " bytes of asm code in unsplit files (" << (unsplit_asm_text_d / asm_text_d * 100.0) << "%)" << endl;
}
cout << endl;
// Report data
@@ -191,9 +199,16 @@ void analyze(string basedir, string version) {
double total_data_d = total_data;
double src_data_d = sizes[0][0];
double asm_data_d = sizes[0][1];
+ double split_asm_data_d = split_sizes[0][0];
+ double unsplit_asm_data_d = split_sizes[0][1];
cout << " " << total_data << " total bytes of data" << endl;
cout << " " << sizes[0][0] << " bytes of data in src (" << (src_data_d / total_data_d * 100.0) << "%)" << endl;
cout << " " << sizes[0][1] << " bytes of data in asm (" << (asm_data_d / total_data_d * 100.0) << "%)" << endl;
+ if (sizes[0][1] > 0) {
+ cout << " " << split_sizes[0][0] << " bytes of asm code in split files (" << (split_asm_data_d / asm_data_d * 100.0) << "%)" << endl;
+ cout << " " << split_sizes[0][1] << " bytes of asm code in unsplit files (" << (unsplit_asm_data_d / asm_data_d * 100.0) << "%)" << endl;
+ }
+
// Let vectors fall to gc
}