Skip to content

Commit

Permalink
Merge pull request #432 from Wuerfel21/W21-fix-case-spintransform
Browse files Browse the repository at this point in the history
Fix Spin transform level for CASE
  • Loading branch information
totalspectrum committed Mar 10, 2024
2 parents 4066117 + 28fa1e0 commit bbbf91b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
37 changes: 37 additions & 0 deletions Test/Expect/test169.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdlib.h>
#define __SPIN2CPP__
#include <propeller.h>
#include "test169.h"

void test169::Func1(int32_t A, int32_t B)
{
int32_t _tmp__0000;
_tmp__0000 = abs((A % 3));
if (_tmp__0000 == 0) {
goto _case__0002;
}
if (_tmp__0000 == 1) {
goto _case__0003;
}
if (_tmp__0000 == 2) {
goto _case__0004;
}
if (_tmp__0000 == (abs(B))) {
goto _case__0005;
}
goto _endswitch_0001;
_case__0002: ;
_OUTA = 1;
goto _endswitch_0001;
_case__0003: ;
_OUTA = 2;
goto _endswitch_0001;
_case__0004: ;
_OUTA = 3;
goto _endswitch_0001;
_case__0005: ;
_OUTA = 4;
goto _endswitch_0001;
_endswitch_0001: ;
}

12 changes: 12 additions & 0 deletions Test/Expect/test169.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef test169_Class_Defined__
#define test169_Class_Defined__

#include <stdint.h>

class test169 {
public:
static void Func1(int32_t A, int32_t B);
private:
};

#endif
8 changes: 8 additions & 0 deletions Test/test169.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

PUB func1(a,b)

case ||(a//3)
0: outa := 1
1: outa := 2
2: outa := 3
||b: outa := 4
2 changes: 1 addition & 1 deletion frontends/spin/spinlang.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ doSpinTransform(AST **astptr, int level, AST *parent)
{
AST *list = ast->right;
const char *case_name = ast->kind == AST_CASETABLE ? "case_fast" : NULL;
doSpinTransform(&ast->left, level, ast);
doSpinTransform(&ast->left, 0, ast);
AstReportAs(ast, &saveinfo); // any newly created AST nodes should reflect debug info from this one
#ifdef NEVER // handled in CreateSwitch now
if (ast->left->kind != AST_IDENTIFIER && ast->left->kind != AST_ASSIGN) {
Expand Down

0 comments on commit bbbf91b

Please sign in to comment.