-
Notifications
You must be signed in to change notification settings - Fork 3
/
Embedder.cs
79 lines (66 loc) · 1.71 KB
/
Embedder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
using System.Net;
namespace Wasm2CIL {
public class WebassemblyEmbedder
{
Parser parser;
Type emitted;
public WebassemblyEmbedder (Stream reader)
{
parser = new Parser (reader);
}
public static WebassemblyEmbedder
FromUrl (string URL)
{
using (var source = WebRequest.Create(URL).GetResponse().GetResponseStream ()) {
return new WebassemblyEmbedder (source);
}
}
public static WebassemblyEmbedder
FromFile (string inputPath)
{
using (var source = File.Open (inputPath, FileMode.Open)) {
return new WebassemblyEmbedder (source);
}
}
// The emitted code subclasses this runtime
public Type
Load (string name)
{
if (this.emitted == null)
this.emitted = this.parser.Emit (name, null);
return emitted;
}
public void
Save (string name, string path)
{
this.parser.Emit (name, path);
}
//public void Run (string functionName, object [] args)
//{
//if (!this.emitted)
//throw new Exception ("Must first Load () WASM Assembly with provided name");
//
// var instance =
//lock (instance) {
//var method = this.emitted.GetMethod (functionName);
//var ret = method.Invoke (instance, args);
//Console.WriteLine ("Function {0} ({1}) returned {2}", functionName, args, ret.ToString ());
//}
//}
public static void Main (string [] args)
{
var inputPath = args [0];
var outputName = args [1];
var outputPath = String.Format ("{0}.dll", outputName);
var driver = WebassemblyEmbedder.FromFile (inputPath);
driver.Save (outputName, outputPath);
//Console.ReadKey();
}
}
}