warmup learning sksl interpreter
Do some TODOs.
I have no idea what I am doing with align()... just following what
appears to be the pattern without understanding what it does.
Change-Id: I1b15240e037769efdacb399992cac1786101cd0f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214329
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/src/sksl/SkSLByteCodeGenerator.cpp b/src/sksl/SkSLByteCodeGenerator.cpp
index 4f69a41..c724483 100644
--- a/src/sksl/SkSLByteCodeGenerator.cpp
+++ b/src/sksl/SkSLByteCodeGenerator.cpp
@@ -751,22 +751,29 @@
}
void ByteCodeGenerator::writeIfStatement(const IfStatement& i) {
- // TODO: For if-else, reorder the statements to remove kNot.
- // For if w/o else, remove the trailing branch.
- this->writeExpression(*i.fTest);
- this->write(ByteCodeInstruction::kNot);
- this->align(2, 1);
- this->write(ByteCodeInstruction::kConditionalBranch);
- DeferredLocation elseLocation(this);
- this->writeStatement(*i.fIfTrue);
- this->align(2, 1);
- this->write(ByteCodeInstruction::kBranch);
- DeferredLocation endLocation(this);
- elseLocation.set();
if (i.fIfFalse) {
+ // if (test) { ..ifTrue.. } else { .. ifFalse .. }
+ this->writeExpression(*i.fTest);
+ this->align(2, 1);
+ this->write(ByteCodeInstruction::kConditionalBranch);
+ DeferredLocation trueLocation(this);
this->writeStatement(*i.fIfFalse);
+ this->align(2, 1);
+ this->write(ByteCodeInstruction::kBranch);
+ DeferredLocation endLocation(this);
+ trueLocation.set();
+ this->writeStatement(*i.fIfTrue);
+ endLocation.set();
+ } else {
+ // if (test) { ..ifTrue.. }
+ this->writeExpression(*i.fTest);
+ this->write(ByteCodeInstruction::kNot);
+ this->align(2, 1);
+ this->write(ByteCodeInstruction::kConditionalBranch);
+ DeferredLocation endLocation(this);
+ this->writeStatement(*i.fIfTrue);
+ endLocation.set();
}
- endLocation.set();
}
void ByteCodeGenerator::writeReturnStatement(const ReturnStatement& r) {