2003-05-02 Alp Toker <alp@atoker.com>
authorAlp Toker <alp@mono-cvs.ximian.com>
Fri, 2 May 2003 18:47:12 +0000 (18:47 -0000)
committerAlp Toker <alp@mono-cvs.ximian.com>
Fri, 2 May 2003 18:47:12 +0000 (18:47 -0000)
        * cilc.cs: Print usage info

svn path=/trunk/mcs/; revision=14221

mcs/tools/cilc/ChangeLog
mcs/tools/cilc/Makefile
mcs/tools/cilc/README
mcs/tools/cilc/TODO
mcs/tools/cilc/Test.cs
mcs/tools/cilc/cilc.cs
mcs/tools/cilc/demo.c

index bcff31b86acbde2eaf27bb2e20dbd13bd80302aa..6bda2982ea5a67fe91f9ba362f89dd2d886689d4 100644 (file)
@@ -1,3 +1,7 @@
+2003-05-02  Alp Toker  <alp@atoker.com>
+
+       * cilc.cs: Print usage info
+
 2003-05-01  Alp Toker  <alp@atoker.com>
 
        * cilc.cs: Support arguments, clean up some gcc warnings
index 26331bfabddce1be06b7d9a389d4eb7ae0c2fb13..e6c1d4e687be60e6771af0bbeffc636a150362d9 100644 (file)
@@ -7,9 +7,9 @@ all: cilc.exe
 test: cilc.exe Test.dll
        rm -rf generated
        mkdir generated
