Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When generating code, what language should you generate?

I've worked on a number of products that make use of code generation. It seems to be the only way to achieve both a high degree of user-customizability and high execution speed.

The downside is that we are requiring users to install a compiler (primarily on MS Windows).

This has been an on-going headache, because vendors like MS keep obsoleting compilers, and some users tend to have more than one compiler installed.

We're considering using GNU C, and possibly C++, but even there, there are continual version issues.

I've considered possibly generating assembly language, in an effort to get off the compiler-version-treadmill, but assembly languages are all machine-specific.

Ideally there would be some way to produce generated code that would be flexible, run fast, and not expose us to the whims of third-party providers.

Maybe I'm overlooking something simple, like Java. Any ideas would be appreciated. Thanks.

like image 328
Mike Dunlavey Avatar asked Feb 25 '09 17:02

Mike Dunlavey


3 Answers

If you're considering C and even assembler, take a look at LLVM first: http://llvm.org

like image 72
Shannon Weyrick Avatar answered Oct 08 '22 00:10

Shannon Weyrick


I might be missing some context here, but could you just pin yourself to a specific version? E.g., .NET 2.0 can be installed side by side with .NET 1.1 and .NET 3.5, as well as other versions that will come out in the future. So as long as your code makes use of a specific version of a compiler, what's the problem?

like image 43
Paul Stovell Avatar answered Oct 08 '22 00:10

Paul Stovell


I've considered possibly generating assembly language, in an effort to get off the compiler-version-treadmill, but assembly languages are all machine-specific.

That would be called a compiler :)

Why don't you stick to C90?

I haven't heard much of severe violations of standards from gcc's side, if you don't use extensions.

And you can always distribute a certain version of gcc along with your product, say, 4.3.2, giving an option to users to use their own compiler at their own risk.

As long as all code is generated by you (i. e. you don't embed your instructions into other's code), there shouldn't be any problems in testing against this version and using it to compile your libraries.

like image 40
Quassnoi Avatar answered Oct 07 '22 23:10

Quassnoi