Опубликован: 12.07.2012 | Доступ: свободный | Студентов: 293 / 18 | Оценка: 4.00 / 4.20 | Длительность: 11:07:00
Специальности: Программист
Лекция 3:

Optimizing compiler Scalar optimizations

< Лекция 2 || Лекция 3: 12345 || Лекция 4 >

Front End


Рис. 3.3.

Parsing is the process of input characters analysis, usually in accordance with a given formal grammar.

During parsing the source code is converted into a data structure. Usually it is a tree that reflects the syntax structure of the input sequence and is well suited for further processing.

Typically, parsing is divided into two levels:

  • lexical analysis - the input stream of characters partitioned into a linear sequence of tokens - "qwords" of language (eg, integers, identifiers, string constants, etc.);
  • semantic analysis - token are converted into statements and expressions of used language, according to grammatical rules.

At the output we get FE related tables, which are called the internal representation of the program. The usual practice is to share one internal representation for the various high-level languages.

 Internal representation

Рис. 3.4. Internal representation

The statements are usually presented in a list and can be linked in two ways:

  1. Lexically. Each statement has a predecessor and a successor.
  2. By control flow graph.
struct Stmt {
  common_members:
  int type;
  Stmt * pred;
  Stmt *succ;
  Basic_Block bblock;
  … 
 }

Some simple scalar optimizations based on walking through the list of statements to find some specific statements and process them:

For_All_Subroutine_Stmt(subroutine,stmt)  {
   if(Stmt_type(stmt) == Stmt_Assign {
      //assignment processing
   }
}
 Expressions

Рис. 3.5. Expressions
< Лекция 2 || Лекция 3: 12345 || Лекция 4 >
Еленеа Бобко
Еленеа Бобко
Беларусь, Минск
Dunduk Dunduk
Dunduk Dunduk
Россия