aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/headergen/sizegen.cpp
blob: 49b64e0e9b08b6ea8510194e3093ca9139db5bd1 (plain) (blame)
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
#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"
#include "JavaScriptCore/JSArrayBufferViewInlines.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 headers\"\n";
  cout << "// 2. \"make sizegen\"\n";
  cout << "// 3. \"make headers\"\n";
  cout << "// ------------------------\n";
  cout << "// You can verify the numbers written in this file at runtime via "
          "the `extern`d types\n";
  cout << "// Run \"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 = 31 - 3;
  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";
  cout << "pub const Bun_FFI_PointerOffsetToTypedArrayVector = "
       << JSC::JSArrayBufferView::offsetOfVector() << ";\n";
  cout << "pub const Bun_FFI_PointerOffsetToTypedArrayLength = "
       << JSC::JSArrayBufferView::offsetOfLength() << ";\n";
  cout << "pub const Bun_CallFrame__codeBlock = ";

  cout << static_cast<int>(JSC::CallFrameSlot::codeBlock) << ";\n";
  cout << "pub const Bun_CallFrame__callee = ";

  cout << static_cast<int>(JSC::CallFrameSlot::callee) << ";\n";
  cout << "pub const Bun_CallFrame__argumentCountIncludingThis = ";

  cout << static_cast<int>(JSC::CallFrameSlot::argumentCountIncludingThis)
       << ";\n";
  cout << "pub const Bun_CallFrame__thisArgument = ";

  cout << static_cast<int>(JSC::CallFrameSlot::thisArgument) << ";\n";
  cout << "pub const Bun_CallFrame__firstArgument = ";

  cout << static_cast<int>(JSC::CallFrameSlot::firstArgument) << ";\n";

  cout << "pub const Bun_CallFrame__size = ";

  cout << sizeof(JSC::CallFrame) << ";\n";

  cout << "pub const Bun_CallFrame__align = ";

  cout << alignof(JSC::CallFrame) << ";\n";
  return 0;
}