From 1403e0a231c2f910b6bdc2379dea4363085ccfb0 Mon Sep 17 00:00:00 2001 From: nitrix Date: Sat, 7 Mar 2020 00:22:22 +0100 Subject: [PATCH] fix indices --- src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java index f99f1f9..7f9bf1b 100644 --- a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java +++ b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java @@ -822,7 +822,7 @@ public class GenASM implements Visitor { this.ex.write(" movq " + Helper.getFieldOffset(structDef, e.path[0]) + "(%rax), %rax\n"); for (int i = 1; i < e.path.length; i++) { // "follow" the current path element - structDef = this.structs.get(structDef.fields[Helper.getFieldIndex(structDef, e.path[i])].type.getName()); + structDef = this.structs.get(structDef.fields[Helper.getFieldIndex(structDef, e.path[i - 1])].type.getName()); this.ex.write(" movq " + Helper.getFieldOffset(structDef, e.path[i]) + "(%rax), %rax\n"); } @@ -880,8 +880,8 @@ public class GenASM implements Visitor { // If there are at least two elements in the path, // move the address of the next referenced struct into rax - for (int i = 0; i < e.path.length - 1; i++) { - structDef = this.structs.get(structDef.fields[Helper.getFieldIndex(structDef, e.path[i])].type.getName()); + for (int i = 1; i < e.path.length - 1; i++) { + structDef = this.structs.get(structDef.fields[Helper.getFieldIndex(structDef, e.path[i - 1])].type.getName()); this.ex.write(" movq " + Helper.getFieldOffset(structDef, e.path[i]) + "(%rax), %rax\n"); }