| 1121 | } |
| 1122 | |
| 1123 | std::tuple<bytes, std::vector<size_t>, size_t> Assembly::createEOFHeader(std::set<ContainerID> const& _referencedSubIds) const |
| 1124 | { |
| 1125 | bytes retBytecode; |
| 1126 | std::vector<size_t> codeSectionSizePositions; |
| 1127 | size_t dataSectionSizePosition; |
| 1128 | |
| 1129 | retBytecode.push_back(0xef); |
| 1130 | retBytecode.push_back(0x00); |
| 1131 | retBytecode.push_back(0x01); // version 1 |
| 1132 | |
| 1133 | retBytecode.push_back(0x01); // kind=type |
| 1134 | appendBigEndianUint16(retBytecode, m_codeSections.size() * 4u); // length of type section |
| 1135 | |
| 1136 | retBytecode.push_back(0x02); // kind=code |
| 1137 | appendBigEndianUint16(retBytecode, m_codeSections.size()); // placeholder for number of code sections |
| 1138 | |
| 1139 | for (auto const& codeSection: m_codeSections) |
| 1140 | { |
| 1141 | (void) codeSection; |
| 1142 | codeSectionSizePositions.emplace_back(retBytecode.size()); |
| 1143 | appendBigEndianUint16(retBytecode, 0u); // placeholder for length of code |
| 1144 | } |
| 1145 | |
| 1146 | if (!_referencedSubIds.empty()) |
| 1147 | { |
| 1148 | retBytecode.push_back(0x03); |
| 1149 | appendBigEndianUint16(retBytecode, _referencedSubIds.size()); |
| 1150 | |
| 1151 | for (auto subId: _referencedSubIds) |
| 1152 | appendBigEndianUint16(retBytecode, m_subs[subId]->assemble().bytecode.size()); |
| 1153 | } |
| 1154 | |
| 1155 | retBytecode.push_back(0x04); // kind=data |
| 1156 | dataSectionSizePosition = retBytecode.size(); |
| 1157 | appendBigEndianUint16(retBytecode, 0u); // length of data |
| 1158 | |
| 1159 | retBytecode.push_back(0x00); // terminator |
| 1160 | |
| 1161 | for (auto const& codeSection: m_codeSections) |
| 1162 | { |
| 1163 | retBytecode.push_back(codeSection.inputs); |
| 1164 | // According to EOF spec function output num equals 0x80 means non-returning function |
| 1165 | retBytecode.push_back(codeSection.nonReturning ? 0x80 : codeSection.outputs); |
| 1166 | appendBigEndianUint16(retBytecode, calculateMaxStackHeight(codeSection)); |
| 1167 | } |
| 1168 | |
| 1169 | return {retBytecode, codeSectionSizePositions, dataSectionSizePosition}; |
| 1170 | } |
| 1171 | |
| 1172 | LinkerObject const& Assembly::assemble() const |
| 1173 | { |
nothing calls this directly
no test coverage detected