Structure of the code table (60) for source program analysis of the LSS Compiler

Source: Internet
Author: User
The code table is used to represent the code block in the code table. The front end puts all the Code attributes in the code table, and the back end generates the code according to the code table. Its structure is as follows: #001 // code table structure definition. #002 // Cai junsheng 2007/07/27 #003 struct Code #004 {#005 // type of the code table. #006 Enum kindtype #007 {#008 blockbeg, // block start. #009 blockend, // block end. #010 local, // local variable. #011 address, // #012 defpoint, // defines the point where the breakpoint can be set. #013 label, // code block. #014 start, // code table entry. #015 Gen, // #016 jump, // jump. #017 switch // generate the switch statement. #018} kind; #019 #020 code Prev, next; #021 Unio N #022 {#023 struct #024 {#025 int level; #026 symbol * locals; #027 table identifiers, types; #028 env X; #029} block; #030 #031 code begin; #032 symbol var; #033 #034 struct #035 {#036 symbol sym; #037 Symbol Base; #038 long offset; #039} ADDR; #040 #041 struct #042 {#043 coordinate SRC; #044 int point; #045} Point; #046 #047 node forest; #048 struct #049 {#050 symbol sym; #051 symbol table; #052 symbol Defla B; #053 int size; #054 long * values; #055 symbol * labels; #056} swtch; #057 #058} U; #059 }; then, the header and tail of the code table are saved through two global pointers, so that the code table can be conveniently operated. The two pointers are as follows: #001 // entry for code creation. #002 struct code codehead = {code: start}; #003 #004 // pointer to the end of the code table. #005 code codelist = & codehead; Add code to the code table through the appendcode function. The Code is as follows: #001 // #002 // Add the block code to the code table. #003 // Cai junsheng 2007/07/27 #004 // #005 code appendcode (Code: kindtype kind) #006 {#007 code CP; #008 #009 if (! Reachable (kind) #010 {#011 warning ("unreachable code/N"); #012} #013 #014 // new (CP, func ); #015 CP = (CODE) allocate (sizeof (* CP), 0); #016 memset (CP, 0, sizeof (* CP )); #017 #018 // code block type. #019 CP-> kind = kind; #020 #021 // refers to a code block forward. #022 CP-> Prev = codelist; #023 #024 // the last part of the flag. #025 CP-> next = NULL; #026 #027 // Add it to the code two-way linked list #028 codelist-> next = CP; #029 #030 // modify codelist to point to the last part. #031 codelist = CP; #032 #033 return CP ;# 034} the code here is already a little different from the code of the LCS, because I am constantly modifying this code, and now I have completely changed it to the C ++ Method for compilation.

 

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.