Skip to content

Commit 93eb8e1

Browse files
committed
Finished transition from templates to generics.
1 parent f251b5d commit 93eb8e1

File tree

320 files changed

+23558
-11693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+23558
-11693
lines changed

Backend/src/function/function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void translateFunction(
239239
GlobalState* globalState,
240240
Function* functionM) {
241241

242-
auto functionL = globalState->getFunction(functionM->prototype->name);
242+
auto functionL = globalState->getFunction(functionM->prototype);
243243
auto returnTypeL = globalState->getRegion(functionM->prototype->returnType)->translateType(functionM->prototype->returnType);
244244

245245
auto localsBlockName = std::string("localsBlock");

Backend/src/globalstate.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ std::vector<LLVMValueRef> GlobalState::getEdgeFunctions(Edge* edge) {
5555
for (int i = 0; i < edge->structPrototypesByInterfaceMethod.size(); i++) {
5656
assert(edge->structPrototypesByInterfaceMethod[i].first == interfaceM->methods[i]);
5757

58-
auto funcName = edge->structPrototypesByInterfaceMethod[i].second->name;
59-
auto edgeFunctionL = getFunction(funcName);
58+
auto funcPrototype = edge->structPrototypesByInterfaceMethod[i].second;
59+
auto edgeFunctionL = getFunction(funcPrototype);
6060
edgeFunctionsL.push_back(edgeFunctionL);
6161
}
6262

@@ -133,10 +133,18 @@ IRegion* GlobalState::getRegion(RegionId* regionId) {
133133
}
134134
}
135135

136-
LLVMValueRef GlobalState::getFunction(Name* name) {
137-
auto functionIter = functions.find(name->name);
138-
assert(functionIter != functions.end());
139-
return functionIter->second;
136+
LLVMValueRef GlobalState::getFunction(Prototype* prototype) {
137+
auto functionIter = functions.find(prototype->name->name);
138+
if (functionIter != functions.end()) {
139+
return functionIter->second;
140+
}
141+
142+
auto extraFunctionIter = extraFunctions.find(prototype);
143+
if (extraFunctionIter != extraFunctions.end()) {
144+
return extraFunctionIter->second;
145+
}
146+
147+
assert(false);
140148
}
141149

142150
LLVMValueRef GlobalState::getInterfaceTablePtr(Edge* edge) {

Backend/src/globalstate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class GlobalState {
224224
Name* serializeThunkName = nullptr;
225225
Name* unserializeName = nullptr;
226226
Name* unserializeThunkName = nullptr;
227+
Name* freeName = nullptr;
228+
Name* freeThunkName = nullptr;
227229

228230
RCImm* rcImm = nullptr;
229231
IRegion* mutRegion = nullptr;
@@ -244,7 +246,7 @@ class GlobalState {
244246
IRegion* getRegion(Reference* referenceM);
245247
IRegion* getRegion(Kind* kindM);
246248
IRegion* getRegion(RegionId* regionId);
247-
LLVMValueRef getFunction(Name* name);
249+
LLVMValueRef getFunction(Prototype* proto);
248250
LLVMValueRef getInterfaceTablePtr(Edge* edge);
249251
LLVMValueRef getOrMakeStringConstant(const std::string& str);
250252
};

Backend/src/metal/ast.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ class Package {
4545
std::unordered_map<std::string, StructDefinition*> structs;
4646
std::unordered_map<std::string, StaticSizedArrayDefinitionT*> staticSizedArrays;
4747
std::unordered_map<std::string, RuntimeSizedArrayDefinitionT*> runtimeSizedArrays;
48-
// std::unordered_map<std::string, Prototype*> externs;
4948
std::unordered_map<std::string, Function*> functions;
50-
std::unordered_map<Kind*, Prototype*, AddressHasher<Kind*>> immDestructorsByKind;
49+
// std::unordered_map<Kind*, Prototype*, AddressHasher<Kind*>> immDestructorsByKind;
5150

5251
// This only contains exports defined in this package. Though, the things they're exporting can
5352
// be defined somewhere else.
@@ -69,7 +68,7 @@ class Package {
6968
std::unordered_map<std::string, StaticSizedArrayDefinitionT*> staticSizedArrays_,
7069
std::unordered_map<std::string, RuntimeSizedArrayDefinitionT*> runtimeSizedArrays_,
7170
std::unordered_map<std::string, Function*> functions_,
72-
std::unordered_map<Kind*, Prototype*, AddressHasher<Kind*>> immDestructorsByKind_,
71+
// std::unordered_map<Kind*, Prototype*, AddressHasher<Kind*>> immDestructorsByKind_,
7372
std::unordered_map<std::string, Prototype*> exportNameToFunction_,
7473
std::unordered_map<std::string, Kind*> exportNameToKind_,
7574
std::unordered_map<std::string, Prototype*> externNameToFunction_,
@@ -80,7 +79,7 @@ class Package {
8079
staticSizedArrays(std::move(staticSizedArrays_)),
8180
runtimeSizedArrays(std::move(runtimeSizedArrays_)),
8281
functions(std::move(functions_)),
83-
immDestructorsByKind(std::move(immDestructorsByKind_)),
82+
// immDestructorsByKind(std::move(immDestructorsByKind_)),
8483
exportNameToFunction(std::move(exportNameToFunction_)),
8584
exportNameToKind(std::move(exportNameToKind_)),
8685
externNameToFunction(std::move(externNameToFunction_)),
@@ -173,11 +172,11 @@ class Package {
173172
}
174173
return std::optional(iter->second);
175174
}
176-
Prototype* getImmDestructor(Kind* kind) {
177-
auto iter = immDestructorsByKind.find(kind);
178-
assert(iter != immDestructorsByKind.end());
179-
return iter->second;
180-
}
175+
// Prototype* getImmDestructor(Kind* kind) {
176+
// auto iter = immDestructorsByKind.find(kind);
177+
// assert(iter != immDestructorsByKind.end());
178+
// return iter->second;
179+
// }
181180

182181
std::string getKindExportName(Kind* kind, bool includeProjectName) const {
183182
if (auto innt = dynamic_cast<Int *>(kind)) {
@@ -299,9 +298,9 @@ class Program {
299298
RuntimeSizedArrayDefinitionT* getRuntimeSizedArray(RuntimeSizedArrayT* rsaMT) {
300299
return getPackage(rsaMT->name->packageCoord)->getRuntimeSizedArray(rsaMT);
301300
}
302-
Prototype* getImmDestructor(Kind* kind) {
303-
return getPackage(kind->getPackageCoordinate())->getImmDestructor(kind);
304-
}
301+
// Prototype* getImmDestructor(Kind* kind) {
302+
// return getPackage(kind->getPackageCoordinate())->getImmDestructor(kind);
303+
// }
305304
// bool isExported(Name* name) {
306305
// return getPackage(name->packageCoord)->isExported(name);
307306
// }

Backend/src/metal/readjson.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,12 @@ Package* readPackage(MetalCache* cache, const json& program) {
720720
auto f = readFunction(cache, j);
721721
return std::make_pair(f->prototype->name->name, f);
722722
}),
723-
readArrayIntoMap<Kind*, Prototype*>(
724-
cache,
725-
AddressHasher<Kind*>(cache->addressNumberer),
726-
std::equal_to<Kind*>(),
727-
program["immDestructorsByKind"],
728-
readKindAndPrototypeEntry),
723+
// readArrayIntoMap<Kind*, Prototype*>(
724+
// cache,
725+
// AddressHasher<Kind*>(cache->addressNumberer),
726+
// std::equal_to<Kind*>(),
727+
// program["immDestructorsByKind"],
728+
// readKindAndPrototypeEntry),
729729
readArrayIntoMap<std::string, Prototype*>(
730730
cache,
731731
std::hash<std::string>(),

Backend/src/region/linear/linearstructs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ void LinearStructs::declareStruct(StructKind* structM) {
6666
void LinearStructs::declareEdge(StructKind* structKind, InterfaceKind* interfaceKind) {
6767
// There aren't edges per se, just tag numbers. That's all we have to do here.
6868

69-
// Creates one if it doesnt already exist.
70-
auto* os = &orderedStructsByInterface[interfaceKind];
69+
auto iter = orderedStructsByInterface.find(interfaceKind);
70+
assert(iter != orderedStructsByInterface.end()); // declareInterface should have made it
71+
auto* os = &iter->second;
7172

7273
assert(std::count(os->begin(), os->end(), structKind) == 0);
7374
os->push_back(structKind);
@@ -88,6 +89,8 @@ void LinearStructs::declareInterface(InterfaceKind* interface) {
8889

8990
interfaceRefStructsL.emplace(interface, interfaceRefStructL);
9091

92+
orderedStructsByInterface.emplace(interface, std::vector<StructKind*>{});
93+
9194
// No need to make interface table structs, there are no itables for Linear.
9295
}
9396

0 commit comments

Comments
 (0)