summaryrefslogtreecommitdiff
path: root/python/generator.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-08-17 02:04:50 -0400
committerRusty Wagner <rusty@vector35.com>2017-08-17 02:04:50 -0400
commit5e25409d02479285d1f16d6cc55df1b267e9ba06 (patch)
treeca7a800c57bb907e04e916d5c90f72c601544679 /python/generator.cpp
parentec2d882e1a165b703e8fedaa81246dcdd91f50f3 (diff)
Support custom calling conventions in the type parser and type objects
Diffstat (limited to 'python/generator.cpp')
-rw-r--r--python/generator.cpp63
1 files changed, 51 insertions, 12 deletions
diff --git a/python/generator.cpp b/python/generator.cpp
index 554f82cd..f838b36d 100644
--- a/python/generator.cpp
+++ b/python/generator.cpp
@@ -172,7 +172,7 @@ int main(int argc, char* argv[])
return 1;
}
- bool ok = arch->ParseTypesFromSourceFile(argv[1], types, vars, funcs, errors);
+ bool ok = arch->GetStandalonePlatform()->ParseTypesFromSourceFile(argv[1], types, vars, funcs, errors);
fprintf(stderr, "Errors: %s", errors.c_str());
if (!ok)
return 1;
@@ -237,22 +237,61 @@ int main(int argc, char* argv[])
fprintf(out, "\n# Structure definitions\n");
+ set<QualifiedName> structsToProcess;
+ set<QualifiedName> finishedStructs;
for (auto& i : types)
+ structsToProcess.insert(i.first);
+ while (structsToProcess.size() != 0)
{
- string name;
- if (i.first.size() != 1)
- continue;
- name = i.first[0];
- if ((i.second->GetClass() == StructureTypeClass) && (i.second->GetStructure()->GetMembers().size() != 0))
+ set<QualifiedName> currentStructList = structsToProcess;
+ structsToProcess.clear();
+ bool processedSome = false;
+ for (auto& i : currentStructList)
{
- fprintf(out, "%s._fields_ = [\n", name.c_str());
- for (auto& j : i.second->GetStructure()->GetMembers())
+ string name;
+ if (i.size() != 1)
+ continue;
+ Ref<Type> type = types[i];
+ name = i[0];
+ if ((type->GetClass() == StructureTypeClass) && (type->GetStructure()->GetMembers().size() != 0))
{
- fprintf(out, "\t\t(\"%s\", ", j.name.c_str());
- OutputType(out, j.type);
- fprintf(out, "),\n");
+ bool requiresDependency = false;
+ for (auto& j : type->GetStructure()->GetMembers())
+ {
+ if ((j.type->GetClass() == NamedTypeReferenceClass) &&
+ (types[j.type->GetNamedTypeReference()->GetName()]->GetClass() == StructureTypeClass) &&
+ (finishedStructs.count(j.type->GetNamedTypeReference()->GetName()) == 0))
+ {
+ // This structure needs another structure that isn't fully defined yet, need to wait
+ // for the dependencies to be defined
+ structsToProcess.insert(i);
+ requiresDependency = true;
+ break;
+ }
+ }
+
+ if (requiresDependency)
+ continue;
+
+ fprintf(out, "%s._fields_ = [\n", name.c_str());
+ for (auto& j : type->GetStructure()->GetMembers())
+ {
+ fprintf(out, "\t\t(\"%s\", ", j.name.c_str());
+ OutputType(out, j.type);
+ fprintf(out, "),\n");
+ }
+ fprintf(out, "\t]\n");
+ finishedStructs.insert(i);
+ processedSome = true;
}
- fprintf(out, "\t]\n");
+ }
+
+ if (!processedSome)
+ {
+ fprintf(stderr, "Detected dependency cycle in structures\n");
+ for (auto& i : structsToProcess)
+ fprintf(stderr, "%s\n", i.GetString().c_str());
+ return 1;
}
}