Skip to content

Commit 41783c0

Browse files
committed
Implement net-ssa-cli and test case.
1 parent b4a2c03 commit 41783c0

11 files changed

Lines changed: 124 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
2222
sudo apt update
2323
sudo apt-get install mono-devel=6.12.0.122-0xamarin1+ubuntu1804b1
24+
sudo apt-get install mono-utils
25+
- name: Setup llvm-tools
26+
run: |
27+
sudo apt-get install llvm-12-tools
2428
- name: Setup .NET
2529
uses: actions/setup-dotnet@v1
2630
with:

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ find_package(Souffle REQUIRED)
88
find_package(Python3 REQUIRED COMPONENTS Interpreter)
99
find_package(Mono 6.12 REQUIRED COMPONENTS)
1010

11+
find_program(LLVM_CONFIG NAMES llvm-config REQUIRED)
12+
message(STATUS "Using llvm-config: ${LLVM_CONFIG}")
13+
exec_program("${LLVM_CONFIG} --bindir" OUTPUT_VARIABLE LLVM_BINDIR)
14+
1115
add_subdirectory(souffle)
1216

1317
set(NET_SSA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin/net-ssa)

integration-test/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
config.substitutions.append(('%mono', config.mono_bin))
1515
config.substitutions.append(('%mcs', config.mcs_bin))
16+
config.substitutions.append(('%net-ssa-cli', os.path.join(config.net_ssa_bin_dir, "net-ssa-cli")))
17+
config.substitutions.append(('%FileCheck', os.path.join(config.llvm_bin_dir, "FileCheck")))
1618

1719
def _clean_test_directory(directory):
1820
for entry in os.scandir(directory):

integration-test/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ config.souffle_bin_dir = "@SOUFFLE_BIN_DIR@"
44
config.my_src_root = r'@CMAKE_SOURCE_DIR@'
55
config.my_obj_root = r'@CMAKE_BINARY_DIR@'
66

7+
config.llvm_bin_dir = r'@LLVM_BINDIR@'
8+
79
config.mono_bin = "@MONO_EXECUTABLE@"
810
config.mcs_bin = "@MCS_EXECUTABLE@"
911

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %mcs -target:library -out:%T/Test.dll %s
2+
// RUN: %net-ssa-cli %T/Test.dll list classes > %t.classes
3+
// RUN: %FileCheck %s < %t.classes
4+
5+
// CHECK: Test
6+
7+
public class Test { }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %mcs -target:library -out:%T/Test.dll %s
2+
// RUN: %net-ssa-cli %T/Test.dll list classes > %t.classes
3+
// RUN: %FileCheck %s < %t.classes
4+
5+
// CHECK: Test
6+
// CHECK: Test/Nested
7+
8+
public class Test
9+
{
10+
public class Nested { }
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %mcs -target:library -out:%T/Test.dll %s
2+
// RUN: %net-ssa-cli %T/Test.dll list classes > %t.classes
3+
// RUN: %FileCheck %s < %t.classes
4+
5+
// CHECK: Test`1
6+
7+
public class Test<T> { }

integration-test/test0/Test.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

net-ssa-cli/Program.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.CommandLine;
3+
using System.CommandLine.Invocation;
4+
using System.IO;
5+
using Mono.Cecil;
6+
namespace NetSsaCli
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
var rootCommand = new RootCommand{
13+
new Argument<FileInfo>("input", "Assembly to process.").ExistingOnly(),
14+
};
15+
16+
addListSubCommand(rootCommand);
17+
18+
var disassemble = new Command("disassemble");
19+
disassemble.Handler = CommandHandler.Create(() =>
20+
{
21+
Console.WriteLine("Disassembling");
22+
});
23+
24+
rootCommand.Add(disassemble);
25+
rootCommand.InvokeAsync(args);
26+
}
27+
28+
static void addListSubCommand(RootCommand rootCommand)
29+
{
30+
var list = new Command("list", "List classes or methods in the assembly.");
31+
var classes = new Command("classes", "List all classes in the assembly.");
32+
list.Add(classes);
33+
34+
classes.Handler = CommandHandler.Create<FileInfo>(PrintClasses);
35+
36+
rootCommand.Add(list);
37+
}
38+
39+
static void PrintClasses(FileInfo input)
40+
{
41+
using (AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(input.FullName))
42+
{
43+
foreach (TypeDefinition type in assembly.MainModule.Types)
44+
{
45+
Console.WriteLine(type.FullName);
46+
foreach (TypeDefinition nested in type.NestedTypes)
47+
{
48+
Console.WriteLine(nested);
49+
}
50+
}
51+
}
52+
53+
}
54+
}
55+
}

net-ssa-cli/net-ssa-cli.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\net-ssa-lib\net-ssa-lib.csproj" />
5+
</ItemGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
9+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
10+
</ItemGroup>
11+
12+
<PropertyGroup>
13+
<OutputType>Exe</OutputType>
14+
<TargetFramework>net5.0</TargetFramework>
15+
<RootNamespace>net_ssa_cli</RootNamespace>
16+
</PropertyGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)