changeset 38:27b2f40bdb58 trunk

[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back. Fiddled a bit the the testing system. Added a very simple SDL graphics demo.
author lindquist
date Wed, 10 Oct 2007 06:16:48 +0200
parents 77cdca8c210f
children fd5e8bbfcb25
files demos/sdl.d demos/sdldemo1.d dmd/mars.c gen/logger.c gen/logger.h gen/toobj.c runalltests.d test/structinit.d
diffstat 8 files changed, 146 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/sdl.d	Wed Oct 10 06:16:48 2007 +0200
@@ -0,0 +1,46 @@
+module sdl;
+
+version(build)
+    pragma(link,"SDL");
+
+extern(C):
+struct SDL_Rect {
+    short x, y;
+    ushort w, h;
+}
+struct SDL_PixelFormat {
+    //SDL_Palette *palette;
+    void *palette;
+    ubyte BitsPerPixel, BytesPerPixel, Rloss, Gloss, Bloss, Aloss, Rshift, Gshift, Bshift, Ashift;
+    uint Rmask, Gmask, Bmask, Amask, colorkey; ubyte alpha;
+}
+struct SDL_Surface {
+    uint flags;
+    SDL_PixelFormat *format;
+    int w, h;
+    ushort pitch;
+    void *pixels;
+    int offset;
+    void *hwdata;
+    SDL_Rect clip_rect;
+    uint unused;
+    uint locked;
+    void *map;
+    uint format_version;
+    int refcount;
+}
+uint SDL_MapRGBA(SDL_PixelFormat *format, ubyte r, ubyte g, ubyte b, ubyte a);
+void SDL_GetRGBA(uint pixel, SDL_PixelFormat *fmt, ubyte *r, ubyte *g, ubyte *b, ubyte *a);
+int SDL_LockSurface(SDL_Surface *);
+void SDL_UnlockSurface(SDL_Surface *);
+SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags);
+int SDL_Flip(SDL_Surface *);
+void SDL_Delay(uint);
+int SDL_FillRect(SDL_Surface*,SDL_Rect*,uint);
+enum : uint {
+    SDL_SWSURFACE=0,
+    SDL_HWSURFACE=1,
+    SDL_DOUBLEBUF=0x40000000,
+    SDL_FULLSCREEN=0x80000000
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/sdldemo1.d	Wed Oct 10 06:16:48 2007 +0200
@@ -0,0 +1,15 @@
+module sdldemo1;
+import sdl;
+void main()
+{
+    auto disp = SDL_SetVideoMode(640,480,0,SDL_HWSURFACE|SDL_DOUBLEBUF);
+    auto r = SDL_Rect(0,190,100,100);
+    auto c = SDL_MapRGBA(disp.format,255,100,0,255);
+    while (r.x < disp.w-100) {
+        SDL_FillRect(disp, null, 0);
+        SDL_FillRect(disp, &r, c);
+        SDL_Flip(disp);
+        r.x++;
+    }
+}
+
--- a/dmd/mars.c	Wed Oct 10 03:38:24 2007 +0200
+++ b/dmd/mars.c	Wed Oct 10 06:16:48 2007 +0200
@@ -38,7 +38,9 @@
 #include "id.h"
 #include "cond.h"
 #include "expression.h"
-#include "lexer.h"
+#include "lexer.h"
+
+#include "gen/logger.h"
 
 void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
 
@@ -167,8 +169,8 @@
   -c             do not link\n\
   -cov           do code coverage analysis\n\
   -D             generate documentation\n\
-  -Dddocdir      write documentation file to docdir directory\n\
-  -Dffilename    write documentation file to filename\n\
+  -Dd<docdir>    write documentation file to <docdir> directory\n\
+  -Df<filename>  write documentation file to <filename>\n\
   -d             allow deprecated features\n\
   -debug         compile in debug code\n\
   -debug=level   compile in debug code <= level\n\
@@ -178,31 +180,32 @@
   -g             add symbolic debug info\n\
   -gc            add symbolic debug info, pretend to be C\n\
   -H             generate 'header' file\n\
-  -Hdhdrdir      write 'header' file to hdrdir directory\n\
-  -Hffilename    write 'header' file to filename\n\
+  -Hd<hdrdir>    write 'header' file to <hdrdir> directory\n\
+  -Hf<filename>  write 'header' file to <filename>\n\
   --help         print help\n\
-  -Ipath         where to look for imports\n\
-  -Epath         where to look for the core runtime\n\
-  -Jpath         where to look for string imports\n\
+  -I<path>       where to look for imports\n\
+  -E<path>       where to look for the core runtime\n\
+  -J<path>       where to look for string imports\n\
   -inline        do function inlining\n\
   -Llinkerflag   pass linkerflag to link\n\
-  -march         emit code specific to arch\n\
+  -m<arch>       emit code specific to <arch>\n\
                  x86 x86-64 ppc32 ppc64\n\
   -nofloat       do not emit reference to floating point\n\
   -noruntime     do not allow code that generates implicit runtime calls\n\
   -novalidate    do not run the validation pass before writing bitcode\n\
   -O             optimize, same as -O2\n\
-  -On            optimize at level n (0-5)\n\
+  -O<n>          optimize at level <n> (0-5)\n\
   -o-            do not write object file\n\
-  -odobjdir      write object files to directory objdir\n\
-  -offilename	 name output file to filename\n\
+  -od<objdir>    write object files to directory <objdir>\n\
+  -of<filename>	 name output file to <filename>\n\
   -op            do not strip paths from source file\n\
-  -profile	 profile runtime performance of generated code\n\
+  -profile	     profile runtime performance of generated code\n\
   -quiet         suppress unnecessary messages\n\
-  -release	 compile release version\n\
+  -release	     compile release version\n\
   -run srcfile args...   run resulting program, passing args\n\
   -unittest      compile in unit tests\n\
-  -v             verbose\n\
+  -v             verbose\n\
+  -vv            very verbose (does not include -v)\n\
   -v1            D language version 1\n\
   -version=level compile in version code >= level\n\
   -version=ident compile in version code identified by ident\n\
@@ -226,7 +229,8 @@
     int argcstart = argc;
     char* tt_arch = 0;
     char* tt_os = 0;
-    char* data_layout = 0;
+    char* data_layout = 0;
+    bool very_verbose = false;
 
     // Check for malformed input
     if (argc < 1 || !argv)
@@ -351,7 +355,11 @@
 	    else if (strcmp(p + 1, "profile") == 0)
 		global.params.trace = 1;
 	    else if (strcmp(p + 1, "v") == 0)
-		global.params.verbose = 1;
+		global.params.verbose = 1;
+		else if (strcmp(p + 1, "vv") == 0) {
+    		Logger::enable();
+    		very_verbose = true;
+		}
 	    else if (strcmp(p + 1, "v1") == 0)
 		global.params.Dversion = 1;
 	    else if (strcmp(p + 1, "w") == 0)
@@ -653,7 +661,8 @@
             fatal();
         }
         else {
-            global.params.llvmArch = const_cast<char*>(e->Name);
+            global.params.llvmArch = const_cast<char*>(e->Name);
+            if (global.params.verbose || very_verbose)
             printf("Default target found: %s\n", global.params.llvmArch);
         }
     }
