Click to See Complete Forum and Search --> : converting source code betweeen languages


Chess007
08-02-2007, 08:24 AM
Is it possible to make a program that will convert source code from one language to another language? For example, converting C++ to asm. Wouldn't that code - asm - be much more efficent?

saikee
08-02-2007, 09:25 AM
I think there are a few computer language translators knocking around but my experience is each language will have features not supported in another language and so the effort put into the translators doesn't pay usually.

Even the same language can be different between versions, between platforms and even between CPUs. There is simply no end to it.

I know even a simple language like Basic can be different in PDP11 Basic, VME Basic, Basica, MS Basic, Turbo Basic, Power basic, Visual Basic and Visual Basic.net. As soon as you have written a translator someone will make it obsolete by bringing out another version.

When all the different combinations and permutations are put together I really don't see end result could justify the input.

ph34r
08-02-2007, 09:59 AM
They are called work-study employees and/or interns :)

JRefL5
08-02-2007, 11:29 AM
Or if you are looking for asm, just complie it and then run it through a disassembler.
Of corse it will still have the overhead of the orignal languages system Libs/runtime env, and will be a mess of meaningless labels & variables.

I like the intern method better.

phlipant
08-02-2007, 03:20 PM
gcc has a switch (-S) which produces the asm code in a .s file. It will be no more efficient then compling directly, since this is the code used (internally) to generate the object file.

A simple code snatch like

#include <stdio.h>

main(void)
{
printf("hello world\n");
}

Becomes the following helloworld.s when compiled with -S

.file "helloworld.c"
.section .rodata
.LC0:
.string "hello world"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $4, %esp
movl $.LC0, (%esp)
call puts
addl $4, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.2 20070626 (Red Hat 4.1.2-13)"
.section .note.GNU-stack,"",@progbits

Chess007
08-03-2007, 05:24 AM
I see. My thought was if source code was converted to a more efficient language, the final program would be more efficient.

I was thinking specifically about games. The system requirements for some "modern day" games are almost insane. I don't know if thats poor coding or if games really have to be that taxing on hardware.

ph34r
08-03-2007, 09:02 AM
Chess007 - could be either. I mean, with LOTS of resources on most computers, you don't need to do things like use 2 digits for a year since you only have 16k of ram and hey, they won't be using the program any more in 25 years... :)

High end games may not need all the horsepower/clock cycles a cpu or gpu can offer, but may need one or two of the instructions they offer...