[LLVMdev] C++ to C?

Andrew Beyer beyer.andrew at gmail.com
Sat Oct 11 13:58:49 PDT 2008


I think LLVM is capable of what you're asking, but it isn't really a
goal of the project, and thus might require you to put in a fair
amount of work yourself to get there. LLVM is targeted much more at
the compiler side of things...it makes a great educational tool in
that domain, but the virtual instruction set is tailored more to the
needs of compiler front-ends, optimizers, and code generators than to
being a realistic model of a processor architecture.

Have you taken a look at Knuth's MMIX? (
http://www-cs-faculty.stanford.edu/~uno/mmix.html ) It seems like that
might be a closer match to what you are looking for. Last I looked,
the core MMIX software included an assembler, but not a compiler...but
I believe there is an MMIX backend for gcc available. Also, although
it isn't a virtual machine, the MIPS architecture is relatively simple
and regular, and thus has been commonly used educationally as an
introduction to machine architecture and code generation.

On Sat, Oct 11, 2008 at 1:28 PM, Michael McDonnell
<michaeldmcdonnell at yahoo.com> wrote:
> Hi Daniel,
>
> Thanks for your help.
>
> You mentioned that "the current interpreter makes no pretense of running on
> a "virtual machine"", but isn't the interpreter itself a virtual machine?
> I'm not looking to emulate any particular processor - just interested in a
> tool that will help teach how a processor works.
>
> Can LLVM help, or am I completely off track?
>
> Thanks,
> M. McDonnell
>
> --- On Sat, 10/11/08, Daniel Dunbar <daniel at zuster.org> wrote:
>
> From: Daniel Dunbar <daniel at zuster.org>
> Subject: Re: [LLVMdev] C++ to C?
> To: michaeldmcdonnell at yahoo.com, "LLVM Developers Mailing List"
> <llvmdev at cs.uiuc.edu>
> Cc: "Duncan Sands" <baldrick at free.fr>
> Date: Saturday, October 11, 2008, 1:18 PM
>
> Hi Michael,
>
> On Sat, Oct 11, 2008 at 12:44 PM, Michael McDonnell
> <michaeldmcdonnell at yahoo.com> wrote:
>>
>> My assumption has been that LLVM generates machine code for a virtual
>> machine, and that you supply an interpreter that will execute the code.
>
> The name can be somewhat confusing. LLVM is a lot of things, the web page
> gives some important areas (http://llvm.org/). In your case it sounds like
> you are mainly interested in the "virtual instruction set" aspect. In this
> case, yes, llvm-gcc does generate "machine code" (LLVM intermediate
> representation (IR)) for the virtual instruction set, which lli can
> interpret directly. Additionally, LLVM supplies a variety of tools for
> working with .bc files (serialized versions of this formation), i.e. for
> linking, archiving, etc.
>
>>
>>
>> I'm interested in this from an educational standpoint. What I'd like is a
>> C/C++ compiler that generates machine code for a virtual software machine.
>> Ideally the machine would support interrupts, timers, DMA controllers, etc..
>> I know that your interpreter does not, but I thought I might add these
>> peripherals in.
>>
>
> Using LLVM is a viable strategy for this. However, it is a question of how
> much support you are expecting. The main benefit you are getting is precise
> semantics for LLVM IR and the tool chain for working with .bc files. This
> allows you to avoid dealing with many nitty particulars of x86 (assuming
> that is your target). On the other hand, the current interpreter makes no
> pretense of running on a "virtual machine", so if this is your goal you will
> need to build those facilities yourself. Finally, using LLVM IR directly may
> pose some issues depending on what level of precision you want. Since a
> significant amount of work is done in code generation for the particular
> target, the actual x86 instructions which are generated may access memory
> "differently" than your interpretation of the LLVM IR would; generally this
> would be because the source code didn't constrain things appropriately
> (volatile) but it is something to be cognizant of.
>
>  - Daniel
>
>> If you have any suggestions I'd appreciate hearing them. I know about the
>> various PC emulators like BOCHS, but they're doing a lot more than I need.
>>
>> Thanks,
>> M. McDonnell
>> --- On Sat, 10/11/08, Duncan Sands <baldrick at free.fr> wrote:
>>
>> From: Duncan Sands <baldrick at free.fr>
>> Subject: Re: [LLVMdev] C++ to C?
>> To: michaeldmcdonnell at yahoo.com
>> Cc: llvmdev at cs.uiuc.edu
>> Date: Saturday, October 11, 2008, 12:25 PM
>>
>> Hi Michael,
>>
>> > Thank you very much for your help. I have a few more questions if you
>> > have
>> a moment...
>> >
>> > * Are there executables available for windows?
>>
>> I think so, but since I don't use windows I can't say for sure.
>>
>> > * Is the source code for the interpreter available, and if so, what
>> > is/are
>> the filename(s)?
>>
>> Sure, all source code is available: this is an open source project!
>> Do you really mean the interpreter?  You seemed more interested in
>> the C backend.  In any case, you can find source code here:
>>   http://llvm.org/releases/
>> For the 2.3 release:
>>   http://llvm.org/releases/download.html#2.3
>>
>> > * Is there an IDE available?
>>
>> LLVM is not a compiler.  It is used by various compilers such
>> as llvm-gcc and clang.  One of those might have an IDE, but I
>> wouldn't know since I never use IDE's myself.
>>
>> Ciao,
>>
>> Duncan.
>>
>> PS: Please don't send messages just to me: CC to mailing
>> list too.  That way others can answer you too, and the
>> discussion is recorded in the archives where others with
>> the same questions can find it.
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>



More information about the llvm-dev mailing list