Author: massi
Date: 2007-03-07 17:20:15 -0500 (Wed, 07 Mar 2007)
New Revision: 73919
Added:
trunk/cecil/gcc4cil/Makefile
trunk/cecil/gcc4cil/gcc4cil.exe.sources
Modified:
trunk/cecil/gcc4cil/Mono.Merge/Driver.cs
trunk/cecil/gcc4cil/Mono.Merge/FixReflectionAfterMerge.cs
trunk/cecil/gcc4cil/Mono.Merge/InternalSymbolTable.cs
trunk/cecil/gcc4cil/Mono.Merge/MergeContext.cs
trunk/cecil/gcc4cil/Mono.Merge/NativeLibraryHandler.cs
trunk/cecil/gcc4cil/Mono.Merge/ReflectionMerger.cs
Log:
Second code dump: implementation should be complete, but there are bugs...
Added: trunk/cecil/gcc4cil/Makefile
===================================================================
--- trunk/cecil/gcc4cil/Makefile 2007-03-07 22:19:44 UTC (rev 73918)
+++ trunk/cecil/gcc4cil/Makefile 2007-03-07 22:20:15 UTC (rev 73919)
@@ -0,0 +1,14 @@
+
+MCS = gmcs
+KEY_FILE = ../../mcs/class/mono.snk
+MONO.CECIL.DLL = Mono.Cecil.dll
+MCS_FLAGS = -keyfile:$(KEY_FILE) -r:$(MONO.CECIL.DLL) -debug
+GCC4CIL = gcc4cil.exe
+
+all:
+ cp ../lib/$(MONO.CECIL.DLL) .
+ $(MCS) $(MCS_FLAGS) @gcc4cil.exe.sources /out:$(GCC4CIL)
+
+clean:
+ rm -f $(MERGE)
+ rm -f $(MONO.CECIL.DLL)
Modified: trunk/cecil/gcc4cil/Mono.Merge/Driver.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/Driver.cs 2007-03-07 22:19:44 UTC (rev
73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/Driver.cs 2007-03-07 22:20:15 UTC (rev
73919)
@@ -45,7 +45,7 @@
public static int Main (string [] args)
{
- if (true) {
+ if (false) {
NativeLibraryHandler nh = new
NativeLibraryHandler ();
nh.Libraries.Add ("c");
nh.LibrariesSearchPaths.Add ("/lib");
@@ -100,6 +100,14 @@
if (token == "o" || token == "out")
context.OutputPath = (string)
q.Dequeue ();
+ else if (token == "e" || token == "exe")
+ context.OutputIsExecutable =
true;
+ else if (token == "d" || token == "dll")
+ context.OutputIsExecutable =
false;
+ else if (token == "L")
+
context.NativeLibraries.LibrariesSearchPaths.Add ((string) q.Dequeue ());
+ else if (token == "l")
+
context.NativeLibraries.Libraries.Add ((string) q.Dequeue ());
else
Usage ();
} else {
Modified: trunk/cecil/gcc4cil/Mono.Merge/FixReflectionAfterMerge.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/FixReflectionAfterMerge.cs 2007-03-07
22:19:44 UTC (rev 73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/FixReflectionAfterMerge.cs 2007-03-07
22:20:15 UTC (rev 73919)
@@ -383,7 +383,7 @@
{
EventReference res = null;
if (type is TypeDefinition) {
- EventDefinition md = eventa as EventDefinition;
+ //EventDefinition md = eventa as
EventDefinition;
TypeDefinition td = type as TypeDefinition;
res = td.Events.GetEvent (eventa.Name);
}
Modified: trunk/cecil/gcc4cil/Mono.Merge/InternalSymbolTable.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/InternalSymbolTable.cs 2007-03-07
22:19:44 UTC (rev 73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/InternalSymbolTable.cs 2007-03-07
22:20:15 UTC (rev 73919)
@@ -35,6 +35,12 @@
public class InternalSymbolTable {
+ MethodDefinition entryPoint = null;
+ public MethodDefinition EntryPoint {
+ get { return entryPoint; }
+ }
+
+
Dictionary<string,MethodDefinition> methods = new
Dictionary<string,MethodDefinition> ();
public MethodDefinition InsertMethod (MethodDefinition method,
bool clone) {
if (methods.ContainsKey (method.Name)) {
@@ -45,6 +51,12 @@
method = method.Clone ();
}
methods [method.Name] = method;
+
+ if (method.Name == ".start") {
+ //TODO More sanity checks here...
+ entryPoint = method;
+ }
+
return method;
}
}
Modified: trunk/cecil/gcc4cil/Mono.Merge/MergeContext.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/MergeContext.cs 2007-03-07 22:19:44 UTC
(rev 73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/MergeContext.cs 2007-03-07 22:20:15 UTC
(rev 73919)
@@ -41,7 +41,7 @@
string mainModuleName = "<Module>";
string mainTypeName = "<Module>";
- string externalAssemblyName = "ExternalAssembly";
+ string externalAssemblyName = "ExternalAssemblyXXX";
List<string> assemblies = new List<string> ();
List<AssemblyDefinition> merged_assemblies = new
List<AssemblyDefinition> ();
@@ -130,6 +130,7 @@
if (OutputIsExecutable) {
outputAssembly.Kind = AssemblyKind.Console;
+ outputAssembly.EntryPoint =
InternalSymbols.EntryPoint;
} else {
outputAssembly.Kind = AssemblyKind.Dll;
}
Modified: trunk/cecil/gcc4cil/Mono.Merge/NativeLibraryHandler.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/NativeLibraryHandler.cs 2007-03-07
22:19:44 UTC (rev 73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/NativeLibraryHandler.cs 2007-03-07
22:20:15 UTC (rev 73919)
@@ -32,9 +32,67 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
+using Mono.Cecil;
+
namespace Mono.Merge {
public class NativeLibraryHandler {
+ static bool CompareMethodSignatures (MethodReference mr,
MethodDefinition md) {
+ if (mr.ReturnType.ReturnType.FullName !=
md.ReturnType.ReturnType.FullName) {
+ return false;
+ } else if (mr.Parameters.Count != md.Parameters.Count) {
+ return false;
+ } else {
+ for (int i = 0; i < mr.Parameters.Count; i++) {
+ if (mr.Parameters
[i].ParameterType.FullName != md.Parameters [i].ParameterType.FullName) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ Dictionary<string,List<MethodDefinition>> externalMethods = new
Dictionary<string,List<MethodDefinition>> ();
+ Dictionary<string,ModuleReference> referredLibraries = new
Dictionary<string,ModuleReference> ();
+
+ MethodDefinition CreateExternalMethod (MethodReference mr,
string library, ModuleReference referredLibrary) {
+ MethodDefinition md = new MethodDefinition(mr.Name,
+ MethodAttributes.PInvokeImpl |
MethodAttributes.HideBySig | MethodAttributes.Private |
+ MethodAttributes.Static,
mr.ReturnType.ReturnType);
+ foreach (ParameterDefinition pd in mr.Parameters) {
+ md.Parameters.Add (pd);
+ }
+ md.PInvokeInfo = new PInvokeInfo(md,
+ PInvokeAttributes.CharSetAnsi |
PInvokeAttributes.CallConvCdecl, md.Name, referredLibrary);
+ return md;
+
+ }
+ public MethodDefinition GetExternalMethod (MethodReference mr) {
+ string library = GetSymbolLibrary (mr.Name);
+
+ if (library != null) {
+ List<MethodDefinition> methods =
externalMethods [mr.Name];
+ if (methods != null) {
+ foreach (MethodDefinition method in
methods) {
+ if (CompareMethodSignatures
(mr, method)) {
+ return method;
+ }
+ }
+ } else {
+ methods = new List<MethodDefinition> ();
+ externalMethods [mr.Name] = methods;
+ }
+ if (referredLibraries [library] == null) {
+ referredLibraries [library] = new
ModuleReference (library);
+ }
+ MethodDefinition md = CreateExternalMethod (mr,
library, referredLibraries [library]);
+ methods.Add (md);
+ return md;
+ } else {
+ return null;
+ }
+ }
+
List<string> libraries = new List<string> ();
List<string> librariesSearchPaths = new List<string> ();
Modified: trunk/cecil/gcc4cil/Mono.Merge/ReflectionMerger.cs
===================================================================
--- trunk/cecil/gcc4cil/Mono.Merge/ReflectionMerger.cs 2007-03-07 22:19:44 UTC
(rev 73918)
+++ trunk/cecil/gcc4cil/Mono.Merge/ReflectionMerger.cs 2007-03-07 22:20:15 UTC
(rev 73919)
@@ -48,6 +48,8 @@
if (type.Name == Context.MainTypeName) {
bool clone = (type != Context.MainType);
+ Console.WriteLine ("Found main type in assembly
{0}. clone is {1}", type.Module.Assembly.Name.Name, clone);
+
foreach (MethodDefinition method in
type.Methods) {
MethodDefinition md =
Context.InternalSymbols.InsertMethod (method, clone);
if (md != null) {
@@ -59,7 +61,7 @@
}
}
- foreach (FieldDefinition field in type.Methods)
{
+ foreach (FieldDefinition field in type.Fields) {
FieldDefinition fd =
Context.InternalSymbols.InsertField (field, clone);
if (fd != null) {
if (clone) {
Added: trunk/cecil/gcc4cil/gcc4cil.exe.sources
===================================================================
--- trunk/cecil/gcc4cil/gcc4cil.exe.sources 2007-03-07 22:19:44 UTC (rev
73918)
+++ trunk/cecil/gcc4cil/gcc4cil.exe.sources 2007-03-07 22:20:15 UTC (rev
73919)
@@ -0,0 +1,9 @@
+./Mono.Merge/AssemblyInfo.cs
+./Mono.Merge/BaseMergeReflectionVisitor.cs
+./Mono.Merge/Driver.cs
+./Mono.Merge/FixReflectionAfterMerge.cs
+./Mono.Merge/MergeContext.cs
+./Mono.Merge/ReflectionMerger.cs
+./Mono.Merge/StructureMerger.cs
+./Mono.Merge/NativeLibraryHandler.cs
+./Mono.Merge/InternalSymbolTable.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches