Skip to content

Commit

Permalink
Determine If A Function May Need To BE Mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Jun 7, 2022
1 parent 552cb8e commit bd98fe6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Binary file modified Resources/Linker.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions Resources/runtime/constants.br
Original file line number Diff line number Diff line change
@@ -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;
Binary file modified Resources/runtime/constants.wasm
Binary file not shown.
22 changes: 19 additions & 3 deletions src/Linker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
// addElement,
// addExport,
// addFunction,
// addGlobal,
addGlobal,
// addImport,
// addMemory,
// addType,
Expand Down Expand Up @@ -129,12 +129,15 @@ class FileDecoder extends Decoder {
functionOffset: number,
func: number[]
): Promise<WasmFunction> {
// 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<WasmModule> {
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit bd98fe6

Please sign in to comment.