--- a/gen/logger.c	Wed Oct 10 03:38:24 2007 +0200
+++ b/gen/logger.c	Wed Oct 10 06:16:48 2007 +0200
@@ -1,10 +1,9 @@
-#ifndef LLVMD_NO_LOGGER
-
 #include <cassert>
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
 #include <iostream>
+#include <fstream>
 #include <string>
 
 #include "gen/logger.h"
@@ -12,36 +11,56 @@
 namespace Logger
 {
     static std::string indent_str;
+    static std::ofstream null_out("/dev/null");
+
+    static bool enabled = false;
     void indent()
     {
+        if (enabled)
         indent_str += "  ";
     }
     void undent()
     {
-        assert(!indent_str.empty());
-        indent_str.resize(indent_str.size()-2);
+        if (enabled) {
+            assert(!indent_str.empty());
+            indent_str.resize(indent_str.size()-2);
+        }
     }
     std::ostream& cout()
     {
-        return std::cout << indent_str;
+        if (enabled)
+            return std::cout << indent_str;
+        else
+            return null_out;
     }
     void println(const char* fmt,...)
     {
-        printf(indent_str.c_str());
-        va_list va;
-        va_start(va,fmt);
-        vprintf(fmt,va);
-        va_end(va);
-        printf("\n");
+        if (enabled) {
+            printf(indent_str.c_str());
+            va_list va;
+            va_start(va,fmt);
+            vprintf(fmt,va);
+            va_end(va);
+            printf("\n");
+        }
     }
     void print(const char* fmt,...)
     {
-        printf(indent_str.c_str());
-        va_list va;
-        va_start(va,fmt);
-        vprintf(fmt,va);
-        va_end(va);
+        if (enabled) {
+            printf(indent_str.c_str());
+            va_list va;
+            va_start(va,fmt);
+            vprintf(fmt,va);
+            va_end(va);
+        }
+    }
+    void enable()
+    {
+        enabled = true;
+    }
+    void disable()
+    {
+        enabled = false;
     }
 }
 
