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.
Yes, I am interested in the interpreter, but perhaps I misunderstand what LLVM is…
My assumption has been that LLVM generates machine code for a virtual machine, and that you supply an interpreter that will execute the code.
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.
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.
> From: Duncan Sands baldrick@free.fr > Subject: Re: [LLVMdev] C++ to C? > To: michaeldmcdonnell@yahoo.com > Cc: llvmdev@cs.uiuc.edu > Date: Saturday, October 11, 2008, 12:25 PM > > <br>> Hi Michael,<br>> <br>> > Thank you very much for your help. I have a few more questions if you have<br>> a moment...<br>> > <br>> > * Are there executables available for windows?<br>> <br>> I think so, but since I don't use windows I can't say for sure.<br>> <br>> > * Is the source code for the interpreter available, and if so, what is/are<br>> the filename(s)?<br>> <br>> Sure, all source code is available: this is an open source project!<br>> Do you really mean the interpreter? You seemed more interested in<br>> the C backend. In any case, you can find source code here:<br>> http://llvm.org/releases/<br>> For the 2.3 release:<br>> http://llvm.org/releases/download.html#2.3<br>> <br>> > * Is there an IDE available?<br>> <br>> LLVM is not a compiler. It is used by various compilers such<br>> as llvm-gcc and clang. One of those might have an IDE, but I<br>> wouldn't know since I never use IDE's myself.<br>> <br>> Ciao,<br>> <br>> Duncan.<br>> <br>> PS: Please don't send messages just to me: CC to mailing<br>> list too. That way others can answer you too, and the<br>> discussion is recorded in the archives where others with<br>> the same questions can find it.<br>> <br>>
The term "virtual" in LLVM doesn't refer to emulating hardware, or
providing a hypervisor. It simply refers to the intermediate instruction
format (please correct me if I am wrong).
LLVM is already capable to generate *native* machine code from C/C++ on
its own.
There is also a JIT and interpreter that run your program in the same
process.
The JIT translates to native code on the fly, and the interpreter is
like a bytecode interpreter (say compare to Lua), and not an interpreter for
instructions of a processor (say compare to a MIPS emulator/simulator).
It is not a hypervisor, and doesn't emulate peripherals and such.
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.
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.
What I meant with this comment is that lli doesn’t add any abstractions to the machine. For example, lli allows calling out to native functions which happen to be linked in to the executable. Additionally, decisions like the size of various types have already been hardened in the LLVM IR by whatever front end generated the code. I don’t find the term “virtual machine” to be very precise; but I would be hesitant to say the interpreter is (implements?) one.
It isn’t clear to me yet. I have used LLVM for a different but similar purpose, which effectively implements a stronger virtual machine on top of the LLVM IR. I have been very happy with the decision to use LLVM instead of, say, working with x86 directly.
On the other hand, if you are only interested in a teaching tool, why not use something like SPIM for example? If your usage model is different than SPIM then explaining it may clarify how LLVM would fit.
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? ( Knuth: MMIX ) 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.
Thank you Andrew and Daniel for your comments and help.
I understand a bit better now what LLVM is (a good idea by the way).
I’ve only heard about Knuth’s system; I’ll check it out. I’m really looking for a system with a C/C++ compiler though; hopefully someone has integrated gcc into it.
> From: Andrew Beyer beyer.andrew@gmail.com > Subject: Re: [LLVMdev] C++ to C? > To: michaeldmcdonnell@yahoo.com, “LLVM Developers Mailing List” llvmdev@cs.uiuc.edu > Date: Saturday, October 11, 2008, 1:58 PM > > <br>> I think LLVM is capable of what you're asking, but it isn't really a<br>> goal of the project, and thus might require you to put in a fair<br>> amount of work yourself to get there. LLVM is targeted much more at<br>> the compiler side of things...it makes a great educational tool in<br>> that domain, but the virtual instruction set is tailored more to the<br>> needs of compiler front-ends, optimizers, and code generators than to<br>> being a realistic model of a processor architecture.<br>> <br>> Have you taken a look at Knuth's MMIX? (<br>> http://www-cs-faculty.stanford.edu/~uno/mmix.html ) It seems like that<br>> might be a closer match to what you are looking for. Last I looked,<br>> the core MMIX software included an assembler, but not a compiler...but<br>> I believe there is an MMIX backend for gcc available. Also, although<br>> it isn't a virtual machine, the MIPS architecture is relatively simple<br>> and regular, and thus has been commonly used educationally as an<br>> introduction to machine architecture and code generation.<br>> <br>> On Sat, Oct 11, 2008 at 1:28 PM, Michael McDonnell<br>> <michaeldmcdonnell@yahoo.com> wrote:<br>> > Hi Daniel,<br>> ><br>> > Thanks for your help.<br>> ><br>> > You mentioned that "the current interpreter makes no pretense of<br>> running on<br>> > a "virtual machine"", but isn't the interpreter itself<br>> a virtual machine?<br>> > I'm not looking to emulate any particular processor - just interested<br>> in a<br>> > tool that will help teach how a processor works.<br>> ><br>> > Can LLVM help, or am I completely off track?<br>> ><br>> > Thanks,<br>> > M. McDonnell<br>> ><br>> > --- On Sat, 10/11/08, Daniel Dunbar <daniel@zuster.org> wrote:<br>> ><br>> > From: Daniel Dunbar <daniel@zuster.org><br>> > Subject: Re: [LLVMdev] C++ to C?<br>> > To: michaeldmcdonnell@yahoo.com, "LLVM Developers Mailing List"<br>> > <llvmdev@cs.uiuc.edu><br>> > Cc: "Duncan Sands" <baldrick@free.fr><br>> > Date: Saturday, October 11, 2008, 1:18 PM<br>> ><br>> > Hi Michael,<br>> ><br>> > On Sat, Oct 11, 2008 at 12:44 PM, Michael McDonnell<br>> > <michaeldmcdonnell@yahoo.com> wrote:<br>> >><br>> >> My assumption has been that LLVM generates machine code for a virtual<br>> >> machine, and that you supply an interpreter that will execute the<br>> code.<br>> ><br>> > The name can be somewhat confusing. LLVM is a lot of things, the web page<br>> > gives some important areas (http://llvm.org/). In your case it sounds like<br>> > you are mainly interested in the "virtual instruction set"<br>> aspect. In this<br>> > case, yes, llvm-gcc does generate "machine code" (LLVM<br>> intermediate<br>> > representation (IR)) for the virtual instruction set, which lli can<br>> > interpret directly. Additionally, LLVM supplies a variety of tools for<br>> > working with .bc files (serialized versions of this formation), i.e. for<br>> > linking, archiving, etc.<br>> ><br>> >><br>> >><br>> >> I'm interested in this from an educational standpoint. What<br>> I'd like is a<br>> >> C/C++ compiler that generates machine code for a virtual software<br>> machine.<br>> >> Ideally the machine would support interrupts, timers, DMA controllers,<br>> etc..<br>> >> I know that your interpreter does not, but I thought I might add these<br>> >> peripherals in.<br>> >><br>> ><br>> > Using LLVM is a viable strategy for this. However, it is a question of how<br>> > much support you are expecting. The main benefit you are getting is<br>> precise<br>> > semantics for LLVM IR and the tool chain for working with .bc files. This<br>> > allows you to avoid dealing with many nitty particulars of x86 (assuming<br>> > that is your target). On the other hand, the current interpreter makes no<br>> > pretense of running on a "virtual machine", so if this is your<br>> goal you will<br>> > need to build those facilities yourself. Finally, using LLVM IR directly<br>> may<br>> > pose some issues depending on what level of precision you want. Since a<br>> > significant amount of work is done in code generation for the particular<br>> > target, the actual x86 instructions which are generated may access memory<br>> > "differently" than your interpretation of the LLVM IR would;<br>> generally this<br>> > would be because the source code didn't constrain things appropriately<br>> > (volatile) but it is something to be cognizant of.<br>> ><br>> > - Daniel<br>> ><br>> >> If you have any suggestions I'd appreciate hearing them. I know<br>> about the<br>> >> various PC emulators like BOCHS, but they're doing a lot more than<br>> I need.<br>> >><br>> >> Thanks,<br>> >> M. McDonnell<br>> >> --- On Sat, 10/11/08, Duncan Sands <baldrick@free.fr> wrote:<br>> >><br>> >> From: Duncan Sands <baldrick@free.fr><br>> >> Subject: Re: [LLVMdev] C++ to C?<br>> >> To: michaeldmcdonnell@yahoo.com<br>> >> Cc: llvmdev@cs.uiuc.edu<br>> >> Date: Saturday, October 11, 2008, 12:25 PM<br>> >><br>> >> Hi Michael,<br>> >><br>> >> > Thank you very much for your help. I have a few more questions if<br>> you<br>> >> > have<br>> >> a moment...<br>> >> ><br>> >> > * Are there executables available for windows?<br>> >><br>> >> I think so, but since I don't use windows I can't say for<br>> sure.<br>> >><br>> >> > * Is the source code for the interpreter available, and if so,<br>> what<br>> >> > is/are<br>> >> the filename(s)?<br>> >><br>> >> Sure, all source code is available: this is an open source project!<br>> >> Do you really mean the interpreter? You seemed more interested in<br>> >> the C backend. In any case, you can find source code here:<br>> >> http://llvm.org/releases/<br>> >> For the 2.3 release:<br>> >> http://llvm.org/releases/download.html#2.3<br>> >><br>> >> > * Is there an IDE available?<br>> >><br>> >> LLVM is not a compiler. It is used by various compilers such<br>> >> as llvm-gcc and clang. One of those might have an IDE, but I<br>> >> wouldn't know since I never use IDE's myself.<br>> >><br>> >> Ciao,<br>> >><br>> >> Duncan.<br>> >><br>> >> PS: Please don't send messages just to me: CC to mailing<br>> >> list too. That way others can answer you too, and the<br>> >> discussion is recorded in the archives where others with<br>> >> the same questions can find it.<br>> >><br>> >><br>> >> _______________________________________________<br>> >> LLVM Developers mailing list<br>> >> LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu<br>> >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<br>> >><br>> ><br>> ><br>> ><br>> > _______________________________________________<br>> > LLVM Developers mailing list<br>> > LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu<br>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<br>> ><br>> ><br>> <br>>
Thanks for the reference to SPIM. It looks interesting, but appears to be an assembler that can also execute the code (it does not execute binary files). In addition, I’m probably asking for too much. Ideally, I’m looking for something like MS Visual Studio with that executes on a virtual software machine, whose source code is freely available.
I think LLVM is way overkill for what you need (which I assume to be
some sort of introductory course in computer architecture), "The
Elements of Computing Systems" [1] and the accompanying software [2]
would probably be great teaching material instead, I haven't really
used them but I've watched a short video lecture about it [3], and it
looks quite well done
just my quick comment (not really much of a poster here):
but, have you looked into the Java VM?..
just from what all I have read, this is probably closer to what you might be asking for.
more so, there are some compilers that allow compiling from C to java bytecode, but I have not looked much into them (I personally have doubts as to how effectively C can be mapped to the JVM, but this is a different issue).
there are also IDE’s like Eclipse and similar…
there is also GCJ (GNU compiler for Java), which has some interesting features, some of which may be useful.
MS’s .NET stuff might also be worth looking into, where here we have C++/CLI and similar, which compiles to MSIL/CIL, which is a bytecode format (granted though, it is typically JIT-compiled though, as the bytecode is not particularly well suited to efficient interpretation). likewise, all of this stuff is supported in Visual Studio.
a lot more free code is available for the JVM than .NET though (actually, between them, I like the JVM better, although I will admit that technically there are things .NET does a little better IMO…).
ok, granted, I don’t really use Java or .NET personally… (I have my own reasons for preferring to stick with targeting the native architecture… and personally don’t really care for IDE’s either…).