http://blog.csdn.net/makethyme/archive/2007/07/23/1703992.aspx
ARM编译程序参考
介绍ARM编译程序的ARM特有方面,包括:
Pragmas
编译指示
Function keywords
函数关键字
Variable declaration keywords 变量声明关键字
Pragmas
ARM编译程序可识别一下格式的编译指示:
#pragma [no_] feature-name
编译指示优于相关的命令行选项。
能识别的编译选项如下:
|
Pragma name
|
Default
|
Reference
|
|
arm section
|
Off
|
Pragmas controlling code generation
|
|
check_printf_formats
|
Off
|
Pragmas controlling printf and scanf argument checking
|
|
check_scanf_formats
|
Off
|
Pragmas controlling printf and scanf argument checking
|
|
check_stack
|
On
|
Pragmas controlling code generation
|
|
debug
|
On
|
Pragmas controlling debugging
|
|
import
|
|
code generation
|
|
Ospace
|
|
optimization
|
|
Otime
|
|
optimization
|
|
Onum
|
|
optimization
|
|
softfp_linkage
|
Off
|
code generation
|
- check_printf_formats
该编译指示标记类似于printf的函数,如果存在文字格式串,则对照进行类型检查。
#pragma check_printf_formats
extern void myprintf(const char *format, …);
#pragma no_check_printf_formats
- check_scanf_formats
该编译指示对声明为类似于scanf的函数做标记,以便对照文字格式串检查自变量的格式。
#pragma check_scanf_formats
extern void myformat(const char *format, …);
#pragma no_check_scanf_formats
- debug 该编译指示可打开或关闭调试表生成, 如果指定#pragma no_debug,则不会为随后的声明和函数生成调试信息表条目,直到下一个#pragma debug出现。
- Pragmas controlling optimization
Ospace
Otime
Onum
- Pragmas controlling code generation
- check_stack 如果已经使用了#pragma no_check_stack和-apcs/swst命令行选项禁止栈检查,则该编译指示可使的检查是否违反了栈限制的函数入口代码的重新生成。
- once 同#ifndef …#endif效果相类似,用于头文件。但一般推荐使用#ifndef…#define。
- softfp_linkage 该编译指示指定了至下一个#pragma no_softfp_linkage之间的所有函数声明描述了使用软件浮点链接的函数。__softfp关键字与该编译指示的效果相同
- import(symbol_name) 该编译指示生成对symbol_name的导入引用。同如下汇编语言相同:IMPORT symbol_name。符号名作为外部符号放在映像的符号表中。
- arm section section_sort_list This pragma specifies the code or data section name that used for subsequent function or objects.This include definitions of anonymous objects the compiler creates for initializations.该编译指示可指定代码或数据段的名称用于随后的函数或对象。包括编译程序为初始化而创建的匿名对象的定义。该选项对一下情况没有影响:
内联函数(及其局部静态变量)
模板实例(及其局部静态变量)
消除未使用的变量和函数
将定义写入目标文件中的顺序
该编译指示完整语法为:
#pragma arm section [sort_type[[=]“name”]][,sort_type=
“name”]
此处name用于段名称,sort_type可为如下之一code, rwdata, rodata
和zidata。若指定sort_type,没有指定name,则sort_type的段名被
重新设置为默认值。单独输入#pragma arm section,则所以对象段的
恢复为其默认值
int
x1
=
5
;
//
in .data (default)
int y1[ 100 ]; // in .bss (default)
int const z1[ 3 ] = {1,2,3} ; // in .constdata (default)
#pragma
arm section rwdata = "foo", rodata = "bar"

int
x2
=
5
;
//
in foo (data part of region)
int
y2[
100
];
//
in .bss
int const z2[ 3 ] = {1,2,3} ; // in bar
char
*
s2
=
"
abc
"
;
//
s2 in foo, "abc" in bar
#pragma
arm section rodata
int
x3
=
5
;
//
in foo
int
y3[
100
];
//
in .bss
int const z3[ 3 ] = {1,2,3} ; // in .constdata
char
*
s3
=
"
abc
"
;
//
s3 in foo, "abc" in .constdata
#pragma
arm section code = "foo"
int
add1(
int
x)
//
in foo (code part of region)
{
return x+1;
}
#pragma
arm section code
使用分散加载描述文件和链接程序,以控制将命名段放置在存储器中
的特定地址。
· Function keywords
一些关键字指示编译程序对其某个函数进行特殊处理。包括函数内的声明,函数限定符及函数存储类限定符。即Declarations inside function, Function qualifiers and Function storage.
__asm{assembler-code} 指示编译程序该语句是用汇编语言编写的。
__irq
This enables a C or C++ function to be used as an interrupt routine called by the IRQ, or FIQ vectors. All corrupted registers except floating-point registers are preserved, not only those that are normally preserved under the ATPCS. The default ATPCS mode must be used. The function exits by setting the pc to lr-4 and the CPSR to the value in SPSR. It is not available in tcc or tcpp. No arguments or return values can be used with __irq functions.
__pure
指明函数声明为纯的。纯函数没有了公共子表达式。默认情况下,函数假定是不纯的(产生副作用)。纯函数需要满足:其结果仅取决于其自变量的值;没有副作用,其不能调用非纯函数。不能使用全局变量或废弃指针,同一参数两次调用纯函数,返回应该相同。
本文详细介绍了ARM编译器特有的编译指示(pragmas)、函数关键字(function keywords)及变量声明关键字等内容。针对不同的编译指示,如debug、check_printf_formats等进行了说明,并解释了它们如何影响代码生成和优化。
1403

被折叠的 条评论
为什么被折叠?



