aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/headergen/sizegen.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
commit729d445b6885f69dd2c6355f38707bd42851c791 (patch)
treef87a7c408929ea3f57bbb7ace380cf869da83c0e /src/bun.js/headergen/sizegen.cpp
parent25f820c6bf1d8ec6d444ef579cc036b8c0607b75 (diff)
downloadbun-729d445b6885f69dd2c6355f38707bd42851c791.tar.gz
bun-729d445b6885f69dd2c6355f38707bd42851c791.tar.zst
bun-729d445b6885f69dd2c6355f38707bd42851c791.zip
change the directory structurejarred/rename
Diffstat (limited to 'src/bun.js/headergen/sizegen.cpp')
-rw-r--r--src/bun.js/headergen/sizegen.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/bun.js/headergen/sizegen.cpp b/src/bun.js/headergen/sizegen.cpp
new file mode 100644
index 000000000..1249d93b1
--- /dev/null
+++ b/src/bun.js/headergen/sizegen.cpp
@@ -0,0 +1,60 @@
+#include <ctime>
+#include <fstream>
+#include <iostream>
+using namespace std;
+
+#include "root.h"
+
+#include "ZigGlobalObject.h"
+
+#include "Path.h"
+
+#include "DOMURL.h"
+
+#include "headers-cpp.h"
+
+#include "JavaScriptCore/CallFrame.h"
+
+int main() {
+ time_t rawtime;
+ struct tm *timeinfo;
+ char buf[80];
+
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+
+ strftime(buf, 80, "%Y-%m-%d %H:%M:%s", timeinfo);
+
+ cout << "// Auto-generated by src/bun.js/headergen/sizegen.cpp at " << buf
+ << ".\n";
+ cout << "// These are the byte sizes for the different object types with "
+ "bindings in JavaScriptCore.\n";
+ cout << "// This allows us to safely return stack allocated C++ types to "
+ "Zig.\n";
+ cout << "// It is only safe to do this when these sizes are correct.\n";
+ cout << "// That means:\n";
+ cout << "// 1. We can't dynamically link JavaScriptCore\n";
+ cout << "// 2. It's important that this is run whenever JavaScriptCore is "
+ "updated or the bindings on the Zig side change.\n";
+ cout << "// Failure to do so will lead to undefined behavior and probably "
+ "some frustrated people.\n";
+ cout << "// --- Regenerate this: --- \n";
+ cout << "// 1. \"make jsc-bindings-headers\"\n";
+ cout << "// 2. \"make sizegen\"\n";
+ cout << "// 3. \"make jsc-bindings-headers\"\n";
+ cout << "// ------------------------\n";
+ cout << "// You can verify the numbers written in this file at runtime via "
+ "the `extern`d types\n";
+ cout << "// Run \"jsc-bindings-headers\" twice because it uses these values "
+ "in the output. That's how all the bJSC__.* types are created - from "
+ "these values. \n";
+ int i = 0;
+ int len = sizeof(sizes) / sizeof(sizes[0]);
+ for (i = 0; i < len; i++) {
+ cout << "pub const " << names[i] << " = " << sizes[i] << ";\n";
+ cout << "pub const " << names[i] << "_align = " << aligns[i] << ";\n";
+ }
+ cout << "pub const Bun_FFI_PointerOffsetToArgumentsList = << "
+ << JSC::CallFrame::argumentOffset(0) << ";\n";
+ return 0;
+} \ No newline at end of file