TOK_Wang 发表于 2010-08-18 17:30

Semo Compiler(析码)编译框架 0.2.0 代码,ARM、ELF、SSA等

本帖最后由 TOK_Wang 于 2011-01-29 10:17 编辑

http://www.tok.cc/postpics/semo2.jpg
Semo Compiler(析码)0.2.0 架构

最新的代码中我们完成了SASM汇编代码生成、ARM汇编器基础架构,ELF连接器,SSA优化等等,以下是析码0.2.0的代码与演示程序欢迎对该项目该兴趣的朋友了解,由于C语言前段还未完成,在输入无法识别的语法时可能会引发异常,请按照我们提供的测试代码运行演示程序。

关于编译参数:

Format :
sc option1-option2...-optionn <SET module=para> file1 file2...filen
Options :
-ccompile for c language based on C99,基于C99标准语法集解析源代码。
-cpp compile for c plus plus language,基于C++语法集解析源代码。
-java compile for java language,基于java语法集解析源代码。
-po export pre-compiling results to external file,输出预编译结果到外部文件。
-lac export IR to external file,输出IR到外部文件。
-sasm export smart assembly code to external file,输出SASM汇编代码到外部文件。
-cr enable compiling-render and export results,开启compiling-render,并输出结果。
-elf generate object-file with ELF format by default,基于ELF格式生成目标文件,默认。
-link compile and link,编译并连接。
-nlink compile only by default,仅编译,默认。
-arm compile for the ARM architecture by default,基于ARM指令集编码。
-x80386 compile for the x80386 architecture,基于x80386指令集编码。

SET :
该指令为某些模块设置特定参数,例如预编译与compiling-render。
module : po pre-compiling,预编译。
parameter : dc delete comments,删除注释。
parameter : ms marco substitution,宏替换。
parameter : dm both dc and ms features by default,开启删除注释与宏替换两特性,默认。

module : cr compiling-render
parameter : lga lgnosia graph
parameter : exp expression graph

Example :
sc test.c -c -x80386
sc -c -lac -sasm test.c test2.c test3.c
sc -c -lac -sasm -cr -arm SET po=dc,ms SET cr=lga test.c test2.c

以上参数的输入顺序任意。

关于“Compiling-Render”:
其是Smart Compiler的一个调试工具,主要用来图形化编译器内部的数据模型,例如“抽象语法树”、“控制流”、“数据流”、“生命域”等等。此前,像是表达式翻译我们需要花费大量时间手工绘制相关图形然后人工验证翻译结果,而现在使用“Compiling-Render”可以自动将想要的模型图形化,使得我们可以将主要精力集中在中后段的优化上,方便开发。后续版本会加入“寄存器分配热度分布图”、“时间开销分布图”、“内存开销分布图”等等。下图是由其生成的一颗图形化的“LGNOSIA”。在Compiling-Render启用后,析码会生成一个bmp,若要查看请点击:右键->编辑,直接双击可能会无法显示。

http://www.tok.cc/postpics/cr1.jpg
expression graph

http://www.tok.cc/postpics/cr2.jpg
lgnosia graph of control-flow

代码:http://www.tok.cc/postpics/SCSSAC.rar
演示程序:http://www.tok.cc/postpics/SCSSA.rar

http://www.tok.cc/postpics/smartc.jpg
析码编译框架

http://avatar.profile.csdn.net/D/5/9/1_webpla.jpg
突壳开源

联动帖:http://linux.chinaunix.net/bbs/thread-1167794-1-3.html

EricFisher 发表于 2010-08-18 17:58

> SSA优化

很强悍啊

prolj 发表于 2010-08-18 18:21

本帖最后由 prolj 于 2010-08-18 18:23 编辑

麻烦你不要仅仅广告,出来跟大家交流。我不介意这里成为你项目的交流地,但是你总是广告拉人的话。
我是想封号的。
因为你的行为没有给bbs带来任何好处,仅仅是宣传你自己了。

steven_known 发表于 2010-08-20 11:11

你们已经在SSA上做了哪些优化?

EricFisher 发表于 2010-08-20 19:19

有IRC么?哈哈

TOK_Wang 发表于 2010-08-21 00:11

麻烦你不要仅仅广告,出来跟大家交流。我不介意这里成为你项目的交流地,但是你总是广告拉人的话。
我是想 ...
prolj 发表于 2010-08-18 18:21 http://linux.chinaunix.net/bbs/images/common/back.gif

呵呵,prolj兄说的是。

TOK_Wang 发表于 2010-08-21 00:13

本帖最后由 TOK_Wang 于 2010-08-21 00:25 编辑

