Add size_t, ptrdiff_t, and [u]intptr_t types.
This commit is contained in:
@@ -1394,8 +1394,8 @@ Types
|
|||||||
Basic Types and Type Qualifiers
|
Basic Types and Type Qualifiers
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
``ispc`` is a statically-typed language. It supports a variety of basic
|
``ispc`` is a statically-typed language. It supports a variety of core
|
||||||
types.
|
basic types:
|
||||||
|
|
||||||
* ``void``: "empty" type representing no value.
|
* ``void``: "empty" type representing no value.
|
||||||
* ``bool``: boolean value; may be assigned ``true``, ``false``, or the
|
* ``bool``: boolean value; may be assigned ``true``, ``false``, or the
|
||||||
@@ -1412,6 +1412,15 @@ types.
|
|||||||
* ``unsigned int64``: 64-bit unsigned integer.
|
* ``unsigned int64``: 64-bit unsigned integer.
|
||||||
* ``double``: 64-bit double-precision floating point value.
|
* ``double``: 64-bit double-precision floating point value.
|
||||||
|
|
||||||
|
There are also a few built-in types related to pointers and memory:
|
||||||
|
|
||||||
|
* ``size_t``: the maximum size of any object (structure or array)
|
||||||
|
* ``ptrdiff_t``: an integer type large enough to represent the difference
|
||||||
|
between two pointers
|
||||||
|
* ``intptr_t``: signed integer type that is large enough to represent
|
||||||
|
a pointer value
|
||||||
|
* ``uintptr_t``: unsigned integer type large enough to represent a pointer
|
||||||
|
|
||||||
Implicit type conversion between values of different types is done
|
Implicit type conversion between values of different types is done
|
||||||
automatically by the ``ispc`` compiler. Thus, a value of ``float`` type
|
automatically by the ``ispc`` compiler. Thus, a value of ``float`` type
|
||||||
can be assigned to a variable of ``int`` type directly. In binary
|
can be assigned to a variable of ``int`` type directly. In binary
|
||||||
|
|||||||
20
module.cpp
20
module.cpp
@@ -88,6 +88,24 @@
|
|||||||
#include <llvm/Support/raw_ostream.h>
|
#include <llvm/Support/raw_ostream.h>
|
||||||
#include <llvm/Bitcode/ReaderWriter.h>
|
#include <llvm/Bitcode/ReaderWriter.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
lDeclareSizeAndPtrIntTypes(SymbolTable *symbolTable) {
|
||||||
|
const Type *ptrIntType = (g->target.is32Bit) ? AtomicType::VaryingInt32 :
|
||||||
|
AtomicType::VaryingInt64;
|
||||||
|
ptrIntType = ptrIntType->GetAsUnboundVariabilityType();
|
||||||
|
|
||||||
|
symbolTable->AddType("intptr_t", ptrIntType, SourcePos());
|
||||||
|
symbolTable->AddType("uintptr_t", ptrIntType->GetAsUnsignedType(),
|
||||||
|
SourcePos());
|
||||||
|
symbolTable->AddType("ptrdiff_t", ptrIntType, SourcePos());
|
||||||
|
|
||||||
|
const Type *sizeType = (g->target.is32Bit || g->opt.force32BitAddressing) ?
|
||||||
|
AtomicType::VaryingInt32 : AtomicType::VaryingInt64;
|
||||||
|
sizeType = sizeType->GetAsUnboundVariabilityType();
|
||||||
|
symbolTable->AddType("size_t", sizeType, SourcePos());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Module
|
// Module
|
||||||
|
|
||||||
@@ -103,6 +121,8 @@ Module::Module(const char *fn) {
|
|||||||
symbolTable = new SymbolTable;
|
symbolTable = new SymbolTable;
|
||||||
ast = new AST;
|
ast = new AST;
|
||||||
|
|
||||||
|
lDeclareSizeAndPtrIntTypes(symbolTable);
|
||||||
|
|
||||||
module = new llvm::Module(filename ? filename : "<stdin>", *g->ctx);
|
module = new llvm::Module(filename ? filename : "<stdin>", *g->ctx);
|
||||||
module->setTargetTriple(g->target.GetTripleString());
|
module->setTargetTriple(g->target.GetTripleString());
|
||||||
|
|
||||||
|
|||||||
19
tests/intptr.ispc
Normal file
19
tests/intptr.ispc
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
export uniform int width() { return programCount; }
|
||||||
|
|
||||||
|
|
||||||
|
export void f_v(uniform float RET[]) {
|
||||||
|
RET[programIndex] = sizeof(uniform intptr_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
export void result(uniform float RET[]) {
|
||||||
|
RET[programIndex] =
|
||||||
|
#if (ISPC_POINTER_SIZE==32)
|
||||||
|
4
|
||||||
|
#elif (ISPC_POINTER_SIZE==64)
|
||||||
|
8
|
||||||
|
#else
|
||||||
|
#error Unknown pointer size
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user