@@ -9,6 +9,8 @@ import Interrupt = WARDuino.Interrupt;
99import State = WARDuino . State ;
1010import Value = WASM . Value ;
1111import Type = WASM . Type ;
12+ import { CompileOutput , CompilerFactory } from '../manage/Compiler' ;
13+ import { WABT } from '../util/env' ;
1214
1315// An acknowledgement returned by the debugger
1416export interface Ack {
@@ -125,9 +127,14 @@ export namespace Message {
125127 }
126128 }
127129
128- export function updateModule ( program : string ) : Request < Ack > {
129- function payload ( wasm : Buffer ) : string {
130- const w = new Uint8Array ( wasm ) ;
130+ export async function uploadFile ( program : string ) : Promise < Request < Ack > > {
131+ let compiled : CompileOutput = await new CompilerFactory ( WABT ) . pickCompiler ( program ) . compile ( program ) ;
132+ return updateModule ( compiled . file ) ;
133+ }
134+
135+ export function updateModule ( wasm : string ) : Request < Ack > {
136+ function payload ( binary : Buffer ) : string {
137+ const w = new Uint8Array ( binary ) ;
131138 const sizeHex : string = WASM . leb128 ( w . length ) ;
132139 const sizeBuffer = Buffer . allocUnsafe ( 4 ) ;
133140 sizeBuffer . writeUint32BE ( w . length ) ;
@@ -137,7 +144,7 @@ export namespace Message {
137144
138145 return {
139146 type : Interrupt . updateModule ,
140- payload : ( map : SourceMap . Mapping ) => payload ( readFileSync ( program ) ) ,
147+ payload : ( map : SourceMap . Mapping ) => payload ( readFileSync ( wasm ) ) ,
141148 parser : ( line : string ) => {
142149 return ackParser ( line , 'CHANGE Module' ) ;
143150 }
0 commit comments