Description of identifier in llvm assembly language guide

Source: Internet
Author: User
Identifier)

Llvm identifiers exist in two basic types: global and local. The GLobal IDEntifier (function, global variable) starts with the '@' character. The local identifier (register name, type) starts with '%. In addition, there are three different identifiers with their own purposes:

1. The specified (self-defined) variable is expressed as adding their prefix to a string. For example, % Foo, @ divisionbyzero, % A. Really. Long. identifier. The actually used regular expression is '[% @] [A-Za-Z $. _] [A-Za-Z $. _ 0-9]'. For example, XX is an ascii code for hexadecimal characters. You can use "\ xx" in this way ". In this way, any character can be used in a specified value or even referenced by itself.

2. An untitled variable (I think it is a temporary variable in IR) is expressed as a prefix for an unsigned number. For example, % 12, @ 2, % 44.

3. constants, which will be introduced later.

Llvm requires that all variables are prefixed with % or @. Two reasons: the compiler does not need to worry about name conflicts with reserved words of llvm. In the future, llvm can expand the reserved word set. In addition, unnamed identifiers allow the compiler to quickly propose a temporary variable without considering avoiding symbol table conflicts.

The reserved words of llvm are similar to those of other languages. There are keywords for different operation codes ('add', 'bitcast', 'ret ', Etc ...), keyword for the original type name ('void', 'i32', Etc ....) and so on. These reserved words do not conflict with the variable name, because none of these reserved words start with % or.

The following is an example of llvm code. Multiply the integer variable '% x' by 8:

Simple Method:

% Result = Mul i32 % x, 8

Another method:

% Result = SHL i32 % x, i8 3

Difficult methods:

Add i32 % x, % x; yields {i32}: % 0

Add i32 % 0, % 0; yields {i32}: % 1

% Result = add i32 % 1, % 1

The last % x multiplied by 8 illustrates several important lexical features of llvm:

1. The comment starts with ';' until the end of the line.

2. When the calculation result is not specified as a variable value, a temporary variable is created.

3. Temporary variables are ordered by numbers.

This also sets out the habits of our subsequent documents. To illustrate the command, we will add a comment (to define the type and variable name) after the command ). The comment is in italic.

 

 

 

 

 

 

 

 

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.