From 2b655476c079f05d686f42b507bfef52d951c26f Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sat, 1 Oct 2016 20:50:06 -0400 Subject: [PATCH] Made Setexpression iterative rather than recursive --- High_level_prototypes/M0-macro.c | 12 +++++++----- stage1/M0-macro.s | 27 +++++++++++++++------------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/High_level_prototypes/M0-macro.c b/High_level_prototypes/M0-macro.c index 27521c4..b868576 100644 --- a/High_level_prototypes/M0-macro.c +++ b/High_level_prototypes/M0-macro.c @@ -133,14 +133,10 @@ struct Token* Tokenize_Line(struct Token* head) void setExpression(struct Token* p, char match[], char Exp[]) { - if(NULL != p->next) - { - setExpression(p->next, match, Exp); - } - /* Leave macros alone */ if((p->type & macro)) { + setExpression(p->next, match, Exp); return; } @@ -149,6 +145,12 @@ void setExpression(struct Token* p, char match[], char Exp[]) { p->Expression = Exp; } + + if(NULL != p->next) + { + setExpression(p->next, match, Exp); + } + } void identify_macros(struct Token* p) diff --git a/stage1/M0-macro.s b/stage1/M0-macro.s index 9b09461..647771c 100644 --- a/stage1/M0-macro.s +++ b/stage1/M0-macro.s @@ -415,25 +415,28 @@ ;; Preserve registers PUSHR R0 R15 PUSHR R3 R15 + PUSHR R4 R15 - LOAD32 R3 R0 0 ; Load Next - SWAP R0 R3 ; Protect R0 - CMPSKIP.E R0 0 ; if Next is Null - CALLI R15 @setExpression ; Don't recurse - MOVE R0 R3 ; Restore R0 + ;; Initialize + MOVE R4 R1 ; Put Macro Text in a safe place +:setExpression_0 LOAD32 R3 R0 4 ; Load type into R3 - CMPSKIP.NE R3 1 ; If Node is a macro - JUMP @setExpression_Done ; Be done - LOAD32 R3 R0 8 ; Load Text into R3 - SWAP R0 R3 ; Prepare for strncmp + CMPSKIP.NE R3 1 ; Check if Macro + JUMP @setExpression_1 ; Move to next if Macro + MOVE R3 R0 ; Preserve node Pointer + LOAD32 R0 R3 8 ; Load Text pointer into R0 for Comparision + COPY R1 R4 ; Put Macro Text for comparision CALLI R15 @strcmp ; compare Text and Macro Text - JUMP.NE R0 @setExpression_Done - - ;; Node matches + JUMP.NE R0 @setExpression_1 ; Move to next if not Match STORE32 R2 R3 12 ; Set node->Expression = Exp +:setExpression_1 + LOAD32 R0 R3 0 ; Load Next + JUMP.NZ R0 @setExpression_0 ; Loop if next isn't NULL + :setExpression_Done ;; Restore registers + POPR R4 R15 POPR R3 R15 POPR R0 R15 RET R15