- added switch/case processing. Right now it is just a sequence of test/jmp instructions. It may make sense to add a special opcode that can perform the comparisons natively but that's an option for later.
- added a TESTN instruction. This is like TEST but negates the operand. This was added to avoid flooding the constant table with too many case labels. With TEST and TESTN combined, all numbers between -65535 and 65535 can be kept entirely inside the instruction. Numbers outside this range still use a BEQ instruction.
This commit is contained in:
parent
6587828e32
commit
f9cd2c9af7
6 changed files with 304 additions and 2 deletions
|
|
@ -2677,9 +2677,26 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast)
|
|||
|
||||
// not yet done
|
||||
case AST_SwitchStmt:
|
||||
case AST_CaseStmt:
|
||||
break;
|
||||
{
|
||||
auto swtch = static_cast<ZCC_SwitchStmt *>(ast);
|
||||
if (swtch->Content->NodeType != AST_CompoundStmt)
|
||||
{
|
||||
Error(ast, "Expecting { after 'switch'");
|
||||
return new FxNop(*ast); // allow compiler to continue looking for errors.
|
||||
}
|
||||
else
|
||||
{
|
||||
// The switch content is wrapped into a compound statement which needs to be unraveled here.
|
||||
auto cmpnd = static_cast<ZCC_CompoundStmt *>(swtch->Content);
|
||||
return new FxSwitchStatement(ConvertNode(swtch->Condition), ConvertNodeList(cmpnd->Content), *ast);
|
||||
}
|
||||
}
|
||||
|
||||
case AST_CaseStmt:
|
||||
{
|
||||
auto cases = static_cast<ZCC_CaseStmt *>(ast);
|
||||
return new FxCaseStatement(ConvertNode(cases->Condition), *ast);
|
||||
}
|
||||
|
||||
case AST_CompoundStmt:
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue