Add experimental (and undocumented for now) export syntax.
This allows adding types to the list that are included in the automatically-generated
header files.
struct Foo { . . . };
struct Bar { . . . };
export { Foo, Bar };
This commit is contained in:
28
module.cpp
28
module.cpp
@@ -824,6 +824,22 @@ Module::AddFunctionDefinition(const std::string &name, const FunctionType *type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Module::AddExportedTypes(const std::vector<std::pair<const Type *,
|
||||||
|
SourcePos> > &types) {
|
||||||
|
for (int i = 0; i < (int)types.size(); ++i) {
|
||||||
|
if (CastType<StructType>(types[i].first) == NULL &&
|
||||||
|
CastType<VectorType>(types[i].first) == NULL &&
|
||||||
|
CastType<EnumType>(types[i].first) == NULL)
|
||||||
|
Error(types[i].second, "Only struct, vector, and enum types, "
|
||||||
|
"not \"%s\", are allowed in type export lists.",
|
||||||
|
types[i].first->GetString().c_str());
|
||||||
|
else
|
||||||
|
exportedTypes.push_back(types[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Module::writeOutput(OutputType outputType, const char *outFileName,
|
Module::writeOutput(OutputType outputType, const char *outFileName,
|
||||||
const char *includeFileName) {
|
const char *includeFileName) {
|
||||||
@@ -1251,6 +1267,18 @@ Module::writeHeader(const char *fn) {
|
|||||||
lGetExportedParamTypes(externCFuncs, &exportedStructTypes,
|
lGetExportedParamTypes(externCFuncs, &exportedStructTypes,
|
||||||
&exportedEnumTypes, &exportedVectorTypes);
|
&exportedEnumTypes, &exportedVectorTypes);
|
||||||
|
|
||||||
|
// Go through the explicitly exported types
|
||||||
|
for (int i = 0; i < (int)exportedTypes.size(); ++i) {
|
||||||
|
if (const StructType *st = CastType<StructType>(exportedTypes[i].first))
|
||||||
|
exportedStructTypes.push_back(st->GetAsUniformType());
|
||||||
|
else if (const EnumType *et = CastType<EnumType>(exportedTypes[i].first))
|
||||||
|
exportedEnumTypes.push_back(et->GetAsUniformType());
|
||||||
|
else if (const VectorType *vt = CastType<VectorType>(exportedTypes[i].first))
|
||||||
|
exportedVectorTypes.push_back(vt->GetAsUniformType());
|
||||||
|
else
|
||||||
|
FATAL("Unexpected type in export list");
|
||||||
|
}
|
||||||
|
|
||||||
// And print them
|
// And print them
|
||||||
lEmitVectorTypedefs(exportedVectorTypes, f);
|
lEmitVectorTypedefs(exportedVectorTypes, f);
|
||||||
lEmitEnumDecls(exportedEnumTypes, f);
|
lEmitEnumDecls(exportedEnumTypes, f);
|
||||||
|
|||||||
7
module.h
7
module.h
@@ -80,6 +80,11 @@ public:
|
|||||||
void AddFunctionDefinition(const std::string &name,
|
void AddFunctionDefinition(const std::string &name,
|
||||||
const FunctionType *ftype, Stmt *code);
|
const FunctionType *ftype, Stmt *code);
|
||||||
|
|
||||||
|
/** Adds the given type to the set of types that have their definitions
|
||||||
|
included in automatically generated header files. */
|
||||||
|
void AddExportedTypes(const std::vector<std::pair<const Type *,
|
||||||
|
SourcePos> > &types);
|
||||||
|
|
||||||
/** After a source file has been compiled, output can be generated in a
|
/** After a source file has been compiled, output can be generated in a
|
||||||
number of different formats. */
|
number of different formats. */
|
||||||
enum OutputType { Asm, /** Generate text assembly language output */
|
enum OutputType { Asm, /** Generate text assembly language output */
|
||||||
@@ -145,6 +150,8 @@ private:
|
|||||||
const char *filename;
|
const char *filename;
|
||||||
AST *ast;
|
AST *ast;
|
||||||
|
|
||||||
|
std::vector<std::pair<const Type *, SourcePos> > exportedTypes;
|
||||||
|
|
||||||
/** Write the corresponding output type to the given file. Returns
|
/** Write the corresponding output type to the given file. Returns
|
||||||
true on success, false if there has been an error. The given
|
true on success, false if there has been an error. The given
|
||||||
filename may be NULL, indicating that output should go to standard
|
filename may be NULL, indicating that output should go to standard
|
||||||
|
|||||||
29
parse.yy
29
parse.yy
@@ -151,6 +151,7 @@ struct ForeachDimension {
|
|||||||
Expr *expr;
|
Expr *expr;
|
||||||
ExprList *exprList;
|
ExprList *exprList;
|
||||||
const Type *type;
|
const Type *type;
|
||||||
|
std::vector<std::pair<const Type *, SourcePos> > *typeList;
|
||||||
const AtomicType *atomicType;
|
const AtomicType *atomicType;
|
||||||
int typeQualifier;
|
int typeQualifier;
|
||||||
StorageClass storageClass;
|
StorageClass storageClass;
|
||||||
@@ -232,6 +233,7 @@ struct ForeachDimension {
|
|||||||
%type <type> specifier_qualifier_list struct_or_union_specifier
|
%type <type> specifier_qualifier_list struct_or_union_specifier
|
||||||
%type <type> type_specifier type_name rate_qualified_type_specifier
|
%type <type> type_specifier type_name rate_qualified_type_specifier
|
||||||
%type <type> short_vec_specifier
|
%type <type> short_vec_specifier
|
||||||
|
%type <typeList> type_specifier_list
|
||||||
%type <atomicType> atomic_var_type_specifier
|
%type <atomicType> atomic_var_type_specifier
|
||||||
|
|
||||||
%type <typeQualifier> type_qualifier type_qualifier_list
|
%type <typeQualifier> type_qualifier type_qualifier_list
|
||||||
@@ -826,6 +828,28 @@ type_specifier
|
|||||||
| enum_specifier { $$ = $1; }
|
| enum_specifier { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
type_specifier_list
|
||||||
|
: type_specifier
|
||||||
|
{
|
||||||
|
if ($1 == NULL)
|
||||||
|
$$ = NULL;
|
||||||
|
else {
|
||||||
|
std::vector<std::pair<const Type *, SourcePos> > *vec =
|
||||||
|
new std::vector<std::pair<const Type *, SourcePos> >;
|
||||||
|
vec->push_back(std::make_pair($1, @1));
|
||||||
|
$$ = vec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| type_specifier_list ',' type_specifier
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
if ($1 == NULL)
|
||||||
|
Assert(m->errorCount > 0);
|
||||||
|
else
|
||||||
|
$$->push_back(std::make_pair($3, @3));
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
atomic_var_type_specifier
|
atomic_var_type_specifier
|
||||||
: TOKEN_VOID { $$ = AtomicType::Void; }
|
: TOKEN_VOID { $$ = AtomicType::Void; }
|
||||||
| TOKEN_BOOL { $$ = AtomicType::UniformBool->GetAsUnboundVariabilityType(); }
|
| TOKEN_BOOL { $$ = AtomicType::UniformBool->GetAsUnboundVariabilityType(); }
|
||||||
@@ -1837,6 +1861,11 @@ translation_unit
|
|||||||
external_declaration
|
external_declaration
|
||||||
: function_definition
|
: function_definition
|
||||||
| TOKEN_EXTERN TOKEN_STRING_C_LITERAL '{' declaration '}'
|
| TOKEN_EXTERN TOKEN_STRING_C_LITERAL '{' declaration '}'
|
||||||
|
| TOKEN_EXPORT '{' type_specifier_list '}' ';'
|
||||||
|
{
|
||||||
|
if ($3 != NULL)
|
||||||
|
m->AddExportedTypes(*$3);
|
||||||
|
}
|
||||||
| declaration
|
| declaration
|
||||||
{
|
{
|
||||||
if ($1 != NULL)
|
if ($1 != NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user