What is the difference between object code and intermediate code?

In this question a user answered that the object code is different from intermediate code.

Since most courses say that object code is in the middle of the process, so couldn't we call it intermediate code? So what's the difference?

as you can see here:

Author: Maniero, 2020-05-29

1 answers

Intermediate code can have several forms, including it can be a source, while Object Code is usually a machine code. It's not that the object can't be a source, but it usually isn't.

Intermediate code is an easier way for the compiler to work. The source code follows the rules of the language, which may not be easy for the compiler to handle, so it compiles the source of the language to a language of it, which is intermediate because it is not the final code which is the machine code. Most complex compilers, which intend to do optimization or create certain features have this, otherwise the result will be inferior or it will be very difficult to work with it internally.

The subject is a bit complicated because it depends a bit on the context.

Two-phase compilation

For example, the intermediate code that the C# compiler generates is the CIL (more ) and ends up in a format binary and is sent as part of the executable. In a way that's intermediate code and it's in code that's a bit of an object, but it's encapsulated in an executable. So it's hard to define these things well. What is certain is that this CIL is not the executable machine code, this will only occur after it has a jitting (in most CLR implementations).

Something similar occurs with other languages like Java and others of script that the people say it is interpreted , but it was compiled before. In general all these languages generate an intermediate code called bytecode (I did not find link from here to post #ficaadica). This bytecode , is not the source of the language and is not the machine code. In general it is not a text, it is a binary, it is a form of Assembly that is written as machine code on a virtual platform, unlike the actual machine code that is for a processor who will perform for real.

Some of these bytecodes will be Jittled and others will be "interpreted". I'm not going to go into details here.

Internal use of compilers

But it is very common for compilers to use intermediate code that is not even exposed outside of it, it is only for use of it, so it does not usually (sometimes can) write it somewhere.

For example Rust says it improved the speed of the compiler when it passed adopting a code intermediate instead of doing everything in the original code. I don't know if it's true, it's still very slow. It has two intermediate code because the backend is the LLVM.

This can be more useful because you separate the compiler into two parts. A frontend that takes the source of the program to be compiled and creates intermediate code. And a backend that takes that intermediate code and generates the machine code for the target platform. Without this he would have to do all together and it gets complicated.

Has software that is only backends so the only way to use them is through an IR, as is the case of LLVM.

GCC has some IRs of its own and can generate from third parties like LLVM.

The IR is the intermediate representation of a code, which is a generic term to talk about what the intermediate code will be.

Conclusion

I don't think the object code is intermediate, it's contexts different, and the object code being the machine code definitely it is not intermediate.

Cannot confuse the term code in these two cases. Intermediate code is a language, object code is an end product. But in fact it is the kind of thing that gives room for interpretation. They are different functions.

Most of these things are only useful for those who are messing with compilers and tools attached or doing much more advanced things. I think everyone should learn these things to be better, but not fundamental. A pilot does not need to understand mechanics, but he will be better if he understands.

 4
Author: Maniero, 2020-06-11 14:45:34