void CompilerContext::appendInlineAssembly( string const& _assembly, vector<string> const& _localVariables, map<string, string> const& _replacements ) { string replacedAssembly; string const* assembly = &_assembly; if (!_replacements.empty()) { replacedAssembly = _assembly; for (auto const& replacement: _replacements) replacedAssembly = boost::algorithm::replace_all_copy(replacedAssembly, replacement.first, replacement.second); assembly = &replacedAssembly; } unsigned startStackHeight = stackHeight(); auto identifierAccess = [&]( assembly::Identifier const& _identifier, eth::Assembly& _assembly, assembly::CodeGenerator::IdentifierContext _context ) { auto it = std::find(_localVariables.begin(), _localVariables.end(), _identifier.name); if (it == _localVariables.end()) return false; unsigned stackDepth = _localVariables.end() - it; int stackDiff = _assembly.deposit() - startStackHeight + stackDepth; if (stackDiff < 1 || stackDiff > 16) BOOST_THROW_EXCEPTION( CompilerError() << errinfo_comment("Stack too deep, try removing local variables.") ); if (_context == assembly::CodeGenerator::IdentifierContext::RValue) _assembly.append(dupInstruction(stackDiff)); else { _assembly.append(swapInstruction(stackDiff)); _assembly.append(Instruction::POP); } return true; }; solAssert(assembly::InlineAssemblyStack().parseAndAssemble(*assembly, m_asm, identifierAccess), ""); }
int main(int argc, char *argv[]) { stItem_t *stackItem_A; stItem_t *stackItem_B; stItem_t *stackItem_1; stItem_t *stackItem_2; mdsDirectory_t dir_1; mdsDirectory_t dir_2; mdsDirectory_t dir_3; mdsDirectory_t dir_4; mdsDirectory_t dir_5; stackInitAll(); strcpy(dir_1.szFilename, "/home/ann/contentExample/E200581216"); strcpy(dir_2.szFilename, "/home/root"); strcpy(dir_3.szFilename, "/home/ann"); strcpy(dir_4.szFilename, "/home/ann/projects"); strcpy(dir_5.szFilename, "/test"); // create a stack item stackItem_A = g_new0(stItem_t, 1); stackItem_A->dirArray = g_array_sized_new(FALSE, TRUE, ERMDS_MAX_FILENAME_SIZE, INITIAL_DIR_COUNT_ARRAY_SIZE); CL_STACKPRINTF("stackItem_A->dirArray - 0x%x", (unsigned int) stackItem_A->dirArray); g_array_append_val(stackItem_A->dirArray, dir_1); g_array_append_val(stackItem_A->dirArray, dir_2); g_array_append_val(stackItem_A->dirArray, dir_3); stackItem_A->sort.ascending = 1; stackItem_A->sort.ft = mdsFieldFile; stackPush(st_ContentTypeBooks, stackItem_A); // create a stack item stackItem_B = g_new0(stItem_t, 1); stackItem_B->dirArray = g_array_sized_new(FALSE, TRUE, ERMDS_MAX_FILENAME_SIZE, INITIAL_DIR_COUNT_ARRAY_SIZE); CL_STACKPRINTF("stackItem_B->dirArray - 0x%x", (unsigned int) stackItem_B->dirArray); g_array_append_val(stackItem_B->dirArray, dir_4); g_array_append_val(stackItem_B->dirArray, dir_5); stackItem_B->sort.ascending = 0; stackItem_B->sort.ft = mdsFieldFile; stackPush(st_ContentTypeBooks, stackItem_B); CL_STACKPRINTF("height %d", stackHeight(st_ContentTypeBooks));; stackItem_2 = stackPeek(st_ContentTypeBooks); stackItemDisplay(stackItem_2); stackPop(st_ContentTypeBooks); stackItem_1 = stackPeek(st_ContentTypeBooks); stackItemDisplay(stackItem_1); stackPop(st_ContentTypeBooks); g_free(stackItem_A); g_free(stackItem_B); stackDestroyAll(); return 0; }