mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-08 14:37:40 +00:00
Moved statements, symbols and values into packages
This commit is contained in:
parent
fd0b667b19
commit
1fa3d8bbbf
@ -1,6 +1,8 @@
|
||||
package dk.camelot64.kickc;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.parser.KickCLexer;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
import dk.camelot64.kickc.passes.*;
|
||||
|
@ -3,6 +3,12 @@ package dk.camelot64.kickc.fragment;
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
/** Formatting of numbers, constants, names and more for KickAssembler */
|
||||
public class AsmFormat {
|
||||
@ -21,7 +27,7 @@ public class AsmFormat {
|
||||
String asmName = constantVar.getAsmName() == null ? constantVar.getLocalName() : constantVar.getAsmName();
|
||||
return getAsmParamName(constantVar.getScope().getRef(), asmName, codeScope);
|
||||
} else if(value instanceof ConstantInteger) {
|
||||
return getAsmNumber(((ConstantInteger) value).getNumber());
|
||||
return getAsmNumber(((ConstantInteger) value).getValue());
|
||||
} else if(value instanceof ConstantChar) {
|
||||
return "'" + ((ConstantChar) value).getValue() + "'";
|
||||
} else if(value instanceof ConstantString) {
|
||||
|
@ -3,6 +3,14 @@ package dk.camelot64.kickc.fragment;
|
||||
import dk.camelot64.kickc.NumberParser;
|
||||
import dk.camelot64.kickc.asm.*;
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.ConstantInteger;
|
||||
import dk.camelot64.kickc.model.values.ConstantValue;
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
|
||||
|
@ -2,6 +2,17 @@ package dk.camelot64.kickc.fragment;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementConditionalJump;
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@ -125,19 +136,19 @@ public class AsmFragmentInstanceSpec {
|
||||
}
|
||||
if(
|
||||
rValue2 instanceof ConstantInteger &&
|
||||
((ConstantInteger) rValue2).getNumber() == 1 &&
|
||||
((ConstantInteger) rValue2).getValue() == 1 &&
|
||||
operator != null &&
|
||||
(operator.getOperator().equals("-") || operator.getOperator().equals("+"))) {
|
||||
signature.append("1");
|
||||
} else if(
|
||||
rValue2 instanceof ConstantInteger &&
|
||||
((ConstantInteger) rValue2).getNumber() <= 7 &&
|
||||
((ConstantInteger) rValue2).getValue() <= 7 &&
|
||||
operator != null &&
|
||||
(operator.getOperator().equals(">>") || operator.getOperator().equals("<<"))) {
|
||||
signature.append(((ConstantInteger) rValue2).getNumber());
|
||||
signature.append(((ConstantInteger) rValue2).getValue());
|
||||
} else if(
|
||||
rValue2 instanceof ConstantInteger &&
|
||||
((ConstantInteger) rValue2).getNumber() == 0 &&
|
||||
((ConstantInteger) rValue2).getValue() == 0 &&
|
||||
operator != null &&
|
||||
(operator.getOperator().equals("-") || operator.getOperator().equals("+"))) {
|
||||
signature.append("0");
|
||||
@ -158,7 +169,7 @@ public class AsmFragmentInstanceSpec {
|
||||
if(conditionalJump.getOperator() != null) {
|
||||
signature.append(getOperatorFragmentName(conditionalJump.getOperator()));
|
||||
}
|
||||
if(conditionalJump.getrValue2() instanceof ConstantInteger && ((ConstantInteger) conditionalJump.getrValue2()).getNumber() == 0) {
|
||||
if(conditionalJump.getrValue2() instanceof ConstantInteger && ((ConstantInteger) conditionalJump.getrValue2()).getValue() == 0) {
|
||||
signature.append("0");
|
||||
} else if(conditionalJump.getrValue2() instanceof ConstantBool) {
|
||||
ConstantBool boolValue = (ConstantBool) conditionalJump.getrValue2();
|
||||
|
@ -3,6 +3,13 @@ package dk.camelot64.kickc.fragment;
|
||||
import dk.camelot64.kickc.asm.AsmClobber;
|
||||
import dk.camelot64.kickc.asm.AsmProgram;
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.ConstantInteger;
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.symbols.VariableVersion;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
import dk.camelot64.kickc.parser.KickCLexer;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
import org.antlr.v4.runtime.*;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
@ -2,18 +2,20 @@ package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
|
||||
/** Can calculate the exact value for constants (used for type inference). */
|
||||
public class ConstantValueCalculator {
|
||||
|
||||
|
||||
public static ConstantValue calcValue(ProgramScope programScope, ConstantValue value) {
|
||||
public static ConstantLiteral calcValue(ProgramScope programScope, ConstantValue value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return value;
|
||||
return (ConstantLiteral) value;
|
||||
} else if(value instanceof ConstantString) {
|
||||
return value;
|
||||
return (ConstantLiteral) value;
|
||||
} else if(value instanceof ConstantChar) {
|
||||
return value;
|
||||
return (ConstantLiteral) value;
|
||||
} else if(value instanceof ConstantRef) {
|
||||
ConstantVar constantVar = programScope.getConstant((ConstantRef) value);
|
||||
ConstantValue constantVarValue = constantVar.getValue();
|
||||
@ -36,7 +38,7 @@ public class ConstantValueCalculator {
|
||||
}
|
||||
|
||||
|
||||
public static ConstantValue calcValue(ProgramScope programScope, Operator operator, ConstantValue value) {
|
||||
public static ConstantLiteral calcValue(ProgramScope programScope, Operator operator, ConstantValue value) {
|
||||
if(operator.equals(Operators.NEG)) {
|
||||
return neg(calcValue(programScope, value));
|
||||
} else if(operator.equals(Operators.POS)) {
|
||||
@ -53,40 +55,39 @@ public class ConstantValueCalculator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue castWord(ConstantValue value) {
|
||||
private static ConstantLiteral castWord(ConstantValue value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(0xffff & ((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue castSWord(ConstantValue value) {
|
||||
private static ConstantLiteral castSWord(ConstantValue value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(0xffff & ((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(0xffff & ((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue castByte(ConstantValue value) {
|
||||
private static ConstantLiteral castByte(ConstantValue value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(0xff & ((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue castSByte(ConstantValue value) {
|
||||
private static ConstantLiteral castSByte(ConstantValue value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(0xff & ((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(0xff & ((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue castPtrByte(ConstantValue value) {
|
||||
private static ConstantLiteral castPtrByte(ConstantLiteral value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public static ConstantValue calcValue(ProgramScope programScope, ConstantValue value1, Operator operator, ConstantValue value2) {
|
||||
public static ConstantLiteral calcValue(ProgramScope programScope, ConstantValue value1, Operator operator, ConstantValue value2) {
|
||||
if(operator.equals(Operators.MULTIPLY)) {
|
||||
return multiply(calcValue(programScope, value1), calcValue(programScope, value2));
|
||||
} else if(operator.equals(Operators.PLUS)) {
|
||||
@ -99,36 +100,36 @@ public class ConstantValueCalculator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue neg(ConstantValue value) {
|
||||
private static ConstantLiteral neg(ConstantLiteral value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(-((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(-((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue pos(ConstantValue value) {
|
||||
private static ConstantLiteral pos(ConstantLiteral value) {
|
||||
if(value instanceof ConstantInteger) {
|
||||
return new ConstantInteger(+((ConstantInteger) value).getNumber());
|
||||
return new ConstantInteger(+((ConstantInteger) value).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue multiply(ConstantValue value1, ConstantValue value2) {
|
||||
private static ConstantLiteral multiply(ConstantLiteral value1, ConstantLiteral value2) {
|
||||
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) value1).getNumber() * ((ConstantInteger) value2).getNumber());
|
||||
return new ConstantInteger(((ConstantInteger) value1).getValue() * ((ConstantInteger) value2).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue plus(ConstantValue value1, ConstantValue value2) {
|
||||
private static ConstantLiteral plus(ConstantLiteral value1, ConstantLiteral value2) {
|
||||
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) value1).getNumber() + ((ConstantInteger) value2).getNumber());
|
||||
return new ConstantInteger(((ConstantInteger) value1).getValue() + ((ConstantInteger) value2).getValue());
|
||||
}
|
||||
if(value1 instanceof ConstantInteger && value2 instanceof ConstantChar) {
|
||||
return new ConstantInteger(((ConstantInteger) value1).getNumber() + ((ConstantChar) value2).getValue());
|
||||
return new ConstantInteger(((ConstantInteger) value1).getValue() + ((ConstantChar) value2).getValue());
|
||||
}
|
||||
if(value1 instanceof ConstantChar && value2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantChar) value1).getValue() + ((ConstantInteger) value2).getNumber());
|
||||
return new ConstantInteger(((ConstantChar) value1).getValue() + ((ConstantInteger) value2).getValue());
|
||||
}
|
||||
if(value1 instanceof ConstantString && value2 instanceof ConstantString) {
|
||||
return new ConstantString(((ConstantString) value1).getValue() + ((ConstantString) value2).getValue());
|
||||
@ -139,16 +140,16 @@ public class ConstantValueCalculator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue minus(ConstantValue value1, ConstantValue value2) {
|
||||
private static ConstantLiteral minus(ConstantLiteral value1, ConstantLiteral value2) {
|
||||
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) value1).getNumber() - ((ConstantInteger) value2).getNumber());
|
||||
return new ConstantInteger(((ConstantInteger) value1).getValue() - ((ConstantInteger) value2).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConstantValue div(ConstantValue value1, ConstantValue value2) {
|
||||
private static ConstantLiteral div(ConstantLiteral value1, ConstantLiteral value2) {
|
||||
if(value1 instanceof ConstantInteger && value2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(((ConstantInteger) value1).getNumber() / ((ConstantInteger) value2).getNumber());
|
||||
return new ConstantInteger(((ConstantInteger) value1).getValue() / ((ConstantInteger) value2).getValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.statements.StatementPhiBlock;
|
||||
import dk.camelot64.kickc.model.symbols.Procedure;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,12 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementPhiBlock;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/** Base visitor for iterating through a control flow graph */
|
||||
|
@ -1,6 +1,11 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,12 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.symbols.Procedure;
|
||||
import dk.camelot64.kickc.model.symbols.Scope;
|
||||
import dk.camelot64.kickc.passes.Pass2AliasElimination;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,11 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementPhiBlock;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -2,6 +2,8 @@ package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.CompileLog;
|
||||
import dk.camelot64.kickc.asm.AsmProgram;
|
||||
import dk.camelot64.kickc.model.statements.StatementInfos;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
import dk.camelot64.kickc.model.values.ScopeRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ConstantValue;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
|
||||
/** The different registers available for a program */
|
||||
public class Registers {
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementLabel;
|
||||
import dk.camelot64.kickc.model.statements.StatementProcedureBegin;
|
||||
import dk.camelot64.kickc.model.statements.StatementProcedureEnd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.SymbolRef;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.symbols.Symbol;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** Cached information about symbols. Contains a symbol table cache for fast access. */
|
||||
|
@ -1,5 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ConstantRef;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.passes.PassNVariableReferenceInfos;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dk.camelot64.kickc.model.operators;
|
||||
|
||||
import dk.camelot64.kickc.model.SymbolType;
|
||||
import dk.camelot64.kickc.model.SymbolTypePointer;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
/** Constainer for all the expression operators */
|
||||
public class Operators {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/**
|
||||
* Single Static Assignment Form Statement.
|
||||
* Intermediate form used for compiler optimization.
|
@ -1,5 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
|
||||
/** Inline ASM code */
|
@ -1,6 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
/**
|
||||
* Single Static Assignment Form Statement.
|
@ -1,4 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.CallGraph;
|
||||
import dk.camelot64.kickc.model.LiveRangeVariables;
|
||||
import dk.camelot64.kickc.model.LiveRangeVariablesEffective;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,6 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
|
||||
/**
|
||||
* Intermediate Compiler Form Statement with a conditional jump.
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.ControlFlowGraph;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/**
|
||||
* Single Static Assignment Form Statement unconditional jump.
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
|
||||
/**
|
||||
* Single Static Assignment Form Statement with an LValuie - that is a statement assigning a value to a variable.
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/**
|
||||
* Single Static Assignment Form Statement Jump target.
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** Procedure declaration in SSA */
|
||||
public class StatementProcedureBegin extends StatementBase {
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/**
|
||||
* Procedure declaration in SSA
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.statements;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.values.RValue;
|
||||
|
||||
/**
|
||||
* Return Statement inside procedure in Single Static Assignment Form.
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.ConstantRef;
|
||||
import dk.camelot64.kickc.model.values.ConstantValue;
|
||||
|
||||
/** A named constant or a variable that has been inferred to be constant in the symbol table */
|
||||
public class ConstantVar extends SymbolVariable {
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A jump label */
|
||||
public class Label implements Symbol {
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
|
||||
import dk.camelot64.kickc.model.values.ProcedureRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeProgram;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.values.SymbolRef;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.Value;
|
||||
|
||||
/** A Symbol (variable, jump label, etc.) */
|
||||
public interface Symbol extends Value {
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.Registers;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** Abstract Variable or a Constant Variable */
|
||||
public abstract class SymbolVariable implements Symbol {
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.Registers;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
/** A Variable (or a Constant) */
|
||||
public abstract class Variable extends SymbolVariable {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* A Symbol (variable, jump label, etc.)
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* A Symbol (variable, jump label, etc.)
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.symbols;
|
||||
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A Symbol (variable, jump label, etc.) */
|
||||
public class VariableVersion extends Variable {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/**
|
||||
* A fixed size array of another type
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** Basic Symbol Types */
|
||||
public class SymbolTypeBasic implements SymbolType {
|
@ -1,7 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
import dk.camelot64.kickc.model.ConstantValueCalculator;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementCall;
|
||||
import dk.camelot64.kickc.model.statements.StatementLValue;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.symbols.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** Integer symbol types (byte, signed byte, word, ...). */
|
||||
public class SymbolTypeInteger implements SymbolType {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** A pointer */
|
||||
public class SymbolTypePointer implements SymbolType {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** A function returning another type */
|
||||
public class SymbolTypeProcedure implements SymbolType {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.types;
|
||||
|
||||
/** A program */
|
||||
public class SymbolTypeProgram implements SymbolType {
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A Cast that requires no actual operation.
|
||||
* The types have the same size and the code will execute as if the value already had the type cast to.
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
||||
|
||||
/**
|
||||
* An zero-filled constant array. The array is allocated in the code memory (as a .fill() ).
|
@ -1,4 +1,9 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,6 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
|
||||
/** A constant defined by a binary operator applied to two constants */
|
||||
public class ConstantBinary implements ConstantValue {
|
@ -1,9 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* SSA form constant integer value
|
||||
*/
|
||||
public class ConstantBool implements ConstantValue {
|
||||
public class ConstantBool implements ConstantLiteral<Boolean> {
|
||||
|
||||
private Boolean value;
|
||||
|
||||
@ -16,6 +20,11 @@ public class ConstantBool implements ConstantValue {
|
||||
return SymbolType.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(null);
|
@ -1,9 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* SSA form constant char value (a byte)
|
||||
*/
|
||||
public class ConstantChar implements ConstantValue {
|
||||
public class ConstantChar implements ConstantLiteral<Character> {
|
||||
|
||||
private Character value;
|
||||
|
||||
@ -16,6 +20,7 @@ public class ConstantChar implements ConstantValue {
|
||||
return SymbolType.BYTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character getValue() {
|
||||
return value;
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* SSA form constant integer value
|
||||
*/
|
||||
public class ConstantDouble implements ConstantValue {
|
||||
public class ConstantDouble implements ConstantLiteral<Double> {
|
||||
|
||||
private Double number;
|
||||
|
||||
@ -16,7 +20,8 @@ public class ConstantDouble implements ConstantValue {
|
||||
return SymbolType.DOUBLE;
|
||||
}
|
||||
|
||||
public Double getNumber() {
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return number;
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInline;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInteger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** SSA form constant integer value */
|
||||
public class ConstantInteger implements ConstantValue {
|
||||
public class ConstantInteger implements ConstantLiteral<Long> {
|
||||
|
||||
private Long number;
|
||||
|
||||
@ -11,7 +17,8 @@ public class ConstantInteger implements ConstantValue {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public Long getNumber() {
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@ -21,7 +28,7 @@ public class ConstantInteger implements ConstantValue {
|
||||
|
||||
public SymbolType getType() {
|
||||
ArrayList<SymbolType> potentialTypes = new ArrayList<>();
|
||||
Long number = getNumber();
|
||||
Long number = getValue();
|
||||
for(SymbolTypeInteger typeInteger : SymbolType.getIntegerTypes()) {
|
||||
if(number >= typeInteger.getMinValue() && number <= typeInteger.getMaxValue()) {
|
||||
potentialTypes.add(typeInteger);
|
@ -0,0 +1,8 @@
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
/** A literal constant value */
|
||||
public interface ConstantLiteral<T> extends ConstantValue {
|
||||
|
||||
T getValue();
|
||||
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.symbols.ConstantVar;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A reference to a named Constant (in the symbol table) */
|
||||
public class ConstantRef extends SymbolRef implements ConstantValue {
|
@ -1,9 +1,13 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/**
|
||||
* SSA form constant integer value
|
||||
*/
|
||||
public class ConstantString implements ConstantValue {
|
||||
public class ConstantString implements ConstantLiteral<String> {
|
||||
|
||||
private String value;
|
||||
|
||||
@ -16,6 +20,7 @@ public class ConstantString implements ConstantValue {
|
||||
return SymbolType.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
|
||||
/** A constant defined by a unary operator appied to another constant */
|
||||
public class ConstantUnary implements ConstantValue {
|
@ -1,4 +1,7 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
/** A constant value. The value might be calculated through a constant expression. */
|
||||
public interface ConstantValue extends RValue {
|
@ -1,4 +1,10 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
/** A pointer to a variable */
|
||||
public class ConstantVarPointer implements ConstantValue {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** Assignable value (capable of being on the left part of an assignment) */
|
||||
public interface LValue extends RValue {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
|
||||
/** A reference to a label */
|
||||
public class LabelRef extends SymbolRef {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/**
|
||||
* LValue containing an intermediate variable during parsing. Must be resolved to a proper LValue (pointer, array, lo/hi, ...) in Pass 1 - or result in failure
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
/** A dereferenced pointer */
|
||||
public interface PointerDereference extends LValue {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** A dereferenced variable pointer plus an index (used for array writes) */
|
||||
public class PointerDereferenceIndexed implements PointerDereference {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** A dereferenced pointer (based on a variable or a constant pointer) */
|
||||
public class PointerDereferenceSimple implements PointerDereference {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
/** A reference to a procedure */
|
||||
public class ProcedureRef extends ScopeRef {
|
@ -1,4 +1,4 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
/** A value usable as part of a calculation (ib the right side of an assignment) */
|
||||
public interface RValue extends Value {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.symbols.Scope;
|
||||
|
||||
/** A reference to a scope */
|
||||
public class ScopeRef extends SymbolRef {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** A reference to a symbol (variable, procedure or label) */
|
||||
public class SymbolRef implements Value {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
/** Any value (variable, constant, label) */
|
||||
public interface Value {
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,6 @@
|
||||
package dk.camelot64.kickc.model;
|
||||
package dk.camelot64.kickc.model.values;
|
||||
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
|
||||
/** A reference to a variable from the symbol table */
|
||||
public class VariableRef extends SymbolRef implements RValue, LValue {
|
@ -1,6 +1,8 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.NumberParser;
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
@ -62,7 +62,7 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
|
||||
|
||||
private static Long getInteger(ConstantValue constant) {
|
||||
if(constant instanceof ConstantInteger) {
|
||||
return ((ConstantInteger) constant).getNumber();
|
||||
return ((ConstantInteger) constant).getValue();
|
||||
} else {
|
||||
throw new RuntimeException("Type Mismatch. Constant is not an integer number " + constant);
|
||||
}
|
||||
@ -70,9 +70,9 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
|
||||
|
||||
private static Double getDouble(ConstantValue constant) {
|
||||
if(constant instanceof ConstantDouble) {
|
||||
return ((ConstantDouble) constant).getNumber();
|
||||
return ((ConstantDouble) constant).getValue();
|
||||
} else if(constant instanceof ConstantInteger) {
|
||||
return ((ConstantInteger) constant).getNumber().doubleValue();
|
||||
return ((ConstantInteger) constant).getValue().doubleValue();
|
||||
} else {
|
||||
throw new RuntimeException("Type Mismatch. Constant is not a number " + constant);
|
||||
}
|
||||
@ -83,10 +83,10 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
|
||||
case "-": {
|
||||
if(c instanceof ConstantInteger) {
|
||||
ConstantInteger cInt = (ConstantInteger) c;
|
||||
return new ConstantInteger(-cInt.getNumber());
|
||||
return new ConstantInteger(-cInt.getValue());
|
||||
} else if(c instanceof ConstantDouble) {
|
||||
ConstantDouble cDoub = (ConstantDouble) c;
|
||||
return new ConstantDouble(-cDoub.getNumber());
|
||||
return new ConstantDouble(-cDoub.getValue());
|
||||
} else {
|
||||
throw new RuntimeException("Type mismatch. Unary Minus cannot handle value " + c);
|
||||
}
|
||||
@ -96,11 +96,11 @@ public class ParseTreeConstantEvaluator extends KickCBaseVisitor<ConstantValue>
|
||||
}
|
||||
case "++": {
|
||||
ConstantInteger cInt = (ConstantInteger) c;
|
||||
return new ConstantInteger(cInt.getNumber() + 1);
|
||||
return new ConstantInteger(cInt.getValue() + 1);
|
||||
}
|
||||
case "--": {
|
||||
ConstantInteger cInt = (ConstantInteger) c;
|
||||
return new ConstantInteger(cInt.getNumber() - 1);
|
||||
return new ConstantInteger(cInt.getValue() - 1);
|
||||
}
|
||||
case "*": { // pointer dereference
|
||||
return null;
|
||||
|
@ -5,6 +5,12 @@ import dk.camelot64.kickc.NumberParser;
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.statements.*;
|
||||
import dk.camelot64.kickc.model.symbols.*;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
||||
import dk.camelot64.kickc.parser.KickCParser;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
@ -405,21 +411,21 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
}
|
||||
// Add increment
|
||||
ConstantInteger beyondLastVal;
|
||||
if(rangeFirst.getNumber() > rangeLast.getNumber()) {
|
||||
if(rangeFirst.getValue() > rangeLast.getValue()) {
|
||||
Statement stmtInc = new StatementAssignment(lValue.getRef(), Operators.DECREMENT, lValue.getRef());
|
||||
sequence.addStatement(stmtInc);
|
||||
if(rangeLast.getNumber() == 0) {
|
||||
if(rangeLast.getValue() == 0) {
|
||||
beyondLastVal = new ConstantInteger(255L);
|
||||
} else {
|
||||
beyondLastVal = new ConstantInteger(rangeLast.getNumber() - 1);
|
||||
beyondLastVal = new ConstantInteger(rangeLast.getValue() - 1);
|
||||
}
|
||||
} else {
|
||||
Statement stmtInc = new StatementAssignment(lValue.getRef(), Operators.INCREMENT, lValue.getRef());
|
||||
sequence.addStatement(stmtInc);
|
||||
if(rangeLast.getNumber() == 255) {
|
||||
if(rangeLast.getValue() == 255) {
|
||||
beyondLastVal = new ConstantInteger(0L);
|
||||
} else {
|
||||
beyondLastVal = new ConstantInteger(rangeLast.getNumber() + 1);
|
||||
beyondLastVal = new ConstantInteger(rangeLast.getValue() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -503,7 +509,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
if(ctx.expr() != null) {
|
||||
ConstantValue size = ParseTreeConstantEvaluator.evaluate(ctx.expr());
|
||||
if(size instanceof ConstantInteger) {
|
||||
return new SymbolTypeArray(elementType, ((ConstantInteger) size).getNumber().intValue());
|
||||
return new SymbolTypeArray(elementType, ((ConstantInteger) size).getValue().intValue());
|
||||
} else {
|
||||
throw new RuntimeException("Array size not a constant integer " + ctx.getText());
|
||||
}
|
||||
|
@ -2,6 +2,12 @@ package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
@ -1,6 +1,11 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.symbols.Variable;
|
||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
||||
|
||||
/**
|
||||
* Asserts that all arrays with lengths and initializers have matching lengths.
|
||||
|
@ -1,6 +1,12 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.values.LvalueIntermediate;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementLValue;
|
||||
|
||||
/**
|
||||
* Asserts that all intermediate lvalues have been replaced by something else
|
||||
|
@ -1,6 +1,14 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.*;
|
||||
import dk.camelot64.kickc.model.values.LabelRef;
|
||||
import dk.camelot64.kickc.model.values.SymbolRef;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.statements.StatementConditionalJump;
|
||||
import dk.camelot64.kickc.model.symbols.Procedure;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user