void codeGen(TreeNode *syntaxTree, const char *codefile) { writeFileHeader(); writeVarSection(); cGen(syntaxTree); fillCodeSection(); writeTempVarSection(); writeVarRefSection(); fillSection(); writeTempVarRefSection(); fillSection(); updateFileHeader(); }
HRESULT CaPerfDataWriter::init(const char* filepath, bool overwrite) { int numSection = 0; if (!filepath) { return E_INVALIDARG; } // if the file already exists return error if (overwrite && (! access(filepath, F_OK))) { return E_ACCESSDENIED; } // Open the file in write mode. m_fd = open(filepath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (-1 == m_fd) { return E_FAIL; } // write the header HRESULT ret = writeHeader(); if (S_OK != ret) { return ret; } // CPU_INFO stuff // write section header entry for cpu info and update the fileheader ret = writeSectionHdr(CAPERF_SECTION_CPU_INFO, 0, 0); if (S_OK != ret) { return ret; } numSection++; // Write the CoreTopology stuff // write section header entry for cpu topology and update the fileheader ret = writeSectionHdr(CAPERF_SECTION_TOPOLOGY, 0, 0); if (S_OK != ret) { return ret; } numSection++; // TARGET_PIDS stuff // write the CAPERF_SECTION_TARGET_PIDS section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_TARGET_PIDS, 0, 0); if (S_OK != ret) { return ret; } numSection++; // FAKE_TIMER_INFO stuff // write the CAPERF_SECTION_FAKE_TIMER_INFO section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_FAKE_TIMER_INFO, 0, 0); if (S_OK != ret) { return ret; } numSection++; // CAPERF_SECTION_DYNAMIC_PMU_TYPES // write the dynamic pmu type ids used by PERF lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_DYNAMIC_PMU_TYPES, 0, 0); if (S_OK != ret) { return ret; } numSection++; ret = updateFileHeader(0, numSection * sizeof(caperf_section_hdr_t)); return ret; }
// function to write the section headers // // Expects counting-events-list and sampling-events-List // HRESULT CaPerfDataWriter::writeEventsConfig(CaPerfEvtList& countEventsList, CaPerfEvtList& sampleEventsList) { gtUByte numberSections = 0; HRESULT ret = S_OK; if (countEventsList.size() || sampleEventsList.size()) { // write the CAPERF_SECTION_EVENT_ATTRIBUTE section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_EVENT_ATTRIBUTE, 0, 0); numberSections++; } if (sampleEventsList.size()) { // write the CAPERF_SECTION_EVENT_ID section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_EVENT_ID, 0, 0); // write the CAPERF_SECTION_SAMPLE_DATA section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_SAMPLE_DATA, 0, 0); numberSections += 2; } if (countEventsList.size()) { // write the CAPERF_SECTION_COUNTER_DATA section header lseek(m_fd, 0, SEEK_END); ret = writeSectionHdr(CAPERF_SECTION_COUNTER_DATA, 0, 0); numberSections++; } // Since, we have added new sections in section-header-table, update the file header // TODO: modify updateFileHeader signature ? updateFileHeader(0, numberSections * sizeof(caperf_section_hdr_t)); // write the cpu-info here, just before writing the counter details. ret = writeCpuInfo(); if (S_OK != ret) { return ret; } // Write the cpu topology ret = writeCpuTopology(); if (S_OK != ret) { return ret; } // Write the dynamic PMU types for IBS fetch and Op if (S_OK != (ret = writeDynamicPmuTypes())) { return ret; } // Add Counter Events ssize_t sectionStOffset = lseek(m_fd, 0, SEEK_END); CaPerfEvtList::iterator iter = countEventsList.begin(); for (; iter != countEventsList.end(); iter++) { writeCountEvent(*iter); } // Add Sampling Events iter = sampleEventsList.begin(); for (; iter != sampleEventsList.end(); iter++) { writeSampleEvent(*iter); } ssize_t sectionEndOffset = lseek(m_fd, 0, SEEK_END); // update the section header entry for CAPERF_SECTION_EVENT_ATTRIBUTE updateSectionHdr(CAPERF_SECTION_EVENT_ATTRIBUTE, sectionStOffset, (sectionEndOffset - sectionStOffset)); // Now write CAPERF_SECTION_EVENT_ID and update the corresponding section header entry if (m_sampleIdList.size()) { writeSampleEventsInfo(); } // set the offset m_offset = lseek(m_fd, m_offset, SEEK_CUR); return S_OK; }