[comp.lang.c++] Porting Cfront's output to other systems.

dror@starnet.uucp (Dror Matalon) (06/22/91)

I'd like to know what would be needed to port Cfront's output to other systems:
1. You need the stream library if you use it.
2. Are there any other libraries that are standard with Cfront and not with C?
3. There is something that is done in link time (I think that it has to do
with the vtables). What is that something and how hard would it be to 
implement on other systems.
4. Any other issues?


Thanks in advance

Dror

benson@odi.com (Benson I. Margulies) (06/23/91)

You need to deal with patch/munch.
-- 
Benson I. Margulies

shankar@india.hp.com (Shankar Unni) (06/24/91)

In comp.lang.{c,c++}, you wrote:

> I'd like to know what would be needed to port Cfront's output to other systems:

Here are some hints for C++ 2.0 and 2.1:

> 1. You need the stream library if you use it.

Yes.

> 2. Are there any other libraries that are standard with Cfront and not
> with C?

Depends on what you mean by "standard". Two functions are *always* needed:

 -  void _main(void).
    This function is called immediately inside main(), before the first
    statement (even before the first local initialization). This function
    calls all the static constructors, and sets the program up to call the
    static destructors on exit.
    
 -  void exit(int exitstatus).
    This function calls the static destructors, and then calls _exit() with
    the same exit code.
    
If you use "new" and "delete", you'll need two functions:

 -  void *__nw__Fui(int size).
    This function implements the basic new() operator. The simplest
    implmentatation is to call "malloc(size)" and return the result.

 -  void __dl__FPv(void *ptr).
    This function implements the basic delete() operator. The simplest
    implementation is to call "free(ptr)".

> 3. There is something that is done in link time (I think that it has to do
> with the vtables). What is that something and how hard would it be to
> implement on other systems.

You need to "munch" the .o's. The simplest "munch" is something that will
run "nm" on all the .o's and .a's that go into the link, and grep for the
strings "__sti__" and "__std__" respectively. Collect all these symbols
into a file, and massage it to generate two functions, one which calls all
the __sti__ functions, and one which calls all the __std__ functions.  Then
compile this file, and link it together with the rest of your .o's and
lib.a's to make your executable. Call the first one from _main(), and the
second one from your exit() function.

By the way, nothing special needs to be done for vtables. Ignore them.


NOTE IF YOU ARE PORTING TO AN ANSI-C COMPLIANT C PLATFORM (or a close
approximation thereof):

If your C platform supports the "atexit" function, then you needn't
(shouldn't) write your own exit() function. Instead, make _main() install
the name of the function which calls all the __std__ functions (described
just above) using "atexit()".
-----
Shankar Unni                                   E-Mail: 
HP India Software Operation, Bangalore       Internet: shankar@india.hp.com
Phone : +91-812-261254 x417                      UUCP: ...!hplabs!hpda!shankar

djones@megatest.UUCP (Dave Jones) (06/25/91)

From article <1991Jun21.211157.10040@starnet.uucp>, by dror@starnet.uucp (Dror Matalon):

> 4. Any other issues?

I'm using a pure-compiler version of c++ now, but the version of cfront
that I used to have produced C code that had already effectively had a cpp
done on it. Therefore, you'll have to be sure that the #include-files
the compiler finds are for the target machine and target-machine libraries,
not for the host machine. Beware of any #ifdef switches on the machine
type in the source code or in the #include-files. Better yet, get a
C++ compiler for the target machine, and don't even try to port the
derived C code.

mnm@hpcupt3.cup.hp.com (Michey Mehta) (06/26/91)

From article <1991Jun21.211157.10040@starnet.uucp>, by dror@starnet.uucp (Dror M
atalon):

> 4. Any other issues?

Note that cfront needs to know exactly how structs are laid out, and the
default layout rules are appropriate for the host machine. If your target
machine has different sizes and alignments, you will have to use the +x
option to specify a file of sizes and alignments.