summaryrefslogtreecommitdiff
path: root/source/slang/type-defs.h
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-10-04 13:54:25 -0700
committerGitHub <noreply@github.com>2017-10-04 13:54:25 -0700
commit54f016e7ef36b7505bf47d188cf4b7e1fdc443a4 (patch)
treef8a385c8a3bbac807c2c0d08a9b1e4cd208db95c /source/slang/type-defs.h
parent8a0ebb9fa25fd44def17b03b3f8aa1a33ad77940 (diff)
IR: overhaul IR design/implementation (#195)
* IR: overhaul IR design/implementation Closes #192 Closes #188 This is a major overhaul of how the IR is implemented, with the primary goal of just using the AST-level type representation as the IR's type representation, rather than inventing an entire shadow set of types (as captured in issue #192). One consequence of this choice is that types in the IR are no longer explicit "instructions" and are not represented as ordinary operands (so a bunch of `+ 1` cases end up going away when enumerating ordinary operands). Along the way I also got rid of the embedded IDs in the IR (issue #188) because this wasn't too hard to deal with at the same time. Another related change was to split the `IRValue` and `IRInst` cases, so that there are values that are not also instructions. Non-instruction values are now used to represent literals, references to declarations, and would eventually be used for an `undef` value if we need one. IR functions, global variables, and basic blocks are all values (because they can appear as operands), but not instructions. The main benefit of this approach is that the top-level structure of a bytecode (BC) module is much simpler to understand and walk, and BC-level types are represented much more directly (such that we could conceivably use them for reflection soon). * fixup: 64-bit build fix * fixup: try to silence clang's pedantic dependent-type errors * fixup: bug in VM loading of constants
Diffstat (limited to 'source/slang/type-defs.h')
-rw-r--r--source/slang/type-defs.h63
1 files changed, 58 insertions, 5 deletions
diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h
index 7883b5c42..7fbefc368 100644
--- a/source/slang/type-defs.h
+++ b/source/slang/type-defs.h
@@ -41,6 +41,20 @@ protected:
)
END_SYNTAX_CLASS()
+// The type of a reference to a basic block
+// in our IR
+SYNTAX_CLASS(IRBasicBlockType, Type)
+RAW(
+public:
+ virtual String ToString() override;
+
+protected:
+ virtual bool EqualsImpl(Type * type) override;
+ virtual Type* CreateCanonicalType() override;
+ virtual int GetHashCode() override;
+)
+END_SYNTAX_CLASS()
+
// A type that takes the form of a reference to some declaration
SYNTAX_CLASS(DeclRefType, Type)
DECL_FIELD(DeclRef<Decl>, declRef)
@@ -221,6 +235,8 @@ END_SYNTAX_CLASS()
// Other cases of generic types known to the compiler
SYNTAX_CLASS(BuiltinGenericType, DeclRefType)
SYNTAX_FIELD(RefPtr<Type>, elementType)
+
+ RAW(Type* getElementType() { return elementType; })
END_SYNTAX_CLASS()
// Types that behave like pointers, in that they can be
@@ -353,6 +369,33 @@ protected:
)
END_SYNTAX_CLASS()
+// Base class for types that map down to
+// simple pointers as part of code generation.
+SYNTAX_CLASS(PtrTypeBase, DeclRefType)
+RAW(
+ // Get the type of the pointed-to value.
+ Type* getValueType();
+)
+END_SYNTAX_CLASS()
+
+// A true (user-visible) pointer type, e.g., `T*`
+SYNTAX_CLASS(PtrType, PtrTypeBase)
+END_SYNTAX_CLASS()
+
+// A type that represents the behind-the-scenes
+// logical pointer that is passed for an `out`
+// or `in out` parameter
+SYNTAX_CLASS(OutTypeBase, PtrTypeBase)
+END_SYNTAX_CLASS()
+
+// The type for an `out` parameter, e.g., `out T`
+SYNTAX_CLASS(OutType, OutTypeBase)
+END_SYNTAX_CLASS()
+
+// The type for an `in out` parameter, e.g., `in out T`
+SYNTAX_CLASS(InOutType, OutTypeBase)
+END_SYNTAX_CLASS()
+
// A type alias of some kind (e.g., via `typedef`)
SYNTAX_CLASS(NamedExpressionType, Type)
DECL_FIELD(DeclRef<TypeDefDecl>, declRef)
@@ -375,17 +418,27 @@ protected:
)
END_SYNTAX_CLASS()
-// Function types are currently used for references to symbols that name
-// either ordinary functions, or "component functions."
-// We do not directly store a representation of the type, and instead
-// use a reference to the symbol to stand in for its logical type
+// A function type is defined by its parameter types
+// and its result type.
SYNTAX_CLASS(FuncType, Type)
- DECL_FIELD(DeclRef<CallableDecl>, declRef)
+
+ // TODO: We may want to preserve parameter names
+ // in the list here, just so that we can print
+ // out friendly names when printing a function
+ // type, even if they don't affect the actual
+ // semantic type underneath.
+
+ FIELD(List<RefPtr<Type>>, paramTypes)
+ FIELD(RefPtr<Type>, resultType)
RAW(
FuncType()
{}
+ UInt getParamCount() { return paramTypes.Count(); }
+ Type* getParamType(UInt index) { return paramTypes[index]; }
+ Type* getResultType() { return resultType; }
+
virtual String ToString() override;
protected:
virtual bool EqualsImpl(Type * type) override;