-#endif
--- a/gen/logger.h	Wed Oct 10 03:38:24 2007 +0200
+++ b/gen/logger.h	Wed Oct 10 06:16:48 2007 +0200
@@ -5,44 +5,30 @@
 
 namespace Logger
 {
-    #ifndef LLVMD_NO_LOGGER
     void indent();
     void undent();
     std::ostream& cout();
-    void println(const char* fmt,...);
-    void print(const char* fmt,...);
-    #else
-    inline void indent() {}
-    inline void undent() {}
-    inline std::ostream& cout() { return std::cout; }
-    inline void println(const char* fmt, ...) {}
-    inline void print(const char* fmt, ...) {}
-    #endif
+    void println(const char* fmt, ...);
+    void print(const char* fmt, ...);
+    void enable();
+    void disable();
+    
 
     struct LoggerScope
     {
         LoggerScope()
         {
-            #ifndef LLVMD_NO_LOGGER
-            //std::cout << "-->indented\n";
             Logger::indent();
-            #endif
             
         }
         ~LoggerScope()
         {
-            #ifndef LLVMD_NO_LOGGER
-            //std::cout << "<--undented\n";
             Logger::undent();
-            #endif
         }
     };
 }
 
-#ifndef LLVMD_NO_LOGGER
 #define LOG_SCOPE    Logger::LoggerScope _logscope;
-#else
-#define LOG_SCOPE
+
 #endif
 
-#endif
--- a/gen/toobj.c	Wed Oct 10 03:38:24 2007 +0200
+++ b/gen/toobj.c	Wed Oct 10 06:16:48 2007 +0200
@@ -133,14 +133,14 @@
 
 void Dsymbol::toObjFile()
 {
-    warning("Ignoring Dsymbol::toObjFile for %s", toChars());
+    Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars());
 }
 
 /* ================================================================== */
 
 void Declaration::toObjFile()
 {
-    warning("Ignoring Declaration::toObjFile for %s", toChars());
+    Logger::println("Ignoring Declaration::toObjFile for %s", toChars());
 }
 
 /* ================================================================== */
@@ -205,7 +205,7 @@
 
 void InterfaceDeclaration::toObjFile()
 {
-    warning("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
+    Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
 }
 
 /* ================================================================== */
@@ -621,7 +621,7 @@
 
 void EnumDeclaration::toObjFile()
 {
-    warning("Ignoring EnumDeclaration::toObjFile for %s", toChars());
+    Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars());
 }
 
 /* ================================================================== */
--- a/runalltests.d	Wed Oct 10 03:38:24 2007 +0200
+++ b/runalltests.d	Wed Oct 10 06:16:48 2007 +0200
@@ -9,30 +9,34 @@
     string[] bad;
     string[] badrun;
 
-    auto contents = listdir("test", "*.d");
+    chdir("test");
+
+    auto contents = listdir(".", "*.d");
     foreach(c; contents) {
-        auto cmd = "./tester.sh "~getName(c);
-        if (system(cmd~" ll") != 0) {
+        auto cmd = "llvmdc -quiet "~c;
+        writefln(cmd);
+        if (system(cmd) != 0) {
             bad ~= c;
         }
-        else if (system(cmd~" run") != 0) {
+        else if (system(getName(c)) != 0) {
             badrun ~= c;
         }
     }
 
     int ret = 0;
     if (bad.length > 0 || badrun.length > 0) {
-        writefln(bad.length, '/', contents.length, " tests failed to compile:");
+        writefln(bad.length, '/', contents.length, " of the tests failed to compile:");
         foreach(b; bad) {
             writefln("  ",b);
         }
-        writefln(badrun.length, '/', contents.length, " tests failed to run:");
+        writefln(badrun.length, '/', contents.length - bad.length, " of the compiled tests failed to run:");
         foreach(b; badrun) {
             writefln("  ",b);
         }
         ret = 1;
     }
 
-    writefln(contents.length - bad.length - badrun.length, '/', contents.length, " tests passed");
+    writefln(contents.length - bad.length - badrun.length, '/', contents.length, " of the tests passed");
     return ret;
 }
+
--- a/test/structinit.d	Wed Oct 10 03:38:24 2007 +0200
+++ b/test/structinit.d	Wed Oct 10 06:16:48 2007 +0200
@@ -22,3 +22,4 @@
     //assert(a == S.init);
     //assert(b == S(0,3.14f,0,real.init));
 }
+