Finish Improving Performance

This commit is contained in:
TheBrokenRail 2024-08-02 00:56:22 -04:00
parent 199eecda97
commit 2a63f1ff52
5 changed files with 42 additions and 31 deletions

View File

@ -1,3 +1,4 @@
#define LEAN_SYMBOLS_HEADER
#include "{{ headerPath }}" #include "{{ headerPath }}"
// Thunk Template // Thunk Template

View File

@ -104,4 +104,5 @@ export function preventConstruction(self: string) {
out += `${INDENT}${self}(const ${self} &) = delete;\n`; out += `${INDENT}${self}(const ${self} &) = delete;\n`;
out += `${INDENT}${self} &operator=(const ${self} &) = delete;\n`; out += `${INDENT}${self} &operator=(const ${self} &) = delete;\n`;
return out; return out;
} }
export const LEAN_HEADER_GUARD = '#ifndef LEAN_SYMBOLS_HEADER\n';

View File

@ -27,24 +27,22 @@ export class Method {
getType() { getType() {
return this.getName() + '_t'; return this.getName() + '_t';
} }
getProperty(hasWrapper: boolean) { #getRawType() {
let out = INDENT; return INTERNAL + 'raw_' + this.getType();
if (hasWrapper) {
out += `${this.getWrapperType()}::ptr_type ${this.shortName}`;
} else {
out += `${formatType(this.returnType.trim())}(*${this.shortName})${this.args.trim()}`;
}
out += ';\n';
return out;
} }
getWrapperType() { getProperty() {
return `std::remove_pointer_t<decltype(${this.getName()})>`; return `${INDENT}${this.#getRawType()} *${this.shortName};\n`;
}
#getSignature() {
return this.returnType.trim() + this.args.trim();
} }
#getFullType() { #getFullType() {
return `${INTERNAL}Function<${this.#getSignature()}>`; return `${INTERNAL}Function<${this.#getRawType()}>`;
}
// Typedefs
generateTypedefs() {
let out = '';
out += `typedef ${formatType(this.returnType.trim())}${this.#getRawType()}${this.args.trim()};\n`;
out += `typedef std::function<${this.#getRawType()}> ${this.getType()};\n`;
return out;
} }
// Overwrite Helper // Overwrite Helper
@ -53,9 +51,7 @@ export class Method {
} }
generate(code: boolean, isVirtual: boolean, parentSelf?: string) { generate(code: boolean, isVirtual: boolean, parentSelf?: string) {
let out = ''; let out = '';
if (!code) { out += 'extern ';
out += 'extern ';
}
const type = this.#getFullType(); const type = this.#getFullType();
out += `${type} *const ${this.getName()}`; out += `${type} *const ${this.getName()}`;
if (code) { if (code) {
@ -64,14 +60,11 @@ export class Method {
const parentMethod = parentSelf ? `(void *) ${this.#getVirtualCall(parentSelf)}` : 'nullptr'; const parentMethod = parentSelf ? `(void *) ${this.#getVirtualCall(parentSelf)}` : 'nullptr';
out += `&${this.#getVirtualCall()}, ${parentMethod}`; out += `&${this.#getVirtualCall()}, ${parentMethod}`;
} else { } else {
out += `${this.getWrapperType()}::ptr_type(${toHex(this.address)})`; out += `(${this.#getRawType()} *) ${toHex(this.address)}`;
} }
out += `, ${INTERNAL}thunk<&${this.getName()}>)`; out += `, ${INTERNAL}thunk<&${this.getName()}>)`;
} }
out += ';\n'; out += ';\n';
if (!code) {
out += `typedef ${this.getWrapperType()}::type ${this.getType()};\n`;
}
return out; return out;
} }
} }

View File

@ -1,4 +1,4 @@
import { INDENT, STRUCTURE_FILES, toHex, assertSize, INTERNAL, preventConstruction } from './common'; import { INDENT, STRUCTURE_FILES, toHex, assertSize, INTERNAL, preventConstruction, LEAN_HEADER_GUARD } from './common';
import { Method } from './method'; import { Method } from './method';
import { Property, StaticProperty } from './property'; import { Property, StaticProperty } from './property';
import { VTable } from './vtable'; import { VTable } from './vtable';
@ -161,6 +161,7 @@ export class Struct {
} }
#generateMethods() { #generateMethods() {
let out = ''; let out = '';
out += LEAN_HEADER_GUARD;
// Normal Methods // Normal Methods
for (const method of this.#methods) { for (const method of this.#methods) {
out += this.#generateMethod(method, false); out += this.#generateMethod(method, false);
@ -175,6 +176,7 @@ export class Struct {
} }
} }
// Return // Return
out += '#endif\n';
return out; return out;
} }
@ -198,11 +200,18 @@ export class Struct {
} }
// Method Wrappers // Method Wrappers
let typedefs = '';
let methodsOut = '';
for (const method of this.#methods) { for (const method of this.#methods) {
if (!method.isInherited) { if (!method.isInherited) {
out += method.generate(false, false); typedefs += method.generateTypedefs();
methodsOut += method.generate(false, false);
} }
} }
out += typedefs;
out += LEAN_HEADER_GUARD;
out += methodsOut;
out += '#endif\n';
// Structure // Structure
out += `struct ${this.#name} {\n`; out += `struct ${this.#name} {\n`;

View File

@ -1,4 +1,4 @@
import { INDENT, POINTER_SIZE, assertSize, getSelfArg, preventConstruction, toHex } from './common'; import { INDENT, LEAN_HEADER_GUARD, POINTER_SIZE, assertSize, getSelfArg, preventConstruction, toHex } from './common';
import { Method } from './method'; import { Method } from './method';
import { Property } from './property'; import { Property } from './property';
@ -116,13 +116,20 @@ export class VTable {
// Wrappers // Wrappers
const methods = this.getMethods(); const methods = this.getMethods();
if (this.canGenerateWrappers()) { let typedefs = '';
for (const info of methods) { let methodsOut = '';
if (info) { for (const info of methods) {
out += info.generate(false, true); if (info) {
typedefs += info.generateTypedefs();
if (this.canGenerateWrappers()) {
methodsOut += info.generate(false, true);
} }
} }
} }
out += typedefs;
out += LEAN_HEADER_GUARD;
out += methodsOut;
out += '#endif\n';
// Structure // Structure
out += `typedef struct ${this.#getName()} ${this.#getName()};\n`; out += `typedef struct ${this.#getName()} ${this.#getName()};\n`;
@ -130,7 +137,7 @@ export class VTable {
for (let i = 0; i < methods.length; i++) { for (let i = 0; i < methods.length; i++) {
const info = methods[i]; const info = methods[i];
if (info) { if (info) {
out += info.getProperty(this.canGenerateWrappers()); out += info.getProperty();
} else { } else {
out += `${INDENT}void *unknown${i};\n`; out += `${INDENT}void *unknown${i};\n`;
} }