The role of XG in Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The previous article probably said some how to read XG's source code, but later because too lazy, always do not want to write some very systematic things, so feel or some worth to say about writing a bit, do a memo.

In fact, the general content of XG is placed in the SRC/CMD/GC, and the entire compilation phase is the most important thing is to go.y this file, because this is the Bison syntax definition file. In fact, go in the compilation phase will simply put all the content into the nodelist data structure as the result of parsing, and then export to write a *.6 (such as the AMD64 architecture), this. 6 of the file is probably this:

Amd64
Exports automatically generated from
Test.go in package "main"

$$//Exports
Package Main
Func "". Main ()
var "". Initdone Road Uint8
Func "". Init ()

$$//local types

$$

....

Specific file format, you can refer to the implementation of the DumpObj function in SRC/CMD/GC/OBJ.C

And if we write an import in the source file, it will actually import the obj file into the current lexical parsing process, such as

Import xxx

It just loads the pkg/amd64-linux/xxx.a in, and then parses the obj file.

If we look at GO.Y's syntax analysis definition, we will see many definitions of hidden and there naming, such as Import_there, Hidden_import, etc., which are actually defined from the obj file.

Another example is that we might see some syntax definitions that don't exist in the source code at all, but it did compile because the source files were inserted into some other fragments as needed during the compilation, such as some libraries of builtin or some of the Lib libraries that were customized.

Understanding this, basically on the go to the compilation process has a knowledge of the fact that the go to compile the process of doing is to turn it into obj finished, at least we do not see more work at the moment. The next step is to get a deeper understanding of the implementation of the XL, which is part of the process of turning obj into executable code, which should be more interesting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.