Files
wasmtime/crates/misc/dotnet/tests/Fixtures/ModuleFixture.cs
Alex Crichton 77e17d8f71 Add a wasmtime-specific wasmtime_wat2wasm C API (#1206)
* Add a wasmtime-specific `wasmtime_wat2wasm` C API

This commit implements a wasmtime-specific C API for converting the text
format to the binary format. An upstream spec issue exists for adding
this to the C API, but in the meantime we can experiment with our own
version of this API and use it in the C# extension, for example!

Closes #1000

* Reorder arguments

* Use wasm_byte_vec_t for input `*.wat`

* Mark wat input as const

* Return an error message and use `fixed`

* Actually include the error message

* Use `fixed` in `Module.cs` as well
2020-03-03 10:29:20 -06:00

49 lines
1.2 KiB
C#

using System;
using System.IO;
using Wasmtime;
namespace Wasmtime.Tests
{
public abstract class ModuleFixture : IDisposable
{
public ModuleFixture()
{
Engine = new EngineBuilder()
.WithMultiValue(true)
.WithReferenceTypes(true)
.Build();
Store = Engine.CreateStore();
var wat = Path.Combine("Modules", ModuleFileName);
var wasm = Engine.WatToWasm(File.ReadAllText(wat));
Module = Store.CreateModule(wat, wasm);
}
public void Dispose()
{
if (!(Module is null))
{
Module.Dispose();
Module = null;
}
if (!(Store is null))
{
Store.Dispose();
Store = null;
}
if (!(Engine is null))
{
Engine.Dispose();
Engine = null;
}
}
public Engine Engine { get; set; }
public Store Store { get; set; }
public Module Module { get; set; }
protected abstract string ModuleFileName { get; }
}
}