hello world in C

This commit is contained in:
Cadey Ratio 2018-06-20 20:06:35 -07:00
parent 17b173bba6
commit 00c3cbf4d7
5 changed files with 17 additions and 12 deletions

View File

@ -229,7 +229,7 @@ func (p *Process) open(fnamesP int32, flags int32) int32 {
case "stdout":
fi = stdFD{
ReadWriteCloser: loggerFile{
Logger: log.New(os.Stdout, p.name, log.LstdFlags),
Logger: log.New(os.Stdout, p.name+" ", log.LstdFlags),
},
}

View File

@ -20,6 +20,7 @@ func testWasmFile(t *testing.T, fname string) *Process {
if err != nil {
t.Fatal(err)
}
p.name = fname
ret, err := p.Main()
if err != nil {
@ -111,3 +112,7 @@ func TestStruct(t *testing.T) {
t.Fatalf("wanted foo.baz to be 255, got: %d", foo.Baz)
}
}
func TestCHelloWorld(t *testing.T) {
testWasmFile(t, "./testdata/helloworld.wasm")
}

View File

@ -2,7 +2,8 @@ include_rules
CFLAGS += --target=wasm32-unknown-unknown-wasm
CFLAGS += --sysroot=~/code/wasmception/sysroot/
CFLAGS += -O0 -nostartfiles -Wl,--no-entry -nostdlib
CFLAGS += -O0 -nostartfiles -nostdlib -fvisibility=hidden
CFLAGS += -Wl,--no-entry,--allow-undefined-file=land.syms
: foreach *.wast |> wat2wasm -o %o %f |> %B.wasm
: foreach *.c |> ~/code/wasmception/dist/bin/clang $(CFLAGS) %f -o %o |> %B.wasm

View File

@ -4,18 +4,11 @@ extern int close(int);
__attribute__ ((visibility ("default")))
int main() {
const char *name = "hello";
const char *name = "stdout";
char *msg = "Hello, world!";
int fd = open(name, 0x42);
int num = write(fd, msg, 13);
if (num == 0) {
return 1;
}
num = close(fd);
if (num == 0) {
return 1;
}
write(fd, msg, 13);
close(fd);
return 0;
}

6
cmd/land/testdata/land.syms vendored Normal file
View File

@ -0,0 +1,6 @@
open
read
write
close
unlink
isatty