Browse Source

+ added DebugWrite to the WASI system unit

git-svn-id: branches/wasm@47182 -
nickysn 4 years ago
parent
commit
76c48eb705
1 changed files with 40 additions and 11 deletions
  1. 40 11
      rtl/wasi/system.pp

+ 40 - 11
rtl/wasi/system.pp

@@ -9,26 +9,55 @@ type
   filerec = integer;
   filerec = integer;
   textrec = integer;
   textrec = integer;
   pbyte = ^byte;
   pbyte = ^byte;
+  pchar = ^Char;
 
 
 procedure fpc_lib_exit; compilerproc;
 procedure fpc_lib_exit; compilerproc;
-
-function test_rtl_function(a, b: integer): integer;
+procedure DebugWrite(const P: PChar);
 
 
 implementation
 implementation
 
 
-procedure fpc_lib_exit; compilerproc;
+type
+  P__wasi_size_t = ^__wasi_size_t;
+  __wasi_size_t = longint;
+  __wasi_fd_t = longint;
+  size_t = longint;
+  __wasi_errno_t = longint;
+
+  P__wasi_ciovec_t = ^__wasi_ciovec_t;
+  __wasi_ciovec_t = record
+    buf: pointer;
+    buf_len: __wasi_size_t;
+  end;
+
+var
+  our_iov: __wasi_ciovec_t;
+  our_nwritten: longint;
+  i: size_t;
+  gp: pchar;
+
+function fd_write(fd: __wasi_fd_t;
+                  iovs: P__wasi_ciovec_t;
+                  iovs_len: size_t;
+                  nwritten: P__wasi_size_t): __wasi_errno_t; external 'wasi_unstable';
+
+function StrLen(P: PChar): size_t;
 begin
 begin
+  gp := p;
+  i := 0;
+  while gp[i]<>#0 do
+    Inc(i);
+  StrLen := i;
 end;
 end;
 
 
-function test_rtl_function(a, b: integer): integer;
-var
-  tempvar: integer;
-  tempvar2: integer;
-  pv: pbyte;
+procedure DebugWrite(const P: PChar);
+begin
+  our_iov.buf := P;
+  our_iov.buf_len := StrLen(P);
+  fd_write(1, @our_iov, 1, @our_nwritten);
+end;
+
+procedure fpc_lib_exit; compilerproc;
 begin
 begin
-  tempvar := a - b;
-  test_rtl_function := a + b;
-{  pv := @tempvar2;}
 end;
 end;
 
 
 end.
 end.