From 52a6e717037a5e8a470ebd791dc07ec37522d46a Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Wed, 10 Oct 2007 06:16:48 +0200 Subject: [PATCH] [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. --- demos/sdl.d | 46 ++++++++++++++++++++++++++++++++++++++++ demos/sdldemo1.d | 15 ++++++++++++++ dmd/mars.c | 45 ++++++++++++++++++++++++---------------- gen/logger.c | 53 ++++++++++++++++++++++++++++++++--------------- gen/logger.h | 26 ++++++----------------- gen/toobj.c | 8 +++---- runalltests.d | 18 +++++++++------- test/structinit.d | 1 + 8 files changed, 146 insertions(+), 66 deletions(-) create mode 100644 demos/sdl.d create mode 100644 demos/sdldemo1.d diff --git a/demos/sdl.d b/demos/sdl.d new file mode 100644 index 00000000..4afe2602 --- /dev/null +++ b/demos/sdl.d @@ -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 +} + diff --git a/demos/sdldemo1.d b/demos/sdldemo1.d new file mode 100644 index 00000000..d64d6610 --- /dev/null +++ b/demos/sdldemo1.d @@ -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++; + } +} + diff --git a/dmd/mars.c b/dmd/mars.c index 0f8b47eb..95ad7621 100644 --- a/dmd/mars.c +++ b/dmd/mars.c @@ -38,7 +38,9 @@ long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep); #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 @@ Usage:\n\ -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 write documentation file to directory\n\ + -Df write documentation file to \n\ -d allow deprecated features\n\ -debug compile in debug code\n\ -debug=level compile in debug code <= level\n\ @@ -178,31 +180,32 @@ Usage:\n\ -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 write 'header' file to directory\n\ + -Hf write 'header' file to \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 where to look for imports\n\ + -E where to look for the core runtime\n\ + -J 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 emit code specific to \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 optimize at level (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 write object files to directory \n\ + -of name output file to \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 main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) fatal(); } else { - global.params.llvmArch = const_cast(e->Name); + global.params.llvmArch = const_cast(e->Name); + if (global.params.verbose || very_verbose) printf("Default target found: %s\n", global.params.llvmArch); } } diff --git a/gen/logger.c b/gen/logger.c index 91ae80b8..06c182ec 100644 --- a/gen/logger.c +++ b/gen/logger.c @@ -1,10 +1,9 @@ -#ifndef LLVMD_NO_LOGGER - #include #include #include #include #include +#include #include #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 diff --git a/gen/logger.h b/gen/logger.h index aec6cea9..cd362757 100644 --- a/gen/logger.h +++ b/gen/logger.h @@ -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 + diff --git a/gen/toobj.c b/gen/toobj.c index 4fee0c31..784994c6 100644 --- a/gen/toobj.c +++ b/gen/toobj.c @@ -133,14 +133,14 @@ void Module::genmoduleinfo() 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 ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector void InterfaceDeclaration::toObjFile() { - warning("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); + Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); } /* ================================================================== */ @@ -621,7 +621,7 @@ void TypedefDeclaration::toObjFile() void EnumDeclaration::toObjFile() { - warning("Ignoring EnumDeclaration::toObjFile for %s", toChars()); + Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); } /* ================================================================== */ diff --git a/runalltests.d b/runalltests.d index 5f2eb815..a7205248 100644 --- a/runalltests.d +++ b/runalltests.d @@ -9,30 +9,34 @@ int main(string[] args) { 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; } + diff --git a/test/structinit.d b/test/structinit.d index 3268a79b..3a92dd35 100644 --- a/test/structinit.d +++ b/test/structinit.d @@ -22,3 +22,4 @@ void main() //assert(a == S.init); //assert(b == S(0,3.14f,0,real.init)); } +