Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Spec.Test/WastJson/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ public Value[] Invoke(ref WasmRuntime runtime, ref Module? module)
}
if (addr == null)
throw new InvalidDataException(
$"Could not get exported function {moduleName}.{Field}");

$"Could not get exported function {moduleName}.{Field}");

var options = new InvokerOptions();
if (runtime.TraceExecution)
{
Console.Error.WriteLine($"\nInvoking wasm function {Field}");
options.LogInstructionExecution = InstructionLogging.All;
}

//Compute type from action.Args and action.Expected
var invoker = runtime.CreateStackInvoker(addr.Value);
var invoker = runtime.CreateStackInvoker(addr.Value, options);

var pVals = Args.Select(arg => arg.AsValue).ToArray();
return invoker(pVals);
Expand Down
2 changes: 2 additions & 0 deletions Spec.Test/WastJson/WastJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ public class WastJson
public string Path { get; set; } = "";

public override string ToString() => $"{SourceFilename}";

public bool TraceExecution;
}
}
3 changes: 3 additions & 0 deletions Spec.Test/WastJsonTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static WastJsonTestData()
.Select(cfg => cfg.Value ?? "")
.ToHashSet();

public static bool TraceExecution => Configuration["TraceExecution"] == "True";

public IEnumerator<object[]> GetEnumerator()
{
var files = Directory.GetFiles(JsonDirectory, "*.json", SearchOption.AllDirectories).OrderBy(path => path);
Expand Down Expand Up @@ -88,6 +90,7 @@ static WastJson.WastJson LoadTestDefinition(string jsonPath)
throw new JsonException($"Error while parsing {jsonPath}");

testDefinition.Path = Path.GetDirectoryName(jsonPath)!;
testDefinition.TraceExecution = TraceExecution;
return testDefinition;
}
}
Expand Down
1 change: 1 addition & 0 deletions Spec.Test/WastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void RunWast(WastJson.WastJson file)
WasmRuntime runtime = new();
env.BindToRuntime(runtime);
runtime.TranspileModules = false;
runtime.TraceExecution = file.TraceExecution;

Module? module = null;
foreach (var command in file.Commands)
Expand Down
1 change: 1 addition & 0 deletions Spec.Test/testsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"JsonDirectory": "../../../generated-json",
"RunTranspilerTests": true,
"TraceExecution": false,
"Single": null,
"SkipWasts": [
"comments.wast",
Expand Down
22 changes: 18 additions & 4 deletions Wacs.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CommandLine;
Expand Down Expand Up @@ -121,10 +122,22 @@ static int RunWithOptions(CommandLineOptions opts)

var runtime = new WasmRuntime();

var parseTimer = new Stopwatch();
if (opts.LogProg)
{
parseTimer.Start();
}

//Parse the module
using var fileStream = new FileStream(opts.WasmModule, FileMode.Open);
var module = BinaryModuleParser.ParseWasm(fileStream);

if (opts.LogProg)
{
parseTimer.Stop();
System.Console.Error.WriteLine($"Parsing module took {parseTimer.ElapsedMilliseconds:#0.###}ms");
}

if (opts.Render)
{
string outputFilePath = Path.ChangeExtension(opts.WasmModule, ".wat");
Expand Down Expand Up @@ -210,13 +223,13 @@ static int RunWithOptions(CommandLineOptions opts)
if (opts.LogProg)
System.Console.Error.WriteLine($"Instantiating Module {moduleName}");

if (opts.Transpile)
runtime.TranspileModules = true;

//Validation normally happens after instantiation, but you can skip it if you did it after parsing, or you're like super confident.
var modInst = runtime.InstantiateModule(module, new RuntimeOptions { SkipModuleValidation = true });
var modInst = runtime.InstantiateModule(module, new RuntimeOptions { SkipModuleValidation = true, TimeInstantiation = opts.LogProg});
runtime.RegisterModule(moduleName, modInst);

if (opts.Transpile)
runtime.TranspileModule(modInst);

var callOptions = new InvokerOptions
{
LogGas = opts.LogGas,
Expand All @@ -225,6 +238,7 @@ static int RunWithOptions(CommandLineOptions opts)
LogInstructionExecution = opts.LogInstructionExecution,
CalculateLineNumbers = opts.CalculateLineNumbers,
CollectStats = opts.CollectStats,
SynchronousExecution = true,
};

//Wasm/WASI entry points
Expand Down
4 changes: 4 additions & 0 deletions Wacs.Console/Wacs.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<PackageId>Wacs.Console</PackageId>
<Product>Wacs.Console</Product>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;STRICT_EXECUTION</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Wacs.Core\Wacs.Core.csproj" />
Expand Down
28 changes: 13 additions & 15 deletions Wacs.Core/Attributes/OpCodeAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// /*
// * Copyright 2024 Kelvin Nishikawa
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
// Copyright 2024 Kelvin Nishikawa
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

Expand Down
28 changes: 13 additions & 15 deletions Wacs.Core/Attributes/WasmTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// /*
// * Copyright 2024 Kelvin Nishikawa
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
// Copyright 2024 Kelvin Nishikawa
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using Wacs.Core.Types.Defs;
Expand Down
28 changes: 13 additions & 15 deletions Wacs.Core/Attributes/WatTokenAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// /*
// * Copyright 2024 Kelvin Nishikawa
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
// Copyright 2024 Kelvin Nishikawa
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

Expand Down
Loading
Loading