-       mono cilc.exe Test.dll
-       gcc -Wall -fpic -shared `pkg-config --cflags --libs glib-2.0 mono` -lpthread generated/*.c -o generated/libtest.so
-       gcc -Wall `pkg-config --cflags --libs glib-2.0 mono` -Igenerated -Lgenerated -ltest demo.c -o generated/demo
+       mono cilc.exe Test.dll generated
+       $(MAKE) -C generated
+       gcc -Wall `pkg-config --cflags --libs glib-2.0 mono` -Igenerated -Lgenerated -ldemo demo.c -o generated/demo
        cp Test.dll generated
 
 cilc.exe: cilc.cs
index 24123fa72ee854ef5e9ad15e1603ec5b7da3ed13..eddc7433828972d7b0a9e4c473641220b2719d7c 100644 (file)
@@ -18,13 +18,6 @@ Then run:
 $ make test
 $ cd generated
 $ ./demo
-$ make test
-$ cd generated
-$ ./demo
-c# static method invoked
-c# ctor invoked
-c# instance method invoked
-c# method with an unusual name invoked
 
 -- 
 Alp Toker <alp@atoker.com>
index 64e59cf6a82418a343c476a5dd3e1ed6d17d5fb4..88f09b8a7ac29521f59fed487833f36111dce84c 100644 (file)
@@ -1,48 +1,21 @@
 TODO
 ====
 
-Support return values
-
---
-
-Make cilc.exe installable and provide a man page in mono/man
-
---
+Support return values and ref/out parameters
 
 Complete GObject support including macros and GType, taking into account
 inheritance etc.
 
---
-
 Enums, delegates, events etc.
 
---
-
 generate autoconf/automake build files. set AC_VERSION using the assembly's
 version attribute
 
---
-
 Automatically generate inline API documentation using documentation in the
 Monodoc format. The GTK+ API documentation generator can then be used to create
 documentation familiar to GTK+ developers.
 
---
-
-<lupus> my plan is to do something like that in the future, but smarter
-<lupus> basically, have the jit create the thunk
-<lupus> so you would not have to generate code for the assemblies
-<lupus> just header files, basically
-
---
-
-<lupus> note that glib-allocated memory is not scammed by the GC, so you'll have to deal with that somehow
-<alp> something like overriding glib's malloc with something from libgc?
-<lupus> would work, but I wouldn't reccomend that
-<lupus> you may need to play with weak references
-<lupus> or storing the objects in something like a MonoGHashTable or something like that
-
---
-
-<rachel> I would give the implementor extra points if they handled passing in wrapped objects automatically (pass in a GtkWidget*, managed gets Gtk.Widget)
+Resolve GC issues using weak references or storing objects in something like a
+MonoGHashTable
 
+Wish: pass in a GtkWidget*, managed gets Gtk.Widget
index 687dba57eda77843075b7e1b4571de56affac83f..6ef6d1eedf0888b40824dd91ec3f69198f717f2a 100644 (file)
@@ -55,7 +55,7 @@ namespace Demo
                        set { title = value; }
                }
 
-               public void Method3 (string arg1string)
+               public void Echo (string arg1string)
                {
                        Console.WriteLine ("string: " + arg1string);
                }
index 81468c6397b253d281440aed1341fe46275175b8..bba71652161e98a697bb6d2e409019c0b6a03ec1 100644 (file)
@@ -12,20 +12,42 @@ class cilc
        public static CodeWriter C, H, Cindex, Hindex;
        static string ns, dllname;
        static string cur_class;
+       static string target_dir;
 
        static ArrayList funcs_done;
 
-       public static void Main(string[] args)
+       public static int Main(string[] args)
        {
+               if (args.Length != 2) {
+                       Console.WriteLine ("Mono CIL-to-C binding generator");
+                       Console.WriteLine ("Usage: cilc [options] assembly target");
+                       return 1;
+               }
+
                ns = "Unnamed";
-               Generate (args[0]);
+               Generate (args[0], args[1]);
+
+               return 0;
        }
 
-       static void Generate (string assembly)
+       static void Generate (string assembly, string target)
        {
+               target_dir = target + Path.DirectorySeparatorChar;
+               if (!Directory.Exists (target_dir)) Directory.CreateDirectory (target_dir);
+
                Assembly a = Assembly.LoadFrom (assembly);
                dllname = Path.GetFileName (assembly);
                AssemblyGen (a);
+
+               //create a makefile
+               CodeWriter makefile = new CodeWriter (target_dir + "Makefile");
+               makefile.Indenter = "\t";
+               makefile.WriteLine ("all: lib" + ns.ToLower () + ".so");
+               makefile.LineBreak ();
+               makefile.WriteLine ("lib" + ns.ToLower () + ".so: *.c");
+               makefile.Indent ();
+               makefile.WriteLine ("gcc -Wall -fpic -shared `pkg-config --cflags --libs glib-2.0 mono` -lpthread *.c -o lib" + ns.ToLower () + ".so");
+               makefile.Close ();
        }
 
        static void AssemblyGen (Assembly a)
@@ -33,8 +55,8 @@ class cilc
                Type[] types = a.GetTypes ();
 
                ns = types[0].Namespace;
-               Hindex = new CodeWriter (ns.ToLower () + ".h");
-               Cindex = new CodeWriter (ns.ToLower () + ".c");
+               Hindex = new CodeWriter (target_dir + ns.ToLower () + ".h");
+               Cindex = new CodeWriter (target_dir + ns.ToLower () + ".c");
 
                string Hindex_id = "__" + ns.ToUpper () + "_H__";
                Hindex.WriteLine ("#ifndef " + Hindex_id);
@@ -85,8 +107,8 @@ class cilc
 
                //ns = t.Namespace;
                string fname = ns.ToLower () + t.Name.ToLower ();
-               C = new CodeWriter (fname + ".c");
-               H = new CodeWriter (fname + ".h");
+               C = new CodeWriter (target_dir + fname + ".c");
+               H = new CodeWriter (target_dir + fname + ".h");
                Hindex.WriteLine ("#include <" + fname + ".h" + ">");
 
 
@@ -363,7 +385,7 @@ class CodeWriter
 
        public CodeWriter (string fname)
        {
-               FileStream fs = new FileStream ("generated/" + fname, FileMode.OpenOrCreate, FileAccess.Write);
+               FileStream fs = new FileStream (fname, FileMode.OpenOrCreate, FileAccess.Write);
                w = new StreamWriter (fs);
        }
 
index 87bbffd847baf054f24202c219997a10e2f90c85..1b62b9e82d81c663808e5e668bcfb2a51796a018 100644 (file)
@@ -16,7 +16,10 @@ int main () {
   demo_test_add_number (my_test, 2);
 
   //run an instance method with arguments
-  demo_test_set_title (my_test, "hello from c");
+  demo_test_echo (my_test, "hello from c");
+
+  //run a property set accessor
+  demo_test_set_title (my_test, "set property from c");
   
   //TODO: return value
   //g_printf ("returned string: %s\n", demo_test_get_title (my_test));