Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor type element #70

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions cr-examples/spirv/src/main/java/intel/code/spirv/PointerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,27 @@

package intel.code.spirv;

import java.lang.reflect.code.TypeElement;
import java.lang.reflect.code.type.TypeDefinition;
import java.lang.reflect.code.CodeType;
import java.util.Objects;
import java.util.List;

public final class PointerType extends SpirvType {
static final String NAME = "spirv.pointer";
private final TypeElement referentType;
private final TypeElement storageType;
private final CodeType referentType;
private final CodeType storageType;

public PointerType(TypeElement referentType, TypeElement storageType)
public PointerType(CodeType referentType, CodeType storageType)
{
this.referentType = referentType;
this.storageType = storageType;
}

public TypeElement referentType()
public CodeType referentType()
{
return referentType;
}

public TypeElement storageType()
public CodeType storageType()
{
return storageType;
}
Expand All @@ -65,12 +64,12 @@ public int hashCode() {
}

@Override
public TypeDefinition toTypeDefinition() {
return new TypeDefinition(NAME, List.of(referentType.toTypeDefinition(), storageType.toTypeDefinition()));
public ExternalizedCodeType externalize() {
return new ExternalizedCodeType(NAME, List.of(referentType.externalize(), storageType.externalize()));
}

@Override
public String toString() {
return toTypeDefinition().toString();
return externalize().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import java.lang.reflect.code.Op;
import java.lang.reflect.code.Value;
import java.lang.reflect.code.op.CoreOps;
import java.lang.reflect.code.TypeElement;
import java.lang.reflect.code.CodeType;
import java.lang.reflect.code.type.MethodRef;
import java.lang.reflect.code.type.ClassType;
import java.lang.reflect.code.type.JavaType;
Expand Down Expand Up @@ -124,10 +124,10 @@ private MemorySegment generateModuleInternal(String moduleName, SpirvOps.FuncOp
}

private void generateFunction(String moduleName, String fnName, SpirvOps.FuncOp func) {
TypeElement returnType = func.invokableType().returnType();
CodeType returnType = func.invokableType().returnType();
SPIRVId functionID = nextId(fnName);
String signature = func.invokableType().returnType().toString();
List<TypeElement> paramTypes = func.invokableType().parameterTypes();
List<CodeType> paramTypes = func.invokableType().parameterTypes();
// build signature string
for (int i = 0; i < paramTypes.size(); i++) {
signature += "_" + paramTypes.get(i).toString();
Expand Down
10 changes: 5 additions & 5 deletions cr-examples/spirv/src/main/java/intel/code/spirv/SpirvOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
import java.lang.reflect.code.Op;
import java.lang.reflect.code.Value;
import java.lang.reflect.code.CopyContext;
import java.lang.reflect.code.TypeElement;
import java.lang.reflect.code.CodeType;
import java.lang.reflect.code.type.JavaType;

public abstract class SpirvOp extends Op {
private final TypeElement type;
private final CodeType type;

SpirvOp(String opName) {
super(opName, List.of());
this.type = JavaType.VOID;
}

SpirvOp(String opName, TypeElement type, List<Value> operands) {
SpirvOp(String opName, CodeType type, List<Value> operands) {
super(opName, operands);
this.type = type;
}

SpirvOp(String opName, TypeElement type, List<Value> operands, Map<String, Object> attributes) {
SpirvOp(String opName, CodeType type, List<Value> operands, Map<String, Object> attributes) {
super(opName, operands);
this.type = type;
}
Expand All @@ -57,7 +57,7 @@ public abstract class SpirvOp extends Op {
}

@Override
public TypeElement resultType() {
public CodeType resultType() {
return type;
}
}
54 changes: 27 additions & 27 deletions cr-examples/spirv/src/main/java/intel/code/spirv/SpirvOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.lang.reflect.code.Value;
import java.lang.reflect.code.CopyContext;
import java.lang.reflect.code.OpTransformer;
import java.lang.reflect.code.TypeElement;
import java.lang.reflect.code.CodeType;
import java.lang.reflect.code.type.MethodRef;
import java.lang.reflect.code.type.FieldRef;
import java.lang.reflect.code.type.FunctionType;
Expand Down Expand Up @@ -65,7 +65,7 @@ public ModuleOp transform(CopyContext cc, OpTransformer ot) {
public static final class LoadOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "load";

public LoadOp(TypeElement resultType, List<Value> operands) {
public LoadOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand All @@ -83,7 +83,7 @@ public static final class FieldLoadOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "fieldload";
private final FieldRef fieldDesc;

public FieldLoadOp(TypeElement resultType, FieldRef fieldRef, List<Value> operands) {
public FieldLoadOp(CodeType resultType, FieldRef fieldRef, List<Value> operands) {
super(OPNAME, resultType, operands);
this.fieldDesc = fieldRef;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private static String nameString(MethodRef descriptor) {
public static final class ArrayLengthOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "arraylength";

public ArrayLengthOp(TypeElement resultType, List<Value> operands) {
public ArrayLengthOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -168,7 +168,7 @@ public static final class ConstantOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "constant";
private final Object value;

public ConstantOp(TypeElement resultType, Object value) {
public ConstantOp(CodeType resultType, Object value) {
super(OPNAME, resultType, List.of());
this.value = value;
}
Expand All @@ -191,7 +191,7 @@ public Object value() {
public static final class ConvertOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "sconvert";

public ConvertOp(TypeElement resultType, List<Value> operands) {
public ConvertOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand All @@ -208,7 +208,7 @@ public ConvertOp transform(CopyContext cc, OpTransformer ot) {
public static final class IAddOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "iadd";

public IAddOp(TypeElement resultType, List<Value> operands) {
public IAddOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -225,7 +225,7 @@ public IAddOp transform(CopyContext cc, OpTransformer ot) {
public static final class FAddOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fadd";

public FAddOp(TypeElement resultType, List<Value> operands) {
public FAddOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -242,7 +242,7 @@ public FAddOp transform(CopyContext cc, OpTransformer ot) {
public static final class ISubOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "isub";

public ISubOp(TypeElement resultType, List<Value> operands) {
public ISubOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -259,7 +259,7 @@ public ISubOp transform(CopyContext cc, OpTransformer ot) {
public static final class FSubOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fsub";

public FSubOp(TypeElement resultType, List<Value> operands) {
public FSubOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -276,7 +276,7 @@ public FSubOp transform(CopyContext cc, OpTransformer ot) {
public static final class IMulOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "imul";

public IMulOp(TypeElement resultType, List<Value> operands) {
public IMulOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -293,7 +293,7 @@ public IMulOp transform(CopyContext cc, OpTransformer ot) {
public static final class FMulOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fmul";

public FMulOp(TypeElement resultType, List<Value> operands) {
public FMulOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -310,7 +310,7 @@ public FMulOp transform(CopyContext cc, OpTransformer ot) {
public static final class IDivOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "idiv";

public IDivOp(TypeElement resultType, List<Value> operands) {
public IDivOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -327,7 +327,7 @@ public IDivOp transform(CopyContext cc, OpTransformer ot) {
public static final class FDivOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fdiv";

public FDivOp(TypeElement resultType, List<Value> operands) {
public FDivOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -344,7 +344,7 @@ public FDivOp transform(CopyContext cc, OpTransformer ot) {
public static final class ModOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "mod";

public ModOp(TypeElement resultType, List<Value> operands) {
public ModOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -361,7 +361,7 @@ public ModOp transform(CopyContext cc, OpTransformer ot) {
public static final class IEqualOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "iequal";

public IEqualOp(TypeElement resultType, List<Value> operands) {
public IEqualOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -378,7 +378,7 @@ public IEqualOp transform(CopyContext cc, OpTransformer ot) {
public static final class FEqualOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fequal";

public FEqualOp(TypeElement resultType, List<Value> operands) {
public FEqualOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -395,7 +395,7 @@ public FEqualOp transform(CopyContext cc, OpTransformer ot) {
public static final class INotEqualOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "inotequal";

public INotEqualOp(TypeElement resultType, List<Value> operands) {
public INotEqualOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -413,7 +413,7 @@ public INotEqualOp transform(CopyContext cc, OpTransformer ot) {
public static final class FNotEqualOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "fnotequal";

public FNotEqualOp(TypeElement resultType, List<Value> operands) {
public FNotEqualOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand All @@ -430,7 +430,7 @@ public FNotEqualOp transform(CopyContext cc, OpTransformer ot) {
public static final class LtOp extends SpirvOp {
public static final String NAME = NAME_PREFIX + "lt";

public LtOp(TypeElement resultType, List<Value> operands) {
public LtOp(CodeType resultType, List<Value> operands) {
super(NAME, resultType, operands);
}

Expand Down Expand Up @@ -512,9 +512,9 @@ public List<Block.Reference> successors() {
public static final class VariableOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "variable";
private final String varName;
private final TypeElement varType;
private final CodeType varType;

public VariableOp(String varName, TypeElement type, TypeElement varType) {
public VariableOp(String varName, CodeType type, CodeType varType) {
super(OPNAME + " @" + varName, type, List.of());
this.varName = varName;
this.varType = varType;
Expand All @@ -531,7 +531,7 @@ public VariableOp transform(CopyContext cc, OpTransformer ot) {
return new VariableOp(this, cc);
}

public TypeElement varType() {
public CodeType varType() {
return varType;
}

Expand All @@ -543,7 +543,7 @@ public String varName() {
public static final class CompositeExtractOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "compositeExtract";

public CompositeExtractOp(TypeElement resultType, List<Value> operands) {
public CompositeExtractOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand All @@ -560,7 +560,7 @@ public CompositeExtractOp transform(CopyContext cc, OpTransformer ot) {
public static final class InBoundAccessChainOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "inBoundAccessChain";

public InBoundAccessChainOp(TypeElement resultType, List<Value> operands) {
public InBoundAccessChainOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand All @@ -577,7 +577,7 @@ public InBoundAccessChainOp transform(CopyContext cc, OpTransformer ot) {
public static final class ReturnOp extends SpirvOp implements Op.Terminating {
public static final String OPNAME = "return";

public ReturnOp(TypeElement resultType, List<Value> operands) {
public ReturnOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand All @@ -594,7 +594,7 @@ public ReturnOp transform(CopyContext cc, OpTransformer ot) {
public static final class FunctionParameterOp extends SpirvOp {
public static final String OPNAME = NAME_PREFIX + "function parameter";

public FunctionParameterOp(TypeElement resultType, List<Value> operands) {
public FunctionParameterOp(CodeType resultType, List<Value> operands) {
super(OPNAME, resultType, operands);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

package intel.code.spirv;

import java.lang.reflect.code.TypeElement;
import java.lang.reflect.code.CodeType;

public abstract sealed class SpirvType implements TypeElement permits PointerType, StorageType {
public abstract sealed class SpirvType implements CodeType permits PointerType, StorageType {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package intel.code.spirv;

import java.lang.reflect.code.type.TypeDefinition;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -88,12 +87,12 @@ public int hashCode() {
}

@Override
public TypeDefinition toTypeDefinition() {
return new TypeDefinition(NAME, List.of());
public ExternalizedCodeType externalize() {
return new ExternalizedCodeType(NAME, List.of());
}

@Override
public String toString() {
return toTypeDefinition().toString();
return externalize().toString();
}
}
Loading