Compiler construction ARB片段If/Else

Compiler construction ARB片段If/Else,compiler-construction,assembly,compiler-theory,Compiler Construction,Assembly,Compiler Theory,我有一个问题,我似乎无法集中注意力,所以我希望这里的人能帮我解决这个问题 我正在为miniGLSL编写一个编译器,到目前为止还不错。我现在需要输出到ARB片段程序,但问题是,我必须针对的ARB不支持分支。(可在此处找到受支持说明的完整列表) 为了模拟if/else,我使用了CMP程序,如下所示(假设0或更大=true,否则,false//将注释表示为#导致此处格式错误): if(a

我有一个问题,我似乎无法集中注意力,所以我希望这里的人能帮我解决这个问题

我正在为miniGLSL编写一个编译器,到目前为止还不错。我现在需要输出到ARB片段程序,但问题是,我必须针对的ARB不支持分支。(可在此处找到受支持说明的完整列表)

为了模拟if/else,我使用了CMP程序,如下所示(假设0或更大=true,否则,false//将注释表示为#导致此处格式错误):

if(a
进入ARB片段:

TEMP cond1, cond2, cond3, tempvar1, tempvar2, tempvar3, tempvar4, a, b, c, d, e, f, g;
//TOP IF
//condition a < b
SLT a, b, cond1;
SUB cond1, 1.0, cond1;

//Assign if true
ADD 1.0, 1.0, tempvar1;
CMP cond1, a, tempvar1, a;

//Condition f < g
SLT f, g, cond2;
SUB cond2, 1.0, cond2;
//if top level if was false, assign false, otherwise assign it to itself
CMP cond1, -1.0, cond2, cond2;
//Assignment
ADD 2.0, 3.0, tempvar2;
CMP cond2, c, tempvar2, c;

//TOP ELSE
//if h < i
SLT h, i, cond2;
SUB cond2, 1.0, cond2;
//If top level if was true, make false
CMP cond1, cond2, -1.0, cond2;
CMP cond2, tempvar3, b, b;
//Else
//if top level if was true, and previous if was false, make true
TEMP cond1、cond2、cond3、tempvar1、tempvar2、tempvar3、tempvar4、a、b、c、d、e、f、g;
//顶级IF
//条件a
这是在我意识到我的代码将开始变得非常难看之前我所得到的。if/else的每一级都将引入连续堆叠比较,另外,最后一级else要求我重新计算cond2,或者使用另一个寄存器。我知道我可能做错了什么,但我不确定是什么。我尝试过使用计数器,尝试过添加if/else块、ANDIN、oring等前几个阶段的结果。但是,对于如何将if/else块转换为ARB片段程序集,我找不到一个好的解决方案,因为在越来越多的CMP语句堆栈中,ARB片段程序集实际上并不存在。有没有人知道如何使它变得更简单,以便我的编译器能够以编程方式输出它?在这一点上,我不太担心优化问题,我只是想让它发挥作用


感谢您在uoft学习csc467,因为如果您是班上的即时通讯员,lol

这就是我认为应该如何实现的,我只是想了想,所以不确定它是否正确

例如: if(a 从我在这里读到的 你可以翻转输入的符号,但如果不是这样,那么我的想法就是垃圾

第一个如果:

//计算条件 SLT a、b、条件1

//计算表达式1+1它不改变任何寄存器 添加1,1,温度; cmp-条件,温度,a,a//如果条件为真-(条件)=-1
TEMP cond1, cond2, cond3, tempvar1, tempvar2, tempvar3, tempvar4, a, b, c, d, e, f, g;
//TOP IF
//condition a < b
SLT a, b, cond1;
SUB cond1, 1.0, cond1;

//Assign if true
ADD 1.0, 1.0, tempvar1;
CMP cond1, a, tempvar1, a;

//Condition f < g
SLT f, g, cond2;
SUB cond2, 1.0, cond2;
//if top level if was false, assign false, otherwise assign it to itself
CMP cond1, -1.0, cond2, cond2;
//Assignment
ADD 2.0, 3.0, tempvar2;
CMP cond2, c, tempvar2, c;

//TOP ELSE
//if h < i
SLT h, i, cond2;
SUB cond2, 1.0, cond2;
//If top level if was true, make false
CMP cond1, cond2, -1.0, cond2;
CMP cond2, tempvar3, b, b;
//Else
//if top level if was true, and previous if was false, make true