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 }}"
// Thunk Template

View File

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

View File

@ -27,24 +27,22 @@ export class Method {
getType() {
return this.getName() + '_t';
}
getProperty(hasWrapper: boolean) {
let out = INDENT;
if (hasWrapper) {
out += `${this.getWrapperType()}::ptr_type ${this.shortName}`;
} else {
out += `${formatType(this.returnType.trim())}(*${this.shortName})${this.args.trim()}`;
#getRawType() {
return INTERNAL + 'raw_' + this.getType();
}
out += ';\n';
return out;
}
getWrapperType() {
return `std::remove_pointer_t<decltype(${this.getName()})>`;
}
#getSignature() {
return this.returnType.trim() + this.args.trim();
getProperty() {
return `${INDENT}${this.#getRawType()} *${this.shortName};\n`;
}
#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
@ -53,9 +51,7 @@ export class Method {
}
generate(code: boolean, isVirtual: boolean, parentSelf?: string) {
let out = '';
if (!code) {
out += 'extern ';
}
const type = this.#getFullType();
out += `${type} *const ${this.getName()}`;
if (code) {
@ -64,14 +60,11 @@ export class Method {
const parentMethod = parentSelf ? `(void *) ${this.#getVirtualCall(parentSelf)}` : 'nullptr';
out += `&${this.#getVirtualCall()}, ${parentMethod}`;
} else {
out += `${this.getWrapperType()}::ptr_type(${toHex(this.address)})`;
out += `(${this.#getRawType()} *) ${toHex(this.address)}`;
}
out += `, ${INTERNAL}thunk<&${this.getName()}>)`;
}
out += ';\n';
if (!code) {
out += `typedef ${this.getWrapperType()}::type ${this.getType()};\n`;
}
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 { Property, StaticProperty } from './property';
import { VTable } from './vtable';
@ -161,6 +161,7 @@ export class Struct {
}
#generateMethods() {
let out = '';
out += LEAN_HEADER_GUARD;
// Normal Methods
for (const method of this.#methods) {
out += this.#generateMethod(method, false);
@ -175,6 +176,7 @@ export class Struct {
}
}
// Return
out += '#endif\n';
return out;
}
@ -198,11 +200,18 @@ export class Struct {
}
// Method Wrappers
let typedefs = '';
let methodsOut = '';
for (const method of this.#methods) {
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
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 { Property } from './property';
@ -116,13 +116,20 @@ export class VTable {
// Wrappers
const methods = this.getMethods();
if (this.canGenerateWrappers()) {
let typedefs = '';
let methodsOut = '';
for (const info of methods) {
if (info) {
out += info.generate(false, true);
typedefs += info.generateTypedefs();
if (this.canGenerateWrappers()) {
methodsOut += info.generate(false, true);
}
}
}
out += typedefs;
out += LEAN_HEADER_GUARD;
out += methodsOut;
out += '#endif\n';
// Structure
out += `typedef struct ${this.#getName()} ${this.#getName()};\n`;
@ -130,7 +137,7 @@ export class VTable {
for (let i = 0; i < methods.length; i++) {
const info = methods[i];
if (info) {
out += info.getProperty(this.canGenerateWrappers());
out += info.getProperty();
} else {
out += `${INDENT}void *unknown${i};\n`;
}