Skip to content

Commit

Permalink
Create A New Test
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Aug 23, 2022
1 parent d4ebef3 commit 9b35714
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Resources/LinkTest/index.br
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import print32 from './print32.br';
print32(0n);
print32(1n);
Binary file added Resources/LinkTest/index.br.wasm
Binary file not shown.
30 changes: 30 additions & 0 deletions Resources/LinkTest/print32.br
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import wasm fd_write: (i32, i32, i32, i32) => i32 from 'wasi_snapshot_preview1';
// TODO: Implement toString32
export const print32: Function = (value: i32): Void => {
// Helper
let writeCharacterCode: Function = (let pointer: i32, character: i32): i32 => {
// Store Character
@wasm.i32.store(pointer, character);
// Add To The Index
pointer++;
// Return Pointer
return(pointer);
};
// Create String
const basePointer: i32 = 0n;
let pointer: i32 = @wasm.i32.add(basePointer, 8n);
let length: i32 = 0n;
// Handle String Conversion In toString
if (@wasm.i32.eqz(value)) {
pointer = writeCharacterCode(pointer, 48n);
length++;
};
// Write New Line
pointer = writeCharacterCode(pointer, 10n);
length++;
// Store Iov Info
@wasm.i32.store(basePointer, 8n);
@wasm.i32.store(@wasm.i32.add(basePointer, 4n), length);
// Write String
fd_write(1n, 0n, 1n, 40n);
};
Binary file added Resources/LinkTest/print32.br.wasm
Binary file not shown.
Binary file modified Resources/LinkerTest/Linker.br.wasm
Binary file not shown.
Binary file modified Resources/LinkerTest/constants.br.wasm
Binary file not shown.
11 changes: 0 additions & 11 deletions src/Compiler/Codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,17 +522,6 @@ const generateCodeProgram = (rawProgram: string, program: ProgramNode): Uint8Arr
Types.createNumericType(WasmTypes.WasmI32),
Expressions.i32_ConstExpression(0)
);
if (program.data._imports.size != 0) {
addImport(
wasmModule,
createGlobalImport(
'brisk:LinkingConstant',
brisk_moduleFunctionOffset,
Types.createNumericType(WasmTypes.WasmI32),
false
)
);
}
// Create Function
let func = createFunction('_start', Types.createFunctionType([], []), [], [], []);
// Build The Body
Expand Down
34 changes: 16 additions & 18 deletions src/wasmBuilder/Build/WasmModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ export const addFunction = (wasmModule: WasmModule, func: WasmFunction): WasmMod
localNames.set(local[1], localNames.size);
}
// Resolve Function Body Labels
const wasmBody: number[] = [];
const wasmBody: number[] = [
...unsignedLEB128(func.locals.length),
// TODO: Optimize The local Format So That They Are Grouped
...func.locals
.map(([local]) => {
// Change The 1 to the local length
return [1, ...local];
})
.flat(),
];
const functionReferences: number[] = [];
const typeReferences: number[] = [];
const globalReferences: number[] = [];
Expand Down Expand Up @@ -175,16 +184,7 @@ export const addFunction = (wasmModule: WasmModule, func: WasmFunction): WasmMod
// Add Function To FunctionSection
wasmModule.functionSection.push([typeReference]);
// Add Function To CodeSection
const code: number[] = [
...unsignedLEB128(func.locals.length),
// TODO: Optimize The local Format So That They Are Grouped
...func.locals
.map(([local]) => {
// Change The 1 to the local length
return [1, ...local];
})
.flat(),
];
const code: number[] = [];
// Push References To Linking Info
wasmModule.codeReferences.push([functionReferences, typeReferences, globalReferences]);
// Finish Code Section
Expand Down Expand Up @@ -314,13 +314,11 @@ export const compileModule = (
includeDataCount = true
): Uint8Array => {
// Add A Table
if (wasmModule.elementSection.length > 0) {
wasmModule.tableSection.push([
0x70, // Table Type
0x00, // Limit Flag That We Only Want A Min Value
...unsignedLEB128(wasmModule.elementSection.length), // Min Value
]);
}
wasmModule.tableSection.push([
0x70, // Table Type
0x00, // Limit Flag That We Only Want A Min Value
...unsignedLEB128(wasmModule.elementSection.length), // Min Value
]);
// Compile Name Section
const funcNameSection: number[] = [wasmModule.functionMap.size];
for (const [name, index] of wasmModule.functionMap.entries()) {
Expand Down

0 comments on commit 9b35714

Please sign in to comment.