-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (64 loc) · 2.77 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (64 loc) · 2.77 KB
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
using ObjectIR.Core.AST;
using System.Text;
namespace ObjectAOT
{
public class Program
{
public string filePath;
public static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: ObjectAOT <input-file>");
return;
}
var input = File.ReadAllText(args[0], Encoding.UTF8);
var module = TextIrParser.ParseModule(input);
Console.WriteLine($"Parsed module: {module.Name} (version: {(module.Version != null ? module.Version :"1.0.0")}");
// Generate C++ output for the parsed module and write to disk
var outputs = CodeGen.CppEmitter.GenerateCpp(module);
var outDir = Path.Combine(Directory.GetCurrentDirectory(), "out");
Directory.CreateDirectory(outDir);
foreach (var kv in outputs)
{
var path = Path.Combine(outDir, kv.Key);
File.WriteAllText(path, kv.Value, Encoding.UTF8);
Console.WriteLine($"Wrote: {path}");
}
}
void PrintModule(ModuleNode m)
{
Console.WriteLine("Interfaces:");
foreach (var iface in m.Interfaces)
{
Console.WriteLine($" - {iface.Name}");
foreach (var sig in iface.Methods)
{
Console.WriteLine($" method {sig.Name}({string.Join(", ", sig.Parameters.Select(p => p.Name + ": " + p.ParameterType.Name))}) -> {sig.ReturnType.Name}");
}
}
Console.WriteLine("Classes:");
foreach (var cls in m.Classes)
{
Console.WriteLine($" - {cls.Name} : {string.Join(", ", cls.BaseTypes)}");
foreach (var f in cls.Fields)
{
Console.WriteLine($" field {f.Name}: {f.FieldType.Name} ({f.Access})");
}
foreach (var c in cls.Constructors)
{
Console.WriteLine($" ctor({string.Join(", ", c.Parameters.Select(p => p.Name + ": " + p.ParameterType.Name))})");
}
foreach (var mth in cls.Methods)
{
Console.WriteLine($" method {mth.Name}({string.Join(", ", mth.Parameters.Select(p => p.Name + ": " + p.ParameterType.Name))}) -> {mth.ReturnType.Name} {(mth.Implements is not null ? "implements " + mth.Implements : string.Empty)}");
Console.WriteLine($" Body statements: {mth.Body.Statements.Count}");
foreach (var stmt in mth.Body.Statements)
{
Console.WriteLine($" {stmt}");
}
}
}
}
}
}