# HG changeset patch # User vnorilo # Date 1669191058 -7200 # Wed Nov 23 10:10:58 2022 +0200 # Branch dev # Node ID bb3b2eb0b087f28600052ee2b83cfad0b6a12b9e # Parent 644b0cac2213e10caacf6c673cc9815296dea4db Fix header generation for unsafe externals diff --git a/src/backends/LLVMModule.cpp b/src/backends/LLVMModule.cpp --- a/src/backends/LLVMModule.cpp +++ b/src/backends/LLVMModule.cpp @@ -338,23 +338,24 @@ auto slotI = globalSymbolTable.find(gv.second.uid); auto slotIndex = slotI != globalSymbolTable.end() ? std::int32_t(slotI->second) : -1; - bool noDefaultVal = + bool constructorParameter = ((gv.second.varType == External || gv.second.varType == Configuration) && globalKeyTable.find(gv.first) != globalKeyTable.end()); - + if (slotIndex >= 0) { std::stringstream driverName; if (gv.second.varType == Stream) { gv.second.clock.OutputText(driverName); } - cppHeader.DeclareSlot(sym.str(), slotIndex, gv.second.data, noDefaultVal, driverName.str()); + cppHeader.DeclareSlot(sym.str(), slotIndex, gv.second.data, constructorParameter, driverName.str()); } if (trigger != inputCall.end()) { cppHeader.DeclareDriver(trigger->second->getName()); } - + + bool noDefaultVal = constructorParameter || gv.second.varType == UnsafeExternal; symTableEntry.emplace_back( ConstantStruct::get(symTy, { diff --git a/src/backends/LLVMModule.h b/src/backends/LLVMModule.h --- a/src/backends/LLVMModule.h +++ b/src/backends/LLVMModule.h @@ -149,7 +149,7 @@ << wrapperName << "(" << wrapperName << " const&) = delete;\n\t" << wrapperName << "(" << wrapperName << "&& from) { instance = from.instance; from.instance = nullptr; };\n\t" << "void operator=(" << wrapperName << " const&) = delete;\n\t" - << wrapperName << "& operator=(" << wrapperName << "&& from) { auto tmp = from.instance; from.instance = instance; instance = tmp; }\n" + << wrapperName << "& operator=(" << wrapperName << "&& from) { auto tmp = from.instance; from.instance = instance; instance = tmp; return *this; }\n" // << "#endif\n" "\n"; @@ -236,12 +236,12 @@ std::vector configSlots; - void DeclareSlot(std::string slotName, int slotIndex, const Type& inputType, bool nodefault, std::string streamingDriver) { + void DeclareSlot(std::string slotName, int slotIndex, const Type& inputType, bool constructorParameter, std::string streamingDriver) { if (header.is_open()) { auto typeName = GenerateType(className + slotName + "InputType", inputType); auto cName = CSymbolize(slotName); - if (nodefault) { + if (constructorParameter) { header << "\n// You must set this before calling `" << className << "Initialize()`\n"; configSlots.push_back(ConfigValue{ typeName, cName }); header << "static void " << className << "Configure" << cName << "(const " << typeName << "* data) { \n\t" diff --git a/src/k3/DynamicVariables.cpp b/src/k3/DynamicVariables.cpp --- a/src/k3/DynamicVariables.cpp +++ b/src/k3/DynamicVariables.cpp @@ -47,8 +47,8 @@ key.result.Fix(), std::make_pair(1,1), nullptr, - External), - initType); + UnsafeExternal), + initType); } if (spec.mode == SpecializationState::Configuration) { diff --git a/src/k3/DynamicVariables.h b/src/k3/DynamicVariables.h --- a/src/k3/DynamicVariables.h +++ b/src/k3/DynamicVariables.h @@ -23,6 +23,7 @@ Internal, External, Stream, + UnsafeExternal, NumVarTypes };