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:
Matt Pharr
2012-06-05 12:51:21 -07:00
parent 96aaf6d53b
commit 592affb984
3 changed files with 64 additions and 0 deletions

View File

@@ -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
Module::writeOutput(OutputType outputType, const char *outFileName,
const char *includeFileName) {
@@ -1251,6 +1267,18 @@ Module::writeHeader(const char *fn) {
lGetExportedParamTypes(externCFuncs, &exportedStructTypes,
&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
lEmitVectorTypedefs(exportedVectorTypes, f);
lEmitEnumDecls(exportedEnumTypes, f);