From bd98fe636d09dfa54a269bbabcd719a66ca1c118 Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Tue, 7 Jun 2022 13:45:07 -0400 Subject: [PATCH] Determine If A Function May Need To BE Mapped --- Resources/Linker.wasm | Bin 339 -> 47 bytes Resources/runtime/constants.br | 1 + Resources/runtime/constants.wasm | Bin 228 -> 287 bytes src/Linker/index.ts | 22 +++++++++++++++++++--- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Resources/Linker.wasm b/Resources/Linker.wasm index 271da952276e3648daeeb54888a446d111ef8b0e..9e711af1211307110ef76c3ba02e8dab65ee30f3 100644 GIT binary patch literal 47 zcmZQbEY4+QU|`^2U{GesOUzAW5EBhbEzU13N=_}-_sPu5PA$?a2PtA?U}9td00jUG AcmMzZ literal 339 zcmaKoF;BxV5QX2_NlFt2kZ1=are;nUn7RQH69}oW(=@o1Rcu#h8;L1@og|bEv7B^w zPj}yYXuKf+G!<*=s9OVqy5>7GWW7rnDhh^%^N$?$OgH_ZR2xJhhd6y~$4 dUMcS)x60Q;DvEn2bSCg)fU>tfAr3+k;T!#YT|WQ- diff --git a/Resources/runtime/constants.br b/Resources/runtime/constants.br index 4261769..44d1c09 100644 --- a/Resources/runtime/constants.br +++ b/Resources/runtime/constants.br @@ -1,4 +1,5 @@ // export const heapOffset: i32 = 0n; import wasm print: (f32) => i32 from 'env'; +const testFunction: Function = (t: i32): i32 => 1n; print(1f); export const True: i32 = 1n; \ No newline at end of file diff --git a/Resources/runtime/constants.wasm b/Resources/runtime/constants.wasm index 61e5f671d27b24846b9b998c08004f1cc1ab97c1..9a83a08b6f13376205f8becf64228ffaaf6e96b6 100644 GIT binary patch delta 157 zcmYj}F%E)26hvqKf{Eg4sg-DNBUYB%cm_Kmgo1*Vz}L=jhCP8t@KPQ`5*wSzE8d$A zUy`Bd8v@|MzC^N5wfq|Kck&%Ukv4DYb xqLDElBPTl}gChesBLkN(qu|6=M@G|$$K}NYm>3}H8QJ2COA?Dpn3x$E832Es5?KHM diff --git a/src/Linker/index.ts b/src/Linker/index.ts index fcdcd37..7c9247f 100644 --- a/src/Linker/index.ts +++ b/src/Linker/index.ts @@ -12,7 +12,7 @@ import { // addElement, // addExport, // addFunction, - // addGlobal, + addGlobal, // addImport, // addMemory, // addType, @@ -129,12 +129,15 @@ class FileDecoder extends Decoder { functionOffset: number, func: number[] ): Promise { + // Check If Anything may need To Be Mapped + const mayNeedMapping = func.some((byte) => byte == 0x23 || byte == 0x24 || 0x10); // Global.get, Global.set, call + console.log(mayNeedMapping); // Get Names From Parent Function // TODO: Remap Globals // TODO: Remap Calls // const func = createFunction(); // TODO: Return The Function - return createFunction(functionOffset); + // return createFunction(functionOffset); } // Link Function public async link(filePath: string): Promise { @@ -147,6 +150,9 @@ class FileDecoder extends Decoder { let functionCount = 1; // Set to 1 for the New Main Function // For Each Module for (const [importPath, briskImport] of depTree) { + // TODO: Remap External Imports + // TODO: Map Brisk Imports + // TODO: Replace The Function Index // TODO: Combine The Function Tables if (briskImport.tableSection.length != 0) { const tableDecoder = new Decoder(briskImport.tableSection, 1); @@ -156,9 +162,19 @@ class FileDecoder extends Decoder { } // TODO: Move The Table Elements // TODO: Set The Function Offset - // TODO: Resolve Imports // TODO: Rename The Globals And Functions // TODO: Remap Each Function + const codeDecoder = new Decoder(briskImport.codeSection, 0); + const functionCount = codeDecoder.decodeUnSignedLeb128(); + for (let i = 0; i < functionCount; i++) { + const functionSize = codeDecoder.decodeUnSignedLeb128(); + const functionBody = codeDecoder.getCurrentSlice(functionSize); + console.log(functionSize); + console.log(functionBody); + console.log(functionBody.length); + } + // console.log(codeDecoder); + // console.log(functionCount); // TODO: Move Over Data Sections // Combine The Other Parts // TODO: Remap Name Function