你们已经在SSA上做了哪些优化?
steven_known 发表于 2010-08-20 11:11 http://linux.chinaunix.net/bbs/images/common/back.gif


: SC Generated
gtkings()
{
L0:
L1:
L2:
L3:
L4:
L5:
L6:
L7:
L8:
                %$R.1 = a1+a1;
        if ( %$R.1 ) FALSE goto L15:
L9:
                        %$R.1 = a1+a1;
                if ( %$R.1 ) FALSE goto L15:
L10:
                        %$R.1 = a1+a1;
                        a2 = %$R.1 ;
L11:
                        %$R.2 = a2+a2;
                        a3 = %$R.2 ;
L12:
                                %$R.1 = %$SSA_MEG(a3,a1)+%$SSA_MEG(a3,a1);
                        if ( %$R.1 ) FALSE goto L15:
L13:
                                %$R.1 = %$SSA_MEG(a3,a1)+%$SSA_MEG(a3,a1);
                                a4 = %$R.1 ;
L14:
                                %$R.2 = a4+a4;
                                a5 = %$R.2 ;
                        goto L15:
                goto L15:
        goto L15:
L15:
                %$R.1 = %$SSA_MEG(a5,a3,a1)+%$SSA_MEG(a5,a3,a1);
        if ( %$R.1 ) FALSE goto L18:
L16:
                %$R.1 = %$SSA_MEG(a5,a3,a1)+%$SSA_MEG(a5,a3,a1);
                a6 = %$R.1 ;
L17:
                %$R.2 = a6+a6;
                a7 = %$R.2 ;
        goto L18:
L18:
                %$R.1 = %$SSA_MEG(a1,a3,a5,a7)+%$SSA_MEG(a1,a3,a5,a7);
        if ( %$R.1 ) FALSE goto L28:
L19:
                        %$R.1 = %$SSA_MEG(a7,a5,a3,a1)+%$SSA_MEG(a7,a5,a3,a1);
                if ( %$R.1 ) FALSE goto L28:
L20:
                        %$R.1 = %$SSA_MEG(a7,a5,a3,a1)+%$SSA_MEG(a7,a5,a3,a1);
                        a8 = %$R.1 ;
L21:
                        %$R.2 = a8+a8;
                        a9 = %$R.2 ;
L22:
                                %$R.1 = %$SSA_MEG(a9,a7,a5,a3,a1)+%$SSA_MEG(a9,a7,a5,a3,a1);
                        if ( %$R.1 ) FALSE goto L28:
L23:
                                %$R.1 = %$SSA_MEG(a9,a7,a5,a3,a1)+%$SSA_MEG(a9,a7,a5,a3,a1);
                                a10 = %$R.1 ;
L24:
                                %$R.2 = a10+a10;
                                a11 = %$R.2 ;
                        goto L28:
L25:
                        %$R.3 = e1+b1;
                        a12 = %$R.3 ;
L26:
                        %$R.4 = a12+b1;
                        e2 = %$R.4 ;
                goto L28:
L27:
                %$R.1 = %$SSA_MEG(e2,e1)+%$SSA_MEG(a12,a11,a3,a1);
                b2 = %$R.1 ;
        goto L28:
L28:
        %$R.1 = %$SSA_MEG(b2,b1)+%$SSA_MEG(a12,a11,a3,a1);
        e3 = %$R.1 ;
L29:
        %$R.2 = %$SSA_MEG(b2,b1)+%$SSA_MEG(b2,b1);
        b3 = %$R.2 ;
L30:
        %$R.3 = %$SSA_MEG(a12,a11,a3,a1)+%$SSA_MEG(a12,a11,a3,a1);
        a13 = %$R.3 ;
}

只是在IR中实现了SSA,其它还在逐步完善。:)

TOK_Wang 发表于 2010-08-21 00:14

有IRC么?哈哈
EricFisher 发表于 2010-08-20 19:19 http://linux.chinaunix.net/bbs/images/common/back.gif
IRC是?

steven_known 发表于 2010-08-21 13:56

回复 7# TOK_Wang
SSA_MEG是表示PHI节点吗。$R.*是表示临时寄存器变量吗

erlangsir 发表于 2010-08-22 22:57

文本文件test内容为:
void test()
{
    int a;
    int b;
    int c;

    a = b + c;
}
使用sc -c -sasm test命令编译后,得到文件test.sasm,其内容为:

proc test
L0:
L1:
L2:
L3:
ADD R1,R1,R1
end

为什么a、b、c三个变量使用相同的寄存器
页: [1] 2 3
查看完整版本: Semo Compiler(析码)编译框架 0.2.0 代码,ARM、ELF、SSA等