From: Chris Wilson <cwilson@CS.Stanford.EDU> Date: Fri, 9 Feb 96 19:01:51 PST Subject: Porting notes: SUIFLIB to MSVC++ on NT Message-Id: <CMM.0.90.4.823921311.cwilson@Xenon.Stanford.EDU>
Here's a report we received on porting some of the basic parts of SUIF to Microsoft Visual C++ on Windows NT. I thought it might be of interest to the SUIF community at large, and the author kindly consented to have it posted here. --Chris ------- Forwarded Message Return-Path: BROYLES@maven.dnet.teradyne.com Received: by mojave.Stanford.EDU (5.57/Ultrix2.4-C) id AA03268; Fri, 9 Feb 96 07:32:42 PST Received: from steadfast.teradyne.com (steadfast.teradyne.com [131.101.1.200]) by Sunburn.Stanford.EDU (8.7.1/8.7.1) with ESMTP id HAA13259 for <lam@cs.stanford.edu>; Fri, 9 Feb 1996 07:32:39 -0800 (PST) From: BROYLES@maven.dnet.teradyne.com Posted-Date: Fri, 9 Feb 1996 07:32:39 -0800 (PST) Received: from A1GATE.TERADYNE.COM (a1gate.teradyne.com [131.101.1.184]) by steadfast.teradyne.com (8.7.1/8.7.1) with ESMTP id KAA25969 for <lam@cs.stanford.edu>; Fri, 9 Feb 1996 10:32:49 -0500 (EST) Received: from decnet-mail (BROYLES@MAVEN) by A1GATE.TERADYNE.COM (PMDF V4.3-10 #6667) id <01I108ELJ78W0020TJ@A1GATE.TERADYNE.COM>; Fri, 09 Feb 1996 10:27:36 -0500 (EST) Date: Fri, 09 Feb 1996 10:27:36 -0500 (EST) Subject: Porting notes: SUIFLIB to MSVC++ on NT To: lam@cs.stanford.edu Message-Id: <01I108ELL2R60020TJ@A1GATE.TERADYNE.COM> X-Vms-To: A1GATE::IN%"lam@cs.stanford.edu" Mime-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-Transfer-Encoding: 7BIT /* Changes made to port suiflib to Microsoft Visual C++ on Windows NT * * The SUIF team may wish to review this list for changes that would * enhance direct portability. * * 9 Feb 1996 */ Introduction Overall, the suif code is very clean and easily ported. I have at this point converted suiflib, useful, porky, and snoot, and can use them (as NT "Console Applications") to process toy .c programs successfully. I originally started the work of porting suiflib to Visual C++ on a Windows 3.1 machine. That's a 16-bit environment, and I don't know whether it would be feasible to accomplish a port there. I suspect not. In any case, I resolved a number of issues but ran into a brick wall when attempting to link, so I moved the code over to an NT machine running the latest Visual version 4.0 which is a full 32-bit environment. Changes I had already made for file name length and int/long differences are not required in the 32-bit NT world. Summary of major changes . Microsoft likes its C++ files to have the .cpp extension . The use of #pragma is a pain. I hacked it to reduce the warnings, but a clean solution would be nice. Some way to #define PRAGMA(a,b)... . The unix version depends on the make process to create some variables containing the versions of the libraries used in the build. These have to be explicitly created on NT. Hack. . The unix version depends on the make process to create start_suif(). This must be explicitly created on NT. Hack. . The one true portability issue is the use of fcntl() in fileset.cpp. I commented this out. Means my suiflib can't count open files. No big deal for me right now. Should be fixed at some point. . Microsoft's _setnewhandler() has a different format than gnu's. . One bug in the Microsoft compiler needs a workaround. . Rather than have lots of include paths for the compiler, I modified <suif.h> to <suif/suif.h> and set an include point that was above all of the project directories. . Snoot had a number of attempts to assign an int to an enum. . Left unresolved are a number of signed/unsigned compare warnings. I chose a particular way of rendering MSVC's "workspaces": each suif directory is a unique workspace. I'm sure there are other ways to do this (sub-projects come to mind), but I'm new to the Visual environment, and the method I chose works ok enough. I did my best to keep notes as I went along, but I may have forgotten something. Caveat emptor. I've probably spent a three days of my time over the past month getting the code to build. Six days total, including getting a new machine set up, NT and MSVC installed, files moved, learning how to run MSVC, etc. The porting issues have necessarily caused me to have to learn a bit about how suif works, but that's a rather weak understanding, so some of the changes I made may have been naive. Regards, Steve Broyles (steve.broyles@teradyne.com) ========= Build under MSVC++ 4.0 under Win NT 3.51 ============== Create directories 'suif', 'useful', 'snoot', 'porky' under c:\msdev\projects Fill the directories with code from the suif release Use File Manager to Rename *.cc to *.cpp in all directories Suif ==== New>>Workspace "suif", of type Static Library Insert>>Files>> add all .cpp and .h Build>>Settings>>C++ General>> add #define SUIFLIB Build>>Settings>>C++ Preprocessor>> add c:\msdev\projects to Include Path Wrap all #pragmas in each .h with #ifdef unix. (Reduces warnings substantially) In dlist.h and glist.h Modified dlist.h's definition of DECLARE_LIST_CLASS_LIST() to have a semicolon as last parameter (corresponds to EXTRA). This is the proper way to have a null parameter. Otherwise generates warnings. Ditto, DECLARE_LIST_CLASS_E In mtflist.h Ditto, DECLARE_LIST_CLASS_E In initsuif.cpp add #include <new.h>. Put ifdef unix around set_new_handler call. In #else, call Microsoft's _set_new_handler (found in new.h). It calls a function that returns int and takes size_t as a parameter. Change the definition and call to _set_suif_handler accordingly. at top of file, add definitions for 20 character arrays for libsuif_suif_* and prog_*, wrapped with #ifndef unix Create a new file called startsuif.cpp. Insert it into Project In it put start_suif(int argc, char *argv[]){ register_libraries("useful","1.1",init_useful,exit_useful); init_suif(argc,argv); } Wrap this in #ifndef unix In suifstrm.cpp changed write_int() to have long parameter i (decl differs from defn) wrap #ifdef unix around #include unistd.h Add #include <stdlib.h> to pick up sys_errlist In fileset.cpp bracketed the 'check for non-suif files' with #ifdef unix because fcntl() isn't a DOS/Windows function. Means suif can't check for open files??? In misc..h remove declaration for sys_errlist. It's declared in stdlib.h Put a copy of suif_copyright.h in c:\msdev\projects (satisfies includes) Useful ====== New>>Workspace "useful", of type Static Library Insert>>Files>> add all .cpp and .h Build>>Settings>>C++ General>> add #define SUIFLIB Build>>Settings>>C++ Preprocessor>> add c:\msdev\projects to Include Path This library builds cleanly. Snoot ===== New>>Workspace "snoot", of type Console Application Insert>>Files>> add all .cpp and .h, plus find_params.c Build>>Settings>>C++ General>> add #define SUIFLIB Build>>Settings>>C++ Preprocessor>> add c:\msdev\projects to Include Path Insert>>Files Into Project. add suiflib.lib and useful.lib (from sister directories) Change #include <suif.h> to #include <suif/suif.h> in a number of places. In c.h change t from enum tokencode to plain int. Removes a pile of errors associated with assigning an int value to t. In expr.cpp change Opcode op to int op in 3 places In find_params.c (be sure NOT to rename this to .cpp, by the way!) cast to (boolean) in two places (This file generates a lot of signed/unsigned compare warnings.) In enode.cpp "struct genop" appears to be error for "static genop" (Bug?) In typerror(), cast constant 0 to (Opcode)0 remove 'static' from definition of opnode[] function. (Bug) In stypes.cpp There's an assignment conflict cause by differing definitions of machine_params (in suif/misc.h) and target_info_block (in target_info.h). One uses C_type for ptr_diff_type and the other uses int. Change in favor of int. Porky ===== New>>Workspace "porky", of type Console Application Insert>>Files>> add all .cpp and .h, plus find_params.c Build>>Settings>>C++ General>> add #define SUIFLIB Build>>Settings>>C++ Preprocessor>> add c:\msdev\projects to Include Path Insert>>Files Into Project. add suiflib.lib and useful.lib (from sister directories) In porky.h change <suif.h> to <suif/suif.h> change <useful.h> to <useful/useful.h> In structured_facts.cpp remove #include <useful.h> already done by porky.h In structured_facts.h change <suif.h> to <suif/suif.h> In fact.h change <suif.h> to <suif/suif.h> =============================== At this point the suif and useful libraries build cleanly At this point the snoot and porky executables build cleanly. =============================== Runtime error occurs when executing snoot on test1.c (a trivial test). This is caused by a bug in MS compiler relating to dealing with INT_MIN as defined in <limits.h>. Without going into detail: in useful/inumbers.cpp after line 3700 (an assert in subtract_string_magnitudes() ) #undef INT_MIN #define INT_MIN (-2147483648) You could equally well redefine INT_MIN in Microsoft's limits.h, but this will cause warning related to unarily negating an unsigned int. ------- End of Forwarded Message