From c5512389da036a1437a02212b197815e33f21566 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 7 May 2014 17:22:20 +0200 Subject: [PATCH] changed project structure to qtcreator, added timed out powerdown --- dram/.cproject | 260 --- dram/.project | 27 - dram/.settings/language.settings.xml | 23 - .../org.eclipse.cdt.codan.core.prefs | 67 - dram/.settings/org.eclipse.cdt.core.prefs | 174 -- .../org.eclipse.cdt.managedbuilder.core.prefs | 25 - dram/.settings/org.eclipse.cdt.ui.prefs | 3 - .../org.eclipse.core.resources.prefs | 2 - .../org.eclipse.ltk.core.refactoring.prefs | 2 - dram/dramSys/dramSys.pro | 110 + .../configs/memconfigs/memconfig.xml | 4 +- dram/resources/simulations/sim-batch.xml | 5 +- dram/src/common/TlmRecorder.cpp | 314 +-- dram/src/common/Utils.h | 44 +- dram/src/common/dramExtension.cpp | 120 +- dram/src/common/third_party/tinystr.cpp | 111 - dram/src/common/third_party/tinystr.h | 305 --- dram/src/common/third_party/tinyxml.cpp | 1886 ----------------- dram/src/common/third_party/tinyxml.h | 1805 ---------------- dram/src/common/third_party/tinyxmlerror.cpp | 52 - dram/src/common/third_party/tinyxmlparser.cpp | 1638 -------------- dram/src/common/xmlAddressdecoder.cpp | 131 +- dram/src/common/xmlAddressdecoder.h | 91 +- dram/src/controller/Controller.h | 423 ++++ dram/src/controller/core/BankStates.cpp | 68 + dram/src/controller/core/BankStates.h | 35 + dram/src/{ => controller}/core/Command.cpp | 0 dram/src/{ => controller}/core/Command.h | 0 .../{ => controller}/core/ControllerCore.cpp | 6 +- .../{ => controller}/core/ControllerCore.h | 2 +- dram/src/controller/core/ControllerState.cpp | 112 + .../{ => controller}/core/ControllerState.h | 0 .../{ => controller}/core/IWrapperConnector.h | 0 dram/src/{ => controller}/core/Slots.cpp | 0 dram/src/{ => controller}/core/Slots.h | 0 .../core/TimingCalculation.cpp | 4 +- .../{ => controller}/core/TimingCalculation.h | 14 +- .../core/configuration/Configuration.cpp | 0 .../core/configuration/Configuration.h | 0 .../core/configuration/MemSpecLoader.cpp | 174 ++ .../core/configuration/MemSpecLoader.h | 4 +- .../core/configuration/TimingConfiguration.h | 2 +- .../core/powerdown/IPowerDownManager.h | 2 +- .../core/powerdown/PowerDownManager.cpp | 165 ++ .../core/powerdown/PowerDownManager.h | 0 .../powerdown/PowerDownManagerBankwise.cpp | 2 +- .../core/powerdown/PowerDownManagerBankwise.h | 2 +- .../powerdown/PowerDownManagerTimeout.cpp | 140 ++ .../core/powerdown/PowerDownManagerTimeout.h | 47 + .../core/refresh/IRefreshManager.h | 0 .../core/refresh/RefreshManager.cpp | 2 +- .../core/refresh/RefreshManager.h | 0 .../core/refresh/RefreshManagerBankwise.cpp | 2 +- .../core/refresh/RefreshManagerBankwise.h | 2 +- .../core/scheduling/CommandSchedule.h | 4 +- .../scheduling/CommandSequenceGenerator.cpp | 2 +- .../scheduling/CommandSequenceGenerator.h | 0 .../scheduling/CommandSequenceScheduler.cpp | 2 +- .../scheduling/CommandSequenceScheduler.h | 0 .../core/scheduling/ScheduledCommand.cpp | 2 +- .../core/scheduling/ScheduledCommand.h | 68 + .../core/scheduling/Trigger.h | 0 .../scheduling/checker/ActivateChecker.cpp | 4 +- .../core/scheduling/checker/ActivateChecker.h | 0 .../core/scheduling/checker/ICommandChecker.h | 0 .../scheduling/checker/PowerDownChecker.cpp | 2 +- .../scheduling/checker/PowerDownChecker.h | 0 .../checker/PrechargeAllChecker.cpp | 2 +- .../scheduling/checker/PrechargeAllChecker.h | 0 .../scheduling/checker/PrechargeChecker.cpp | 48 + .../scheduling/checker/PrechargeChecker.h | 0 .../core/scheduling/checker/ReadChecker.cpp | 2 +- .../core/scheduling/checker/ReadChecker.h | 0 .../scheduling/checker/RefreshChecker.cpp | 2 +- .../core/scheduling/checker/RefreshChecker.h | 0 .../core/scheduling/checker/WriteChecker.cpp | 2 +- .../core/scheduling/checker/WriteChecker.h | 0 dram/src/{ => controller}/scheduler/Fifo.cpp | 0 dram/src/{ => controller}/scheduler/Fifo.h | 0 .../{ => controller}/scheduler/Fr_Fcfs.cpp | 2 +- dram/src/{ => controller}/scheduler/Fr_Fcfs.h | 0 dram/src/{ => controller}/scheduler/PARBS.cpp | 2 +- dram/src/{ => controller}/scheduler/PARBS.h | 0 .../{ => controller}/scheduler/Scheduler.h | 2 +- .../{ => controller}/scheduler/ThreadLoad.cpp | 0 .../{ => controller}/scheduler/ThreadLoad.h | 2 +- dram/src/core/BankStates.cpp | 68 - dram/src/core/BankStates.h | 35 - dram/src/core/ControllerState.cpp | 111 - dram/src/core/configuration/MemSpecLoader.cpp | 175 -- dram/src/core/powerdown/PowerDownManager.cpp | 166 -- .../powerdown/PowerDownManagerTimeout.cpp | 140 -- .../core/powerdown/PowerDownManagerTimeout.h | 51 - dram/src/core/scheduling/ScheduledCommand.h | 68 - .../scheduling/checker/PrechargeChecker.cpp | 40 - dram/src/simulation/Arbiter.h | 196 +- dram/src/simulation/Controller.h | 424 ---- dram/src/simulation/Dram.h | 162 +- dram/src/simulation/Simulation.cpp | 186 +- dram/src/simulation/Simulation.h | 72 +- dram/src/simulation/SimulationManager.cpp | 212 +- dram/src/simulation/TracePlayer.h | 234 +- dram/src/simulation/main.cpp | 31 +- dram/testing/BankwiseRefreshManager_test.cpp | 88 - dram/testing/CommandBus_test.cpp | 125 -- dram/testing/CommandGenerator_test.cpp | 68 - .../testing/CommandSequenceScheduler_test.cpp | 12 - dram/testing/Controller_test.cpp | 40 - dram/testing/PowerDownManager_test.cpp | 12 - dram/testing/RefreshManager_test.cpp | 107 - dram/testing/Utils_test.cpp | 83 - dram/testing/main.cpp | 33 - dram/testing/testUtils.cpp | 47 - dram/testing/testUtils.h | 29 - 114 files changed, 2324 insertions(+), 9246 deletions(-) delete mode 100644 dram/.cproject delete mode 100644 dram/.project delete mode 100644 dram/.settings/language.settings.xml delete mode 100644 dram/.settings/org.eclipse.cdt.codan.core.prefs delete mode 100644 dram/.settings/org.eclipse.cdt.core.prefs delete mode 100644 dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs delete mode 100644 dram/.settings/org.eclipse.cdt.ui.prefs delete mode 100644 dram/.settings/org.eclipse.core.resources.prefs delete mode 100644 dram/.settings/org.eclipse.ltk.core.refactoring.prefs create mode 100644 dram/dramSys/dramSys.pro delete mode 100755 dram/src/common/third_party/tinystr.cpp delete mode 100755 dram/src/common/third_party/tinystr.h delete mode 100755 dram/src/common/third_party/tinyxml.cpp delete mode 100755 dram/src/common/third_party/tinyxml.h delete mode 100755 dram/src/common/third_party/tinyxmlerror.cpp delete mode 100755 dram/src/common/third_party/tinyxmlparser.cpp create mode 100644 dram/src/controller/Controller.h create mode 100644 dram/src/controller/core/BankStates.cpp create mode 100644 dram/src/controller/core/BankStates.h rename dram/src/{ => controller}/core/Command.cpp (100%) rename dram/src/{ => controller}/core/Command.h (100%) rename dram/src/{ => controller}/core/ControllerCore.cpp (98%) rename dram/src/{ => controller}/core/ControllerCore.h (97%) create mode 100644 dram/src/controller/core/ControllerState.cpp rename dram/src/{ => controller}/core/ControllerState.h (100%) rename dram/src/{ => controller}/core/IWrapperConnector.h (100%) rename dram/src/{ => controller}/core/Slots.cpp (100%) rename dram/src/{ => controller}/core/Slots.h (100%) rename dram/src/{ => controller}/core/TimingCalculation.cpp (97%) rename dram/src/{ => controller}/core/TimingCalculation.h (68%) rename dram/src/{ => controller}/core/configuration/Configuration.cpp (100%) rename dram/src/{ => controller}/core/configuration/Configuration.h (100%) create mode 100644 dram/src/controller/core/configuration/MemSpecLoader.cpp rename dram/src/{ => controller}/core/configuration/MemSpecLoader.h (87%) rename dram/src/{ => controller}/core/configuration/TimingConfiguration.h (97%) rename dram/src/{ => controller}/core/powerdown/IPowerDownManager.h (98%) create mode 100644 dram/src/controller/core/powerdown/PowerDownManager.cpp rename dram/src/{ => controller}/core/powerdown/PowerDownManager.h (100%) rename dram/src/{ => controller}/core/powerdown/PowerDownManagerBankwise.cpp (99%) rename dram/src/{ => controller}/core/powerdown/PowerDownManagerBankwise.h (97%) create mode 100644 dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp create mode 100644 dram/src/controller/core/powerdown/PowerDownManagerTimeout.h rename dram/src/{ => controller}/core/refresh/IRefreshManager.h (100%) rename dram/src/{ => controller}/core/refresh/RefreshManager.cpp (98%) rename dram/src/{ => controller}/core/refresh/RefreshManager.h (100%) rename dram/src/{ => controller}/core/refresh/RefreshManagerBankwise.cpp (98%) rename dram/src/{ => controller}/core/refresh/RefreshManagerBankwise.h (96%) rename dram/src/{ => controller}/core/scheduling/CommandSchedule.h (93%) rename dram/src/{ => controller}/core/scheduling/CommandSequenceGenerator.cpp (97%) rename dram/src/{ => controller}/core/scheduling/CommandSequenceGenerator.h (100%) rename dram/src/{ => controller}/core/scheduling/CommandSequenceScheduler.cpp (95%) rename dram/src/{ => controller}/core/scheduling/CommandSequenceScheduler.h (100%) rename dram/src/{ => controller}/core/scheduling/ScheduledCommand.cpp (98%) create mode 100644 dram/src/controller/core/scheduling/ScheduledCommand.h rename dram/src/{ => controller}/core/scheduling/Trigger.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/ActivateChecker.cpp (97%) rename dram/src/{ => controller}/core/scheduling/checker/ActivateChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/ICommandChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/PowerDownChecker.cpp (98%) rename dram/src/{ => controller}/core/scheduling/checker/PowerDownChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/PrechargeAllChecker.cpp (98%) rename dram/src/{ => controller}/core/scheduling/checker/PrechargeAllChecker.h (100%) create mode 100644 dram/src/controller/core/scheduling/checker/PrechargeChecker.cpp rename dram/src/{ => controller}/core/scheduling/checker/PrechargeChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/ReadChecker.cpp (99%) rename dram/src/{ => controller}/core/scheduling/checker/ReadChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/RefreshChecker.cpp (97%) rename dram/src/{ => controller}/core/scheduling/checker/RefreshChecker.h (100%) rename dram/src/{ => controller}/core/scheduling/checker/WriteChecker.cpp (98%) rename dram/src/{ => controller}/core/scheduling/checker/WriteChecker.h (100%) rename dram/src/{ => controller}/scheduler/Fifo.cpp (100%) rename dram/src/{ => controller}/scheduler/Fifo.h (100%) rename dram/src/{ => controller}/scheduler/Fr_Fcfs.cpp (98%) rename dram/src/{ => controller}/scheduler/Fr_Fcfs.h (100%) rename dram/src/{ => controller}/scheduler/PARBS.cpp (98%) rename dram/src/{ => controller}/scheduler/PARBS.h (100%) rename dram/src/{ => controller}/scheduler/Scheduler.h (91%) rename dram/src/{ => controller}/scheduler/ThreadLoad.cpp (100%) rename dram/src/{ => controller}/scheduler/ThreadLoad.h (94%) delete mode 100644 dram/src/core/BankStates.cpp delete mode 100644 dram/src/core/BankStates.h delete mode 100644 dram/src/core/ControllerState.cpp delete mode 100644 dram/src/core/configuration/MemSpecLoader.cpp delete mode 100644 dram/src/core/powerdown/PowerDownManager.cpp delete mode 100644 dram/src/core/powerdown/PowerDownManagerTimeout.cpp delete mode 100644 dram/src/core/powerdown/PowerDownManagerTimeout.h delete mode 100644 dram/src/core/scheduling/ScheduledCommand.h delete mode 100644 dram/src/core/scheduling/checker/PrechargeChecker.cpp delete mode 100644 dram/src/simulation/Controller.h delete mode 100644 dram/testing/BankwiseRefreshManager_test.cpp delete mode 100644 dram/testing/CommandBus_test.cpp delete mode 100644 dram/testing/CommandGenerator_test.cpp delete mode 100644 dram/testing/CommandSequenceScheduler_test.cpp delete mode 100644 dram/testing/Controller_test.cpp delete mode 100644 dram/testing/PowerDownManager_test.cpp delete mode 100644 dram/testing/RefreshManager_test.cpp delete mode 100644 dram/testing/Utils_test.cpp delete mode 100644 dram/testing/main.cpp delete mode 100644 dram/testing/testUtils.cpp delete mode 100644 dram/testing/testUtils.h diff --git a/dram/.cproject b/dram/.cproject deleted file mode 100644 index 79dda475..00000000 --- a/dram/.cproject +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - make - - standalone - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dram/.project b/dram/.project deleted file mode 100644 index 0ebeb50d..00000000 --- a/dram/.project +++ /dev/null @@ -1,27 +0,0 @@ - - - dram - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - diff --git a/dram/.settings/language.settings.xml b/dram/.settings/language.settings.xml deleted file mode 100644 index ae137ce7..00000000 --- a/dram/.settings/language.settings.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dram/.settings/org.eclipse.cdt.codan.core.prefs b/dram/.settings/org.eclipse.cdt.codan.core.prefs deleted file mode 100644 index 77386c23..00000000 --- a/dram/.settings/org.eclipse.cdt.codan.core.prefs +++ /dev/null @@ -1,67 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.cdt.codan.checkers.errnoreturn=Warning -org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} -org.eclipse.cdt.codan.checkers.errreturnvalue=Error -org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.checkers.noreturn=Error -org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} -org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error -org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error -org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning -org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error -org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning -org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false} -org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning -org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()} -org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error -org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning -org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true} -org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error -org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error -org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error -org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error -org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error -org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error -org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error -org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info -org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} -org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning -org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error -org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error -org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error -org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning -org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning -org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning -org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()} -org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning -org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false} -org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning -org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false} -org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error -org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning -org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} -org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning -org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} -org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning -org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")} -org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error -org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} diff --git a/dram/.settings/org.eclipse.cdt.core.prefs b/dram/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index ac28a4dd..00000000 --- a/dram/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,174 +0,0 @@ -eclipse.preferences.version=1 -indexer/indexAllFiles=true -indexer/indexOnOpen=false -indexer/indexUnusedHeadersWithAlternateLang=false -indexer/indexUnusedHeadersWithDefaultLang=true -indexer/indexerId=org.eclipse.cdt.core.fastIndexer -indexer/skipFilesLargerThanMB=8 -indexer/skipImplicitReferences=false -indexer/skipMacroReferences=false -indexer/skipReferences=false -indexer/skipTypeReferences=false -indexer/useHeuristicIncludeResolution=true -org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.cdt.core.formatter.alignment_for_assignment=16 -org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80 -org.eclipse.cdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.cdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.cdt.core.formatter.alignment_for_conditional_expression=34 -org.eclipse.cdt.core.formatter.alignment_for_conditional_expression_chain=18 -org.eclipse.cdt.core.formatter.alignment_for_constructor_initializer_list=0 -org.eclipse.cdt.core.formatter.alignment_for_declarator_list=16 -org.eclipse.cdt.core.formatter.alignment_for_enumerator_list=48 -org.eclipse.cdt.core.formatter.alignment_for_expression_list=0 -org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.cdt.core.formatter.alignment_for_member_access=0 -org.eclipse.cdt.core.formatter.alignment_for_overloaded_left_shift_chain=16 -org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.cdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_block=next_line -org.eclipse.cdt.core.formatter.brace_position_for_block_in_case=next_line -org.eclipse.cdt.core.formatter.brace_position_for_method_declaration=next_line -org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_switch=next_line -org.eclipse.cdt.core.formatter.brace_position_for_type_declaration=next_line -org.eclipse.cdt.core.formatter.comment.min_distance_between_code_and_line_comment=1 -org.eclipse.cdt.core.formatter.comment.never_indent_line_comments_on_first_column=true -org.eclipse.cdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true -org.eclipse.cdt.core.formatter.compact_else_if=true -org.eclipse.cdt.core.formatter.continuation_indentation=2 -org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header=false -org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces=0 -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier=true -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header=false -org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header=false -org.eclipse.cdt.core.formatter.indent_empty_lines=false -org.eclipse.cdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.cdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch=true -org.eclipse.cdt.core.formatter.indentation.size=4 -org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert -org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_colon_in_constructor_initializer_list=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement=insert -org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement=insert -org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.join_wrapped_lines=true -org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.cdt.core.formatter.lineSplit=130 -org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.cdt.core.formatter.tabulation.char=tab -org.eclipse.cdt.core.formatter.tabulation.size=4 -org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations=false diff --git a/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs deleted file mode 100644 index c9647567..00000000 --- a/dram/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ /dev/null @@ -1,25 +0,0 @@ -eclipse.preferences.version=1 -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/CPLUS_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPLUS_INCLUDE_PATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/CPLUS_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/C_INCLUDE_PATH/delimiter=\: -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.exe.debug.513647443/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/delimiter=\: -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443.1530924826/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/delimiter=\: -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.exe.debug.513647443/appendContributed=true diff --git a/dram/.settings/org.eclipse.cdt.ui.prefs b/dram/.settings/org.eclipse.cdt.ui.prefs deleted file mode 100644 index d8b6f7f7..00000000 --- a/dram/.settings/org.eclipse.cdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -formatter_profile=_Unmanaged profile "agile formatter" -formatter_settings_version=1 diff --git a/dram/.settings/org.eclipse.core.resources.prefs b/dram/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index bd61a50f..00000000 --- a/dram/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/core/Command.cpp=UTF-8 diff --git a/dram/.settings/org.eclipse.ltk.core.refactoring.prefs b/dram/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index b196c64a..00000000 --- a/dram/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/dram/dramSys/dramSys.pro b/dram/dramSys/dramSys.pro new file mode 100644 index 00000000..d7c7844c --- /dev/null +++ b/dram/dramSys/dramSys.pro @@ -0,0 +1,110 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + + +LIBS += -L/opt/systemc/lib-linux64 -lsystemc +LIBS += -lsqlite3 +LIBS += -lpthread +INCLUDEPATH += /opt/systemc/include + +DEFINES += TIXML_USE_STL +DEFINES += SC_INCLUDE_DYNAMIC_PROCESSES +QMAKE_CXXFLAGS += -std=c++11 +QMAKE_CXXFLAGS += -isystem /opt/systemc/include + +SOURCES += \ + ../src/common/third_party/tinyxml2.cpp \ + ../src/common/xmlAddressdecoder.cpp \ + ../src/common/Utils.cpp \ + ../src/common/TlmRecorder.cpp \ + ../src/common/dramExtension.cpp \ + ../src/common/DebugManager.cpp \ + ../src/controller/core/configuration/MemSpecLoader.cpp \ + ../src/controller/core/configuration/Configuration.cpp \ + ../src/controller/core/powerdown/PowerDownManagerTimeout.cpp \ + ../src/controller/core/powerdown/PowerDownManagerBankwise.cpp \ + ../src/controller/core/powerdown/PowerDownManager.cpp \ + ../src/controller/scheduler/ThreadLoad.cpp \ + ../src/controller/scheduler/PARBS.cpp \ + ../src/controller/scheduler/Fr_Fcfs.cpp \ + ../src/controller/scheduler/Fifo.cpp \ + ../src/controller/core/refresh/RefreshManagerBankwise.cpp \ + ../src/controller/core/refresh/RefreshManager.cpp \ + ../src/controller/core/scheduling/checker/WriteChecker.cpp \ + ../src/controller/core/scheduling/checker/RefreshChecker.cpp \ + ../src/controller/core/scheduling/checker/ReadChecker.cpp \ + ../src/controller/core/scheduling/checker/PrechargeChecker.cpp \ + ../src/controller/core/scheduling/checker/PrechargeAllChecker.cpp \ + ../src/controller/core/scheduling/checker/PowerDownChecker.cpp \ + ../src/controller/core/scheduling/checker/ActivateChecker.cpp \ + ../src/controller/core/scheduling/ScheduledCommand.cpp \ + ../src/controller/core/scheduling/CommandSequenceScheduler.cpp \ + ../src/controller/core/scheduling/CommandSequenceGenerator.cpp \ + ../src/controller/core/TimingCalculation.cpp \ + ../src/controller/core/Slots.cpp \ + ../src/controller/core/ControllerState.cpp \ + ../src/controller/core/ControllerCore.cpp \ + ../src/controller/core/Command.cpp \ + ../src/controller/core/BankStates.cpp \ + ../src/simulation/SimulationManager.cpp \ + ../src/simulation/Simulation.cpp \ + ../src/simulation/MemoryManager.cpp \ + ../src/simulation/main.cpp + +HEADERS += \ + ../src/common/third_party/tinyxml2.h \ + ../src/common/xmlConfig.h \ + ../src/common/xmlAddressdecoder.h \ + ../src/common/Utils.h \ + ../src/common/TlmRecorder.h \ + ../src/common/tlm2_base_protocol_checker.h \ + ../src/common/protocol.h \ + ../src/common/dramExtension.h \ + ../src/common/DebugManager.h \ + ../src/controller/core/configuration/TimingConfiguration.h \ + ../src/controller/core/configuration/MemSpecLoader.h \ + ../src/controller/core/configuration/Configuration.h \ + ../src/controller/core/powerdown/PowerDownManagerTimeout.h \ + ../src/controller/core/powerdown/PowerDownManagerBankwise.h \ + ../src/controller/core/powerdown/PowerDownManager.h \ + ../src/controller/core/powerdown/IPowerDownManager.h \ + ../src/controller/scheduler/ThreadLoad.h \ + ../src/controller/scheduler/Scheduler.h \ + ../src/controller/scheduler/PARBS.h \ + ../src/controller/scheduler/Fr_Fcfs.h \ + ../src/controller/scheduler/Fifo.h \ + ../src/controller/Controller.h \ + ../src/controller/core/refresh/RefreshManagerBankwise.h \ + ../src/controller/core/refresh/RefreshManager.h \ + ../src/controller/core/refresh/IRefreshManager.h \ + ../src/controller/core/scheduling/checker/WriteChecker.h \ + ../src/controller/core/scheduling/checker/RefreshChecker.h \ + ../src/controller/core/scheduling/checker/ReadChecker.h \ + ../src/controller/core/scheduling/checker/PrechargeChecker.h \ + ../src/controller/core/scheduling/checker/PrechargeAllChecker.h \ + ../src/controller/core/scheduling/checker/PowerDownChecker.h \ + ../src/controller/core/scheduling/checker/ICommandChecker.h \ + ../src/controller/core/scheduling/checker/ActivateChecker.h \ + ../src/controller/core/scheduling/Trigger.h \ + ../src/controller/core/scheduling/ScheduledCommand.h \ + ../src/controller/core/scheduling/CommandSequenceScheduler.h \ + ../src/controller/core/scheduling/CommandSequenceGenerator.h \ + ../src/controller/core/scheduling/CommandSchedule.h \ + ../src/controller/core/TimingCalculation.h \ + ../src/controller/core/Slots.h \ + ../src/controller/core/IWrapperConnector.h \ + ../src/controller/core/ControllerState.h \ + ../src/controller/core/ControllerCore.h \ + ../src/controller/core/Command.h \ + ../src/controller/core/BankStates.h \ + ../src/simulation/TracePlayer.h \ + ../src/simulation/SimulationManager.h \ + ../src/simulation/Simulation.h \ + ../src/simulation/MemoryManager.h \ + ../src/simulation/ISimulation.h \ + ../src/simulation/Dram.h \ + ../src/simulation/Arbiter.h + + diff --git a/dram/resources/configs/memconfigs/memconfig.xml b/dram/resources/configs/memconfigs/memconfig.xml index 97697f61..5e944984 100644 --- a/dram/resources/configs/memconfigs/memconfig.xml +++ b/dram/resources/configs/memconfigs/memconfig.xml @@ -7,7 +7,7 @@ - - + + diff --git a/dram/resources/simulations/sim-batch.xml b/dram/resources/simulations/sim-batch.xml index 0cbcd8e6..e582e0aa 100644 --- a/dram/resources/simulations/sim-batch.xml +++ b/dram/resources/simulations/sim-batch.xml @@ -11,8 +11,11 @@ memconfig.xml - + chstone-jpeg_32.stl + + + chstone-sha_32.stl diff --git a/dram/src/common/TlmRecorder.cpp b/dram/src/common/TlmRecorder.cpp index ff10f69b..18e77778 100644 --- a/dram/src/common/TlmRecorder.cpp +++ b/dram/src/common/TlmRecorder.cpp @@ -3,7 +3,7 @@ #include "dramExtension.h" #include "xmlAddressdecoder.h" #include "Utils.h" -#include "../core/configuration/Configuration.h" +#include "../controller/core/configuration/Configuration.h" #include using namespace std; @@ -13,252 +13,252 @@ string TlmRecorder::sqlScriptURI = ""; string TlmRecorder::senderName = "TlmRecorder"; TlmRecorder::TlmRecorder() : - transactionIDCounter(1), recordingEndTime(SC_ZERO_TIME) + transactionIDCounter(1), recordingEndTime(SC_ZERO_TIME) { - setUpTransactionTerminatingPhases(); - openDB(TlmRecorder::dbName.c_str()); - createTables(TlmRecorder::sqlScriptURI); - prepareSqlStatements(); - sqlite3_exec(db, "BEGIN", 0, 0, 0); + setUpTransactionTerminatingPhases(); + openDB(TlmRecorder::dbName.c_str()); + createTables(TlmRecorder::sqlScriptURI); + prepareSqlStatements(); + sqlite3_exec(db, "BEGIN", 0, 0, 0); - printDebugMessage("Starting new database transaction"); + printDebugMessage("Starting new database transaction"); } TlmRecorder::~TlmRecorder() { - if (db) - closeConnection(); + if (db) + closeConnection(); } void TlmRecorder::recordPhase(tlm::tlm_generic_payload& trans, tlm::tlm_phase phase, sc_time time) { - if (currentTransactionsInSystem.count(&trans) == 0) - introduceNewTransactionToSystem(time, trans); + if (currentTransactionsInSystem.count(&trans) == 0) + introduceNewTransactionToSystem(time, trans); - string phaseName = phaseNameToString(phase); - string phaseBeginPrefix = "BEGIN_"; - string phaseEndPrefix = "END_"; + string phaseName = phaseNameToString(phase); + string phaseBeginPrefix = "BEGIN_"; + string phaseEndPrefix = "END_"; - if (phaseName.find(phaseBeginPrefix) != string::npos) - { - phaseName.erase(0, phaseBeginPrefix.length()); - insertPhaseInDB(phaseName, time, time, trans); - } - else - { - phaseName.erase(0, phaseEndPrefix.length()); - updatePhaseEndInDB(phaseName, time, trans); - } + if (phaseName.find(phaseBeginPrefix) != string::npos) + { + phaseName.erase(0, phaseBeginPrefix.length()); + insertPhaseInDB(phaseName, time, time, trans); + } + else + { + phaseName.erase(0, phaseEndPrefix.length()); + updatePhaseEndInDB(phaseName, time, trans); + } - bool phaseTerminatesTransaction = count(transactionTerminatingPhases.begin(), - transactionTerminatingPhases.end(), phase) == 1; - if (phaseTerminatesTransaction) - removeTransactionFromSystem(time, trans); + bool phaseTerminatesTransaction = count(transactionTerminatingPhases.begin(), + transactionTerminatingPhases.end(), phase) == 1; + if (phaseTerminatesTransaction) + removeTransactionFromSystem(time, trans); - recordingEndTime = time; + recordingEndTime = time; } void TlmRecorder::recordDebugMessage(std::string message, sc_time time) { - insertDebugMessageInDB(message, time); + insertDebugMessageInDB(message, time); } void TlmRecorder::createTables(string pathToURI) { - string initial = loadTextFileContents(pathToURI); - executeSqlCommand(initial); + string initial = loadTextFileContents(pathToURI); + executeSqlCommand(initial); } void TlmRecorder::setUpTransactionTerminatingPhases() { - transactionTerminatingPhases.push_back(tlm::END_RESP); - transactionTerminatingPhases.push_back(static_cast(END_AUTO_REFRESH)); - transactionTerminatingPhases.push_back(static_cast(END_PDNP)); - transactionTerminatingPhases.push_back(static_cast(END_PDNA)); - transactionTerminatingPhases.push_back(static_cast(END_SREF)); + transactionTerminatingPhases.push_back(tlm::END_RESP); + transactionTerminatingPhases.push_back(static_cast(END_AUTO_REFRESH)); + transactionTerminatingPhases.push_back(static_cast(END_PDNP)); + transactionTerminatingPhases.push_back(static_cast(END_PDNA)); + transactionTerminatingPhases.push_back(static_cast(END_SREF)); } void TlmRecorder::prepareSqlStatements() { - insertTransactionString = - "INSERT INTO Transactions VALUES (:id,:rangeID,:address,:burstlength,:thread,:channel,:bank,:bankgroup,:row,:column,:dataStrobeBegin,:dataStrobeEnd, :timeOfGeneration,:command)"; - insertRangeString = "INSERT INTO Ranges VALUES (:id,:begin,:end)"; - updateRangeString = "UPDATE Ranges SET End = :end WHERE ID = :id"; - updateDataStrobeString = "UPDATE Transactions SET DataStrobeBegin = :begin, DataStrobeEnd = :end WHERE ID = :id"; + insertTransactionString = + "INSERT INTO Transactions VALUES (:id,:rangeID,:address,:burstlength,:thread,:channel,:bank,:bankgroup,:row,:column,:dataStrobeBegin,:dataStrobeEnd, :timeOfGeneration,:command)"; + insertRangeString = "INSERT INTO Ranges VALUES (:id,:begin,:end)"; + updateRangeString = "UPDATE Ranges SET End = :end WHERE ID = :id"; + updateDataStrobeString = "UPDATE Transactions SET DataStrobeBegin = :begin, DataStrobeEnd = :end WHERE ID = :id"; - insertPhaseString = - "INSERT INTO Phases (PhaseName,PhaseBegin,PhaseEnd,Transact) VALUES (:name,:begin,:end,:transaction)"; - updatePhaseString = - "UPDATE Phases SET PhaseEnd = :end WHERE Transact = :trans AND PhaseName = :name"; - insertGeneralInfoString = - "INSERT INTO GeneralInfo (NumberOfTransactions,TraceEnd,NumberOfBanks,clk,UnitOfTime,Memconfig,Memspec,Traces) Values " - "(:numberOfTransactions,:end,:numberOfBanks,:clk,:unitOfTime,:memconfig,:memspec,:traces)"; - insertDebugMessageString = "INSERT INTO DebugMessages (Time,Message) Values (:time,:message)"; + insertPhaseString = + "INSERT INTO Phases (PhaseName,PhaseBegin,PhaseEnd,Transact) VALUES (:name,:begin,:end,:transaction)"; + updatePhaseString = + "UPDATE Phases SET PhaseEnd = :end WHERE Transact = :trans AND PhaseName = :name"; + insertGeneralInfoString = + "INSERT INTO GeneralInfo (NumberOfTransactions,TraceEnd,NumberOfBanks,clk,UnitOfTime,Memconfig,Memspec,Traces) Values " + "(:numberOfTransactions,:end,:numberOfBanks,:clk,:unitOfTime,:memconfig,:memspec,:traces)"; + insertDebugMessageString = "INSERT INTO DebugMessages (Time,Message) Values (:time,:message)"; - sqlite3_prepare(db, insertTransactionString.c_str(), -1, &insertTransactionStatement, 0); - sqlite3_prepare(db, insertRangeString.c_str(), -1, &insertRangeStatement, 0); - sqlite3_prepare(db, updateRangeString.c_str(), -1, &updateRangeStatement, 0); - sqlite3_prepare(db, insertPhaseString.c_str(), -1, &insertPhaseStatement, 0); - sqlite3_prepare(db, updatePhaseString.c_str(), -1, &updatePhaseStatement, 0); - sqlite3_prepare(db, updateDataStrobeString.c_str(), -1, &updateDataStrobeStatement, 0); - sqlite3_prepare(db, insertGeneralInfoString.c_str(), -1, &insertGeneralInfoStatement, 0); - sqlite3_prepare(db, insertDebugMessageString.c_str(), -1, &insertDebugMessageStatement, 0); + sqlite3_prepare(db, insertTransactionString.c_str(), -1, &insertTransactionStatement, 0); + sqlite3_prepare(db, insertRangeString.c_str(), -1, &insertRangeStatement, 0); + sqlite3_prepare(db, updateRangeString.c_str(), -1, &updateRangeStatement, 0); + sqlite3_prepare(db, insertPhaseString.c_str(), -1, &insertPhaseStatement, 0); + sqlite3_prepare(db, updatePhaseString.c_str(), -1, &updatePhaseStatement, 0); + sqlite3_prepare(db, updateDataStrobeString.c_str(), -1, &updateDataStrobeStatement, 0); + sqlite3_prepare(db, insertGeneralInfoString.c_str(), -1, &insertGeneralInfoStatement, 0); + sqlite3_prepare(db, insertDebugMessageString.c_str(), -1, &insertDebugMessageStatement, 0); } void TlmRecorder::openDB(std::string name) { - if (sqlite3_open(name.c_str(), &db)) - { - SC_REPORT_FATAL("Error in TraceRecorder", "Error cannot open database"); - sqlite3_close(db); - } + if (sqlite3_open(name.c_str(), &db)) + { + SC_REPORT_FATAL("Error in TraceRecorder", "Error cannot open database"); + sqlite3_close(db); + } } void TlmRecorder::insertDebugMessageInDB(string message, const sc_time& time) { - sqlite3_bind_int64(insertDebugMessageStatement, 1, time.value()); - sqlite3_bind_text(insertDebugMessageStatement, 2, message.c_str(), message.length(), 0); - executeSqlStatement(insertDebugMessageStatement); + sqlite3_bind_int64(insertDebugMessageStatement, 1, time.value()); + sqlite3_bind_text(insertDebugMessageStatement, 2, message.c_str(), message.length(), 0); + executeSqlStatement(insertDebugMessageStatement); } void TlmRecorder::insertGeneralInfo() { - sqlite3_bind_int64(insertGeneralInfoStatement, 1, transactionIDCounter - 1); - sqlite3_bind_int64(insertGeneralInfoStatement, 2, recordingEndTime.value()); - sqlite3_bind_int(insertGeneralInfoStatement, 3, - core::Configuration::getInstance().NumberOfBanks); - sqlite3_bind_int(insertGeneralInfoStatement, 4, core::Configuration::getInstance().Timings.clk.value()); - sqlite3_bind_text(insertGeneralInfoStatement, 5, "PS", 2, NULL); - sqlite3_bind_text(insertGeneralInfoStatement, 6, memconfig.c_str(), memconfig.length(), NULL); - sqlite3_bind_text(insertGeneralInfoStatement, 7, memspec.c_str(), memspec.length(), NULL); - sqlite3_bind_text(insertGeneralInfoStatement, 8, traces.c_str(), traces.length(), NULL); - executeSqlStatement(insertGeneralInfoStatement); + sqlite3_bind_int64(insertGeneralInfoStatement, 1, transactionIDCounter - 1); + sqlite3_bind_int64(insertGeneralInfoStatement, 2, recordingEndTime.value()); + sqlite3_bind_int(insertGeneralInfoStatement, 3, + core::Configuration::getInstance().NumberOfBanks); + sqlite3_bind_int(insertGeneralInfoStatement, 4, core::Configuration::getInstance().Timings.clk.value()); + sqlite3_bind_text(insertGeneralInfoStatement, 5, "PS", 2, NULL); + sqlite3_bind_text(insertGeneralInfoStatement, 6, memconfig.c_str(), memconfig.length(), NULL); + sqlite3_bind_text(insertGeneralInfoStatement, 7, memspec.c_str(), memspec.length(), NULL); + sqlite3_bind_text(insertGeneralInfoStatement, 8, traces.c_str(), traces.length(), NULL); + executeSqlStatement(insertGeneralInfoStatement); } void TlmRecorder::insertTransactionInDB(unsigned int id, tlm::tlm_generic_payload& trans) { - sqlite3_bind_int(insertTransactionStatement, 1, id); - sqlite3_bind_int(insertTransactionStatement, 2, id); - sqlite3_bind_int(insertTransactionStatement, 3, trans.get_address()); - sqlite3_bind_int(insertTransactionStatement, 4, trans.get_streaming_width()); + sqlite3_bind_int(insertTransactionStatement, 1, id); + sqlite3_bind_int(insertTransactionStatement, 2, id); + sqlite3_bind_int(insertTransactionStatement, 3, trans.get_address()); + sqlite3_bind_int(insertTransactionStatement, 4, trans.get_streaming_width()); - const DramExtension& extension = DramExtension::getExtension(trans); - sqlite3_bind_int(insertTransactionStatement, 5, extension.getThread().ID()); - sqlite3_bind_int(insertTransactionStatement, 6, extension.getChannel().ID()); - sqlite3_bind_int(insertTransactionStatement, 7, extension.getBank().ID()); - sqlite3_bind_int(insertTransactionStatement, 8, extension.getBankGroup().ID()); - sqlite3_bind_int(insertTransactionStatement, 9, extension.getRow().ID()); - sqlite3_bind_int(insertTransactionStatement, 10, extension.getColumn().ID()); - sqlite3_bind_int(insertTransactionStatement, 11, 0); - sqlite3_bind_int(insertTransactionStatement, 12, 0); + const DramExtension& extension = DramExtension::getExtension(trans); + sqlite3_bind_int(insertTransactionStatement, 5, extension.getThread().ID()); + sqlite3_bind_int(insertTransactionStatement, 6, extension.getChannel().ID()); + sqlite3_bind_int(insertTransactionStatement, 7, extension.getBank().ID()); + sqlite3_bind_int(insertTransactionStatement, 8, extension.getBankGroup().ID()); + sqlite3_bind_int(insertTransactionStatement, 9, extension.getRow().ID()); + sqlite3_bind_int(insertTransactionStatement, 10, extension.getColumn().ID()); + sqlite3_bind_int(insertTransactionStatement, 11, 0); + sqlite3_bind_int(insertTransactionStatement, 12, 0); - if(extension.getThread().ID() == 0) - sqlite3_bind_int64(insertTransactionStatement, 13, 0); - else - sqlite3_bind_int64(insertTransactionStatement, 13, GenerationExtension::getExtension(&trans).TimeOfGeneration().value()); + if(extension.getThread().ID() == 0) + sqlite3_bind_int64(insertTransactionStatement, 13, 0); + else + sqlite3_bind_int64(insertTransactionStatement, 13, GenerationExtension::getExtension(&trans).TimeOfGeneration().value()); - executeSqlStatement(insertTransactionStatement); + executeSqlStatement(insertTransactionStatement); } void TlmRecorder::insertRangeInDB(unsigned int id, const sc_time& time) { - sqlite3_bind_int(insertRangeStatement, 1, id); - sqlite3_bind_int64(insertRangeStatement, 2, time.value()); - sqlite3_bind_int64(insertRangeStatement, 3, time.value()); - executeSqlStatement(insertRangeStatement); + sqlite3_bind_int(insertRangeStatement, 1, id); + sqlite3_bind_int64(insertRangeStatement, 2, time.value()); + sqlite3_bind_int64(insertRangeStatement, 3, time.value()); + executeSqlStatement(insertRangeStatement); } void TlmRecorder::insertPhaseInDB(string phaseName, const sc_time& begin, const sc_time& end, - tlm::tlm_generic_payload& trans) + tlm::tlm_generic_payload& trans) { - unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); - sqlite3_bind_text(insertPhaseStatement, 1, phaseName.c_str(), phaseName.length(), 0); - sqlite3_bind_int64(insertPhaseStatement, 2, begin.value()); - sqlite3_bind_int64(insertPhaseStatement, 3, end.value()); - sqlite3_bind_int(insertPhaseStatement, 4, id); - executeSqlStatement(insertPhaseStatement); + unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); + sqlite3_bind_text(insertPhaseStatement, 1, phaseName.c_str(), phaseName.length(), 0); + sqlite3_bind_int64(insertPhaseStatement, 2, begin.value()); + sqlite3_bind_int64(insertPhaseStatement, 3, end.value()); + sqlite3_bind_int(insertPhaseStatement, 4, id); + executeSqlStatement(insertPhaseStatement); } void TlmRecorder::updatePhaseEndInDB(string phaseName, const sc_time& time, - tlm::tlm_generic_payload& trans) + tlm::tlm_generic_payload& trans) { - unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); - sqlite3_bind_int64(updatePhaseStatement, 1, time.value()); - sqlite3_bind_int(updatePhaseStatement, 2, id); - sqlite3_bind_text(updatePhaseStatement, 3, phaseName.c_str(), phaseName.length(), 0); - executeSqlStatement(updatePhaseStatement); + unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); + sqlite3_bind_int64(updatePhaseStatement, 1, time.value()); + sqlite3_bind_int(updatePhaseStatement, 2, id); + sqlite3_bind_text(updatePhaseStatement, 3, phaseName.c_str(), phaseName.length(), 0); + executeSqlStatement(updatePhaseStatement); } void TlmRecorder::updateDataStrobe(const sc_time& begin,const sc_time& end, tlm::tlm_generic_payload& trans) { - unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); - sqlite3_bind_int64(updateDataStrobeStatement, 1, begin.value()); - sqlite3_bind_int64(updateDataStrobeStatement, 2, end.value()); - sqlite3_bind_int(updateDataStrobeStatement, 3, id); - executeSqlStatement(updateDataStrobeStatement); + unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); + sqlite3_bind_int64(updateDataStrobeStatement, 1, begin.value()); + sqlite3_bind_int64(updateDataStrobeStatement, 2, end.value()); + sqlite3_bind_int(updateDataStrobeStatement, 3, id); + executeSqlStatement(updateDataStrobeStatement); } void TlmRecorder::introduceNewTransactionToSystem(const sc_time& time, - tlm::tlm_generic_payload& trans) + tlm::tlm_generic_payload& trans) { - unsigned int id = transactionIDCounter++; - currentTransactionsInSystem[&trans] = id; - insertTransactionInDB(id, trans); - insertRangeInDB(id, time); - if (id % transactionCommitRate == 0) - { - sqlite3_exec(db, "COMMIT", 0, 0, 0); - printDebugMessage( - "Committing transactions " + to_string(id - transactionCommitRate + 1) + " - " - + to_string(id)); - sqlite3_exec(db, "BEGIN", 0, 0, 0); - } + unsigned int id = transactionIDCounter++; + currentTransactionsInSystem[&trans] = id; + insertTransactionInDB(id, trans); + insertRangeInDB(id, time); + if (id % transactionCommitRate == 0) + { + sqlite3_exec(db, "COMMIT", 0, 0, 0); + printDebugMessage( + "Committing transactions " + to_string(id - transactionCommitRate + 1) + " - " + + to_string(id)); + sqlite3_exec(db, "BEGIN", 0, 0, 0); + } } void TlmRecorder::removeTransactionFromSystem(const sc_time& time, tlm::tlm_generic_payload& trans) { - unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); - currentTransactionsInSystem.erase(&trans); - sqlite3_bind_int64(updateRangeStatement, 1, time.value()); - sqlite3_bind_int(updateRangeStatement, 2, id); - executeSqlStatement(updateRangeStatement); + unsigned int id = getElementFromMap(currentTransactionsInSystem, &trans); + currentTransactionsInSystem.erase(&trans); + sqlite3_bind_int64(updateRangeStatement, 1, time.value()); + sqlite3_bind_int(updateRangeStatement, 2, id); + executeSqlStatement(updateRangeStatement); } void TlmRecorder::executeSqlStatement(sqlite3_stmt* statement) { - if (sqlite3_step(statement) != SQLITE_DONE) - { - SC_REPORT_FATAL("Error in TraceRecorder", "Could not execute statement"); - } - sqlite3_reset(statement); + if (sqlite3_step(statement) != SQLITE_DONE) + { + SC_REPORT_FATAL("Error in TraceRecorder", "Could not execute statement"); + } + sqlite3_reset(statement); } void TlmRecorder::executeSqlCommand(string command) { - printDebugMessage("Creating database by running provided sql script"); + printDebugMessage("Creating database by running provided sql script"); - char * errMsg = 0; - int rc = sqlite3_exec(db, command.c_str(), NULL, 0, &errMsg); - if (rc != SQLITE_OK) - { - SC_REPORT_FATAL("SQLITE Error", errMsg); - sqlite3_free(errMsg); - } + char * errMsg = 0; + int rc = sqlite3_exec(db, command.c_str(), NULL, 0, &errMsg); + if (rc != SQLITE_OK) + { + SC_REPORT_FATAL("SQLITE Error", errMsg); + sqlite3_free(errMsg); + } - printDebugMessage("Database created successfully"); + printDebugMessage("Database created successfully"); } void TlmRecorder::printDebugMessage(std::string message) { - DebugManager::getInstance().printDebugMessage(TlmRecorder::senderName, message); + DebugManager::getInstance().printDebugMessage(TlmRecorder::senderName, message); } void TlmRecorder::closeConnection() { - insertGeneralInfo(); - sqlite3_exec(db, "COMMIT", 0, 0, 0); - printDebugMessage( - "Number of transactions written to DB: " + std::to_string(transactionIDCounter - 1)); - printDebugMessage("tlmPhaseRecorder:\tEnd Recording"); - sqlite3_close(db); - db = NULL; + insertGeneralInfo(); + sqlite3_exec(db, "COMMIT", 0, 0, 0); + printDebugMessage( + "Number of transactions written to DB: " + std::to_string(transactionIDCounter - 1)); + printDebugMessage("tlmPhaseRecorder:\tEnd Recording"); + sqlite3_close(db); + db = NULL; } diff --git a/dram/src/common/Utils.h b/dram/src/common/Utils.h index 25cecfee..7b2dfbf1 100644 --- a/dram/src/common/Utils.h +++ b/dram/src/common/Utils.h @@ -20,40 +20,40 @@ constexpr const char headline[] = "========================================================="; template -Val getElementFromMap(std::map& m, Key key) +inline Val getElementFromMap(const std::map& m, Key key) { - if (m.count(key) == 0) - { - SC_REPORT_FATAL("Map", "Element not in map"); - } + if (m.count(key) == 0) + { + SC_REPORT_FATAL("Map", "Element not in map"); + } - return m.at(key); + return m.at(key); } template bool isIn(const T& value, const std::vector& collection) { - for (T t : collection) - { - if (t == value) - return true; - } - return false; + for (T t : collection) + { + if (t == value) + return true; + } + return false; } static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50, unsigned int granularity = 1) { - if ((x != n) && (x % (n / 100 * granularity) != 0)) - return; + if ((x != n) && (x % (n / 100 * granularity) != 0)) + return; - float ratio = x / (float) n; - unsigned int c = (ratio * w); - std::cout << std::setw(3) << round(ratio * 100) << "% ["; - for (unsigned int x = 0; x < c; x++) - std::cout << "="; - for (unsigned int x = c; x < w; x++) - std::cout << " "; - std::cout << "]\r" << std::flush; + float ratio = x / (float) n; + unsigned int c = (ratio * w); + std::cout << std::setw(3) << round(ratio * 100) << "% ["; + for (unsigned int x = 0; x < c; x++) + std::cout << "="; + for (unsigned int x = c; x < w; x++) + std::cout << " "; + std::cout << "]\r" << std::flush; } void reportFatal(std::string sender, std::string message); diff --git a/dram/src/common/dramExtension.cpp b/dram/src/common/dramExtension.cpp index 22534fa2..5d05f538 100644 --- a/dram/src/common/dramExtension.cpp +++ b/dram/src/common/dramExtension.cpp @@ -1,6 +1,7 @@ #include "dramExtension.h" -#include "../core/configuration/Configuration.h" +#include "../controller/core/configuration/Configuration.h" #include "map" +#include "Utils.h" using namespace tlm; @@ -9,182 +10,183 @@ using namespace tlm; */ DramExtension& DramExtension::getExtension(const tlm_generic_payload *payload) { - DramExtension *result = NULL; - payload->get_extension(result); - sc_assert(result!=NULL); + DramExtension *result = NULL; + payload->get_extension(result); + sc_assert(result!=NULL); - return *result; + return *result; } DramExtension& DramExtension::getExtension(const tlm_generic_payload &payload) { - return DramExtension::getExtension(&payload); + return DramExtension::getExtension(&payload); } bool operator ==(const Thread& lhs, const Thread& rhs) { - return lhs.ID() == rhs.ID(); + return lhs.ID() == rhs.ID(); } bool operator !=(const Thread& lhs, const Thread& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } bool operator <(const Thread& lhs, const Thread& rhs) { - return lhs.ID() < rhs.ID(); + return lhs.ID() < rhs.ID(); } bool operator ==(const Channel& lhs, const Channel& rhs) { - return lhs.ID() == rhs.ID(); + return lhs.ID() == rhs.ID(); } bool operator !=(const Channel& lhs, const Channel& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } BankGroup Bank::getBankGroup() { - static std::map bankgroups; - if (bankgroups.size() == 0) - { - core::Configuration& config = core::Configuration::getInstance(); - sc_assert(config.NumberOfBanks % config.NumberOfBankGroups == 0); + static std::map bankgroups; + if (bankgroups.size() == 0) + { + core::Configuration& config = core::Configuration::getInstance(); + sc_assert(config.NumberOfBanks % config.NumberOfBankGroups == 0); - for (unsigned int bank = 0; bank < config.NumberOfBanks; bank++) - { - unsigned int group = bank % config.NumberOfBankGroups; - bankgroups.insert(std::pair(Bank(bank), BankGroup(group))); - } - } - return bankgroups.at(*this); + for (unsigned int bank = 0; bank < config.NumberOfBanks; bank++) + { + unsigned int group = bank % config.NumberOfBankGroups; + bankgroups.insert(std::pair(Bank(bank), BankGroup(group))); + } + } + + return getElementFromMap(bankgroups, *this); } bool operator ==(const Bank& lhs, const Bank& rhs) { - return lhs.ID() == rhs.ID(); + return lhs.ID() == rhs.ID(); } bool operator !=(const Bank& lhs, const Bank& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } bool operator ==(const BankGroup& lhs, const BankGroup& rhs) { - return lhs.ID() == rhs.ID(); + return lhs.ID() == rhs.ID(); } bool operator !=(const BankGroup& lhs, const BankGroup& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } bool operator <(const Bank& lhs, const Bank& rhs) { - return lhs.ID() < rhs.ID(); + return lhs.ID() < rhs.ID(); } const Row Row::NO_ROW; const Row Row::operator ++() { - id = (id + 1) % core::Configuration::getInstance().NumberOfRows; - return *this; + id = (id + 1) % core::Configuration::getInstance().NumberOfRows; + return *this; } bool operator ==(const Row& lhs, const Row& rhs) { - if (lhs.isNoRow != rhs.isNoRow) - return false; - return lhs.ID() == rhs.ID(); + if (lhs.isNoRow != rhs.isNoRow) + return false; + return lhs.ID() == rhs.ID(); } bool operator !=(const Row& lhs, const Row& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } bool operator ==(const Column& lhs, const Column& rhs) { - return lhs.ID() == rhs.ID(); + return lhs.ID() == rhs.ID(); } bool operator !=(const Column& lhs, const Column& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); } tlm_extension_base* DramExtension::clone() const { - return new DramExtension(thread, bank, bankgroup, row, column, burstlength); + return new DramExtension(thread, bank, bankgroup, row, column, burstlength); } void DramExtension::copy_from(const tlm_extension_base& ext) { - const DramExtension& cpyFrom = static_cast(ext); - thread = cpyFrom.thread; - bank = cpyFrom.bank; - bankgroup = cpyFrom.bankgroup; - row = cpyFrom.row; - column = cpyFrom.column; - burstlength = cpyFrom.burstlength; + const DramExtension& cpyFrom = static_cast(ext); + thread = cpyFrom.thread; + bank = cpyFrom.bank; + bankgroup = cpyFrom.bankgroup; + row = cpyFrom.row; + column = cpyFrom.column; + burstlength = cpyFrom.burstlength; } const Thread& DramExtension::getThread() const { - return thread; + return thread; } const Channel& DramExtension::getChannel() const { - return channel; + return channel; } const Bank& DramExtension::getBank() const { - return bank; + return bank; } const BankGroup& DramExtension::getBankGroup() const { - return bankgroup; + return bankgroup; } const Row& DramExtension::getRow() const { - return row; + return row; } const Column& DramExtension::getColumn() const { - return column; + return column; } const unsigned int DramExtension::getBurstlength() const { - return burstlength; + return burstlength; } void DramExtension::increaseRow() { - ++row; + ++row; } tlm_extension_base* GenerationExtension::clone() const { - return new GenerationExtension(timeOfGeneration); + return new GenerationExtension(timeOfGeneration); } void GenerationExtension::copy_from(const tlm_extension_base& ext) { - const GenerationExtension& cpyFrom = static_cast(ext); - timeOfGeneration = cpyFrom.timeOfGeneration; + const GenerationExtension& cpyFrom = static_cast(ext); + timeOfGeneration = cpyFrom.timeOfGeneration; } GenerationExtension& GenerationExtension::getExtension(const tlm::tlm_generic_payload* payload) { - GenerationExtension *result = NULL; - payload->get_extension(result); - sc_assert(result!=NULL); - return *result; + GenerationExtension *result = NULL; + payload->get_extension(result); + sc_assert(result!=NULL); + return *result; } diff --git a/dram/src/common/third_party/tinystr.cpp b/dram/src/common/third_party/tinystr.cpp deleted file mode 100755 index 06657682..00000000 --- a/dram/src/common/third_party/tinystr.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#ifndef TIXML_USE_STL - -#include "tinystr.h" - -// Error value for find primitive -const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); - - -// Null rep. -TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; - - -void TiXmlString::reserve (size_type cap) -{ - if (cap > capacity()) - { - TiXmlString tmp; - tmp.init(length(), cap); - memcpy(tmp.start(), data(), length()); - swap(tmp); - } -} - - -TiXmlString& TiXmlString::assign(const char* str, size_type len) -{ - size_type cap = capacity(); - if (len > cap || cap > 3*(len + 8)) - { - TiXmlString tmp; - tmp.init(len); - memcpy(tmp.start(), str, len); - swap(tmp); - } - else - { - memmove(start(), str, len); - set_size(len); - } - return *this; -} - - -TiXmlString& TiXmlString::append(const char* str, size_type len) -{ - size_type newsize = length() + len; - if (newsize > capacity()) - { - reserve (newsize + capacity()); - } - memmove(finish(), str, len); - set_size(newsize); - return *this; -} - - -TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) -{ - TiXmlString tmp; - tmp.reserve(a.length() + b.length()); - tmp += a; - tmp += b; - return tmp; -} - -TiXmlString operator + (const TiXmlString & a, const char* b) -{ - TiXmlString tmp; - TiXmlString::size_type b_len = static_cast( strlen(b) ); - tmp.reserve(a.length() + b_len); - tmp += a; - tmp.append(b, b_len); - return tmp; -} - -TiXmlString operator + (const char* a, const TiXmlString & b) -{ - TiXmlString tmp; - TiXmlString::size_type a_len = static_cast( strlen(a) ); - tmp.reserve(a_len + b.length()); - tmp.append(a, a_len); - tmp += b; - return tmp; -} - - -#endif // TIXML_USE_STL diff --git a/dram/src/common/third_party/tinystr.h b/dram/src/common/third_party/tinystr.h deleted file mode 100755 index 89cca334..00000000 --- a/dram/src/common/third_party/tinystr.h +++ /dev/null @@ -1,305 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#ifndef TIXML_USE_STL - -#ifndef TIXML_STRING_INCLUDED -#define TIXML_STRING_INCLUDED - -#include -#include - -/* The support for explicit isn't that universal, and it isn't really - required - it is used to check that the TiXmlString class isn't incorrectly - used. Be nice to old compilers and macro it here: -*/ -#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) - // Microsoft visual studio, version 6 and higher. - #define TIXML_EXPLICIT explicit -#elif defined(__GNUC__) && (__GNUC__ >= 3 ) - // GCC version 3 and higher.s - #define TIXML_EXPLICIT explicit -#else - #define TIXML_EXPLICIT -#endif - - -/* - TiXmlString is an emulation of a subset of the std::string template. - Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. - Only the member functions relevant to the TinyXML project have been implemented. - The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase - a string and there's no more room, we allocate a buffer twice as big as we need. -*/ -class TiXmlString -{ - public : - // The size type used - typedef size_t size_type; - - // Error value for find primitive - static const size_type npos; // = -1; - - - // TiXmlString empty constructor - TiXmlString () : rep_(&nullrep_) - { - } - - // TiXmlString copy constructor - TiXmlString ( const TiXmlString & copy) : rep_(0) - { - init(copy.length()); - memcpy(start(), copy.data(), length()); - } - - // TiXmlString constructor, based on a string - TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) - { - init( static_cast( strlen(copy) )); - memcpy(start(), copy, length()); - } - - // TiXmlString constructor, based on a string - TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) - { - init(len); - memcpy(start(), str, len); - } - - // TiXmlString destructor - ~TiXmlString () - { - quit(); - } - - TiXmlString& operator = (const char * copy) - { - return assign( copy, (size_type)strlen(copy)); - } - - TiXmlString& operator = (const TiXmlString & copy) - { - return assign(copy.start(), copy.length()); - } - - - // += operator. Maps to append - TiXmlString& operator += (const char * suffix) - { - return append(suffix, static_cast( strlen(suffix) )); - } - - // += operator. Maps to append - TiXmlString& operator += (char single) - { - return append(&single, 1); - } - - // += operator. Maps to append - TiXmlString& operator += (const TiXmlString & suffix) - { - return append(suffix.data(), suffix.length()); - } - - - // Convert a TiXmlString into a null-terminated char * - const char * c_str () const { return rep_->str; } - - // Convert a TiXmlString into a char * (need not be null terminated). - const char * data () const { return rep_->str; } - - // Return the length of a TiXmlString - size_type length () const { return rep_->size; } - - // Alias for length() - size_type size () const { return rep_->size; } - - // Checks if a TiXmlString is empty - bool empty () const { return rep_->size == 0; } - - // Return capacity of string - size_type capacity () const { return rep_->capacity; } - - - // single char extraction - const char& at (size_type index) const - { - assert( index < length() ); - return rep_->str[ index ]; - } - - // [] operator - char& operator [] (size_type index) const - { - assert( index < length() ); - return rep_->str[ index ]; - } - - // find a char in a string. Return TiXmlString::npos if not found - size_type find (char lookup) const - { - return find(lookup, 0); - } - - // find a char in a string from an offset. Return TiXmlString::npos if not found - size_type find (char tofind, size_type offset) const - { - if (offset >= length()) return npos; - - for (const char* p = c_str() + offset; *p != '\0'; ++p) - { - if (*p == tofind) return static_cast< size_type >( p - c_str() ); - } - return npos; - } - - void clear () - { - //Lee: - //The original was just too strange, though correct: - // TiXmlString().swap(*this); - //Instead use the quit & re-init: - quit(); - init(0,0); - } - - /* Function to reserve a big amount of data when we know we'll need it. Be aware that this - function DOES NOT clear the content of the TiXmlString if any exists. - */ - void reserve (size_type cap); - - TiXmlString& assign (const char* str, size_type len); - - TiXmlString& append (const char* str, size_type len); - - void swap (TiXmlString& other) - { - Rep* r = rep_; - rep_ = other.rep_; - other.rep_ = r; - } - - private: - - void init(size_type sz) { init(sz, sz); } - void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } - char* start() const { return rep_->str; } - char* finish() const { return rep_->str + rep_->size; } - - struct Rep - { - size_type size, capacity; - char str[1]; - }; - - void init(size_type sz, size_type cap) - { - if (cap) - { - // Lee: the original form: - // rep_ = static_cast(operator new(sizeof(Rep) + cap)); - // doesn't work in some cases of new being overloaded. Switching - // to the normal allocation, although use an 'int' for systems - // that are overly picky about structure alignment. - const size_type bytesNeeded = sizeof(Rep) + cap; - const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); - rep_ = reinterpret_cast( new int[ intsNeeded ] ); - - rep_->str[ rep_->size = sz ] = '\0'; - rep_->capacity = cap; - } - else - { - rep_ = &nullrep_; - } - } - - void quit() - { - if (rep_ != &nullrep_) - { - // The rep_ is really an array of ints. (see the allocator, above). - // Cast it back before delete, so the compiler won't incorrectly call destructors. - delete [] ( reinterpret_cast( rep_ ) ); - } - } - - Rep * rep_; - static Rep nullrep_; - -} ; - - -inline bool operator == (const TiXmlString & a, const TiXmlString & b) -{ - return ( a.length() == b.length() ) // optimization on some platforms - && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare -} -inline bool operator < (const TiXmlString & a, const TiXmlString & b) -{ - return strcmp(a.c_str(), b.c_str()) < 0; -} - -inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } -inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } -inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } -inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } - -inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } -inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } -inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } -inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } - -TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); -TiXmlString operator + (const TiXmlString & a, const char* b); -TiXmlString operator + (const char* a, const TiXmlString & b); - - -/* - TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. - Only the operators that we need for TinyXML have been developped. -*/ -class TiXmlOutStream : public TiXmlString -{ -public : - - // TiXmlOutStream << operator. - TiXmlOutStream & operator << (const TiXmlString & in) - { - *this += in; - return *this; - } - - // TiXmlOutStream << operator. - TiXmlOutStream & operator << (const char * in) - { - *this += in; - return *this; - } - -} ; - -#endif // TIXML_STRING_INCLUDED -#endif // TIXML_USE_STL diff --git a/dram/src/common/third_party/tinyxml.cpp b/dram/src/common/third_party/tinyxml.cpp deleted file mode 100755 index 9c161dfc..00000000 --- a/dram/src/common/third_party/tinyxml.cpp +++ /dev/null @@ -1,1886 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original code by Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#include - -#ifdef TIXML_USE_STL -#include -#include -#endif - -#include "tinyxml.h" - -FILE* TiXmlFOpen( const char* filename, const char* mode ); - -bool TiXmlBase::condenseWhiteSpace = true; - -// Microsoft compiler security -FILE* TiXmlFOpen( const char* filename, const char* mode ) -{ - #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - FILE* fp = 0; - errno_t err = fopen_s( &fp, filename, mode ); - if ( !err && fp ) - return fp; - return 0; - #else - return fopen( filename, mode ); - #endif -} - -void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) -{ - int i=0; - - while( i<(int)str.length() ) - { - unsigned char c = (unsigned char) str[i]; - - if ( c == '&' - && i < ( (int)str.length() - 2 ) - && str[i+1] == '#' - && str[i+2] == 'x' ) - { - // Hexadecimal character reference. - // Pass through unchanged. - // © -- copyright symbol, for example. - // - // The -1 is a bug fix from Rob Laveaux. It keeps - // an overflow from happening if there is no ';'. - // There are actually 2 ways to exit this loop - - // while fails (error case) and break (semicolon found). - // However, there is no mechanism (currently) for - // this function to return an error. - while ( i<(int)str.length()-1 ) - { - outString->append( str.c_str() + i, 1 ); - ++i; - if ( str[i] == ';' ) - break; - } - } - else if ( c == '&' ) - { - outString->append( entity[0].str, entity[0].strLength ); - ++i; - } - else if ( c == '<' ) - { - outString->append( entity[1].str, entity[1].strLength ); - ++i; - } - else if ( c == '>' ) - { - outString->append( entity[2].str, entity[2].strLength ); - ++i; - } - else if ( c == '\"' ) - { - outString->append( entity[3].str, entity[3].strLength ); - ++i; - } - else if ( c == '\'' ) - { - outString->append( entity[4].str, entity[4].strLength ); - ++i; - } - else if ( c < 32 ) - { - // Easy pass at non-alpha/numeric/symbol - // Below 32 is symbolic. - char buf[ 32 ]; - - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); - #else - sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); - #endif - - //*ME: warning C4267: convert 'size_t' to 'int' - //*ME: Int-Cast to make compiler happy ... - outString->append( buf, (int)strlen( buf ) ); - ++i; - } - else - { - //char realc = (char) c; - //outString->append( &realc, 1 ); - *outString += (char) c; // somewhat more efficient function call. - ++i; - } - } -} - - -TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() -{ - parent = 0; - type = _type; - firstChild = 0; - lastChild = 0; - prev = 0; - next = 0; -} - - -TiXmlNode::~TiXmlNode() -{ - TiXmlNode* node = firstChild; - TiXmlNode* temp = 0; - - while ( node ) - { - temp = node; - node = node->next; - delete temp; - } -} - - -void TiXmlNode::CopyTo( TiXmlNode* target ) const -{ - target->SetValue (value.c_str() ); - target->userData = userData; - target->location = location; -} - - -void TiXmlNode::Clear() -{ - TiXmlNode* node = firstChild; - TiXmlNode* temp = 0; - - while ( node ) - { - temp = node; - node = node->next; - delete temp; - } - - firstChild = 0; - lastChild = 0; -} - - -TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) -{ - assert( node->parent == 0 || node->parent == this ); - assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); - - if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT ) - { - delete node; - if ( GetDocument() ) - GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - node->parent = this; - - node->prev = lastChild; - node->next = 0; - - if ( lastChild ) - lastChild->next = node; - else - firstChild = node; // it was an empty list. - - lastChild = node; - return node; -} - - -TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) -{ - if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) - { - if ( GetDocument() ) - GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - - return LinkEndChild( node ); -} - - -TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) -{ - if ( !beforeThis || beforeThis->parent != this ) { - return 0; - } - if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) - { - if ( GetDocument() ) - GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - node->parent = this; - - node->next = beforeThis; - node->prev = beforeThis->prev; - if ( beforeThis->prev ) - { - beforeThis->prev->next = node; - } - else - { - assert( firstChild == beforeThis ); - firstChild = node; - } - beforeThis->prev = node; - return node; -} - - -TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) -{ - if ( !afterThis || afterThis->parent != this ) { - return 0; - } - if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) - { - if ( GetDocument() ) - GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - node->parent = this; - - node->prev = afterThis; - node->next = afterThis->next; - if ( afterThis->next ) - { - afterThis->next->prev = node; - } - else - { - assert( lastChild == afterThis ); - lastChild = node; - } - afterThis->next = node; - return node; -} - - -TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) -{ - if ( !replaceThis ) - return 0; - - if ( replaceThis->parent != this ) - return 0; - - if ( withThis.ToDocument() ) { - // A document can never be a child. Thanks to Noam. - TiXmlDocument* document = GetDocument(); - if ( document ) - document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - TiXmlNode* node = withThis.Clone(); - if ( !node ) - return 0; - - node->next = replaceThis->next; - node->prev = replaceThis->prev; - - if ( replaceThis->next ) - replaceThis->next->prev = node; - else - lastChild = node; - - if ( replaceThis->prev ) - replaceThis->prev->next = node; - else - firstChild = node; - - delete replaceThis; - node->parent = this; - return node; -} - - -bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) -{ - if ( !removeThis ) { - return false; - } - - if ( removeThis->parent != this ) - { - assert( 0 ); - return false; - } - - if ( removeThis->next ) - removeThis->next->prev = removeThis->prev; - else - lastChild = removeThis->prev; - - if ( removeThis->prev ) - removeThis->prev->next = removeThis->next; - else - firstChild = removeThis->next; - - delete removeThis; - return true; -} - -const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = firstChild; node; node = node->next ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = lastChild; node; node = node->prev ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const -{ - if ( !previous ) - { - return FirstChild(); - } - else - { - assert( previous->parent == this ); - return previous->NextSibling(); - } -} - - -const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const -{ - if ( !previous ) - { - return FirstChild( val ); - } - else - { - assert( previous->parent == this ); - return previous->NextSibling( val ); - } -} - - -const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = next; node; node = node->next ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = prev; node; node = node->prev ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -void TiXmlElement::RemoveAttribute( const char * name ) -{ - #ifdef TIXML_USE_STL - TIXML_STRING str( name ); - TiXmlAttribute* node = attributeSet.Find( str ); - #else - TiXmlAttribute* node = attributeSet.Find( name ); - #endif - if ( node ) - { - attributeSet.Remove( node ); - delete node; - } -} - -const TiXmlElement* TiXmlNode::FirstChildElement() const -{ - const TiXmlNode* node; - - for ( node = FirstChild(); - node; - node = node->NextSibling() ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const -{ - const TiXmlNode* node; - - for ( node = FirstChild( _value ); - node; - node = node->NextSibling( _value ) ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::NextSiblingElement() const -{ - const TiXmlNode* node; - - for ( node = NextSibling(); - node; - node = node->NextSibling() ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const -{ - const TiXmlNode* node; - - for ( node = NextSibling( _value ); - node; - node = node->NextSibling( _value ) ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlDocument* TiXmlNode::GetDocument() const -{ - const TiXmlNode* node; - - for( node = this; node; node = node->parent ) - { - if ( node->ToDocument() ) - return node->ToDocument(); - } - return 0; -} - - -TiXmlElement::TiXmlElement (const char * _value) - : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) -{ - firstChild = lastChild = 0; - value = _value; -} - - -#ifdef TIXML_USE_STL -TiXmlElement::TiXmlElement( const std::string& _value ) - : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) -{ - firstChild = lastChild = 0; - value = _value; -} -#endif - - -TiXmlElement::TiXmlElement( const TiXmlElement& copy) - : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) -{ - firstChild = lastChild = 0; - copy.CopyTo( this ); -} - - -TiXmlElement& TiXmlElement::operator=( const TiXmlElement& base ) -{ - ClearThis(); - base.CopyTo( this ); - return *this; -} - - -TiXmlElement::~TiXmlElement() -{ - ClearThis(); -} - - -void TiXmlElement::ClearThis() -{ - Clear(); - while( attributeSet.First() ) - { - TiXmlAttribute* node = attributeSet.First(); - attributeSet.Remove( node ); - delete node; - } -} - - -const char* TiXmlElement::Attribute( const char* name ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( node ) - return node->Value(); - return 0; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - if ( attrib ) - return &attrib->ValueStr(); - return 0; -} -#endif - - -const char* TiXmlElement::Attribute( const char* name, int* i ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - const char* result = 0; - - if ( attrib ) { - result = attrib->Value(); - if ( i ) { - attrib->QueryIntValue( i ); - } - } - return result; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - const std::string* result = 0; - - if ( attrib ) { - result = &attrib->ValueStr(); - if ( i ) { - attrib->QueryIntValue( i ); - } - } - return result; -} -#endif - - -const char* TiXmlElement::Attribute( const char* name, double* d ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - const char* result = 0; - - if ( attrib ) { - result = attrib->Value(); - if ( d ) { - attrib->QueryDoubleValue( d ); - } - } - return result; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - const std::string* result = 0; - - if ( attrib ) { - result = &attrib->ValueStr(); - if ( d ) { - attrib->QueryDoubleValue( d ); - } - } - return result; -} -#endif - - -int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - if ( !attrib ) - return TIXML_NO_ATTRIBUTE; - return attrib->QueryIntValue( ival ); -} - - -int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* value ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - - int ival = 0; - int result = node->QueryIntValue( &ival ); - *value = (unsigned)ival; - return result; -} - - -int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - - int result = TIXML_WRONG_TYPE; - if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN ) - || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN ) - || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) ) - { - *bval = true; - result = TIXML_SUCCESS; - } - else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN ) - || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN ) - || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) ) - { - *bval = false; - result = TIXML_SUCCESS; - } - return result; -} - - - -#ifdef TIXML_USE_STL -int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - if ( !attrib ) - return TIXML_NO_ATTRIBUTE; - return attrib->QueryIntValue( ival ); -} -#endif - - -int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - if ( !attrib ) - return TIXML_NO_ATTRIBUTE; - return attrib->QueryDoubleValue( dval ); -} - - -#ifdef TIXML_USE_STL -int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const -{ - const TiXmlAttribute* attrib = attributeSet.Find( name ); - if ( !attrib ) - return TIXML_NO_ATTRIBUTE; - return attrib->QueryDoubleValue( dval ); -} -#endif - - -void TiXmlElement::SetAttribute( const char * name, int val ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); - if ( attrib ) { - attrib->SetIntValue( val ); - } -} - - -#ifdef TIXML_USE_STL -void TiXmlElement::SetAttribute( const std::string& name, int val ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); - if ( attrib ) { - attrib->SetIntValue( val ); - } -} -#endif - - -void TiXmlElement::SetDoubleAttribute( const char * name, double val ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); - if ( attrib ) { - attrib->SetDoubleValue( val ); - } -} - - -#ifdef TIXML_USE_STL -void TiXmlElement::SetDoubleAttribute( const std::string& name, double val ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); - if ( attrib ) { - attrib->SetDoubleValue( val ); - } -} -#endif - - -void TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname ); - if ( attrib ) { - attrib->SetValue( cvalue ); - } -} - - -#ifdef TIXML_USE_STL -void TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value ) -{ - TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name ); - if ( attrib ) { - attrib->SetValue( _value ); - } -} -#endif - - -void TiXmlElement::Print( FILE* cfile, int depth ) const -{ - int i; - assert( cfile ); - for ( i=0; iNext() ) - { - fprintf( cfile, " " ); - attrib->Print( cfile, depth ); - } - - // There are 3 different formatting approaches: - // 1) An element without children is printed as a node - // 2) An element with only a text child is printed as text - // 3) An element with children is printed on multiple lines. - TiXmlNode* node; - if ( !firstChild ) - { - fprintf( cfile, " />" ); - } - else if ( firstChild == lastChild && firstChild->ToText() ) - { - fprintf( cfile, ">" ); - firstChild->Print( cfile, depth + 1 ); - fprintf( cfile, "", value.c_str() ); - } - else - { - fprintf( cfile, ">" ); - - for ( node = firstChild; node; node=node->NextSibling() ) - { - if ( !node->ToText() ) - { - fprintf( cfile, "\n" ); - } - node->Print( cfile, depth+1 ); - } - fprintf( cfile, "\n" ); - for( i=0; i", value.c_str() ); - } -} - - -void TiXmlElement::CopyTo( TiXmlElement* target ) const -{ - // superclass: - TiXmlNode::CopyTo( target ); - - // Element class: - // Clone the attributes, then clone the children. - const TiXmlAttribute* attribute = 0; - for( attribute = attributeSet.First(); - attribute; - attribute = attribute->Next() ) - { - target->SetAttribute( attribute->Name(), attribute->Value() ); - } - - TiXmlNode* node = 0; - for ( node = firstChild; node; node = node->NextSibling() ) - { - target->LinkEndChild( node->Clone() ); - } -} - -bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const -{ - if ( visitor->VisitEnter( *this, attributeSet.First() ) ) - { - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - if ( !node->Accept( visitor ) ) - break; - } - } - return visitor->VisitExit( *this ); -} - - -TiXmlNode* TiXmlElement::Clone() const -{ - TiXmlElement* clone = new TiXmlElement( Value() ); - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -const char* TiXmlElement::GetText() const -{ - const TiXmlNode* child = this->FirstChild(); - if ( child ) { - const TiXmlText* childText = child->ToText(); - if ( childText ) { - return childText->Value(); - } - } - return 0; -} - - -TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - ClearError(); -} - -TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - value = documentName; - ClearError(); -} - - -#ifdef TIXML_USE_STL -TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - value = documentName; - ClearError(); -} -#endif - - -TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) -{ - copy.CopyTo( this ); -} - - -TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy ) -{ - Clear(); - copy.CopyTo( this ); - return *this; -} - - -bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) -{ - return LoadFile( Value(), encoding ); -} - - -bool TiXmlDocument::SaveFile() const -{ - return SaveFile( Value() ); -} - -bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) -{ - TIXML_STRING filename( _filename ); - value = filename; - - // reading in binary mode so that tinyxml can normalize the EOL - FILE* file = TiXmlFOpen( value.c_str (), "rb" ); - - if ( file ) - { - bool result = LoadFile( file, encoding ); - fclose( file ); - return result; - } - else - { - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } -} - -bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) -{ - if ( !file ) - { - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - // Delete the existing data: - Clear(); - location.Clear(); - - // Get the file size, so we can pre-allocate the string. HUGE speed impact. - long length = 0; - fseek( file, 0, SEEK_END ); - length = ftell( file ); - fseek( file, 0, SEEK_SET ); - - // Strange case, but good to handle up front. - if ( length <= 0 ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - // Subtle bug here. TinyXml did use fgets. But from the XML spec: - // 2.11 End-of-Line Handling - // - // - // ...the XML processor MUST behave as if it normalized all line breaks in external - // parsed entities (including the document entity) on input, before parsing, by translating - // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to - // a single #xA character. - // - // - // It is not clear fgets does that, and certainly isn't clear it works cross platform. - // Generally, you expect fgets to translate from the convention of the OS to the c/unix - // convention, and not work generally. - - /* - while( fgets( buf, sizeof(buf), file ) ) - { - data += buf; - } - */ - - char* buf = new char[ length+1 ]; - buf[0] = 0; - - if ( fread( buf, length, 1, file ) != 1 ) { - delete [] buf; - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - // Process the buffer in place to normalize new lines. (See comment above.) - // Copies from the 'p' to 'q' pointer, where p can advance faster if - // a newline-carriage return is hit. - // - // Wikipedia: - // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or - // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)... - // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others - // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS - // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 - - const char* p = buf; // the read head - char* q = buf; // the write head - const char CR = 0x0d; - const char LF = 0x0a; - - buf[length] = 0; - while( *p ) { - assert( p < (buf+length) ); - assert( q <= (buf+length) ); - assert( q <= p ); - - if ( *p == CR ) { - *q++ = LF; - p++; - if ( *p == LF ) { // check for CR+LF (and skip LF) - p++; - } - } - else { - *q++ = *p++; - } - } - assert( q <= (buf+length) ); - *q = 0; - - Parse( buf, 0, encoding ); - - delete [] buf; - return !Error(); -} - - -bool TiXmlDocument::SaveFile( const char * filename ) const -{ - // The old c stuff lives on... - FILE* fp = TiXmlFOpen( filename, "w" ); - if ( fp ) - { - bool result = SaveFile( fp ); - fclose( fp ); - return result; - } - return false; -} - - -bool TiXmlDocument::SaveFile( FILE* fp ) const -{ - if ( useMicrosoftBOM ) - { - const unsigned char TIXML_UTF_LEAD_0 = 0xefU; - const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; - const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - - fputc( TIXML_UTF_LEAD_0, fp ); - fputc( TIXML_UTF_LEAD_1, fp ); - fputc( TIXML_UTF_LEAD_2, fp ); - } - Print( fp, 0 ); - return (ferror(fp) == 0); -} - - -void TiXmlDocument::CopyTo( TiXmlDocument* target ) const -{ - TiXmlNode::CopyTo( target ); - - target->error = error; - target->errorId = errorId; - target->errorDesc = errorDesc; - target->tabsize = tabsize; - target->errorLocation = errorLocation; - target->useMicrosoftBOM = useMicrosoftBOM; - - TiXmlNode* node = 0; - for ( node = firstChild; node; node = node->NextSibling() ) - { - target->LinkEndChild( node->Clone() ); - } -} - - -TiXmlNode* TiXmlDocument::Clone() const -{ - TiXmlDocument* clone = new TiXmlDocument(); - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlDocument::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - node->Print( cfile, depth ); - fprintf( cfile, "\n" ); - } -} - - -bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const -{ - if ( visitor->VisitEnter( *this ) ) - { - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - if ( !node->Accept( visitor ) ) - break; - } - } - return visitor->VisitExit( *this ); -} - - -const TiXmlAttribute* TiXmlAttribute::Next() const -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( next->value.empty() && next->name.empty() ) - return 0; - return next; -} - -/* -TiXmlAttribute* TiXmlAttribute::Next() -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( next->value.empty() && next->name.empty() ) - return 0; - return next; -} -*/ - -const TiXmlAttribute* TiXmlAttribute::Previous() const -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( prev->value.empty() && prev->name.empty() ) - return 0; - return prev; -} - -/* -TiXmlAttribute* TiXmlAttribute::Previous() -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( prev->value.empty() && prev->name.empty() ) - return 0; - return prev; -} -*/ - -void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const -{ - TIXML_STRING n, v; - - EncodeString( name, &n ); - EncodeString( value, &v ); - - if (value.find ('\"') == TIXML_STRING::npos) { - if ( cfile ) { - fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); - } - if ( str ) { - (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; - } - } - else { - if ( cfile ) { - fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); - } - if ( str ) { - (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; - } - } -} - - -int TiXmlAttribute::QueryIntValue( int* ival ) const -{ - if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; -} - -int TiXmlAttribute::QueryDoubleValue( double* dval ) const -{ - if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; -} - -void TiXmlAttribute::SetIntValue( int _value ) -{ - char buf [64]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); - #else - sprintf (buf, "%d", _value); - #endif - SetValue (buf); -} - -void TiXmlAttribute::SetDoubleValue( double _value ) -{ - char buf [256]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); - #else - sprintf (buf, "%g", _value); - #endif - SetValue (buf); -} - -int TiXmlAttribute::IntValue() const -{ - return atoi (value.c_str ()); -} - -double TiXmlAttribute::DoubleValue() const -{ - return atof (value.c_str ()); -} - - -TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) -{ - copy.CopyTo( this ); -} - - -TiXmlComment& TiXmlComment::operator=( const TiXmlComment& base ) -{ - Clear(); - base.CopyTo( this ); - return *this; -} - - -void TiXmlComment::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - for ( int i=0; i", value.c_str() ); -} - - -void TiXmlComment::CopyTo( TiXmlComment* target ) const -{ - TiXmlNode::CopyTo( target ); -} - - -bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlComment::Clone() const -{ - TiXmlComment* clone = new TiXmlComment(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlText::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - if ( cdata ) - { - int i; - fprintf( cfile, "\n" ); - for ( i=0; i\n", value.c_str() ); // unformatted output - } - else - { - TIXML_STRING buffer; - EncodeString( value, &buffer ); - fprintf( cfile, "%s", buffer.c_str() ); - } -} - - -void TiXmlText::CopyTo( TiXmlText* target ) const -{ - TiXmlNode::CopyTo( target ); - target->cdata = cdata; -} - - -bool TiXmlText::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlText::Clone() const -{ - TiXmlText* clone = 0; - clone = new TiXmlText( "" ); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -TiXmlDeclaration::TiXmlDeclaration( const char * _version, - const char * _encoding, - const char * _standalone ) - : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) -{ - version = _version; - encoding = _encoding; - standalone = _standalone; -} - - -#ifdef TIXML_USE_STL -TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, - const std::string& _encoding, - const std::string& _standalone ) - : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) -{ - version = _version; - encoding = _encoding; - standalone = _standalone; -} -#endif - - -TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) - : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) -{ - copy.CopyTo( this ); -} - - -TiXmlDeclaration& TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) -{ - Clear(); - copy.CopyTo( this ); - return *this; -} - - -void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const -{ - if ( cfile ) fprintf( cfile, "" ); - if ( str ) (*str) += "?>"; -} - - -void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const -{ - TiXmlNode::CopyTo( target ); - - target->version = version; - target->encoding = encoding; - target->standalone = standalone; -} - - -bool TiXmlDeclaration::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlDeclaration::Clone() const -{ - TiXmlDeclaration* clone = new TiXmlDeclaration(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlUnknown::Print( FILE* cfile, int depth ) const -{ - for ( int i=0; i", value.c_str() ); -} - - -void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const -{ - TiXmlNode::CopyTo( target ); -} - - -bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlUnknown::Clone() const -{ - TiXmlUnknown* clone = new TiXmlUnknown(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -TiXmlAttributeSet::TiXmlAttributeSet() -{ - sentinel.next = &sentinel; - sentinel.prev = &sentinel; -} - - -TiXmlAttributeSet::~TiXmlAttributeSet() -{ - assert( sentinel.next == &sentinel ); - assert( sentinel.prev == &sentinel ); -} - - -void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) -{ - #ifdef TIXML_USE_STL - assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. - #else - assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. - #endif - - addMe->next = &sentinel; - addMe->prev = sentinel.prev; - - sentinel.prev->next = addMe; - sentinel.prev = addMe; -} - -void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) -{ - TiXmlAttribute* node; - - for( node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( node == removeMe ) - { - node->prev->next = node->next; - node->next->prev = node->prev; - node->next = 0; - node->prev = 0; - return; - } - } - assert( 0 ); // we tried to remove a non-linked attribute. -} - - -#ifdef TIXML_USE_STL -TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const -{ - for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( node->name == name ) - return node; - } - return 0; -} - -TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const std::string& _name ) -{ - TiXmlAttribute* attrib = Find( _name ); - if ( !attrib ) { - attrib = new TiXmlAttribute(); - Add( attrib ); - attrib->SetName( _name ); - } - return attrib; -} -#endif - - -TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const -{ - for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( strcmp( node->name.c_str(), name ) == 0 ) - return node; - } - return 0; -} - - -TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const char* _name ) -{ - TiXmlAttribute* attrib = Find( _name ); - if ( !attrib ) { - attrib = new TiXmlAttribute(); - Add( attrib ); - attrib->SetName( _name ); - } - return attrib; -} - - -#ifdef TIXML_USE_STL -std::istream& operator>> (std::istream & in, TiXmlNode & base) -{ - TIXML_STRING tag; - tag.reserve( 8 * 1000 ); - base.StreamIn( &in, &tag ); - - base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); - return in; -} -#endif - - -#ifdef TIXML_USE_STL -std::ostream& operator<< (std::ostream & out, const TiXmlNode & base) -{ - TiXmlPrinter printer; - printer.SetStreamPrinting(); - base.Accept( &printer ); - out << printer.Str(); - - return out; -} - - -std::string& operator<< (std::string& out, const TiXmlNode& base ) -{ - TiXmlPrinter printer; - printer.SetStreamPrinting(); - base.Accept( &printer ); - out.append( printer.Str() ); - - return out; -} -#endif - - -TiXmlHandle TiXmlHandle::FirstChild() const -{ - if ( node ) - { - TiXmlNode* child = node->FirstChild(); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const -{ - if ( node ) - { - TiXmlNode* child = node->FirstChild( value ); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChildElement() const -{ - if ( node ) - { - TiXmlElement* child = node->FirstChildElement(); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const -{ - if ( node ) - { - TiXmlElement* child = node->FirstChildElement( value ); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::Child( int count ) const -{ - if ( node ) - { - int i; - TiXmlNode* child = node->FirstChild(); - for ( i=0; - child && iNextSibling(), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const -{ - if ( node ) - { - int i; - TiXmlNode* child = node->FirstChild( value ); - for ( i=0; - child && iNextSibling( value ), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::ChildElement( int count ) const -{ - if ( node ) - { - int i; - TiXmlElement* child = node->FirstChildElement(); - for ( i=0; - child && iNextSiblingElement(), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const -{ - if ( node ) - { - int i; - TiXmlElement* child = node->FirstChildElement( value ); - for ( i=0; - child && iNextSiblingElement( value ), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -bool TiXmlPrinter::VisitEnter( const TiXmlDocument& ) -{ - return true; -} - -bool TiXmlPrinter::VisitExit( const TiXmlDocument& ) -{ - return true; -} - -bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) -{ - DoIndent(); - buffer += "<"; - buffer += element.Value(); - - for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) - { - buffer += " "; - attrib->Print( 0, 0, &buffer ); - } - - if ( !element.FirstChild() ) - { - buffer += " />"; - DoLineBreak(); - } - else - { - buffer += ">"; - if ( element.FirstChild()->ToText() - && element.LastChild() == element.FirstChild() - && element.FirstChild()->ToText()->CDATA() == false ) - { - simpleTextPrint = true; - // no DoLineBreak()! - } - else - { - DoLineBreak(); - } - } - ++depth; - return true; -} - - -bool TiXmlPrinter::VisitExit( const TiXmlElement& element ) -{ - --depth; - if ( !element.FirstChild() ) - { - // nothing. - } - else - { - if ( simpleTextPrint ) - { - simpleTextPrint = false; - } - else - { - DoIndent(); - } - buffer += ""; - DoLineBreak(); - } - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlText& text ) -{ - if ( text.CDATA() ) - { - DoIndent(); - buffer += ""; - DoLineBreak(); - } - else if ( simpleTextPrint ) - { - TIXML_STRING str; - TiXmlBase::EncodeString( text.ValueTStr(), &str ); - buffer += str; - } - else - { - DoIndent(); - TIXML_STRING str; - TiXmlBase::EncodeString( text.ValueTStr(), &str ); - buffer += str; - DoLineBreak(); - } - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration ) -{ - DoIndent(); - declaration.Print( 0, 0, &buffer ); - DoLineBreak(); - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlComment& comment ) -{ - DoIndent(); - buffer += ""; - DoLineBreak(); - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown ) -{ - DoIndent(); - buffer += "<"; - buffer += unknown.Value(); - buffer += ">"; - DoLineBreak(); - return true; -} - diff --git a/dram/src/common/third_party/tinyxml.h b/dram/src/common/third_party/tinyxml.h deleted file mode 100755 index a3589e5b..00000000 --- a/dram/src/common/third_party/tinyxml.h +++ /dev/null @@ -1,1805 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original code by Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#ifndef TINYXML_INCLUDED -#define TINYXML_INCLUDED - -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4530 ) -#pragma warning( disable : 4786 ) -#endif - -#include -#include -#include -#include -#include - -// Help out windows: -#if defined( _DEBUG ) && !defined( DEBUG ) -#define DEBUG -#endif - -#ifdef TIXML_USE_STL - #include - #include - #include - #define TIXML_STRING std::string -#else - #include "tinystr.h" - #define TIXML_STRING TiXmlString -#endif - -// Deprecated library function hell. Compilers want to use the -// new safe versions. This probably doesn't fully address the problem, -// but it gets closer. There are too many compilers for me to fully -// test. If you get compilation troubles, undefine TIXML_SAFE -#define TIXML_SAFE - -#ifdef TIXML_SAFE - #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - // Microsoft visual studio, version 2005 and higher. - #define TIXML_SNPRINTF _snprintf_s - #define TIXML_SSCANF sscanf_s - #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) - // Microsoft visual studio, version 6 and higher. - //#pragma message( "Using _sn* functions." ) - #define TIXML_SNPRINTF _snprintf - #define TIXML_SSCANF sscanf - #elif defined(__GNUC__) && (__GNUC__ >= 3 ) - // GCC version 3 and higher.s - //#warning( "Using sn* functions." ) - #define TIXML_SNPRINTF snprintf - #define TIXML_SSCANF sscanf - #else - #define TIXML_SNPRINTF snprintf - #define TIXML_SSCANF sscanf - #endif -#endif - -class TiXmlDocument; -class TiXmlElement; -class TiXmlComment; -class TiXmlUnknown; -class TiXmlAttribute; -class TiXmlText; -class TiXmlDeclaration; -class TiXmlParsingData; - -const int TIXML_MAJOR_VERSION = 2; -const int TIXML_MINOR_VERSION = 6; -const int TIXML_PATCH_VERSION = 2; - -/* Internal structure for tracking location of items - in the XML file. -*/ -struct TiXmlCursor -{ - TiXmlCursor() { Clear(); } - void Clear() { row = col = -1; } - - int row; // 0 based. - int col; // 0 based. -}; - - -/** - Implements the interface to the "Visitor pattern" (see the Accept() method.) - If you call the Accept() method, it requires being passed a TiXmlVisitor - class to handle callbacks. For nodes that contain other nodes (Document, Element) - you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves - are simply called with Visit(). - - If you return 'true' from a Visit method, recursive parsing will continue. If you return - false, no children of this node or its sibilings will be Visited. - - All flavors of Visit methods have a default implementation that returns 'true' (continue - visiting). You need to only override methods that are interesting to you. - - Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. - - You should never change the document from a callback. - - @sa TiXmlNode::Accept() -*/ -class TiXmlVisitor -{ -public: - virtual ~TiXmlVisitor() {} - - /// Visit a document. - virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } - /// Visit a document. - virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } - - /// Visit an element. - virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } - /// Visit an element. - virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } - - /// Visit a declaration - virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } - /// Visit a text node - virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } - /// Visit a comment node - virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } - /// Visit an unknown node - virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } -}; - -// Only used by Attribute::Query functions -enum -{ - TIXML_SUCCESS, - TIXML_NO_ATTRIBUTE, - TIXML_WRONG_TYPE -}; - - -// Used by the parsing routines. -enum TiXmlEncoding -{ - TIXML_ENCODING_UNKNOWN, - TIXML_ENCODING_UTF8, - TIXML_ENCODING_LEGACY -}; - -const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; - -/** TiXmlBase is a base class for every class in TinyXml. - It does little except to establish that TinyXml classes - can be printed and provide some utility functions. - - In XML, the document and elements can contain - other elements and other types of nodes. - - @verbatim - A Document can contain: Element (container or leaf) - Comment (leaf) - Unknown (leaf) - Declaration( leaf ) - - An Element can contain: Element (container or leaf) - Text (leaf) - Attributes (not on tree) - Comment (leaf) - Unknown (leaf) - - A Decleration contains: Attributes (not on tree) - @endverbatim -*/ -class TiXmlBase -{ - friend class TiXmlNode; - friend class TiXmlElement; - friend class TiXmlDocument; - -public: - TiXmlBase() : userData(0) {} - virtual ~TiXmlBase() {} - - /** All TinyXml classes can print themselves to a filestream - or the string class (TiXmlString in non-STL mode, std::string - in STL mode.) Either or both cfile and str can be null. - - This is a formatted print, and will insert - tabs and newlines. - - (For an unformatted stream, use the << operator.) - */ - virtual void Print( FILE* cfile, int depth ) const = 0; - - /** The world does not agree on whether white space should be kept or - not. In order to make everyone happy, these global, static functions - are provided to set whether or not TinyXml will condense all white space - into a single space or not. The default is to condense. Note changing this - value is not thread safe. - */ - static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } - - /// Return the current white space setting. - static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } - - /** Return the position, in the original source file, of this node or attribute. - The row and column are 1-based. (That is the first row and first column is - 1,1). If the returns values are 0 or less, then the parser does not have - a row and column value. - - Generally, the row and column value will be set when the TiXmlDocument::Load(), - TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set - when the DOM was created from operator>>. - - The values reflect the initial load. Once the DOM is modified programmatically - (by adding or changing nodes and attributes) the new values will NOT update to - reflect changes in the document. - - There is a minor performance cost to computing the row and column. Computation - can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. - - @sa TiXmlDocument::SetTabSize() - */ - int Row() const { return location.row + 1; } - int Column() const { return location.col + 1; } ///< See Row() - - void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. - void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. - const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. - - // Table that returs, for a given lead byte, the total number of bytes - // in the UTF-8 sequence. - static const int utf8ByteTable[256]; - - virtual const char* Parse( const char* p, - TiXmlParsingData* data, - TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; - - /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, - or they will be transformed into entities! - */ - static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); - - enum - { - TIXML_NO_ERROR = 0, - TIXML_ERROR, - TIXML_ERROR_OPENING_FILE, - TIXML_ERROR_PARSING_ELEMENT, - TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, - TIXML_ERROR_READING_ELEMENT_VALUE, - TIXML_ERROR_READING_ATTRIBUTES, - TIXML_ERROR_PARSING_EMPTY, - TIXML_ERROR_READING_END_TAG, - TIXML_ERROR_PARSING_UNKNOWN, - TIXML_ERROR_PARSING_COMMENT, - TIXML_ERROR_PARSING_DECLARATION, - TIXML_ERROR_DOCUMENT_EMPTY, - TIXML_ERROR_EMBEDDED_NULL, - TIXML_ERROR_PARSING_CDATA, - TIXML_ERROR_DOCUMENT_TOP_ONLY, - - TIXML_ERROR_STRING_COUNT - }; - -protected: - - static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); - - inline static bool IsWhiteSpace( char c ) - { - return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); - } - inline static bool IsWhiteSpace( int c ) - { - if ( c < 256 ) - return IsWhiteSpace( (char) c ); - return false; // Again, only truly correct for English/Latin...but usually works. - } - - #ifdef TIXML_USE_STL - static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); - static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); - #endif - - /* Reads an XML name into the string provided. Returns - a pointer just past the last character of the name, - or 0 if the function has an error. - */ - static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); - - /* Reads text. Returns a pointer past the given end tag. - Wickedly complex options, but it keeps the (sensitive) code in one place. - */ - static const char* ReadText( const char* in, // where to start - TIXML_STRING* text, // the string read - bool ignoreWhiteSpace, // whether to keep the white space - const char* endTag, // what ends this text - bool ignoreCase, // whether to ignore case in the end tag - TiXmlEncoding encoding ); // the current encoding - - // If an entity has been found, transform it into a character. - static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); - - // Get a character, while interpreting entities. - // The length can be from 0 to 4 bytes. - inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) - { - assert( p ); - if ( encoding == TIXML_ENCODING_UTF8 ) - { - *length = utf8ByteTable[ *((const unsigned char*)p) ]; - assert( *length >= 0 && *length < 5 ); - } - else - { - *length = 1; - } - - if ( *length == 1 ) - { - if ( *p == '&' ) - return GetEntity( p, _value, length, encoding ); - *_value = *p; - return p+1; - } - else if ( *length ) - { - //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), - // and the null terminator isn't needed - for( int i=0; p[i] && i<*length; ++i ) { - _value[i] = p[i]; - } - return p + (*length); - } - else - { - // Not valid text. - return 0; - } - } - - // Return true if the next characters in the stream are any of the endTag sequences. - // Ignore case only works for english, and should only be relied on when comparing - // to English words: StringEqual( p, "version", true ) is fine. - static bool StringEqual( const char* p, - const char* endTag, - bool ignoreCase, - TiXmlEncoding encoding ); - - static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; - - TiXmlCursor location; - - /// Field containing a generic user pointer - void* userData; - - // None of these methods are reliable for any language except English. - // Good for approximation, not great for accuracy. - static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); - static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); - inline static int ToLower( int v, TiXmlEncoding encoding ) - { - if ( encoding == TIXML_ENCODING_UTF8 ) - { - if ( v < 128 ) return tolower( v ); - return v; - } - else - { - return tolower( v ); - } - } - static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); - -private: - TiXmlBase( const TiXmlBase& ); // not implemented. - void operator=( const TiXmlBase& base ); // not allowed. - - struct Entity - { - const char* str; - unsigned int strLength; - char chr; - }; - enum - { - NUM_ENTITY = 5, - MAX_ENTITY_LENGTH = 6 - - }; - static Entity entity[ NUM_ENTITY ]; - static bool condenseWhiteSpace; -}; - - -/** The parent class for everything in the Document Object Model. - (Except for attributes). - Nodes have siblings, a parent, and children. A node can be - in a document, or stand on its own. The type of a TiXmlNode - can be queried, and it can be cast to its more defined type. -*/ -class TiXmlNode : public TiXmlBase -{ - friend class TiXmlDocument; - friend class TiXmlElement; - -public: - #ifdef TIXML_USE_STL - - /** An input stream operator, for every class. Tolerant of newlines and - formatting, but doesn't expect them. - */ - friend std::istream& operator >> (std::istream& in, TiXmlNode& base); - - /** An output stream operator, for every class. Note that this outputs - without any newlines or formatting, as opposed to Print(), which - includes tabs and new lines. - - The operator<< and operator>> are not completely symmetric. Writing - a node to a stream is very well defined. You'll get a nice stream - of output, without any extra whitespace or newlines. - - But reading is not as well defined. (As it always is.) If you create - a TiXmlElement (for example) and read that from an input stream, - the text needs to define an element or junk will result. This is - true of all input streams, but it's worth keeping in mind. - - A TiXmlDocument will read nodes until it reads a root element, and - all the children of that root element. - */ - friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); - - /// Appends the XML node or attribute to a std::string. - friend std::string& operator<< (std::string& out, const TiXmlNode& base ); - - #endif - - /** The types of XML nodes supported by TinyXml. (All the - unsupported types are picked up by UNKNOWN.) - */ - enum NodeType - { - TINYXML_DOCUMENT, - TINYXML_ELEMENT, - TINYXML_COMMENT, - TINYXML_UNKNOWN, - TINYXML_TEXT, - TINYXML_DECLARATION, - TINYXML_TYPECOUNT - }; - - virtual ~TiXmlNode(); - - /** The meaning of 'value' changes for the specific type of - TiXmlNode. - @verbatim - Document: filename of the xml file - Element: name of the element - Comment: the comment text - Unknown: the tag contents - Text: the text string - @endverbatim - - The subclasses will wrap this function. - */ - const char *Value() const { return value.c_str (); } - - #ifdef TIXML_USE_STL - /** Return Value() as a std::string. If you only use STL, - this is more efficient than calling Value(). - Only available in STL mode. - */ - const std::string& ValueStr() const { return value; } - #endif - - const TIXML_STRING& ValueTStr() const { return value; } - - /** Changes the value of the node. Defined as: - @verbatim - Document: filename of the xml file - Element: name of the element - Comment: the comment text - Unknown: the tag contents - Text: the text string - @endverbatim - */ - void SetValue(const char * _value) { value = _value;} - - #ifdef TIXML_USE_STL - /// STL std::string form. - void SetValue( const std::string& _value ) { value = _value; } - #endif - - /// Delete all the children of this node. Does not affect 'this'. - void Clear(); - - /// One step up the DOM. - TiXmlNode* Parent() { return parent; } - const TiXmlNode* Parent() const { return parent; } - - const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. - TiXmlNode* FirstChild() { return firstChild; } - const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. - /// The first child of this node with the matching 'value'. Will be null if none found. - TiXmlNode* FirstChild( const char * _value ) { - // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) - // call the method, cast the return back to non-const. - return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value )); - } - const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. - TiXmlNode* LastChild() { return lastChild; } - - const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. - TiXmlNode* LastChild( const char * _value ) { - return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value )); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. - const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. - #endif - - /** An alternate way to walk the children of a node. - One way to iterate over nodes is: - @verbatim - for( child = parent->FirstChild(); child; child = child->NextSibling() ) - @endverbatim - - IterateChildren does the same thing with the syntax: - @verbatim - child = 0; - while( child = parent->IterateChildren( child ) ) - @endverbatim - - IterateChildren takes the previous child as input and finds - the next one. If the previous child is null, it returns the - first. IterateChildren will return null when done. - */ - const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; - TiXmlNode* IterateChildren( const TiXmlNode* previous ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) ); - } - - /// This flavor of IterateChildren searches for children with a particular 'value' - const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; - TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. - TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. - #endif - - /** Add a new node related to this. Adds a child past the LastChild. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); - - - /** Add a new node related to this. Adds a child past the LastChild. - - NOTE: the node to be added is passed by pointer, and will be - henceforth owned (and deleted) by tinyXml. This method is efficient - and avoids an extra copy, but should be used with care as it - uses a different memory model than the other insert functions. - - @sa InsertEndChild - */ - TiXmlNode* LinkEndChild( TiXmlNode* addThis ); - - /** Add a new node related to this. Adds a child before the specified child. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); - - /** Add a new node related to this. Adds a child after the specified child. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); - - /** Replace a child of this node. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); - - /// Delete a child of this node. - bool RemoveChild( TiXmlNode* removeThis ); - - /// Navigate to a sibling node. - const TiXmlNode* PreviousSibling() const { return prev; } - TiXmlNode* PreviousSibling() { return prev; } - - /// Navigate to a sibling node. - const TiXmlNode* PreviousSibling( const char * ) const; - TiXmlNode* PreviousSibling( const char *_prev ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. - const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. - #endif - - /// Navigate to a sibling node. - const TiXmlNode* NextSibling() const { return next; } - TiXmlNode* NextSibling() { return next; } - - /// Navigate to a sibling node with the given 'value'. - const TiXmlNode* NextSibling( const char * ) const; - TiXmlNode* NextSibling( const char* _next ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) ); - } - - /** Convenience function to get through elements. - Calls NextSibling and ToElement. Will skip all non-Element - nodes. Returns 0 if there is not another element. - */ - const TiXmlElement* NextSiblingElement() const; - TiXmlElement* NextSiblingElement() { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() ); - } - - /** Convenience function to get through elements. - Calls NextSibling and ToElement. Will skip all non-Element - nodes. Returns 0 if there is not another element. - */ - const TiXmlElement* NextSiblingElement( const char * ) const; - TiXmlElement* NextSiblingElement( const char *_next ) { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. - TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. - #endif - - /// Convenience function to get through elements. - const TiXmlElement* FirstChildElement() const; - TiXmlElement* FirstChildElement() { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() ); - } - - /// Convenience function to get through elements. - const TiXmlElement* FirstChildElement( const char * _value ) const; - TiXmlElement* FirstChildElement( const char * _value ) { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. - TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. - #endif - - /** Query the type (as an enumerated value, above) of this node. - The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, - TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION. - */ - int Type() const { return type; } - - /** Return a pointer to the Document this node lives in. - Returns null if not in a document. - */ - const TiXmlDocument* GetDocument() const; - TiXmlDocument* GetDocument() { - return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() ); - } - - /// Returns true if this node has no children. - bool NoChildren() const { return !firstChild; } - - virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - - virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - - /** Create an exact duplicate of this node and return it. The memory must be deleted - by the caller. - */ - virtual TiXmlNode* Clone() const = 0; - - /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the - XML tree will be conditionally visited and the host will be called back - via the TiXmlVisitor interface. - - This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse - the XML for the callbacks, so the performance of TinyXML is unchanged by using this - interface versus any other.) - - The interface has been based on ideas from: - - - http://www.saxproject.org/ - - http://c2.com/cgi/wiki?HierarchicalVisitorPattern - - Which are both good references for "visiting". - - An example of using Accept(): - @verbatim - TiXmlPrinter printer; - tinyxmlDoc.Accept( &printer ); - const char* xmlcstr = printer.CStr(); - @endverbatim - */ - virtual bool Accept( TiXmlVisitor* visitor ) const = 0; - -protected: - TiXmlNode( NodeType _type ); - - // Copy to the allocated object. Shared functionality between Clone, Copy constructor, - // and the assignment operator. - void CopyTo( TiXmlNode* target ) const; - - #ifdef TIXML_USE_STL - // The real work of the input operator. - virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; - #endif - - // Figure out what is at *p, and parse it. Returns null if it is not an xml node. - TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); - - TiXmlNode* parent; - NodeType type; - - TiXmlNode* firstChild; - TiXmlNode* lastChild; - - TIXML_STRING value; - - TiXmlNode* prev; - TiXmlNode* next; - -private: - TiXmlNode( const TiXmlNode& ); // not implemented. - void operator=( const TiXmlNode& base ); // not allowed. -}; - - -/** An attribute is a name-value pair. Elements have an arbitrary - number of attributes, each with a unique name. - - @note The attributes are not TiXmlNodes, since they are not - part of the tinyXML document object model. There are other - suggested ways to look at this problem. -*/ -class TiXmlAttribute : public TiXmlBase -{ - friend class TiXmlAttributeSet; - -public: - /// Construct an empty attribute. - TiXmlAttribute() : TiXmlBase() - { - document = 0; - prev = next = 0; - } - - #ifdef TIXML_USE_STL - /// std::string constructor. - TiXmlAttribute( const std::string& _name, const std::string& _value ) - { - name = _name; - value = _value; - document = 0; - prev = next = 0; - } - #endif - - /// Construct an attribute with a name and value. - TiXmlAttribute( const char * _name, const char * _value ) - { - name = _name; - value = _value; - document = 0; - prev = next = 0; - } - - const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. - const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. - #ifdef TIXML_USE_STL - const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. - #endif - int IntValue() const; ///< Return the value of this attribute, converted to an integer. - double DoubleValue() const; ///< Return the value of this attribute, converted to a double. - - // Get the tinyxml string representation - const TIXML_STRING& NameTStr() const { return name; } - - /** QueryIntValue examines the value string. It is an alternative to the - IntValue() method with richer error checking. - If the value is an integer, it is stored in 'value' and - the call returns TIXML_SUCCESS. If it is not - an integer, it returns TIXML_WRONG_TYPE. - - A specialized but useful call. Note that for success it returns 0, - which is the opposite of almost all other TinyXml calls. - */ - int QueryIntValue( int* _value ) const; - /// QueryDoubleValue examines the value string. See QueryIntValue(). - int QueryDoubleValue( double* _value ) const; - - void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. - void SetValue( const char* _value ) { value = _value; } ///< Set the value. - - void SetIntValue( int _value ); ///< Set the value from an integer. - void SetDoubleValue( double _value ); ///< Set the value from a double. - - #ifdef TIXML_USE_STL - /// STL std::string form. - void SetName( const std::string& _name ) { name = _name; } - /// STL std::string form. - void SetValue( const std::string& _value ) { value = _value; } - #endif - - /// Get the next sibling attribute in the DOM. Returns null at end. - const TiXmlAttribute* Next() const; - TiXmlAttribute* Next() { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); - } - - /// Get the previous sibling attribute in the DOM. Returns null at beginning. - const TiXmlAttribute* Previous() const; - TiXmlAttribute* Previous() { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); - } - - bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } - bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } - bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } - - /* Attribute parsing starts: first letter of the name - returns: the next char after the value end quote - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - // Prints this Attribute to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const { - Print( cfile, depth, 0 ); - } - void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; - - // [internal use] - // Set the document pointer so the attribute can report errors. - void SetDocument( TiXmlDocument* doc ) { document = doc; } - -private: - TiXmlAttribute( const TiXmlAttribute& ); // not implemented. - void operator=( const TiXmlAttribute& base ); // not allowed. - - TiXmlDocument* document; // A pointer back to a document, for error reporting. - TIXML_STRING name; - TIXML_STRING value; - TiXmlAttribute* prev; - TiXmlAttribute* next; -}; - - -/* A class used to manage a group of attributes. - It is only used internally, both by the ELEMENT and the DECLARATION. - - The set can be changed transparent to the Element and Declaration - classes that use it, but NOT transparent to the Attribute - which has to implement a next() and previous() method. Which makes - it a bit problematic and prevents the use of STL. - - This version is implemented with circular lists because: - - I like circular lists - - it demonstrates some independence from the (typical) doubly linked list. -*/ -class TiXmlAttributeSet -{ -public: - TiXmlAttributeSet(); - ~TiXmlAttributeSet(); - - void Add( TiXmlAttribute* attribute ); - void Remove( TiXmlAttribute* attribute ); - - const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } - TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } - const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } - TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } - - TiXmlAttribute* Find( const char* _name ) const; - TiXmlAttribute* FindOrCreate( const char* _name ); - -# ifdef TIXML_USE_STL - TiXmlAttribute* Find( const std::string& _name ) const; - TiXmlAttribute* FindOrCreate( const std::string& _name ); -# endif - - -private: - //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), - //*ME: this class must be also use a hidden/disabled copy-constructor !!! - TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed - void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) - - TiXmlAttribute sentinel; -}; - - -/** The element is a container class. It has a value, the element name, - and can contain other elements, text, comments, and unknowns. - Elements also contain an arbitrary number of attributes. -*/ -class TiXmlElement : public TiXmlNode -{ -public: - /// Construct an element. - TiXmlElement (const char * in_value); - - #ifdef TIXML_USE_STL - /// std::string constructor. - TiXmlElement( const std::string& _value ); - #endif - - TiXmlElement( const TiXmlElement& ); - - TiXmlElement& operator=( const TiXmlElement& base ); - - virtual ~TiXmlElement(); - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - */ - const char* Attribute( const char* name ) const; - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - If the attribute exists and can be converted to an integer, - the integer value will be put in the return 'i', if 'i' - is non-null. - */ - const char* Attribute( const char* name, int* i ) const; - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - If the attribute exists and can be converted to an double, - the double value will be put in the return 'd', if 'd' - is non-null. - */ - const char* Attribute( const char* name, double* d ) const; - - /** QueryIntAttribute examines the attribute - it is an alternative to the - Attribute() method with richer error checking. - If the attribute is an integer, it is stored in 'value' and - the call returns TIXML_SUCCESS. If it is not - an integer, it returns TIXML_WRONG_TYPE. If the attribute - does not exist, then TIXML_NO_ATTRIBUTE is returned. - */ - int QueryIntAttribute( const char* name, int* _value ) const; - /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). - int QueryUnsignedAttribute( const char* name, unsigned* _value ) const; - /** QueryBoolAttribute examines the attribute - see QueryIntAttribute(). - Note that '1', 'true', or 'yes' are considered true, while '0', 'false' - and 'no' are considered false. - */ - int QueryBoolAttribute( const char* name, bool* _value ) const; - /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). - int QueryDoubleAttribute( const char* name, double* _value ) const; - /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). - int QueryFloatAttribute( const char* name, float* _value ) const { - double d; - int result = QueryDoubleAttribute( name, &d ); - if ( result == TIXML_SUCCESS ) { - *_value = (float)d; - } - return result; - } - - #ifdef TIXML_USE_STL - /// QueryStringAttribute examines the attribute - see QueryIntAttribute(). - int QueryStringAttribute( const char* name, std::string* _value ) const { - const char* cstr = Attribute( name ); - if ( cstr ) { - *_value = std::string( cstr ); - return TIXML_SUCCESS; - } - return TIXML_NO_ATTRIBUTE; - } - - /** Template form of the attribute query which will try to read the - attribute into the specified type. Very easy, very powerful, but - be careful to make sure to call this with the correct type. - - NOTE: This method doesn't work correctly for 'string' types that contain spaces. - - @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE - */ - template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const - { - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - - std::stringstream sstream( node->ValueStr() ); - sstream >> *outValue; - if ( !sstream.fail() ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; - } - - int QueryValueAttribute( const std::string& name, std::string* outValue ) const - { - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - *outValue = node->ValueStr(); - return TIXML_SUCCESS; - } - #endif - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetAttribute( const char* name, const char * _value ); - - #ifdef TIXML_USE_STL - const std::string* Attribute( const std::string& name ) const; - const std::string* Attribute( const std::string& name, int* i ) const; - const std::string* Attribute( const std::string& name, double* d ) const; - int QueryIntAttribute( const std::string& name, int* _value ) const; - int QueryDoubleAttribute( const std::string& name, double* _value ) const; - - /// STL std::string form. - void SetAttribute( const std::string& name, const std::string& _value ); - ///< STL std::string form. - void SetAttribute( const std::string& name, int _value ); - ///< STL std::string form. - void SetDoubleAttribute( const std::string& name, double value ); - #endif - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetAttribute( const char * name, int value ); - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetDoubleAttribute( const char * name, double value ); - - /** Deletes an attribute with the given name. - */ - void RemoveAttribute( const char * name ); - #ifdef TIXML_USE_STL - void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. - #endif - - const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. - TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } - const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. - TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } - - /** Convenience function for easy access to the text inside an element. Although easy - and concise, GetText() is limited compared to getting the TiXmlText child - and accessing it directly. - - If the first child of 'this' is a TiXmlText, the GetText() - returns the character string of the Text node, else null is returned. - - This is a convenient method for getting the text of simple contained text: - @verbatim - This is text - const char* str = fooElement->GetText(); - @endverbatim - - 'str' will be a pointer to "This is text". - - Note that this function can be misleading. If the element foo was created from - this XML: - @verbatim - This is text - @endverbatim - - then the value of str would be null. The first child node isn't a text node, it is - another element. From this XML: - @verbatim - This is text - @endverbatim - GetText() will return "This is ". - - WARNING: GetText() accesses a child node - don't become confused with the - similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are - safe type casts on the referenced node. - */ - const char* GetText() const; - - /// Creates a new Element and returns it - the returned element is a copy. - virtual TiXmlNode* Clone() const; - // Print the Element to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /* Attribtue parsing starts: next char past '<' - returns: next char past '>' - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - - void CopyTo( TiXmlElement* target ) const; - void ClearThis(); // like clear, but initializes 'this' object as well - - // Used to be public [internal use] - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - /* [internal use] - Reads the "value" of the element -- another element, or text. - This should terminate with the current end tag. - */ - const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); - -private: - TiXmlAttributeSet attributeSet; -}; - - -/** An XML comment. -*/ -class TiXmlComment : public TiXmlNode -{ -public: - /// Constructs an empty comment. - TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {} - /// Construct a comment from text. - TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) { - SetValue( _value ); - } - TiXmlComment( const TiXmlComment& ); - TiXmlComment& operator=( const TiXmlComment& base ); - - virtual ~TiXmlComment() {} - - /// Returns a copy of this Comment. - virtual TiXmlNode* Clone() const; - // Write this Comment to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /* Attribtue parsing starts: at the ! of the !-- - returns: next char past '>' - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - void CopyTo( TiXmlComment* target ) const; - - // used to be public - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif -// virtual void StreamOut( TIXML_OSTREAM * out ) const; - -private: - -}; - - -/** XML text. A text node can have 2 ways to output the next. "normal" output - and CDATA. It will default to the mode it was parsed from the XML file and - you generally want to leave it alone, but you can change the output mode with - SetCDATA() and query it with CDATA(). -*/ -class TiXmlText : public TiXmlNode -{ - friend class TiXmlElement; -public: - /** Constructor for text element. By default, it is treated as - normal, encoded text. If you want it be output as a CDATA text - element, set the parameter _cdata to 'true' - */ - TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) - { - SetValue( initValue ); - cdata = false; - } - virtual ~TiXmlText() {} - - #ifdef TIXML_USE_STL - /// Constructor. - TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) - { - SetValue( initValue ); - cdata = false; - } - #endif - - TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } - TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; } - - // Write this text object to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /// Queries whether this represents text using a CDATA section. - bool CDATA() const { return cdata; } - /// Turns on or off a CDATA representation of text. - void SetCDATA( bool _cdata ) { cdata = _cdata; } - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected : - /// [internal use] Creates a new Element and returns it. - virtual TiXmlNode* Clone() const; - void CopyTo( TiXmlText* target ) const; - - bool Blank() const; // returns true if all white space and new lines - // [internal use] - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - bool cdata; // true if this should be input and output as a CDATA style text element -}; - - -/** In correct XML the declaration is the first entry in the file. - @verbatim - - @endverbatim - - TinyXml will happily read or write files without a declaration, - however. There are 3 possible attributes to the declaration: - version, encoding, and standalone. - - Note: In this version of the code, the attributes are - handled as special cases, not generic attributes, simply - because there can only be at most 3 and they are always the same. -*/ -class TiXmlDeclaration : public TiXmlNode -{ -public: - /// Construct an empty declaration. - TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {} - -#ifdef TIXML_USE_STL - /// Constructor. - TiXmlDeclaration( const std::string& _version, - const std::string& _encoding, - const std::string& _standalone ); -#endif - - /// Construct. - TiXmlDeclaration( const char* _version, - const char* _encoding, - const char* _standalone ); - - TiXmlDeclaration( const TiXmlDeclaration& copy ); - TiXmlDeclaration& operator=( const TiXmlDeclaration& copy ); - - virtual ~TiXmlDeclaration() {} - - /// Version. Will return an empty string if none was found. - const char *Version() const { return version.c_str (); } - /// Encoding. Will return an empty string if none was found. - const char *Encoding() const { return encoding.c_str (); } - /// Is this a standalone document? - const char *Standalone() const { return standalone.c_str (); } - - /// Creates a copy of this Declaration and returns it. - virtual TiXmlNode* Clone() const; - // Print this declaration to a FILE stream. - virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; - virtual void Print( FILE* cfile, int depth ) const { - Print( cfile, depth, 0 ); - } - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - void CopyTo( TiXmlDeclaration* target ) const; - // used to be public - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - - TIXML_STRING version; - TIXML_STRING encoding; - TIXML_STRING standalone; -}; - - -/** Any tag that tinyXml doesn't recognize is saved as an - unknown. It is a tag of text, but should not be modified. - It will be written back to the XML, unchanged, when the file - is saved. - - DTD tags get thrown into TiXmlUnknowns. -*/ -class TiXmlUnknown : public TiXmlNode -{ -public: - TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {} - virtual ~TiXmlUnknown() {} - - TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } - TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; } - - /// Creates a copy of this Unknown and returns it. - virtual TiXmlNode* Clone() const; - // Print this Unknown to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected: - void CopyTo( TiXmlUnknown* target ) const; - - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - -}; - - -/** Always the top level node. A document binds together all the - XML pieces. It can be saved, loaded, and printed to the screen. - The 'value' of a document node is the xml file name. -*/ -class TiXmlDocument : public TiXmlNode -{ -public: - /// Create an empty document, that has no name. - TiXmlDocument(); - /// Create a document with a name. The name of the document is also the filename of the xml. - TiXmlDocument( const char * documentName ); - - #ifdef TIXML_USE_STL - /// Constructor. - TiXmlDocument( const std::string& documentName ); - #endif - - TiXmlDocument( const TiXmlDocument& copy ); - TiXmlDocument& operator=( const TiXmlDocument& copy ); - - virtual ~TiXmlDocument() {} - - /** Load a file using the current document value. - Returns true if successful. Will delete any existing - document data before loading. - */ - bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the current document value. Returns true if successful. - bool SaveFile() const; - /// Load a file using the given filename. Returns true if successful. - bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the given filename. Returns true if successful. - bool SaveFile( const char * filename ) const; - /** Load a file using the given FILE*. Returns true if successful. Note that this method - doesn't stream - the entire object pointed at by the FILE* - will be interpreted as an XML file. TinyXML doesn't stream in XML from the current - file location. Streaming may be added in the future. - */ - bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the given FILE*. Returns true if successful. - bool SaveFile( FILE* ) const; - - #ifdef TIXML_USE_STL - bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. - { - return LoadFile( filename.c_str(), encoding ); - } - bool SaveFile( const std::string& filename ) const ///< STL std::string version. - { - return SaveFile( filename.c_str() ); - } - #endif - - /** Parse the given null terminated block of xml data. Passing in an encoding to this - method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml - to use that encoding, regardless of what TinyXml might otherwise try to detect. - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - - /** Get the root element -- the only top level element -- of the document. - In well formed XML, there should only be one. TinyXml is tolerant of - multiple elements at the document level. - */ - const TiXmlElement* RootElement() const { return FirstChildElement(); } - TiXmlElement* RootElement() { return FirstChildElement(); } - - /** If an error occurs, Error will be set to true. Also, - - The ErrorId() will contain the integer identifier of the error (not generally useful) - - The ErrorDesc() method will return the name of the error. (very useful) - - The ErrorRow() and ErrorCol() will return the location of the error (if known) - */ - bool Error() const { return error; } - - /// Contains a textual (english) description of the error if one occurs. - const char * ErrorDesc() const { return errorDesc.c_str (); } - - /** Generally, you probably want the error string ( ErrorDesc() ). But if you - prefer the ErrorId, this function will fetch it. - */ - int ErrorId() const { return errorId; } - - /** Returns the location (if known) of the error. The first column is column 1, - and the first row is row 1. A value of 0 means the row and column wasn't applicable - (memory errors, for example, have no row/column) or the parser lost the error. (An - error in the error reporting, in that case.) - - @sa SetTabSize, Row, Column - */ - int ErrorRow() const { return errorLocation.row+1; } - int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() - - /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) - to report the correct values for row and column. It does not change the output - or input in any way. - - By calling this method, with a tab size - greater than 0, the row and column of each node and attribute is stored - when the file is loaded. Very useful for tracking the DOM back in to - the source file. - - The tab size is required for calculating the location of nodes. If not - set, the default of 4 is used. The tabsize is set per document. Setting - the tabsize to 0 disables row/column tracking. - - Note that row and column tracking is not supported when using operator>>. - - The tab size needs to be enabled before the parse or load. Correct usage: - @verbatim - TiXmlDocument doc; - doc.SetTabSize( 8 ); - doc.Load( "myfile.xml" ); - @endverbatim - - @sa Row, Column - */ - void SetTabSize( int _tabsize ) { tabsize = _tabsize; } - - int TabSize() const { return tabsize; } - - /** If you have handled the error, it can be reset with this call. The error - state is automatically cleared if you Parse a new XML block. - */ - void ClearError() { error = false; - errorId = 0; - errorDesc = ""; - errorLocation.row = errorLocation.col = 0; - //errorLocation.last = 0; - } - - /** Write the document to standard out using formatted printing ("pretty print"). */ - void Print() const { Print( stdout, 0 ); } - - /* Write the document to a string using formatted printing ("pretty print"). This - will allocate a character array (new char[]) and return it as a pointer. The - calling code pust call delete[] on the return char* to avoid a memory leak. - */ - //char* PrintToMemory() const; - - /// Print this Document to a FILE stream. - virtual void Print( FILE* cfile, int depth = 0 ) const; - // [internal use] - void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); - - virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected : - // [internal use] - virtual TiXmlNode* Clone() const; - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - void CopyTo( TiXmlDocument* target ) const; - - bool error; - int errorId; - TIXML_STRING errorDesc; - int tabsize; - TiXmlCursor errorLocation; - bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. -}; - - -/** - A TiXmlHandle is a class that wraps a node pointer with null checks; this is - an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml - DOM structure. It is a separate utility class. - - Take an example: - @verbatim - - - - - - - @endverbatim - - Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very - easy to write a *lot* of code that looks like: - - @verbatim - TiXmlElement* root = document.FirstChildElement( "Document" ); - if ( root ) - { - TiXmlElement* element = root->FirstChildElement( "Element" ); - if ( element ) - { - TiXmlElement* child = element->FirstChildElement( "Child" ); - if ( child ) - { - TiXmlElement* child2 = child->NextSiblingElement( "Child" ); - if ( child2 ) - { - // Finally do something useful. - @endverbatim - - And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity - of such code. A TiXmlHandle checks for null pointers so it is perfectly safe - and correct to use: - - @verbatim - TiXmlHandle docHandle( &document ); - TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); - if ( child2 ) - { - // do something useful - @endverbatim - - Which is MUCH more concise and useful. - - It is also safe to copy handles - internally they are nothing more than node pointers. - @verbatim - TiXmlHandle handleCopy = handle; - @endverbatim - - What they should not be used for is iteration: - - @verbatim - int i=0; - while ( true ) - { - TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); - if ( !child ) - break; - // do something - ++i; - } - @endverbatim - - It seems reasonable, but it is in fact two embedded while loops. The Child method is - a linear walk to find the element, so this code would iterate much more than it needs - to. Instead, prefer: - - @verbatim - TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); - - for( child; child; child=child->NextSiblingElement() ) - { - // do something - } - @endverbatim -*/ -class TiXmlHandle -{ -public: - /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } - /// Copy constructor - TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } - TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; } - - /// Return a handle to the first child node. - TiXmlHandle FirstChild() const; - /// Return a handle to the first child node with the given name. - TiXmlHandle FirstChild( const char * value ) const; - /// Return a handle to the first child element. - TiXmlHandle FirstChildElement() const; - /// Return a handle to the first child element with the given name. - TiXmlHandle FirstChildElement( const char * value ) const; - - /** Return a handle to the "index" child with the given name. - The first child is 0, the second 1, etc. - */ - TiXmlHandle Child( const char* value, int index ) const; - /** Return a handle to the "index" child. - The first child is 0, the second 1, etc. - */ - TiXmlHandle Child( int index ) const; - /** Return a handle to the "index" child element with the given name. - The first child element is 0, the second 1, etc. Note that only TiXmlElements - are indexed: other types are not counted. - */ - TiXmlHandle ChildElement( const char* value, int index ) const; - /** Return a handle to the "index" child element. - The first child element is 0, the second 1, etc. Note that only TiXmlElements - are indexed: other types are not counted. - */ - TiXmlHandle ChildElement( int index ) const; - - #ifdef TIXML_USE_STL - TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } - TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } - - TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } - TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } - #endif - - /** Return the handle as a TiXmlNode. This may return null. - */ - TiXmlNode* ToNode() const { return node; } - /** Return the handle as a TiXmlElement. This may return null. - */ - TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } - /** Return the handle as a TiXmlText. This may return null. - */ - TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } - /** Return the handle as a TiXmlUnknown. This may return null. - */ - TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } - - /** @deprecated use ToNode. - Return the handle as a TiXmlNode. This may return null. - */ - TiXmlNode* Node() const { return ToNode(); } - /** @deprecated use ToElement. - Return the handle as a TiXmlElement. This may return null. - */ - TiXmlElement* Element() const { return ToElement(); } - /** @deprecated use ToText() - Return the handle as a TiXmlText. This may return null. - */ - TiXmlText* Text() const { return ToText(); } - /** @deprecated use ToUnknown() - Return the handle as a TiXmlUnknown. This may return null. - */ - TiXmlUnknown* Unknown() const { return ToUnknown(); } - -private: - TiXmlNode* node; -}; - - -/** Print to memory functionality. The TiXmlPrinter is useful when you need to: - - -# Print to memory (especially in non-STL mode) - -# Control formatting (line endings, etc.) - - When constructed, the TiXmlPrinter is in its default "pretty printing" mode. - Before calling Accept() you can call methods to control the printing - of the XML document. After TiXmlNode::Accept() is called, the printed document can - be accessed via the CStr(), Str(), and Size() methods. - - TiXmlPrinter uses the Visitor API. - @verbatim - TiXmlPrinter printer; - printer.SetIndent( "\t" ); - - doc.Accept( &printer ); - fprintf( stdout, "%s", printer.CStr() ); - @endverbatim -*/ -class TiXmlPrinter : public TiXmlVisitor -{ -public: - TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), - buffer(), indent( " " ), lineBreak( "\n" ) {} - - virtual bool VisitEnter( const TiXmlDocument& doc ); - virtual bool VisitExit( const TiXmlDocument& doc ); - - virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ); - virtual bool VisitExit( const TiXmlElement& element ); - - virtual bool Visit( const TiXmlDeclaration& declaration ); - virtual bool Visit( const TiXmlText& text ); - virtual bool Visit( const TiXmlComment& comment ); - virtual bool Visit( const TiXmlUnknown& unknown ); - - /** Set the indent characters for printing. By default 4 spaces - but tab (\t) is also useful, or null/empty string for no indentation. - */ - void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } - /// Query the indention string. - const char* Indent() { return indent.c_str(); } - /** Set the line breaking string. By default set to newline (\n). - Some operating systems prefer other characters, or can be - set to the null/empty string for no indenation. - */ - void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } - /// Query the current line breaking string. - const char* LineBreak() { return lineBreak.c_str(); } - - /** Switch over to "stream printing" which is the most dense formatting without - linebreaks. Common when the XML is needed for network transmission. - */ - void SetStreamPrinting() { indent = ""; - lineBreak = ""; - } - /// Return the result. - const char* CStr() { return buffer.c_str(); } - /// Return the length of the result string. - size_t Size() { return buffer.size(); } - - #ifdef TIXML_USE_STL - /// Return the result. - const std::string& Str() { return buffer; } - #endif - -private: - void DoIndent() { - for( int i=0; i -#include - -#include "tinyxml.h" - -//#define DEBUG_PARSER -#if defined( DEBUG_PARSER ) -# if defined( DEBUG ) && defined( _MSC_VER ) -# include -# define TIXML_LOG OutputDebugString -# else -# define TIXML_LOG printf -# endif -#endif - -// Note tha "PutString" hardcodes the same list. This -// is less flexible than it appears. Changing the entries -// or order will break putstring. -TiXmlBase::Entity TiXmlBase::entity[ TiXmlBase::NUM_ENTITY ] = -{ - { "&", 5, '&' }, - { "<", 4, '<' }, - { ">", 4, '>' }, - { """, 6, '\"' }, - { "'", 6, '\'' } -}; - -// Bunch of unicode info at: -// http://www.unicode.org/faq/utf_bom.html -// Including the basic of this table, which determines the #bytes in the -// sequence from the lead byte. 1 placed for invalid sequences -- -// although the result will be junk, pass it through as much as possible. -// Beware of the non-characters in UTF-8: -// ef bb bf (Microsoft "lead bytes") -// ef bf be -// ef bf bf - -const unsigned char TIXML_UTF_LEAD_0 = 0xefU; -const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; -const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - -const int TiXmlBase::utf8ByteTable[256] = -{ - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte - 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid -}; - - -void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) -{ - const unsigned long BYTE_MASK = 0xBF; - const unsigned long BYTE_MARK = 0x80; - const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - - if (input < 0x80) - *length = 1; - else if ( input < 0x800 ) - *length = 2; - else if ( input < 0x10000 ) - *length = 3; - else if ( input < 0x200000 ) - *length = 4; - else - { *length = 0; return; } // This code won't covert this correctly anyway. - - output += *length; - - // Scary scary fall throughs. - switch (*length) - { - case 4: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 3: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 2: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 1: - --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); - } -} - - -/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) -{ - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky trying - // to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - -// if ( encoding == TIXML_ENCODING_UTF8 ) -// { - if ( anyByte < 127 ) - return isalpha( anyByte ); - else - return 1; // What else to do? The unicode set is huge...get the english ones right. -// } -// else -// { -// return isalpha( anyByte ); -// } -} - - -/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) -{ - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky trying - // to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - -// if ( encoding == TIXML_ENCODING_UTF8 ) -// { - if ( anyByte < 127 ) - return isalnum( anyByte ); - else - return 1; // What else to do? The unicode set is huge...get the english ones right. -// } -// else -// { -// return isalnum( anyByte ); -// } -} - - -class TiXmlParsingData -{ - friend class TiXmlDocument; - public: - void Stamp( const char* now, TiXmlEncoding encoding ); - - const TiXmlCursor& Cursor() const { return cursor; } - - private: - // Only used by the document! - TiXmlParsingData( const char* start, int _tabsize, int row, int col ) - { - assert( start ); - stamp = start; - tabsize = _tabsize; - cursor.row = row; - cursor.col = col; - } - - TiXmlCursor cursor; - const char* stamp; - int tabsize; -}; - - -void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) -{ - assert( now ); - - // Do nothing if the tabsize is 0. - if ( tabsize < 1 ) - { - return; - } - - // Get the current row, column. - int row = cursor.row; - int col = cursor.col; - const char* p = stamp; - assert( p ); - - while ( p < now ) - { - // Treat p as unsigned, so we have a happy compiler. - const unsigned char* pU = (const unsigned char*)p; - - // Code contributed by Fletcher Dunn: (modified by lee) - switch (*pU) { - case 0: - // We *should* never get here, but in case we do, don't - // advance past the terminating null character, ever - return; - - case '\r': - // bump down to the next line - ++row; - col = 0; - // Eat the character - ++p; - - // Check for \r\n sequence, and treat this as a single character - if (*p == '\n') { - ++p; - } - break; - - case '\n': - // bump down to the next line - ++row; - col = 0; - - // Eat the character - ++p; - - // Check for \n\r sequence, and treat this as a single - // character. (Yes, this bizarre thing does occur still - // on some arcane platforms...) - if (*p == '\r') { - ++p; - } - break; - - case '\t': - // Eat the character - ++p; - - // Skip to next tab stop - col = (col / tabsize + 1) * tabsize; - break; - - case TIXML_UTF_LEAD_0: - if ( encoding == TIXML_ENCODING_UTF8 ) - { - if ( *(p+1) && *(p+2) ) - { - // In these cases, don't advance the column. These are - // 0-width spaces. - if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) - p += 3; - else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) - p += 3; - else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) - p += 3; - else - { p +=3; ++col; } // A normal character. - } - } - else - { - ++p; - ++col; - } - break; - - default: - if ( encoding == TIXML_ENCODING_UTF8 ) - { - // Eat the 1 to 4 byte utf8 character. - int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; - if ( step == 0 ) - step = 1; // Error case from bad encoding, but handle gracefully. - p += step; - - // Just advance one column, of course. - ++col; - } - else - { - ++p; - ++col; - } - break; - } - } - cursor.row = row; - cursor.col = col; - assert( cursor.row >= -1 ); - assert( cursor.col >= -1 ); - stamp = p; - assert( stamp ); -} - - -const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) -{ - if ( !p || !*p ) - { - return 0; - } - if ( encoding == TIXML_ENCODING_UTF8 ) - { - while ( *p ) - { - const unsigned char* pU = (const unsigned char*)p; - - // Skip the stupid Microsoft UTF-8 Byte order marks - if ( *(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==TIXML_UTF_LEAD_1 - && *(pU+2)==TIXML_UTF_LEAD_2 ) - { - p += 3; - continue; - } - else if(*(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==0xbfU - && *(pU+2)==0xbeU ) - { - p += 3; - continue; - } - else if(*(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==0xbfU - && *(pU+2)==0xbfU ) - { - p += 3; - continue; - } - - if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. - ++p; - else - break; - } - } - else - { - while ( *p && IsWhiteSpace( *p ) ) - ++p; - } - - return p; -} - -#ifdef TIXML_USE_STL -/*static*/ bool TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) -{ - for( ;; ) - { - if ( !in->good() ) return false; - - int c = in->peek(); - // At this scope, we can't get to a document. So fail silently. - if ( !IsWhiteSpace( c ) || c <= 0 ) - return true; - - *tag += (char) in->get(); - } -} - -/*static*/ bool TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) -{ - //assert( character > 0 && character < 128 ); // else it won't work in utf-8 - while ( in->good() ) - { - int c = in->peek(); - if ( c == character ) - return true; - if ( c <= 0 ) // Silent failure: can't get document at this scope - return false; - - in->get(); - *tag += (char) c; - } - return false; -} -#endif - -// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The -// "assign" optimization removes over 10% of the execution time. -// -const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) -{ - // Oddly, not supported on some comilers, - //name->clear(); - // So use this: - *name = ""; - assert( p ); - - // Names start with letters or underscores. - // Of course, in unicode, tinyxml has no idea what a letter *is*. The - // algorithm is generous. - // - // After that, they can be letters, underscores, numbers, - // hyphens, or colons. (Colons are valid ony for namespaces, - // but tinyxml can't tell namespaces from names.) - if ( p && *p - && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) - { - const char* start = p; - while( p && *p - && ( IsAlphaNum( (unsigned char ) *p, encoding ) - || *p == '_' - || *p == '-' - || *p == '.' - || *p == ':' ) ) - { - //(*name) += *p; // expensive - ++p; - } - if ( p-start > 0 ) { - name->assign( start, p-start ); - } - return p; - } - return 0; -} - -const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) -{ - // Presume an entity, and pull it out. - TIXML_STRING ent; - int i; - *length = 0; - - if ( *(p+1) && *(p+1) == '#' && *(p+2) ) - { - unsigned long ucs = 0; - ptrdiff_t delta = 0; - unsigned mult = 1; - - if ( *(p+2) == 'x' ) - { - // Hexadecimal. - if ( !*(p+3) ) return 0; - - const char* q = p+3; - q = strchr( q, ';' ); - - if ( !q || !*q ) return 0; - - delta = q-p; - --q; - - while ( *q != 'x' ) - { - if ( *q >= '0' && *q <= '9' ) - ucs += mult * (*q - '0'); - else if ( *q >= 'a' && *q <= 'f' ) - ucs += mult * (*q - 'a' + 10); - else if ( *q >= 'A' && *q <= 'F' ) - ucs += mult * (*q - 'A' + 10 ); - else - return 0; - mult *= 16; - --q; - } - } - else - { - // Decimal. - if ( !*(p+2) ) return 0; - - const char* q = p+2; - q = strchr( q, ';' ); - - if ( !q || !*q ) return 0; - - delta = q-p; - --q; - - while ( *q != '#' ) - { - if ( *q >= '0' && *q <= '9' ) - ucs += mult * (*q - '0'); - else - return 0; - mult *= 10; - --q; - } - } - if ( encoding == TIXML_ENCODING_UTF8 ) - { - // convert the UCS to UTF-8 - ConvertUTF32ToUTF8( ucs, value, length ); - } - else - { - *value = (char)ucs; - *length = 1; - } - return p + delta + 1; - } - - // Now try to match it. - for( i=0; iappend( cArr, len ); - } - } - else - { - bool whitespace = false; - - // Remove leading white space: - p = SkipWhiteSpace( p, encoding ); - while ( p && *p - && !StringEqual( p, endTag, caseInsensitive, encoding ) ) - { - if ( *p == '\r' || *p == '\n' ) - { - whitespace = true; - ++p; - } - else if ( IsWhiteSpace( *p ) ) - { - whitespace = true; - ++p; - } - else - { - // If we've found whitespace, add it before the - // new character. Any whitespace just becomes a space. - if ( whitespace ) - { - (*text) += ' '; - whitespace = false; - } - int len; - char cArr[4] = { 0, 0, 0, 0 }; - p = GetChar( p, cArr, &len, encoding ); - if ( len == 1 ) - (*text) += cArr[0]; // more efficient - else - text->append( cArr, len ); - } - } - } - if ( p && *p ) - p += strlen( endTag ); - return ( p && *p ) ? p : 0; -} - -#ifdef TIXML_USE_STL - -void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - // The basic issue with a document is that we don't know what we're - // streaming. Read something presumed to be a tag (and hope), then - // identify it, and call the appropriate stream method on the tag. - // - // This "pre-streaming" will never read the closing ">" so the - // sub-tag can orient itself. - - if ( !StreamTo( in, '<', tag ) ) - { - SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - - while ( in->good() ) - { - int tagIndex = (int) tag->length(); - while ( in->good() && in->peek() != '>' ) - { - int c = in->get(); - if ( c <= 0 ) - { - SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - break; - } - (*tag) += (char) c; - } - - if ( in->good() ) - { - // We now have something we presume to be a node of - // some sort. Identify it, and call the node to - // continue streaming. - TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); - - if ( node ) - { - node->StreamIn( in, tag ); - bool isElement = node->ToElement() != 0; - delete node; - node = 0; - - // If this is the root element, we're done. Parsing will be - // done by the >> operator. - if ( isElement ) - { - return; - } - } - else - { - SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - } - } - // We should have returned sooner. - SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); -} - -#endif - -const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) -{ - ClearError(); - - // Parse away, at the document level. Since a document - // contains nothing but other tags, most of what happens - // here is skipping white space. - if ( !p || !*p ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - // Note that, for a document, this needs to come - // before the while space skip, so that parsing - // starts from the pointer we are given. - location.Clear(); - if ( prevData ) - { - location.row = prevData->cursor.row; - location.col = prevData->cursor.col; - } - else - { - location.row = 0; - location.col = 0; - } - TiXmlParsingData data( p, TabSize(), location.row, location.col ); - location = data.Cursor(); - - if ( encoding == TIXML_ENCODING_UNKNOWN ) - { - // Check for the Microsoft UTF-8 lead bytes. - const unsigned char* pU = (const unsigned char*)p; - if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 - && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 - && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) - { - encoding = TIXML_ENCODING_UTF8; - useMicrosoftBOM = true; - } - } - - p = SkipWhiteSpace( p, encoding ); - if ( !p ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - while ( p && *p ) - { - TiXmlNode* node = Identify( p, encoding ); - if ( node ) - { - p = node->Parse( p, &data, encoding ); - LinkEndChild( node ); - } - else - { - break; - } - - // Did we get encoding info? - if ( encoding == TIXML_ENCODING_UNKNOWN - && node->ToDeclaration() ) - { - TiXmlDeclaration* dec = node->ToDeclaration(); - const char* enc = dec->Encoding(); - assert( enc ); - - if ( *enc == 0 ) - encoding = TIXML_ENCODING_UTF8; - else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) - encoding = TIXML_ENCODING_UTF8; - else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) - encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice - else - encoding = TIXML_ENCODING_LEGACY; - } - - p = SkipWhiteSpace( p, encoding ); - } - - // Was this empty? - if ( !firstChild ) { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); - return 0; - } - - // All is well. - return p; -} - -void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - // The first error in a chain is more accurate - don't set again! - if ( error ) - return; - - assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); - error = true; - errorId = err; - errorDesc = errorString[ errorId ]; - - errorLocation.Clear(); - if ( pError && data ) - { - data->Stamp( pError, encoding ); - errorLocation = data->Cursor(); - } -} - - -TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) -{ - TiXmlNode* returnNode = 0; - - p = SkipWhiteSpace( p, encoding ); - if( !p || !*p || *p != '<' ) - { - return 0; - } - - p = SkipWhiteSpace( p, encoding ); - - if ( !p || !*p ) - { - return 0; - } - - // What is this thing? - // - Elements start with a letter or underscore, but xml is reserved. - // - Comments: "; - - if ( !StringEqual( p, startTag, false, encoding ) ) - { - if ( document ) - document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); - return 0; - } - p += strlen( startTag ); - - // [ 1475201 ] TinyXML parses entities in comments - // Oops - ReadText doesn't work, because we don't want to parse the entities. - // p = ReadText( p, &value, false, endTag, false, encoding ); - // - // from the XML spec: - /* - [Definition: Comments may appear anywhere in a document outside other markup; in addition, - they may appear within the document type declaration at places allowed by the grammar. - They are not part of the document's character data; an XML processor MAY, but need not, - make it possible for an application to retrieve the text of comments. For compatibility, - the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity - references MUST NOT be recognized within comments. - - An example of a comment: - - - */ - - value = ""; - // Keep all the white space. - while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) - { - value.append( p, 1 ); - ++p; - } - if ( p && *p ) - p += strlen( endTag ); - - return p; -} - - -const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p ) return 0; - - if ( data ) - { - data->Stamp( p, encoding ); - location = data->Cursor(); - } - // Read the name, the '=' and the value. - const char* pErr = p; - p = ReadName( p, &name, encoding ); - if ( !p || !*p ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); - return 0; - } - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p || *p != '=' ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - - ++p; // skip '=' - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - - const char* end; - const char SINGLE_QUOTE = '\''; - const char DOUBLE_QUOTE = '\"'; - - if ( *p == SINGLE_QUOTE ) - { - ++p; - end = "\'"; // single quote in string - p = ReadText( p, &value, false, end, false, encoding ); - } - else if ( *p == DOUBLE_QUOTE ) - { - ++p; - end = "\""; // double quote in string - p = ReadText( p, &value, false, end, false, encoding ); - } - else - { - // All attribute values should be in single or double quotes. - // But this is such a common error that the parser will try - // its best, even without them. - value = ""; - while ( p && *p // existence - && !IsWhiteSpace( *p ) // whitespace - && *p != '/' && *p != '>' ) // tag end - { - if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { - // [ 1451649 ] Attribute values with trailing quotes not handled correctly - // We did not have an opening quote but seem to have a - // closing one. Give up and throw an error. - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - value += *p; - ++p; - } - } - return p; -} - -#ifdef TIXML_USE_STL -void TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - while ( in->good() ) - { - int c = in->peek(); - if ( !cdata && (c == '<' ) ) - { - return; - } - if ( c <= 0 ) - { - TiXmlDocument* document = GetDocument(); - if ( document ) - document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - - (*tag) += (char) c; - in->get(); // "commits" the peek made above - - if ( cdata && c == '>' && tag->size() >= 3 ) { - size_t len = tag->size(); - if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { - // terminator of cdata. - return; - } - } - } -} -#endif - -const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - value = ""; - TiXmlDocument* document = GetDocument(); - - if ( data ) - { - data->Stamp( p, encoding ); - location = data->Cursor(); - } - - const char* const startTag = ""; - - if ( cdata || StringEqual( p, startTag, false, encoding ) ) - { - cdata = true; - - if ( !StringEqual( p, startTag, false, encoding ) ) - { - if ( document ) - document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); - return 0; - } - p += strlen( startTag ); - - // Keep all the white space, ignore the encoding, etc. - while ( p && *p - && !StringEqual( p, endTag, false, encoding ) - ) - { - value += *p; - ++p; - } - - TIXML_STRING dummy; - p = ReadText( p, &dummy, false, endTag, false, encoding ); - return p; - } - else - { - bool ignoreWhite = true; - - const char* end = "<"; - p = ReadText( p, &value, ignoreWhite, end, false, encoding ); - if ( p && *p ) - return p-1; // don't truncate the '<' - return 0; - } -} - -#ifdef TIXML_USE_STL -void TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - while ( in->good() ) - { - int c = in->get(); - if ( c <= 0 ) - { - TiXmlDocument* document = GetDocument(); - if ( document ) - document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - (*tag) += (char) c; - - if ( c == '>' ) - { - // All is well. - return; - } - } -} -#endif - -const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) -{ - p = SkipWhiteSpace( p, _encoding ); - // Find the beginning, find the end, and look for - // the stuff in-between. - TiXmlDocument* document = GetDocument(); - if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); - return 0; - } - if ( data ) - { - data->Stamp( p, _encoding ); - location = data->Cursor(); - } - p += 5; - - version = ""; - encoding = ""; - standalone = ""; - - while ( p && *p ) - { - if ( *p == '>' ) - { - ++p; - return p; - } - - p = SkipWhiteSpace( p, _encoding ); - if ( StringEqual( p, "version", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - version = attrib.Value(); - } - else if ( StringEqual( p, "encoding", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - encoding = attrib.Value(); - } - else if ( StringEqual( p, "standalone", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - standalone = attrib.Value(); - } - else - { - // Read over whatever it is. - while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) - ++p; - } - } - return 0; -} - -bool TiXmlText::Blank() const -{ - for ( unsigned i=0; i +#include "Utils.h" using namespace std; +using namespace tinyxml2; string xmlAddressDecoder::addressConfigURI = ""; xmlAddressDecoder::xmlAddressDecoder(string addressConfigURI) { - doc = new TiXmlDocument(addressConfigURI.c_str()); - if (doc->LoadFile()) - { - dramconfig = doc->FirstChildElement("dramconfig"); - addressmap = dramconfig->FirstChildElement("addressmap"); + doc = new XMLDocument(); + loadXML(addressConfigURI,*doc); + addressmap = doc->FirstChildElement("dramconfig")->FirstChildElement("addressmap"); - unsigned int from; - unsigned int to; + int from; + int to; - // get channel: -// TiXmlElement* channel = addressmap->FirstChildElement("channel"); -// -// -// from = getAttribute(channel, "from"); -// to = getAttribute(channel, "to"); -// -// channelShift = from; -// channelMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); -// channelSize = pow(2.0, to - from + 1.0); + // get channel: + // TiXmlElement* channel = addressmap->FirstChildElement("channel"); + // + // + // from = getAttribute(channel, "from"); + // to = getAttribute(channel, "to"); + // + // channelShift = from; + // channelMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + // channelSize = pow(2.0, to - from + 1.0); - // get row: - TiXmlElement* row = addressmap->FirstChildElement("row"); + // get row: + XMLElement* row = addressmap->FirstChildElement("row"); + row->QueryIntAttribute("from",&from); + row->QueryIntAttribute("to",&to); - from = getAttribute(row, "from"); - to = getAttribute(row, "to"); + rowShift = from; + rowMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + rowSize = pow(2.0, to - from + 1.0); - rowShift = from; - rowMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - rowSize = pow(2.0, to - from + 1.0); + // get bank: + XMLElement* bank = addressmap->FirstChildElement("bank"); - // get bank: - TiXmlElement* bank = addressmap->FirstChildElement("bank"); + bank->QueryIntAttribute("from",&from); + bank->QueryIntAttribute("to",&to); - from = getAttribute(bank, "from"); - to = getAttribute(bank, "to"); + bankShift = from; + bankMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + bankSize = pow(2.0, to - from + 1.0); - bankShift = from; - bankMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - bankSize = pow(2.0, to - from + 1.0); + // get colum: + XMLElement* colum = addressmap->FirstChildElement("colum"); - // get colum: - TiXmlElement* colum = addressmap->FirstChildElement("colum"); + colum->QueryIntAttribute("from",&from); + colum->QueryIntAttribute("to",&to); - from = getAttribute(colum, "from"); - to = getAttribute(colum, "to"); + columShift = from; + columMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + columSize = pow(2.0, to - from + 1.0); - columShift = from; - columMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - columSize = pow(2.0, to - from + 1.0); + // get bytes: + // TiXmlElement* bytes = addressmap->FirstChildElement("bytes"); + // + // from = getAttribute(bytes, "from"); + // to = getAttribute(bytes, "to"); - // get bytes: -// TiXmlElement* bytes = addressmap->FirstChildElement("bytes"); -// -// from = getAttribute(bytes, "from"); -// to = getAttribute(bytes, "to"); + // bytesShift = from; + // bytesMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + // bytesSize = pow(2.0, to - from + 1.0); -// bytesShift = from; -// bytesMask = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); -// bytesSize = pow(2.0, to - from + 1.0); - } - else - { - SC_REPORT_FATAL("xmlAddressDecoder can not find ", addressConfigURI.c_str()); - } } xmlAddressDecoder::~xmlAddressDecoder() { - delete doc; + delete doc; } void xmlAddressDecoder::getNode(unsigned int addr, node * n) { - n->channel = 0; - n->row = (addr & rowMask) >> rowShift; - n->bank = (addr & bankMask) >> bankShift; - n->colum = (addr & columMask) >> columShift; + n->channel = 0; + n->row = (addr & rowMask) >> rowShift; + n->bank = (addr & bankMask) >> bankShift; + n->colum = (addr & columMask) >> columShift; } void xmlAddressDecoder::getBRC(unsigned int addr, unsigned int &bank, unsigned int &row, - unsigned int &colum) + unsigned int &colum) { - row = (addr & rowMask) >> rowShift; - bank = (addr & bankMask) >> bankShift; - colum = (addr & columMask) >> columShift; + row = (addr & rowMask) >> rowShift; + bank = (addr & bankMask) >> bankShift; + colum = (addr & columMask) >> columShift; } void xmlAddressDecoder::getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank, - unsigned int &row, unsigned int &colum) + unsigned int &row, unsigned int &colum) { - channel = (addr & channelMask) >> channelShift; - getBRC(addr, bank, row, colum); + channel = (addr & channelMask) >> channelShift; + getBRC(addr, bank, row, colum); } void xmlAddressDecoder::getC(unsigned int addr, unsigned int &channel) { - channel = (addr & channelMask) >> channelShift; + channel = (addr & channelMask) >> channelShift; } unsigned int xmlAddressDecoder::getNumberOfBanks() { - return bankSize; + return bankSize; } unsigned int xmlAddressDecoder::getNumberOfRowsPerBank() { - return rowSize; + return rowSize; } unsigned int xmlAddressDecoder::getNumberOfColumsPerRow() { - return columSize; + return columSize; } unsigned int xmlAddressDecoder::getNumberOfBytesPerColumn() { - return 1; + return 1; } diff --git a/dram/src/common/xmlAddressdecoder.h b/dram/src/common/xmlAddressdecoder.h index 61546dde..f6fa9e2a 100755 --- a/dram/src/common/xmlAddressdecoder.h +++ b/dram/src/common/xmlAddressdecoder.h @@ -9,7 +9,7 @@ // /// \file /// \brief XML address decoder -/// \author Matthias Jung +/// \author Matthias Jung /// \date 02.07.2012 // @@ -19,72 +19,63 @@ #include #include -#include "third_party/tinyxml.h" +#include "third_party/tinyxml2.h" struct node { - unsigned int channel; - unsigned int row; - unsigned int bank; - unsigned int colum; - tlm::tlm_command command; - tlm::tlm_phase phase; + unsigned int channel; + unsigned int row; + unsigned int bank; + unsigned int colum; + tlm::tlm_command command; + tlm::tlm_phase phase; }; class xmlAddressDecoder { public: - static std::string addressConfigURI; + static std::string addressConfigURI; - static inline xmlAddressDecoder& getInstance() - { - static xmlAddressDecoder decoder(xmlAddressDecoder::addressConfigURI); - return decoder; - } + static inline xmlAddressDecoder& getInstance() + { + static xmlAddressDecoder decoder(xmlAddressDecoder::addressConfigURI); + return decoder; + } - void getNode(unsigned int addr, node * n); - void getBRC(unsigned int addr, unsigned int &bank, unsigned int &row, unsigned int &colum); - void getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank, unsigned int &row, unsigned int &colum); - void getC(unsigned int addr, unsigned int &channel); - unsigned int getNumberOfBanks(); - unsigned int getNumberOfRowsPerBank(); - unsigned int getNumberOfColumsPerRow(); - unsigned int getNumberOfBytesPerColumn(); + void getNode(unsigned int addr, node * n); + void getBRC(unsigned int addr, unsigned int &bank, unsigned int &row, unsigned int &colum); + void getCBRC(unsigned int addr, unsigned int &channel, unsigned int &bank, unsigned int &row, unsigned int &colum); + void getC(unsigned int addr, unsigned int &channel); + unsigned int getNumberOfBanks(); + unsigned int getNumberOfRowsPerBank(); + unsigned int getNumberOfColumsPerRow(); + unsigned int getNumberOfBytesPerColumn(); private: - xmlAddressDecoder(std::string URI); - ~xmlAddressDecoder(); + xmlAddressDecoder(std::string URI); + ~xmlAddressDecoder(); - unsigned int channelMask; - unsigned int rowMask; - unsigned int bankMask; - unsigned int columMask; - unsigned int bytesMask; + unsigned int channelMask; + unsigned int rowMask; + unsigned int bankMask; + unsigned int columMask; + unsigned int bytesMask; - unsigned int channelShift; - unsigned int rowShift; - unsigned int bankShift; - unsigned int columShift; - unsigned int bytesShift; + unsigned int channelShift; + unsigned int rowShift; + unsigned int bankShift; + unsigned int columShift; + unsigned int bytesShift; - unsigned int channelSize; - unsigned int bankSize; - unsigned int rowSize; - unsigned int columSize; - unsigned int bytesSize; + unsigned int channelSize; + unsigned int bankSize; + unsigned int rowSize; + unsigned int columSize; + unsigned int bytesSize; - TiXmlDocument * doc; - TiXmlElement * dramconfig; - TiXmlElement * addressmap; - - template - T getAttribute(TiXmlElement * element, const std::string s) - { - T d; - element->QueryValueAttribute(s, &d); - return d; - } + tinyxml2::XMLDocument * doc; + tinyxml2::XMLElement* addressmap; }; #endif diff --git a/dram/src/controller/Controller.h b/dram/src/controller/Controller.h new file mode 100644 index 00000000..260ab5ca --- /dev/null +++ b/dram/src/controller/Controller.h @@ -0,0 +1,423 @@ +/* + * ControllerWrapper.h + * + * Created on: Mar 15, 2014 + * Author: gernhard + */ + +#ifndef CONTROLLERWRAPPER_H_ +#define CONTROLLERWRAPPER_H_ + +//#include +//#include +//#include +//#include +//#include +#include +#include +#include + +//#include +#include "/opt/systemc-2.3.0/include/systemc" +#include "/opt/systemc-2.3.0/include/tlm" +#include "/opt/systemc-2.3.0/include/tlm_utils/peq_with_cb_and_phase.h" +#include "/opt/systemc-2.3.0/include/tlm_utils/simple_initiator_socket.h" +#include "/opt/systemc-2.3.0/include/tlm_utils/simple_target_socket.h" +#include "../common/dramExtension.h" +#include "../common/DebugManager.h" +#include "../common/protocol.h" +#include "../common/TlmRecorder.h" +#include "../common/Utils.h" +#include "core/configuration/Configuration.h" +#include "core/configuration/TimingConfiguration.h" +#include "core/Command.h" +#include "core/ControllerCore.h" +#include "core/ControllerState.h" +#include "core/IWrapperConnector.h" +#include "core/powerdown/IPowerDownManager.h" +#include "core/scheduling/ScheduledCommand.h" +#include "core/scheduling/Trigger.h" +#include "core/TimingCalculation.h" +#include "scheduler/Fifo.h" +#include "scheduler/Fr_Fcfs.h" +#include "scheduler/PARBS.h" + +using namespace std; +using namespace tlm; +using namespace core; +using namespace scheduler; + +template +struct Controller: public sc_module, public IWrapperConnector +{ +public: + + tlm_utils::simple_initiator_socket iSocket; + tlm_utils::simple_target_socket tSocket; + + Controller(sc_module_name name) : + frontendPEQ(this, &Controller::frontendPEQCallback), dramPEQ(this, &Controller::dramPEQCallback), controllerCorePEQ( + this, &Controller::controllerCorePEQCallback), debugManager(DebugManager::getInstance()) + { + controller = new ControllerCore(*this, numberOfPayloadsInSystem); + buildScheduler(); + iSocket.register_nb_transport_bw(this, &Controller::nb_transport_bw); + tSocket.register_nb_transport_fw(this, &Controller::nb_transport_fw); + } + + void buildScheduler() + { + string selectedScheduler = Configuration::getInstance().Scheduler; + + if (selectedScheduler == "FR_FCFS") + { + + scheduler = new FR_FCFS(controller->state.bankStates, Configuration::getInstance().RefreshAwareScheduling, + Configuration::getInstance().AdaptiveOpenPagePolicy); + } + else if (selectedScheduler == "PAR_BS") + { + scheduler = new PAR_BS(controller->state.bankStates, Configuration::getInstance().RefreshAwareScheduling, + Configuration::getInstance().Capsize); + } + else if (selectedScheduler == "FIFO") + scheduler = new Fifo(); + else + reportFatal(name(), "unsupported scheduler: " + selectedScheduler); + } + + ~Controller() + { + delete controller; + delete scheduler; + } + + void terminateSimulation() + { + for (Bank bank : controller->getBanks()) + { + controller->powerDownManager->wakeUp(bank, clkAlign(sc_time_stamp())); + } + } + + // ------- Interaction with controller core --------- + virtual void send(const ScheduledCommand& command, tlm_generic_payload& payload) override + { + sc_assert(command.getStart() >= sc_time_stamp()); + TimeInterval dataStrobe; + + switch (command.getCommand()) + { + case Command::Read: + dataStrobe = command.getIntervalOnDataStrobe(); + TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); + controllerCorePEQ.notify(payload, BEGIN_RD, command.getStart() - sc_time_stamp()); + break; + case Command::ReadA: + dataStrobe = command.getIntervalOnDataStrobe(); + TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); + controllerCorePEQ.notify(payload, BEGIN_RDA, command.getStart() - sc_time_stamp()); + break; + case Command::Write: + dataStrobe = command.getIntervalOnDataStrobe(); + TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); + controllerCorePEQ.notify(payload, BEGIN_WR, command.getStart() - sc_time_stamp()); + break; + case Command::WriteA: + dataStrobe = command.getIntervalOnDataStrobe(); + TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); + controllerCorePEQ.notify(payload, BEGIN_WRA, command.getStart() - sc_time_stamp()); + break; + case Command::AutoRefresh: + controllerCorePEQ.notify(payload, BEGIN_AUTO_REFRESH, command.getStart() - sc_time_stamp()); + break; + case Command::Activate: + controllerCorePEQ.notify(payload, BEGIN_ACT, command.getStart() - sc_time_stamp()); + break; + case Command::Precharge: + controllerCorePEQ.notify(payload, BEGIN_PRE, command.getStart() - sc_time_stamp()); + break; + case Command::PrechargeAll: + controllerCorePEQ.notify(payload, BEGIN_PRE_ALL, command.getStart() - sc_time_stamp()); + break; + case Command::PDNA: + controllerCorePEQ.notify(payload, BEGIN_PDNA, command.getStart() - sc_time_stamp()); + break; + case Command::PDNP: + controllerCorePEQ.notify(payload, BEGIN_PDNP, command.getStart() - sc_time_stamp()); + break; + case Command::SREF: + controllerCorePEQ.notify(payload, BEGIN_SREF, command.getStart() - sc_time_stamp()); + break; + case Command::PDNAX: + controllerCorePEQ.notify(payload, END_PDNA, command.getEnd() - sc_time_stamp()); + break; + case Command::PDNPX: + controllerCorePEQ.notify(payload, END_PDNP, command.getEnd() - sc_time_stamp()); + break; + case Command::SREFX: + controllerCorePEQ.notify(payload, END_SREF, command.getEnd() - sc_time_stamp()); + break; + + default: + SC_REPORT_FATAL(0, "unsupported command was sent by controller"); + break; + } + } + + virtual void send(Trigger trigger, sc_time time, tlm_generic_payload& payload) override + { + sc_assert(time >= sc_time_stamp()); + + sc_time delay = time - sc_time_stamp(); + if (trigger == Trigger::REFTrigger) + { + controllerCorePEQ.notify(payload, REF_TRIGGER, delay); + } + else if (trigger == Trigger::PDNTrigger) + { + controllerCorePEQ.notify(payload, PDN_TRIGGER, delay); + } + else + { + SC_REPORT_FATAL("controller wrapper", "unknown trigger"); + } + } + + void controllerCorePEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) + { + if (phase == REF_TRIGGER) + { + controller->triggerRefresh(payload, sc_time_stamp()); + } + else if (phase == PDN_TRIGGER) + { + controller->powerDownManager->sleep(DramExtension::getExtension(payload).getBank(),sc_time_stamp()); + } + else + { + Bank bank = DramExtension::getExtension(payload).getBank(); + sendToDram(payload, phase, SC_ZERO_TIME); + + if (phase == BEGIN_RD || phase == BEGIN_WR) + scheduleNextPayload(bank); + else if (phase == BEGIN_AUTO_REFRESH) + printDebugMessage("Entering auto refresh on bank " + to_string(bank.ID())); + else if (isIn(phase, { BEGIN_PDNA, BEGIN_PDNP, BEGIN_SREF })) + printDebugMessage("Entering PowerDown " + phaseNameToString(phase) + " on bank " + to_string(bank.ID())); + else if (isIn(phase, { END_PDNA, END_PDNP, END_SREF })) + printDebugMessage("Leaving PowerDown " + phaseNameToString(phase) + " on bank " + to_string(bank.ID())); + else if (isIn(phase, { BEGIN_RD, BEGIN_WR, BEGIN_ACT, BEGIN_PRE, BEGIN_PRE_ALL, BEGIN_RDA, BEGIN_WRA })) + { + } + else + SC_REPORT_FATAL(0, "refreshTriggerPEQCallback queue in controller wrapper was triggered with unsupported phase"); + } + } + +private: + ControllerCore* controller; + Scheduler* scheduler; + std::map numberOfPayloadsInSystem; + + tlm::tlm_generic_payload* backpressure = NULL; + + tlm_utils::peq_with_cb_and_phase frontendPEQ; + tlm_utils::peq_with_cb_and_phase dramPEQ; + tlm_utils::peq_with_cb_and_phase controllerCorePEQ; + + DebugManager& debugManager; + + // --- FRONTEND INTERACTION ------ + tlm_sync_enum nb_transport_fw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& fwDelay) + { + if (phase == BEGIN_REQ) + { + TlmRecorder::getInstance().recordPhase(payload, phase, fwDelay + sc_time_stamp()); + frontendPEQ.notify(payload, phase, + clkAlign(sc_time_stamp() + fwDelay) - (sc_time_stamp() + fwDelay) + Configuration::getInstance().Timings.clk); + } + else if (phase == END_RESP) + { + TlmRecorder::getInstance().recordPhase(payload, phase, + fwDelay + sc_time_stamp() + Configuration::getInstance().Timings.clk); + frontendPEQ.notify(payload, phase, clkAlign(sc_time_stamp() + fwDelay) - (sc_time_stamp() + fwDelay)); + } + return TLM_ACCEPTED; + } + + void frontendPEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) + { + if (phase == BEGIN_REQ) + { + payload.acquire(); + payloadEntersSystem(payload); + if (getTotalNumberOfPayloadsInSystem() > controller->config.MaxNrOfTransactions) + { + printDebugMessage("##Backpressure: Max number of transactions in system reached"); + backpressure = &payload; + return; + } + payload.set_response_status(tlm::TLM_OK_RESPONSE); + sendToFrontend(payload, END_REQ, SC_ZERO_TIME); + scheduler->schedule(&payload); + scheduleNextPayload(DramExtension::getExtension(payload).getBank()); + } + else if (phase == END_RESP) + { + if (backpressure != NULL) + { + printDebugMessage("##Backpressure released"); + backpressure->set_response_status(tlm::TLM_OK_RESPONSE); + sendToFrontend(*backpressure, END_REQ, SC_ZERO_TIME); + scheduler->schedule(backpressure); + scheduleNextPayload(DramExtension::getExtension(backpressure).getBank()); + backpressure = NULL; + } + payloadLeavesSystem(payload); + payload.release(); + } + else + { + SC_REPORT_FATAL(0, "Frontend PEQ event queue in controller wrapper was triggered with unknown phase"); + } + } + + void payloadEntersSystem(tlm_generic_payload& payload) + { + Bank bank = DramExtension::getExtension(payload).getBank(); + printDebugMessage( + "Payload enters system on bank " + to_string(bank.ID()) + ". Total number of payloads in Controller: " + + to_string(getTotalNumberOfPayloadsInSystem())); + numberOfPayloadsInSystem[bank]++; + } + + void payloadLeavesSystem(tlm_generic_payload& payload) + { + Bank bank = DramExtension::getExtension(payload).getBank(); + numberOfPayloadsInSystem[bank]--; + printDebugMessage( + "Payload left system on bank " + to_string(bank.ID()) + ". Total number of payloads in Controller: " + + to_string(getTotalNumberOfPayloadsInSystem())); + controller->powerDownManager->triggerSleep(bank, sc_time_stamp()); + + } + + unsigned int getTotalNumberOfPayloadsInSystem() + { + unsigned int sum = 0; + for (Bank bank : controller->getBanks()) + { + sum += numberOfPayloadsInSystem[bank]; + } + return sum; + } + + void scheduleNextPayload(Bank bank) + { + printDebugMessage("Triggering schedule next payload on bank " + to_string(bank.ID())); + if (scheduler->hasTransactionForBank(bank)) + { + controller->powerDownManager->wakeUp(bank, sc_time_stamp()); + + if (controller->isBusy(sc_time_stamp(), bank)) + { + printDebugMessage("\t-> break: controller is busy"); + return; + } + + tlm_generic_payload* nextTransaction = scheduler->getTransactionForBank(bank); + if (controller->scheduleRequest(sc_time_stamp(), *nextTransaction)) + { + scheduler->popTransactionForBank(bank, nextTransaction); + printDebugMessage("\t-> payload was scheduled by core"); + } + else + { + printDebugMessage("\t-> break: payload was not scheduled by core (collision with refresh)"); + } + } + else + { + printDebugMessage("\t-> break: no transaction for bank"); + controller->powerDownManager->sleep(bank, sc_time_stamp()); + } + } + + void sendToFrontend(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + tSocket->nb_transport_bw(payload, TPhase, TDelay); + } + + // --- DRAM INTERACTION ------ + tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) + { + dramPEQ.notify(payload, phase, bwDelay); + TlmRecorder::getInstance().recordPhase(payload, phase, bwDelay + sc_time_stamp()); + return TLM_ACCEPTED; + } + + void dramPEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) + { + Bank bank = DramExtension::getExtension(payload).getBank(); + printDebugMessage("Received " + phaseNameToString(phase) + " on bank " + to_string(bank.ID()) + " from DRAM"); + + if (phase == BEGIN_RD || phase == BEGIN_WR) + { + scheduleNextPayload(bank); + sendToDram(payload, phase, SC_ZERO_TIME); + } + else if (phase == END_RD || phase == END_WR) + { + sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); + } + else if (phase == END_RDA || phase == END_WRA) + { + sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); + scheduleNextPayload(bank); + } + else if (phase == END_AUTO_REFRESH) + { + printDebugMessage("Finished auto refresh on bank " + to_string(bank.ID())); + scheduleNextPayload(DramExtension::getExtension(payload).getBank()); + } + else if (isIn(phase, { END_PRE, END_PRE_ALL, END_ACT })) + { + + } + else + { + string str = string("dramPEQCallback queue in controller wrapper was triggered with unsupported phase ") + + phaseNameToString(phase); + SC_REPORT_FATAL(0, str.c_str()); + } + } + + void sendToDram(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + iSocket->nb_transport_fw(payload, TPhase, TDelay); + } + + //Helpers + void printDebugMessage(string message) + { + debugManager.printDebugMessage(name(), message); + } + + bool isIn(tlm_phase phase, std::vector phases) + { + for (tlm_phase p : phases) + { + if (p == phase) + return true; + } + return false; + } + +}; + +#endif /* CONTROLLERWRAPPER_H_ */ diff --git a/dram/src/controller/core/BankStates.cpp b/dram/src/controller/core/BankStates.cpp new file mode 100644 index 00000000..d6af44ee --- /dev/null +++ b/dram/src/controller/core/BankStates.cpp @@ -0,0 +1,68 @@ +/* + * BankStates.cpp + * + * Created on: Feb 24, 2014 + * Author: robert + */ + +#include "BankStates.h" +#include "ControllerCore.h" +#include "../../common/DebugManager.h" +#include "../../common/Utils.h" + +using namespace std; + +namespace core +{ + +BankStates::BankStates() +{ + closeAllRowBuffers(); +} + +BankStates::~BankStates() +{ +} + +bool BankStates::rowBufferIsOpen(Bank bank) const +{ + return getElementFromMap(rowsInRowBuffers,bank) != Row::NO_ROW; +} + +Row BankStates::getRowInRowBuffer(Bank bank) const +{ + return getElementFromMap(rowsInRowBuffers,bank); +} + +void BankStates::openRowInRowBuffer(Bank bank,Row row) +{ + DebugManager::getInstance().printDebugMessage(ControllerCore::senderName, "Row buffer for bank " + to_string(bank.ID()) + " is now open"); + rowsInRowBuffers[bank] = row; +} + +void BankStates::closeRowBuffer(Bank bank) +{ + DebugManager::getInstance().printDebugMessage(ControllerCore::senderName, "Row buffer for bank " + to_string(bank.ID()) + " is now closed"); + rowsInRowBuffers[bank] = Row::NO_ROW; +} + +bool BankStates::allRowBuffersAreClosed() const +{ + for(unsigned int i=0; i +#include "../../common/dramExtension.h" + +namespace core +{ + +class BankStates { +public: + BankStates(); + virtual ~BankStates(); + + bool rowBufferIsOpen(Bank bank) const; + bool allRowBuffersAreClosed() const; + Row getRowInRowBuffer(Bank bank) const; + + void openRowInRowBuffer(Bank bank, Row row); + void closeRowBuffer(Bank bank); + void closeAllRowBuffers(); + +private: + std::map rowsInRowBuffers; +}; + +} + +#endif /* BANKSTATES_H_ */ diff --git a/dram/src/core/Command.cpp b/dram/src/controller/core/Command.cpp similarity index 100% rename from dram/src/core/Command.cpp rename to dram/src/controller/core/Command.cpp diff --git a/dram/src/core/Command.h b/dram/src/controller/core/Command.h similarity index 100% rename from dram/src/core/Command.h rename to dram/src/controller/core/Command.h diff --git a/dram/src/core/ControllerCore.cpp b/dram/src/controller/core/ControllerCore.cpp similarity index 98% rename from dram/src/core/ControllerCore.cpp rename to dram/src/controller/core/ControllerCore.cpp index abf8f997..adce3198 100644 --- a/dram/src/core/ControllerCore.cpp +++ b/dram/src/controller/core/ControllerCore.cpp @@ -16,12 +16,12 @@ #include "scheduling/checker/PowerDownChecker.h" #include "refresh/RefreshManagerBankwise.h" #include "refresh/RefreshManager.h" -#include "../common/dramExtension.h" -#include "../common/Utils.h" +#include "../../common/dramExtension.h" +#include "../../common/Utils.h" #include "powerdown/PowerDownManager.h" #include "powerdown/PowerDownManagerTimeout.h" #include "powerdown/PowerDownManagerBankwise.h" -#include "../common/DebugManager.h" +#include "../../common/DebugManager.h" namespace core { diff --git a/dram/src/core/ControllerCore.h b/dram/src/controller/core/ControllerCore.h similarity index 97% rename from dram/src/core/ControllerCore.h rename to dram/src/controller/core/ControllerCore.h index 1ab399c4..f47a9c29 100644 --- a/dram/src/core/ControllerCore.h +++ b/dram/src/controller/core/ControllerCore.h @@ -17,7 +17,7 @@ #include "scheduling/CommandSequenceGenerator.h" #include "scheduling/checker/ICommandChecker.h" #include "scheduling/CommandSequenceScheduler.h" -#include "../common/TlmRecorder.h" +#include "../../common/TlmRecorder.h" namespace core { diff --git a/dram/src/controller/core/ControllerState.cpp b/dram/src/controller/core/ControllerState.cpp new file mode 100644 index 00000000..9dfef89e --- /dev/null +++ b/dram/src/controller/core/ControllerState.cpp @@ -0,0 +1,112 @@ +/* + * controller_state.cpp + * + * Created on: Mar 5, 2014 + * Author: jonny + */ + +#include "ControllerState.h" +#include +#include "TimingCalculation.h" + +namespace core { + +const ScheduledCommand ControllerState::getLastCommand(Command command, Bank bank) //TODO const reference? and make const +{ + return lastCommandsOnBus[command][bank]; +} + +const ScheduledCommand ControllerState::getLastCommand(Command command) +{ + ScheduledCommand max; + + for (unsigned int i = 0; i < config->NumberOfBanks; ++i) + { + ScheduledCommand current = getLastCommand(command, Bank(i)); + if (current.getStart() > max.getStart()) + max = current; + } + return max; +} + +const ScheduledCommand ControllerState::getLastScheduledCommand() +{ + ScheduledCommand lastCommand; + + for(Command cmd : getAllCommands()) + { + for(Bank bank : Configuration::getInstance().getBanks()) + { + ScheduledCommand& current = lastCommandsOnBus[cmd][bank]; + if (current.getStart() > lastCommand.getStart()) + lastCommand = current; + } + } + + return lastCommand; +} + +const ScheduledCommand ControllerState::getLastScheduledCommand(Bank bank) +{ + ScheduledCommand lastCommand; + + for(Command cmd : getAllCommands()) + { + ScheduledCommand& current = lastCommandsOnBus[cmd][bank]; + if (current.getStart() > lastCommand.getStart()) + lastCommand = current; + } + + return lastCommand; +} + +void ControllerState::change(const ScheduledCommand& scheduledCommand) +{ + //TODO double check if slot free? + bus.blockSlot(scheduledCommand.getStart()); + lastCommandsOnBus[scheduledCommand.getCommand()][scheduledCommand.getBank()] = scheduledCommand; + + switch (scheduledCommand.getCommand()) + { + case Command::Read: + lastDataStrobeCommands.emplace_back(scheduledCommand); + break; + case Command::ReadA: + bankStates.closeRowBuffer(scheduledCommand.getBank()); + lastDataStrobeCommands.emplace_back(scheduledCommand); + break; + case Command::Write: + lastDataStrobeCommands.emplace_back(scheduledCommand); + break; + case Command::WriteA: + bankStates.closeRowBuffer(scheduledCommand.getBank()); + lastDataStrobeCommands.emplace_back(scheduledCommand); + break; + case Command::AutoRefresh: + break; + case Command::Activate: + bankStates.openRowInRowBuffer(scheduledCommand.getBank(), scheduledCommand.getRow()); + lastActivates.emplace(scheduledCommand.getStart(), scheduledCommand.getBank()); + break; + case Command::Precharge: + bankStates.closeRowBuffer(scheduledCommand.getBank()); + break; + case Command::PrechargeAll: + bankStates.closeAllRowBuffers(); + break; + case Command::SREF: + bankStates.closeRowBuffer(scheduledCommand.getBank()); + break; + default: + break; + } +} + +void ControllerState::cleanUp(sc_time time) +{ + bus.cleanUpSlots(time); + lastDataStrobeCommands.remove_if([&](ScheduledCommand command){return command.getEnd() < time && getDistance(command.getEnd(), time) > config->Timings.tDataStrobeHistory();}); + lastActivates.erase(lastActivates.begin(), lastActivates.lower_bound(time - config->Timings.tActHistory())); +} + +} /* namespace controller */ diff --git a/dram/src/core/ControllerState.h b/dram/src/controller/core/ControllerState.h similarity index 100% rename from dram/src/core/ControllerState.h rename to dram/src/controller/core/ControllerState.h diff --git a/dram/src/core/IWrapperConnector.h b/dram/src/controller/core/IWrapperConnector.h similarity index 100% rename from dram/src/core/IWrapperConnector.h rename to dram/src/controller/core/IWrapperConnector.h diff --git a/dram/src/core/Slots.cpp b/dram/src/controller/core/Slots.cpp similarity index 100% rename from dram/src/core/Slots.cpp rename to dram/src/controller/core/Slots.cpp diff --git a/dram/src/core/Slots.h b/dram/src/controller/core/Slots.h similarity index 100% rename from dram/src/core/Slots.h rename to dram/src/controller/core/Slots.h diff --git a/dram/src/core/TimingCalculation.cpp b/dram/src/controller/core/TimingCalculation.cpp similarity index 97% rename from dram/src/core/TimingCalculation.cpp rename to dram/src/controller/core/TimingCalculation.cpp index 048353a8..262f4000 100644 --- a/dram/src/core/TimingCalculation.cpp +++ b/dram/src/controller/core/TimingCalculation.cpp @@ -8,9 +8,9 @@ #include "TimingCalculation.h" #include "configuration/TimingConfiguration.h" #include "ControllerCore.h" -#include "../common/DebugManager.h" +#include "../../common/DebugManager.h" #include "configuration/Configuration.h" -#include "../common/Utils.h" +#include "../../common/Utils.h" namespace core { diff --git a/dram/src/core/TimingCalculation.h b/dram/src/controller/core/TimingCalculation.h similarity index 68% rename from dram/src/core/TimingCalculation.h rename to dram/src/controller/core/TimingCalculation.h index 3080069b..9dc66d28 100644 --- a/dram/src/core/TimingCalculation.h +++ b/dram/src/controller/core/TimingCalculation.h @@ -10,7 +10,7 @@ #include #include -#include "../common/dramExtension.h" +#include "../../common/dramExtension.h" #include "Command.h" namespace core @@ -19,13 +19,13 @@ namespace core sc_time getDistance(sc_time a, sc_time b); struct TimeInterval { - sc_time start,end; - TimeInterval() : start(SC_ZERO_TIME), end(SC_ZERO_TIME){} - TimeInterval(sc_time start,sc_time end) : start(start), end(end){} + sc_time start,end; + TimeInterval() : start(SC_ZERO_TIME), end(SC_ZERO_TIME){} + TimeInterval(sc_time start,sc_time end) : start(start), end(end){} - sc_time getLength() {return getDistance(start,end);} - bool timeIsInInterval(sc_time time); - bool intersects(TimeInterval other); + sc_time getLength() {return getDistance(start,end);} + bool timeIsInInterval(sc_time time); + bool intersects(TimeInterval other); }; sc_time getMinimalExecutionTime(Command command, tlm::tlm_generic_payload& payload); diff --git a/dram/src/core/configuration/Configuration.cpp b/dram/src/controller/core/configuration/Configuration.cpp similarity index 100% rename from dram/src/core/configuration/Configuration.cpp rename to dram/src/controller/core/configuration/Configuration.cpp diff --git a/dram/src/core/configuration/Configuration.h b/dram/src/controller/core/configuration/Configuration.h similarity index 100% rename from dram/src/core/configuration/Configuration.h rename to dram/src/controller/core/configuration/Configuration.h diff --git a/dram/src/controller/core/configuration/MemSpecLoader.cpp b/dram/src/controller/core/configuration/MemSpecLoader.cpp new file mode 100644 index 00000000..98cfc39d --- /dev/null +++ b/dram/src/controller/core/configuration/MemSpecLoader.cpp @@ -0,0 +1,174 @@ +/* + * MemSpecLoader.cpp + * + * Created on: Apr 7, 2014 + * Author: jonny + */ + +#include "MemSpecLoader.h" +#include "TimingConfiguration.h" + +using namespace tinyxml2; +using namespace std; + +namespace core { + +void MemSpecLoader::loadConfiguration(Configuration& config, string memspecUri, string memconfigUri) +{ + tinyxml2::XMLDocument doc; + loadXML(memspecUri, doc); + + XMLElement* memspec = doc.FirstChildElement("memspec"); + config.MemoryId = queryStringParameter(memspec, "memoryId"); + config.MemoryType = queryStringParameter(memspec, "memoryType"); + + if (config.MemoryType == "DDR4") + { + loadDDR4(config, memspec); + } + else if (config.MemoryType == "WIDEIO_SDR") + { + loadWideIO(config, memspec); + } + else + { + reportFatal("ConfigurationLoader", "Unsupported Configuration"); + } + + loadXML(memconfigUri, doc); + memspec = doc.FirstChildElement("memspec"); + loadConfig(config, memspec); + +} + +void MemSpecLoader::loadConfig(Configuration& config, XMLElement* memspec) +{ + //MemConfiguration + XMLElement* configuration = memspec->FirstChildElement("memconfig"); + + config.BankwiseLogic = queryBoolParameter(configuration, "bankwiseLogic"); + config.OpenPagePolicy = queryBoolParameter(configuration, "openPagePolicy"); + config.AdaptiveOpenPagePolicy = queryBoolParameter(configuration, "adaptiveOpenPagePolicy"); + config.RefreshAwareScheduling = queryBoolParameter(configuration, "refreshAwareScheduling"); + config.MaxNrOfTransactions = queryUIntParameter(configuration, "maxNrOfTransactionsInDram"); + config.Scheduler = queryStringParameter(configuration, "scheduler"); + config.Capsize = queryUIntParameter(configuration, "capsize"); + + string mode = queryStringParameter(configuration, "powerDownMode"); + if (mode.compare("Staggered") == 0) + { + config.powerDownMode = PowerDownMode::Staggered; + } + else if (mode.compare("TimeoutPDN") == 0) + { + config.powerDownMode = PowerDownMode::TimeoutPDN; + } + else if (mode.compare("TimeoutSREF") == 0) + { + config.powerDownMode = PowerDownMode::TimeoutSREF; + } + config.powerDownTimeout = queryUIntParameter(configuration, "powerDownTimeout") * config.Timings.clk; +} + +void MemSpecLoader::loadDDR4(Configuration& config, XMLElement* memspec) +{ + //MemSpecification + XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); + + config.NumberOfBanks = queryUIntParameter(architecture, "nbrOfBanks"); + config.NumberOfBankGroups = queryUIntParameter(architecture, "nbrOfBankGroups"); + config.BurstLength = queryUIntParameter(architecture, "burstLength"); + config.nActivate = 4; + config.DataRate = queryUIntParameter(architecture, "dataRate"); + config.NumberOfRows = queryUIntParameter(architecture, "nbrOfRows"); + + //MemTimings + XMLElement* timings = memspec->FirstChildElement("memtimingspec"); + double clkMhz = queryDoubleParameter(timings, "clkMhz"); + sc_time clk = sc_time(1 / clkMhz, SC_US); + config.Timings.clk = clk; + + config.Timings.tRP = clk * queryUIntParameter(timings, "RP"); + config.Timings.tRAS = clk * queryUIntParameter(timings, "RAS"); + config.Timings.tRC = clk * queryUIntParameter(timings, "RC"); + config.Timings.tRTP = clk * queryUIntParameter(timings, "RTP"); + config.Timings.tRRD_S = clk * queryUIntParameter(timings, "RRD_S"); + config.Timings.tRRD_L = clk * queryUIntParameter(timings, "RRD_L"); + config.Timings.tCCD_S = clk * queryUIntParameter(timings, "CCD_S"); + config.Timings.tCCD_L = clk * queryUIntParameter(timings, "CCD_L"); + config.Timings.tRCD = clk * queryUIntParameter(timings, "RCD"); + config.Timings.tNAW = clk * queryUIntParameter(timings, "FAW"); + config.Timings.tRL = clk * queryUIntParameter(timings, "RL"); + config.Timings.tWL = clk * queryUIntParameter(timings, "WL"); + config.Timings.tWR = clk * queryUIntParameter(timings, "WR"); + config.Timings.tWTR_S = clk * queryUIntParameter(timings, "WTR_S"); + config.Timings.tWTR_L = clk * queryUIntParameter(timings, "WTR_L"); + config.Timings.tCKESR = clk * queryUIntParameter(timings, "CKESR"); + config.Timings.tCKE = clk * queryUIntParameter(timings, "CKE"); + config.Timings.tXP = clk * queryUIntParameter(timings, "XP"); + config.Timings.tXPDLL = clk * queryUIntParameter(timings, "XPDLL"); + config.Timings.tXSR = clk * queryUIntParameter(timings, "XS"); + config.Timings.tXSRDLL = clk * queryUIntParameter(timings, "XSDLL"); + config.Timings.tAL = clk * queryUIntParameter(timings, "AL"); + config.Timings.tRFC = clk * queryUIntParameter(timings, "RFC"); + config.Timings.tREFI = clk * queryUIntParameter(timings, "REFI"); + + config.Timings.refreshTimings.clear(); + for (unsigned int i = 0; i < config.NumberOfBanks; ++i) + { + config.Timings.refreshTimings[Bank(i)] = RefreshTiming(config.Timings.tRFC, config.Timings.tREFI); + } +} + +void MemSpecLoader::loadWideIO(Configuration& config, XMLElement* memspec) +{ + //MemSpecification + XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); + + config.NumberOfBanks = queryUIntParameter(architecture, "nbrOfBanks"); + config.NumberOfBankGroups = 1; + config.BurstLength = queryUIntParameter(architecture, "burstLength"); + config.nActivate = 2; + config.DataRate = queryUIntParameter(architecture, "dataRate"); + config.NumberOfRows = queryUIntParameter(architecture, "nbrOfRows"); + + //MemTimings + XMLElement* timings = memspec->FirstChildElement("memtimingspec"); + double clkMhz = queryDoubleParameter(timings, "clkMhz"); + sc_time clk = sc_time(1 / clkMhz, SC_US); + config.Timings.clk = clk; + + config.Timings.tRP = clk * queryUIntParameter(timings, "RP"); + config.Timings.tRAS = clk * queryUIntParameter(timings, "RAS"); + config.Timings.tRC = clk * queryUIntParameter(timings, "RC"); + config.Timings.tRRD_S = clk * queryUIntParameter(timings, "RRD"); + config.Timings.tRRD_L = config.Timings.tRRD_S; + config.Timings.tCCD_S = clk * queryUIntParameter(timings, "CCD"); + config.Timings.tCCD_L = config.Timings.tCCD_S; + config.Timings.tRCD = clk * queryUIntParameter(timings, "RCD"); + config.Timings.tNAW = clk * queryUIntParameter(timings, "TAW"); + config.Timings.tRL = clk * queryUIntParameter(timings, "RL"); + config.Timings.tWL = clk * queryUIntParameter(timings, "WL"); + config.Timings.tWR = clk * queryUIntParameter(timings, "WR"); + config.Timings.tWTR_S = clk * queryUIntParameter(timings, "WTR"); + config.Timings.tWTR_L = config.Timings.tWTR_S; + config.Timings.tRTP = clk * queryUIntParameter(timings, "RTP"); + config.Timings.tCKESR = clk * queryUIntParameter(timings, "CKESR"); + config.Timings.tCKE = clk * queryUIntParameter(timings, "CKE"); + config.Timings.tXP = clk * queryUIntParameter(timings, "XP"); + config.Timings.tXPDLL = config.Timings.tXP; + config.Timings.tXSR = clk * queryUIntParameter(timings, "XS"); + config.Timings.tXSRDLL = config.Timings.tXSR; + config.Timings.tAL = clk * queryUIntParameter(timings, "AL"); + config.Timings.tRFC = clk * queryUIntParameter(timings, "RFC"); + config.Timings.tREFI = clk * queryUIntParameter(timings, "REFI"); + + config.Timings.refreshTimings.clear(); + for (unsigned int i = 0; i < config.NumberOfBanks; ++i) + { + config.Timings.refreshTimings[Bank(i)] = RefreshTiming(config.Timings.tRFC, config.Timings.tREFI); + } + +} + +} /* namespace core */ diff --git a/dram/src/core/configuration/MemSpecLoader.h b/dram/src/controller/core/configuration/MemSpecLoader.h similarity index 87% rename from dram/src/core/configuration/MemSpecLoader.h rename to dram/src/controller/core/configuration/MemSpecLoader.h index a0df7137..415eb04c 100644 --- a/dram/src/core/configuration/MemSpecLoader.h +++ b/dram/src/controller/core/configuration/MemSpecLoader.h @@ -9,8 +9,8 @@ #define MEMSPECLOADER_H_ #include -#include "../../common/third_party/tinyxml2.h" -#include "../../common/Utils.h" +#include "../../../common/third_party/tinyxml2.h" +#include "../../../common/Utils.h" #include "Configuration.h" namespace core { diff --git a/dram/src/core/configuration/TimingConfiguration.h b/dram/src/controller/core/configuration/TimingConfiguration.h similarity index 97% rename from dram/src/core/configuration/TimingConfiguration.h rename to dram/src/controller/core/configuration/TimingConfiguration.h index 79602d5d..e990c6fd 100644 --- a/dram/src/core/configuration/TimingConfiguration.h +++ b/dram/src/controller/core/configuration/TimingConfiguration.h @@ -10,7 +10,7 @@ #include #include -#include "../../common/dramExtension.h" +#include "../../../common/dramExtension.h" namespace core{ struct RefreshTiming diff --git a/dram/src/core/powerdown/IPowerDownManager.h b/dram/src/controller/core/powerdown/IPowerDownManager.h similarity index 98% rename from dram/src/core/powerdown/IPowerDownManager.h rename to dram/src/controller/core/powerdown/IPowerDownManager.h index d9647973..d6e48c89 100644 --- a/dram/src/core/powerdown/IPowerDownManager.h +++ b/dram/src/controller/core/powerdown/IPowerDownManager.h @@ -9,7 +9,7 @@ #define IPOWERDOWNMANAGER_H_ #include -#include "../../common/dramExtension.h" +#include "../../../common/dramExtension.h" #include "../Command.h" diff --git a/dram/src/controller/core/powerdown/PowerDownManager.cpp b/dram/src/controller/core/powerdown/PowerDownManager.cpp new file mode 100644 index 00000000..ab4a8a66 --- /dev/null +++ b/dram/src/controller/core/powerdown/PowerDownManager.cpp @@ -0,0 +1,165 @@ +/* + * PowerDownManager.cpp + * + * Created on: Apr 1, 2014 + * Author: jonny + */ + +#include +#include +#include "PowerDownManager.h" +#include "../ControllerCore.h" +#include "../TimingCalculation.h" +#include "../../../common/DebugManager.h" +#include +#include "../../../common/Utils.h" + +using namespace tlm; +using namespace std; + +namespace core { + +PowerDownManager::PowerDownManager(ControllerCore& controller) : + controller(controller) +{ + powerDownState = PowerDownState::Awake; + for (Bank bank : controller.getBanks()) + { + setUpDummy(powerDownPayloads[bank], bank); + } +} + +PowerDownManager::~PowerDownManager() +{ + +} + +void PowerDownManager::sleep(Bank bank, sc_time time) +{ + if (!canSleep() || isInPowerDown()) + return; + + PowerDownState state = powerDownState; + + if (state == PowerDownState::Awake) //coming from active + { + state = controller.state.bankStates.allRowBuffersAreClosed() ? PowerDownState::PDNPrecharge : PowerDownState::PDNActive; + } + else if (state == PowerDownState::AwakeForRefresh) //coming from refresh interrupting power down + { + sc_assert(controller.state.bankStates.allRowBuffersAreClosed()); + + if (controller.state.getLastCommand(Command::PDNA).getStart() + >= controller.state.getLastCommand(Command::PDNP).getStart()) + state = PowerDownState::PDNPrecharge; + else + { + state = PowerDownState::PDNSelfRefresh; + } + } + + Command cmd = IPowerDownManager::getSleepCommand(state); + ScheduledCommand pdn(cmd, time, getMinimalExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + + controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); + + if (state != PowerDownState::PDNSelfRefresh && controller.refreshManager->hasCollision(pdn)) + { + return; + } + else + { + setPowerDownState(state); + sendPowerDownPayloads(pdn); + } +} + +void PowerDownManager::wakeUp(Bank bank, sc_time time) +{ + if (isAwakeForRefresh()) //Request enters system during Refresh + { + setPowerDownState(PowerDownState::Awake); + } + else if (isInPowerDown()) //Request wakes up power down + { + Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); + ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); + + if (cmd == Command::SREFX) + controller.refreshManager->reInitialize(bank, pdn.getEnd()); + + setPowerDownState(PowerDownState::Awake); + sendPowerDownPayloads(pdn); + } +} + +void PowerDownManager::wakeUpForRefresh(Bank bank, sc_time time) +{ + if (isInPowerDown()) + { + Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); + ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + + setPowerDownState(PowerDownState::AwakeForRefresh); + sendPowerDownPayloads(pdn); + } +} + +void PowerDownManager::sendPowerDownPayloads(ScheduledCommand& cmd) +{ + controller.state.bus.moveCommandToNextFreeSlot(cmd); + for (Bank bank : controller.getBanks()) + { + tlm_generic_payload& payloadToSend = powerDownPayloads[bank]; + ScheduledCommand pdnToSend(cmd.getCommand(), cmd.getStart(), cmd.getExecutionTime(), + DramExtension::getExtension(payloadToSend)); + controller.state.change(pdnToSend); + controller.wrapper.send(pdnToSend, payloadToSend); + } +} + +void PowerDownManager::setPowerDownState(PowerDownState state) +{ + powerDownState = state; + DebugManager::getInstance().printDebugMessage(PowerDownManagerBankwise::senderName, + "Is now in state " + powerDownStateToString(powerDownState) + " on all banks"); +} + +bool PowerDownManager::isInPowerDown() +{ + return (powerDownState == PowerDownState::PDNActive || powerDownState == PowerDownState::PDNPrecharge + || powerDownState == PowerDownState::PDNSelfRefresh); +} + +bool PowerDownManager::canSleep() +{ + for (Bank bank : controller.getBanks()) + { + if (!controller.numberOfPayloads[bank] == 0) + return false; + } + return true; +} + +bool PowerDownManager::isInSelfRefresh(Bank bank) +{ + return powerDownState == PowerDownState::PDNSelfRefresh; +} + +bool PowerDownManager::isAwakeForRefresh() +{ + return powerDownState == PowerDownState::AwakeForRefresh; +} + +void PowerDownManager::triggerSleep(Bank bank, sc_time time) +{ + sleep(bank, time); +} + +} /* namespace core */ + + diff --git a/dram/src/core/powerdown/PowerDownManager.h b/dram/src/controller/core/powerdown/PowerDownManager.h similarity index 100% rename from dram/src/core/powerdown/PowerDownManager.h rename to dram/src/controller/core/powerdown/PowerDownManager.h diff --git a/dram/src/core/powerdown/PowerDownManagerBankwise.cpp b/dram/src/controller/core/powerdown/PowerDownManagerBankwise.cpp similarity index 99% rename from dram/src/core/powerdown/PowerDownManagerBankwise.cpp rename to dram/src/controller/core/powerdown/PowerDownManagerBankwise.cpp index 7702a0e1..41746b22 100644 --- a/dram/src/core/powerdown/PowerDownManagerBankwise.cpp +++ b/dram/src/controller/core/powerdown/PowerDownManagerBankwise.cpp @@ -7,7 +7,7 @@ #include "PowerDownManager.h" #include "../ControllerCore.h" -#include "../../common/Utils.h" +#include "../../../common/Utils.h" #include "../TimingCalculation.h" using namespace tlm; diff --git a/dram/src/core/powerdown/PowerDownManagerBankwise.h b/dram/src/controller/core/powerdown/PowerDownManagerBankwise.h similarity index 97% rename from dram/src/core/powerdown/PowerDownManagerBankwise.h rename to dram/src/controller/core/powerdown/PowerDownManagerBankwise.h index 0cc3a2a7..60204f15 100644 --- a/dram/src/core/powerdown/PowerDownManagerBankwise.h +++ b/dram/src/controller/core/powerdown/PowerDownManagerBankwise.h @@ -13,7 +13,7 @@ #include #include #include "../Command.h" -#include "../../common/dramExtension.h" +#include "../../../common/dramExtension.h" #include "../scheduling/ScheduledCommand.h" #include "IPowerDownManager.h" diff --git a/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp new file mode 100644 index 00000000..59e4c903 --- /dev/null +++ b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp @@ -0,0 +1,140 @@ +/* + * PowerDownManagerTimeout.cpp + * + * Created on: May 5, 2014 + * Author: jungma + */ + +#include "PowerDownManagerTimeout.h" +#include "../ControllerCore.h" +#include "../../../common/Utils.h" + +using namespace tlm; + +namespace core { + +PowerDownManagerTimeout::PowerDownManagerTimeout(ControllerCore& controller): controller(controller) +{ + for (Bank bank : controller.getBanks()) + { + setUpDummy(powerDownPayloads[bank], bank); + } +} + +PowerDownManagerTimeout::~PowerDownManagerTimeout() +{ + // TODO Auto-generated destructor stub +} + +void PowerDownManagerTimeout::sleep(Bank bank, sc_time time) +{ + if(canSleep() && !isInPowerDown() && (time - controller.state.getLastScheduledCommand().getEnd()) >= Configuration::getInstance().powerDownTimeout) + { + PowerDownState newState; + if(Configuration::getInstance().powerDownMode == PowerDownMode::TimeoutPDN) + { + newState = controller.state.bankStates.allRowBuffersAreClosed() ? PowerDownState::PDNPrecharge : PowerDownState::PDNActive; + } + else + { + newState = PowerDownState::PDNSelfRefresh; + } + + Command cmd = IPowerDownManager::getSleepCommand(newState); + ScheduledCommand pdn(cmd, time, getMinimalExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + + controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); + + if (controller.refreshManager->hasCollision(pdn)) + { + return; + } + else + { + setPowerDownState(newState); + sendPowerDownPayloads(pdn); + } + } +} + +bool PowerDownManagerTimeout::isInPowerDown() +{ + return (powerDownState == PowerDownState::PDNActive || powerDownState == PowerDownState::PDNPrecharge + || powerDownState == PowerDownState::PDNSelfRefresh); +} + +void PowerDownManagerTimeout::setPowerDownState(PowerDownState state) +{ + powerDownState = state; + DebugManager::getInstance().printDebugMessage(PowerDownManagerBankwise::senderName, + "Is now in state " + powerDownStateToString(powerDownState) + " on all banks"); +} + +void PowerDownManagerTimeout::wakeUp(Bank bank, sc_time time) +{ + if (isInPowerDown()) //Request wakes up power down + { + Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); + ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); + + if (cmd == Command::SREFX) + controller.refreshManager->reInitialize(bank, pdn.getEnd()); + + setPowerDownState(PowerDownState::Awake); + sendPowerDownPayloads(pdn); + } +} + +void PowerDownManagerTimeout::wakeUpForRefresh(Bank bank, sc_time time) +{ + if (isInPowerDown()) + { + Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); + ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), + DramExtension::getExtension(powerDownPayloads[bank])); + + setPowerDownState(PowerDownState::AwakeForRefresh); + sendPowerDownPayloads(pdn); + } +} + +void PowerDownManagerTimeout::triggerSleep(Bank bank, sc_time time) +{ + if(canSleep() && !isInPowerDown()) + { + controller.wrapper.send(PDNTrigger, time + controller.config.powerDownTimeout, powerDownPayloads[Bank(0)]); + } +} + +bool PowerDownManagerTimeout::isInSelfRefresh(Bank bank) +{ + return powerDownState == PowerDownState::PDNSelfRefresh; +} + +bool PowerDownManagerTimeout::canSleep() +{ + for (Bank bank : controller.getBanks()) + { + if (!controller.numberOfPayloads[bank] == 0) + return false; + } + return true; +} + +void PowerDownManagerTimeout::sendPowerDownPayloads(ScheduledCommand& cmd) +{ + controller.state.bus.moveCommandToNextFreeSlot(cmd); + for (Bank bank : controller.getBanks()) + { + tlm_generic_payload& payloadToSend = powerDownPayloads[bank]; + ScheduledCommand pdnToSend(cmd.getCommand(), cmd.getStart(), cmd.getExecutionTime(), + DramExtension::getExtension(payloadToSend)); + controller.state.change(pdnToSend); + controller.wrapper.send(pdnToSend, payloadToSend); + } +} + +} diff --git a/dram/src/controller/core/powerdown/PowerDownManagerTimeout.h b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.h new file mode 100644 index 00000000..e41dbd02 --- /dev/null +++ b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.h @@ -0,0 +1,47 @@ +/* + * PowerDownManagerTimeout.h + * + * Created on: May 5, 2014 + * Author: jungma + */ + +#ifndef POWERDOWNMANAGERTIMEOUT_H_ +#define POWERDOWNMANAGERTIMEOUT_H_ + +#include "IPowerDownManager.h" +#include +#include "../../../common/dramExtension.h" +#include +#include "../scheduling/ScheduledCommand.h" + +namespace core { +class ControllerCore; + +class PowerDownManagerTimeout: public core::IPowerDownManager +{ +public: + PowerDownManagerTimeout(ControllerCore& controller); + virtual ~PowerDownManagerTimeout(); + + virtual void triggerSleep(Bank bank, sc_time time); + virtual void sleep(Bank bank, sc_time time); + + virtual void wakeUp(Bank bank, sc_time time); + virtual void wakeUpForRefresh(Bank bank, sc_time time); + + virtual bool isInSelfRefresh(Bank bank); +private: + bool canSleep(); + ControllerCore& controller; + + std::map powerDownPayloads; + void sendPowerDownPayloads(ScheduledCommand& cmd); + + PowerDownState powerDownState; + void setPowerDownState(PowerDownState state); + bool isInPowerDown(); +}; + +} + +#endif /* POWERDOWNMANAGERTIMEOUT_H_ */ diff --git a/dram/src/core/refresh/IRefreshManager.h b/dram/src/controller/core/refresh/IRefreshManager.h similarity index 100% rename from dram/src/core/refresh/IRefreshManager.h rename to dram/src/controller/core/refresh/IRefreshManager.h diff --git a/dram/src/core/refresh/RefreshManager.cpp b/dram/src/controller/core/refresh/RefreshManager.cpp similarity index 98% rename from dram/src/core/refresh/RefreshManager.cpp rename to dram/src/controller/core/refresh/RefreshManager.cpp index 5454ada2..0426739c 100644 --- a/dram/src/core/refresh/RefreshManager.cpp +++ b/dram/src/controller/core/refresh/RefreshManager.cpp @@ -8,7 +8,7 @@ #include "RefreshManager.h" #include "../ControllerCore.h" #include "../TimingCalculation.h" -#include "../../common/Utils.h" +#include "../../../common/Utils.h" #include "../TimingCalculation.h" using namespace tlm; diff --git a/dram/src/core/refresh/RefreshManager.h b/dram/src/controller/core/refresh/RefreshManager.h similarity index 100% rename from dram/src/core/refresh/RefreshManager.h rename to dram/src/controller/core/refresh/RefreshManager.h diff --git a/dram/src/core/refresh/RefreshManagerBankwise.cpp b/dram/src/controller/core/refresh/RefreshManagerBankwise.cpp similarity index 98% rename from dram/src/core/refresh/RefreshManagerBankwise.cpp rename to dram/src/controller/core/refresh/RefreshManagerBankwise.cpp index dbad8403..7147ad9b 100644 --- a/dram/src/core/refresh/RefreshManagerBankwise.cpp +++ b/dram/src/controller/core/refresh/RefreshManagerBankwise.cpp @@ -8,7 +8,7 @@ #include "RefreshManagerBankwise.h" #include "../ControllerCore.h" #include "../TimingCalculation.h" -#include "../../common/Utils.h" +#include "../../../common/Utils.h" using namespace std; diff --git a/dram/src/core/refresh/RefreshManagerBankwise.h b/dram/src/controller/core/refresh/RefreshManagerBankwise.h similarity index 96% rename from dram/src/core/refresh/RefreshManagerBankwise.h rename to dram/src/controller/core/refresh/RefreshManagerBankwise.h index b758e028..a7b69517 100644 --- a/dram/src/core/refresh/RefreshManagerBankwise.h +++ b/dram/src/controller/core/refresh/RefreshManagerBankwise.h @@ -9,7 +9,7 @@ #define BANKWISEREFRESHMANAGER_H_ #include "../scheduling/CommandSchedule.h" -#include "../../common/dramExtension.h" +#include "../../../common/dramExtension.h" #include "../configuration/TimingConfiguration.h" #include "IRefreshManager.h" diff --git a/dram/src/core/scheduling/CommandSchedule.h b/dram/src/controller/core/scheduling/CommandSchedule.h similarity index 93% rename from dram/src/core/scheduling/CommandSchedule.h rename to dram/src/controller/core/scheduling/CommandSchedule.h index 41588a34..f3cedf85 100644 --- a/dram/src/core/scheduling/CommandSchedule.h +++ b/dram/src/controller/core/scheduling/CommandSchedule.h @@ -9,8 +9,8 @@ #define COMMANDSCHEDULE_H_ #include -#include "../../common/dramExtension.h" -#include "../../common/TlmRecorder.h" +#include "../../../common/dramExtension.h" +#include "../../../common/TlmRecorder.h" #include "ScheduledCommand.h" namespace core { diff --git a/dram/src/core/scheduling/CommandSequenceGenerator.cpp b/dram/src/controller/core/scheduling/CommandSequenceGenerator.cpp similarity index 97% rename from dram/src/core/scheduling/CommandSequenceGenerator.cpp rename to dram/src/controller/core/scheduling/CommandSequenceGenerator.cpp index 3bd228e8..bab728b3 100644 --- a/dram/src/core/scheduling/CommandSequenceGenerator.cpp +++ b/dram/src/controller/core/scheduling/CommandSequenceGenerator.cpp @@ -6,7 +6,7 @@ */ #include "CommandSequenceGenerator.h" -#include "../../common/dramExtension.h" +#include "../../../common/dramExtension.h" #include "../configuration/Configuration.h" using namespace std; diff --git a/dram/src/core/scheduling/CommandSequenceGenerator.h b/dram/src/controller/core/scheduling/CommandSequenceGenerator.h similarity index 100% rename from dram/src/core/scheduling/CommandSequenceGenerator.h rename to dram/src/controller/core/scheduling/CommandSequenceGenerator.h diff --git a/dram/src/core/scheduling/CommandSequenceScheduler.cpp b/dram/src/controller/core/scheduling/CommandSequenceScheduler.cpp similarity index 95% rename from dram/src/core/scheduling/CommandSequenceScheduler.cpp rename to dram/src/controller/core/scheduling/CommandSequenceScheduler.cpp index fd165a1f..0f254563 100644 --- a/dram/src/core/scheduling/CommandSequenceScheduler.cpp +++ b/dram/src/controller/core/scheduling/CommandSequenceScheduler.cpp @@ -7,7 +7,7 @@ #include "CommandSequenceScheduler.h" #include "../ControllerCore.h" -#include "../../common/DebugManager.h" +#include "../../../common/DebugManager.h" #include "../TimingCalculation.h" namespace core { diff --git a/dram/src/core/scheduling/CommandSequenceScheduler.h b/dram/src/controller/core/scheduling/CommandSequenceScheduler.h similarity index 100% rename from dram/src/core/scheduling/CommandSequenceScheduler.h rename to dram/src/controller/core/scheduling/CommandSequenceScheduler.h diff --git a/dram/src/core/scheduling/ScheduledCommand.cpp b/dram/src/controller/core/scheduling/ScheduledCommand.cpp similarity index 98% rename from dram/src/core/scheduling/ScheduledCommand.cpp rename to dram/src/controller/core/scheduling/ScheduledCommand.cpp index 4ef2a3b8..e41e8184 100644 --- a/dram/src/core/scheduling/ScheduledCommand.cpp +++ b/dram/src/controller/core/scheduling/ScheduledCommand.cpp @@ -6,7 +6,7 @@ */ #include "ScheduledCommand.h" #include "../TimingCalculation.h" -#include "../../common/Utils.h" +#include "../../../common/Utils.h" #include "../configuration/Configuration.h" namespace core { diff --git a/dram/src/controller/core/scheduling/ScheduledCommand.h b/dram/src/controller/core/scheduling/ScheduledCommand.h new file mode 100644 index 00000000..96344a0c --- /dev/null +++ b/dram/src/controller/core/scheduling/ScheduledCommand.h @@ -0,0 +1,68 @@ +/* + * ScheduledCommand.h + * + * Created on: Mar 10, 2014 + * Author: jonny + */ + +#ifndef SCHEDULEDCOMMAND_H_ +#define SCHEDULEDCOMMAND_H_ + +#include +#include +#include "../Command.h" +#include "../../../common/dramExtension.h" +#include "../../../common/TlmRecorder.h" +#include "../TimingCalculation.h" + +namespace core { + +class ScheduledCommand +{ +public: + + ScheduledCommand(Command command, sc_time start, sc_time executionTime, const DramExtension& extension) : + command(command), start(start), executionTime(executionTime),end(start+executionTime), + extension(extension) + { + } + + + ScheduledCommand() : + command(Command::NOP), start(SC_ZERO_TIME), executionTime(SC_ZERO_TIME), end(SC_ZERO_TIME), extension() + { + } + + bool isNoCommand() const; + bool isValidCommand() const; + + const sc_time getStart() const; + void setStart(sc_time newStart); + void delayStart(sc_time delay); + void delayToMeetConstraint(sc_time previous, sc_time constraint); + + const sc_time getEnd() const; + const Command getCommand() const; + const sc_time getExecutionTime() const; + + Bank getBank() const; + BankGroup getBankGroup() const; + Row getRow() const; + + unsigned int getBurstLength() const; + bool operator ==(const ScheduledCommand& b) const; + bool commandIsIn(const std::vector& commandSet) const; + + TimeInterval getIntervalOnDataStrobe() const; + + +private: + DramExtension extension; + Command command; + sc_time start; + sc_time executionTime; + sc_time end; +}; +} /* namespace controller */ + +#endif /* SCHEDULEDCOMMAND_H_ */ diff --git a/dram/src/core/scheduling/Trigger.h b/dram/src/controller/core/scheduling/Trigger.h similarity index 100% rename from dram/src/core/scheduling/Trigger.h rename to dram/src/controller/core/scheduling/Trigger.h diff --git a/dram/src/core/scheduling/checker/ActivateChecker.cpp b/dram/src/controller/core/scheduling/checker/ActivateChecker.cpp similarity index 97% rename from dram/src/core/scheduling/checker/ActivateChecker.cpp rename to dram/src/controller/core/scheduling/checker/ActivateChecker.cpp index ef062ff2..d654ab9d 100644 --- a/dram/src/core/scheduling/checker/ActivateChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/ActivateChecker.cpp @@ -9,9 +9,9 @@ #include #include "ActivateChecker.h" #include "../../TimingCalculation.h" -#include "../../../common/DebugManager.h" +#include "../../../../common/DebugManager.h" #include "../../Command.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" #include namespace core { diff --git a/dram/src/core/scheduling/checker/ActivateChecker.h b/dram/src/controller/core/scheduling/checker/ActivateChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/ActivateChecker.h rename to dram/src/controller/core/scheduling/checker/ActivateChecker.h diff --git a/dram/src/core/scheduling/checker/ICommandChecker.h b/dram/src/controller/core/scheduling/checker/ICommandChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/ICommandChecker.h rename to dram/src/controller/core/scheduling/checker/ICommandChecker.h diff --git a/dram/src/core/scheduling/checker/PowerDownChecker.cpp b/dram/src/controller/core/scheduling/checker/PowerDownChecker.cpp similarity index 98% rename from dram/src/core/scheduling/checker/PowerDownChecker.cpp rename to dram/src/controller/core/scheduling/checker/PowerDownChecker.cpp index a14ab630..05835453 100644 --- a/dram/src/core/scheduling/checker/PowerDownChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/PowerDownChecker.cpp @@ -6,7 +6,7 @@ */ #include "PowerDownChecker.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" namespace core { void PowerDownChecker::delayToSatisfyConstraints(ScheduledCommand& command) const diff --git a/dram/src/core/scheduling/checker/PowerDownChecker.h b/dram/src/controller/core/scheduling/checker/PowerDownChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/PowerDownChecker.h rename to dram/src/controller/core/scheduling/checker/PowerDownChecker.h diff --git a/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp b/dram/src/controller/core/scheduling/checker/PrechargeAllChecker.cpp similarity index 98% rename from dram/src/core/scheduling/checker/PrechargeAllChecker.cpp rename to dram/src/controller/core/scheduling/checker/PrechargeAllChecker.cpp index 682c96e4..136abb95 100644 --- a/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/PrechargeAllChecker.cpp @@ -6,7 +6,7 @@ */ #include "PrechargeAllChecker.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" namespace core { diff --git a/dram/src/core/scheduling/checker/PrechargeAllChecker.h b/dram/src/controller/core/scheduling/checker/PrechargeAllChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/PrechargeAllChecker.h rename to dram/src/controller/core/scheduling/checker/PrechargeAllChecker.h diff --git a/dram/src/controller/core/scheduling/checker/PrechargeChecker.cpp b/dram/src/controller/core/scheduling/checker/PrechargeChecker.cpp new file mode 100644 index 00000000..fdabc554 --- /dev/null +++ b/dram/src/controller/core/scheduling/checker/PrechargeChecker.cpp @@ -0,0 +1,48 @@ +/* + * PrechargeChecker.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include "PrechargeChecker.h" +#include "../../../../common/Utils.h" + +namespace core { + +void PrechargeChecker::delayToSatisfyConstraints(ScheduledCommand& command) const +{ + sc_assert(command.getCommand() == Command::Precharge); + + ScheduledCommand lastCommand = state.getLastScheduledCommand(command.getBank()); + + if (lastCommand.isValidCommand()) + { + if (lastCommand.getCommand() == Command::Read) + { + command.delayToMeetConstraint(lastCommand.getStart(),config.Timings.tRTP); + } + else if (lastCommand.getCommand() == Command::Write) + { + command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tWL + getWriteAccessTime() + config.Timings.tWR); + } + else if (lastCommand.getCommand() == Command::PDNAX) + { + command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tXP); + } +// else if(!Configuration::getInstance().BankwiseLogic && lastCommand.getCommand() == Command::PDNPX) +// { +// command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tXP); +// } +// else if(!Configuration::getInstance().BankwiseLogic && lastCommand.getCommand() == Command::PDNPX) +// { +// command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tXSR); +// } + else + reportFatal("Precharge Checker", "Precharge can not follow " + commandToString(lastCommand.getCommand())); + } + + state.bus.moveCommandToNextFreeSlot(command); +} + +} /* namespace controller */ diff --git a/dram/src/core/scheduling/checker/PrechargeChecker.h b/dram/src/controller/core/scheduling/checker/PrechargeChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/PrechargeChecker.h rename to dram/src/controller/core/scheduling/checker/PrechargeChecker.h diff --git a/dram/src/core/scheduling/checker/ReadChecker.cpp b/dram/src/controller/core/scheduling/checker/ReadChecker.cpp similarity index 99% rename from dram/src/core/scheduling/checker/ReadChecker.cpp rename to dram/src/controller/core/scheduling/checker/ReadChecker.cpp index b02a2de7..b16b28c6 100644 --- a/dram/src/core/scheduling/checker/ReadChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/ReadChecker.cpp @@ -7,7 +7,7 @@ #include "ReadChecker.h" #include "../../TimingCalculation.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" #include "WriteChecker.h" namespace core { diff --git a/dram/src/core/scheduling/checker/ReadChecker.h b/dram/src/controller/core/scheduling/checker/ReadChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/ReadChecker.h rename to dram/src/controller/core/scheduling/checker/ReadChecker.h diff --git a/dram/src/core/scheduling/checker/RefreshChecker.cpp b/dram/src/controller/core/scheduling/checker/RefreshChecker.cpp similarity index 97% rename from dram/src/core/scheduling/checker/RefreshChecker.cpp rename to dram/src/controller/core/scheduling/checker/RefreshChecker.cpp index 16f3e2e1..4bf022b8 100644 --- a/dram/src/core/scheduling/checker/RefreshChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/RefreshChecker.cpp @@ -6,7 +6,7 @@ */ #include "RefreshChecker.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" namespace core { diff --git a/dram/src/core/scheduling/checker/RefreshChecker.h b/dram/src/controller/core/scheduling/checker/RefreshChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/RefreshChecker.h rename to dram/src/controller/core/scheduling/checker/RefreshChecker.h diff --git a/dram/src/core/scheduling/checker/WriteChecker.cpp b/dram/src/controller/core/scheduling/checker/WriteChecker.cpp similarity index 98% rename from dram/src/core/scheduling/checker/WriteChecker.cpp rename to dram/src/controller/core/scheduling/checker/WriteChecker.cpp index 7fec0fb8..6577a4ec 100644 --- a/dram/src/core/scheduling/checker/WriteChecker.cpp +++ b/dram/src/controller/core/scheduling/checker/WriteChecker.cpp @@ -7,7 +7,7 @@ #include "WriteChecker.h" #include "../../TimingCalculation.h" -#include "../../../common/Utils.h" +#include "../../../../common/Utils.h" #include "ReadChecker.h" namespace core { diff --git a/dram/src/core/scheduling/checker/WriteChecker.h b/dram/src/controller/core/scheduling/checker/WriteChecker.h similarity index 100% rename from dram/src/core/scheduling/checker/WriteChecker.h rename to dram/src/controller/core/scheduling/checker/WriteChecker.h diff --git a/dram/src/scheduler/Fifo.cpp b/dram/src/controller/scheduler/Fifo.cpp similarity index 100% rename from dram/src/scheduler/Fifo.cpp rename to dram/src/controller/scheduler/Fifo.cpp diff --git a/dram/src/scheduler/Fifo.h b/dram/src/controller/scheduler/Fifo.h similarity index 100% rename from dram/src/scheduler/Fifo.h rename to dram/src/controller/scheduler/Fifo.h diff --git a/dram/src/scheduler/Fr_Fcfs.cpp b/dram/src/controller/scheduler/Fr_Fcfs.cpp similarity index 98% rename from dram/src/scheduler/Fr_Fcfs.cpp rename to dram/src/controller/scheduler/Fr_Fcfs.cpp index 3ca88d90..76e4f355 100644 --- a/dram/src/scheduler/Fr_Fcfs.cpp +++ b/dram/src/controller/scheduler/Fr_Fcfs.cpp @@ -1,5 +1,5 @@ #include "Fr_Fcfs.h" -#include "../common/dramExtension.h" +#include "../../common/dramExtension.h" #include "../core/configuration/Configuration.h" #include diff --git a/dram/src/scheduler/Fr_Fcfs.h b/dram/src/controller/scheduler/Fr_Fcfs.h similarity index 100% rename from dram/src/scheduler/Fr_Fcfs.h rename to dram/src/controller/scheduler/Fr_Fcfs.h diff --git a/dram/src/scheduler/PARBS.cpp b/dram/src/controller/scheduler/PARBS.cpp similarity index 98% rename from dram/src/scheduler/PARBS.cpp rename to dram/src/controller/scheduler/PARBS.cpp index ba7c88cc..c5b187e0 100644 --- a/dram/src/scheduler/PARBS.cpp +++ b/dram/src/controller/scheduler/PARBS.cpp @@ -7,7 +7,7 @@ #include "PARBS.h" #include "../core/configuration/Configuration.h" -#include "../common/dramExtension.h" +#include "../../common/dramExtension.h" #include "map" #include "ThreadLoad.h" #include diff --git a/dram/src/scheduler/PARBS.h b/dram/src/controller/scheduler/PARBS.h similarity index 100% rename from dram/src/scheduler/PARBS.h rename to dram/src/controller/scheduler/PARBS.h diff --git a/dram/src/scheduler/Scheduler.h b/dram/src/controller/scheduler/Scheduler.h similarity index 91% rename from dram/src/scheduler/Scheduler.h rename to dram/src/controller/scheduler/Scheduler.h index 931990c0..2337d8bd 100644 --- a/dram/src/scheduler/Scheduler.h +++ b/dram/src/controller/scheduler/Scheduler.h @@ -1,7 +1,7 @@ #ifndef SCHEDULER_H #define SCHEDULER_H #include -#include "../common/dramExtension.h" +#include "../../common/dramExtension.h" namespace scheduler { diff --git a/dram/src/scheduler/ThreadLoad.cpp b/dram/src/controller/scheduler/ThreadLoad.cpp similarity index 100% rename from dram/src/scheduler/ThreadLoad.cpp rename to dram/src/controller/scheduler/ThreadLoad.cpp diff --git a/dram/src/scheduler/ThreadLoad.h b/dram/src/controller/scheduler/ThreadLoad.h similarity index 94% rename from dram/src/scheduler/ThreadLoad.h rename to dram/src/controller/scheduler/ThreadLoad.h index 9ccca269..b26e62e3 100644 --- a/dram/src/scheduler/ThreadLoad.h +++ b/dram/src/controller/scheduler/ThreadLoad.h @@ -9,7 +9,7 @@ #define THREADLOAD_H_ #include #include -#include "../common/dramExtension.h" +#include "../../common/dramExtension.h" namespace scheduler { diff --git a/dram/src/core/BankStates.cpp b/dram/src/core/BankStates.cpp deleted file mode 100644 index d125bbe5..00000000 --- a/dram/src/core/BankStates.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * BankStates.cpp - * - * Created on: Feb 24, 2014 - * Author: robert - */ - -#include "BankStates.h" -#include "ControllerCore.h" -#include "../common/DebugManager.h" -#include "../common/Utils.h" - -using namespace std; - -namespace core -{ - -BankStates::BankStates() -{ - closeAllRowBuffers(); -} - -BankStates::~BankStates() -{ -} - -bool BankStates::rowBufferIsOpen(const Bank &bank) const -{ - return rowsInRowBuffers.at(bank) != Row::NO_ROW; -} - -Row BankStates::getRowInRowBuffer(const Bank &bank) const -{ - return rowsInRowBuffers.at(bank); -} - -void BankStates::openRowInRowBuffer(const Bank &bank, const Row &row) -{ - DebugManager::getInstance().printDebugMessage(ControllerCore::senderName, "Row buffer for bank " + to_string(bank.ID()) + " is now open"); - rowsInRowBuffers[bank] = row; -} - -void BankStates::closeRowBuffer(const Bank &bank) -{ - DebugManager::getInstance().printDebugMessage(ControllerCore::senderName, "Row buffer for bank " + to_string(bank.ID()) + " is now closed"); - rowsInRowBuffers[bank] = Row::NO_ROW; -} - -bool BankStates::allRowBuffersAreClosed() const -{ - for(unsigned int i=0; i -#include "../common/dramExtension.h" - -namespace core -{ - -class BankStates { -public: - BankStates(); - virtual ~BankStates(); - - bool rowBufferIsOpen(const Bank &bank) const; - bool allRowBuffersAreClosed() const; - Row getRowInRowBuffer(const Bank &bank) const; - - void openRowInRowBuffer(const Bank &bank, const Row &row); - void closeRowBuffer(const Bank &bank); - void closeAllRowBuffers(); - -private: - std::map rowsInRowBuffers; -}; - -} - -#endif /* BANKSTATES_H_ */ diff --git a/dram/src/core/ControllerState.cpp b/dram/src/core/ControllerState.cpp deleted file mode 100644 index a051fe0d..00000000 --- a/dram/src/core/ControllerState.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * controller_state.cpp - * - * Created on: Mar 5, 2014 - * Author: jonny - */ - -#include "ControllerState.h" -#include -#include "TimingCalculation.h" - -namespace core { - -const ScheduledCommand ControllerState::getLastCommand(Command command, Bank bank) //TODO const reference? and make const -{ - return lastCommandsOnBus[command][bank]; -} - -const ScheduledCommand ControllerState::getLastCommand(Command command) -{ - ScheduledCommand max; - - for (unsigned int i = 0; i < config->NumberOfBanks; ++i) - { - ScheduledCommand current = getLastCommand(command, Bank(i)); - if (current.getStart() > max.getStart()) - max = current; - } - return max; -} - -const ScheduledCommand ControllerState::getLastScheduledCommand() -{ - ScheduledCommand lastCommand; - - for(Command cmd : getAllCommands()) - { - for(Bank bank : Configuration::getInstance().getBanks()) - { - ScheduledCommand& current = lastCommandsOnBus[cmd][bank]; - if (current.getStart() > lastCommand.getStart()) - lastCommand = current; - } - } - - return lastCommand; -} - -const ScheduledCommand ControllerState::getLastScheduledCommand(Bank bank) -{ - ScheduledCommand lastCommand; - - for(Command cmd : getAllCommands()) - { - ScheduledCommand& current = lastCommandsOnBus[cmd][bank]; - if (current.getStart() > lastCommand.getStart()) - lastCommand = current; - } - - return lastCommand; -} - -void ControllerState::change(const ScheduledCommand& scheduledCommand) -{ - //TODO double check if slot free? - bus.blockSlot(scheduledCommand.getStart()); - lastCommandsOnBus[scheduledCommand.getCommand()][scheduledCommand.getBank()] = scheduledCommand; - - switch (scheduledCommand.getCommand()) - { - case Command::Read: - lastDataStrobeCommands.emplace_back(scheduledCommand); - break; - case Command::ReadA: - bankStates.closeRowBuffer(scheduledCommand.getBank()); - lastDataStrobeCommands.emplace_back(scheduledCommand); - break; - case Command::Write: - lastDataStrobeCommands.emplace_back(scheduledCommand); - break; - case Command::WriteA: - bankStates.closeRowBuffer(scheduledCommand.getBank()); - lastDataStrobeCommands.emplace_back(scheduledCommand); - break; - case Command::AutoRefresh: - break; - case Command::Activate: - bankStates.openRowInRowBuffer(scheduledCommand.getBank(), scheduledCommand.getRow()); - lastActivates.emplace(scheduledCommand.getStart(), scheduledCommand.getBank()); - break; - - case Command::Precharge: - bankStates.closeRowBuffer(scheduledCommand.getBank()); - break; - case Command::PrechargeAll: - bankStates.closeAllRowBuffers(); - break; - default: - break; - } - -} - -void ControllerState::cleanUp(sc_time time) -{ - bus.cleanUpSlots(time); - lastDataStrobeCommands.remove_if([&](ScheduledCommand command){return command.getEnd() < time && getDistance(command.getEnd(), time) > config->Timings.tDataStrobeHistory();}); - lastActivates.erase(lastActivates.begin(), lastActivates.lower_bound(time - config->Timings.tActHistory())); -} - -} /* namespace controller */ diff --git a/dram/src/core/configuration/MemSpecLoader.cpp b/dram/src/core/configuration/MemSpecLoader.cpp deleted file mode 100644 index e1b174ab..00000000 --- a/dram/src/core/configuration/MemSpecLoader.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * MemSpecLoader.cpp - * - * Created on: Apr 7, 2014 - * Author: jonny - */ - -#include "MemSpecLoader.h" -#include "TimingConfiguration.h" - -using namespace tinyxml2; -using namespace std; - -namespace core { - -void MemSpecLoader::loadConfiguration(Configuration& config, string memspecUri, string memconfigUri) -{ - tinyxml2::XMLDocument doc; - loadXML(memspecUri, doc); - - XMLElement* memspec = doc.FirstChildElement("memspec"); - config.MemoryId = queryStringParameter(memspec, "memoryId"); - config.MemoryType = queryStringParameter(memspec, "memoryType"); - - if (config.MemoryType == "DDR4") - { - loadDDR4(config, memspec); - } - else if (config.MemoryType == "WIDEIO_SDR") - { - loadWideIO(config, memspec); - } - else - { - reportFatal("ConfigurationLoader", "Unsupported Configuration"); - } - - loadXML(memconfigUri, doc); - memspec = doc.FirstChildElement("memspec"); - loadConfig(config, memspec); - -} - -void MemSpecLoader::loadConfig(Configuration& config, XMLElement* memspec) -{ - //MemConfiguration - XMLElement* configuration = memspec->FirstChildElement("memconfig"); - - config.BankwiseLogic = queryBoolParameter(configuration, "bankwiseLogic"); - config.OpenPagePolicy = queryBoolParameter(configuration, "openPagePolicy"); - config.AdaptiveOpenPagePolicy = queryBoolParameter(configuration, "adaptiveOpenPagePolicy"); - config.RefreshAwareScheduling = queryBoolParameter(configuration, "refreshAwareScheduling"); - config.MaxNrOfTransactions = queryUIntParameter(configuration, "maxNrOfTransactionsInDram"); - config.Scheduler = queryStringParameter(configuration, "scheduler"); - config.Capsize = queryUIntParameter(configuration, "capsize"); - - string mode = queryStringParameter(configuration, "powerDownMode"); - if (mode.compare("Staggered") == 0) - { - config.powerDownMode = PowerDownMode::Staggered; - } - else if (mode.compare("TimeoutPDN") == 0) - { - config.powerDownMode = PowerDownMode::TimeoutPDN; - } - else if (mode.compare("TimeoutSREF") == 0) - { - config.powerDownMode = PowerDownMode::TimeoutSREF; - } - - config.powerDownTimeout = queryUIntParameter(configuration, "powerDownTimeout") * config.Timings.clk; -} - -void MemSpecLoader::loadDDR4(Configuration& config, XMLElement* memspec) -{ - //MemSpecification - XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); - - config.NumberOfBanks = queryUIntParameter(architecture, "nbrOfBanks"); - config.NumberOfBankGroups = queryUIntParameter(architecture, "nbrOfBankGroups"); - config.BurstLength = queryUIntParameter(architecture, "burstLength"); - config.nActivate = 4; - config.DataRate = queryUIntParameter(architecture, "dataRate"); - config.NumberOfRows = queryUIntParameter(architecture, "nbrOfRows"); - - //MemTimings - XMLElement* timings = memspec->FirstChildElement("memtimingspec"); - double clkMhz = queryDoubleParameter(timings, "clkMhz"); - sc_time clk = sc_time(1 / clkMhz, SC_US); - config.Timings.clk = clk; - - config.Timings.tRP = clk * queryUIntParameter(timings, "RP"); - config.Timings.tRAS = clk * queryUIntParameter(timings, "RAS"); - config.Timings.tRC = clk * queryUIntParameter(timings, "RC"); - config.Timings.tRTP = clk * queryUIntParameter(timings, "RTP"); - config.Timings.tRRD_S = clk * queryUIntParameter(timings, "RRD_S"); - config.Timings.tRRD_L = clk * queryUIntParameter(timings, "RRD_L"); - config.Timings.tCCD_S = clk * queryUIntParameter(timings, "CCD_S"); - config.Timings.tCCD_L = clk * queryUIntParameter(timings, "CCD_L"); - config.Timings.tRCD = clk * queryUIntParameter(timings, "RCD"); - config.Timings.tNAW = clk * queryUIntParameter(timings, "FAW"); - config.Timings.tRL = clk * queryUIntParameter(timings, "RL"); - config.Timings.tWL = clk * queryUIntParameter(timings, "WL"); - config.Timings.tWR = clk * queryUIntParameter(timings, "WR"); - config.Timings.tWTR_S = clk * queryUIntParameter(timings, "WTR_S"); - config.Timings.tWTR_L = clk * queryUIntParameter(timings, "WTR_L"); - config.Timings.tCKESR = clk * queryUIntParameter(timings, "CKESR"); - config.Timings.tCKE = clk * queryUIntParameter(timings, "CKE"); - config.Timings.tXP = clk * queryUIntParameter(timings, "XP"); - config.Timings.tXPDLL = clk * queryUIntParameter(timings, "XPDLL"); - config.Timings.tXSR = clk * queryUIntParameter(timings, "XS"); - config.Timings.tXSRDLL = clk * queryUIntParameter(timings, "XSDLL"); - config.Timings.tAL = clk * queryUIntParameter(timings, "AL"); - config.Timings.tRFC = clk * queryUIntParameter(timings, "RFC"); - config.Timings.tREFI = clk * queryUIntParameter(timings, "REFI"); - - config.Timings.refreshTimings.clear(); - for (unsigned int i = 0; i < config.NumberOfBanks; ++i) - { - config.Timings.refreshTimings[Bank(i)] = RefreshTiming(config.Timings.tRFC, config.Timings.tREFI); - } -} - -void MemSpecLoader::loadWideIO(Configuration& config, XMLElement* memspec) -{ - //MemSpecification - XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); - - config.NumberOfBanks = queryUIntParameter(architecture, "nbrOfBanks"); - config.NumberOfBankGroups = 1; - config.BurstLength = queryUIntParameter(architecture, "burstLength"); - config.nActivate = 2; - config.DataRate = queryUIntParameter(architecture, "dataRate"); - config.NumberOfRows = queryUIntParameter(architecture, "nbrOfRows"); - - //MemTimings - XMLElement* timings = memspec->FirstChildElement("memtimingspec"); - double clkMhz = queryDoubleParameter(timings, "clkMhz"); - sc_time clk = sc_time(1 / clkMhz, SC_US); - config.Timings.clk = clk; - - config.Timings.tRP = clk * queryUIntParameter(timings, "RP"); - config.Timings.tRAS = clk * queryUIntParameter(timings, "RAS"); - config.Timings.tRC = clk * queryUIntParameter(timings, "RC"); - config.Timings.tRRD_S = clk * queryUIntParameter(timings, "RRD"); - config.Timings.tRRD_L = config.Timings.tRRD_S; - config.Timings.tCCD_S = clk * queryUIntParameter(timings, "CCD"); - config.Timings.tCCD_L = config.Timings.tCCD_S; - config.Timings.tRCD = clk * queryUIntParameter(timings, "RCD"); - config.Timings.tNAW = clk * queryUIntParameter(timings, "TAW"); - config.Timings.tRL = clk * queryUIntParameter(timings, "RL"); - config.Timings.tWL = clk * queryUIntParameter(timings, "WL"); - config.Timings.tWR = clk * queryUIntParameter(timings, "WR"); - config.Timings.tWTR_S = clk * queryUIntParameter(timings, "WTR"); - config.Timings.tWTR_L = config.Timings.tWTR_S; - config.Timings.tRTP = clk * queryUIntParameter(timings, "RTP"); - config.Timings.tCKESR = clk * queryUIntParameter(timings, "CKESR"); - config.Timings.tCKE = clk * queryUIntParameter(timings, "CKE"); - config.Timings.tXP = clk * queryUIntParameter(timings, "XP"); - config.Timings.tXPDLL = config.Timings.tXP; - config.Timings.tXSR = clk * queryUIntParameter(timings, "XS"); - config.Timings.tXSRDLL = config.Timings.tXSR; - config.Timings.tAL = clk * queryUIntParameter(timings, "AL"); - config.Timings.tRFC = clk * queryUIntParameter(timings, "RFC"); - config.Timings.tREFI = clk * queryUIntParameter(timings, "REFI"); - - config.Timings.refreshTimings.clear(); - for (unsigned int i = 0; i < config.NumberOfBanks; ++i) - { - config.Timings.refreshTimings[Bank(i)] = RefreshTiming(config.Timings.tRFC, config.Timings.tREFI); - } - -} - -} /* namespace core */ diff --git a/dram/src/core/powerdown/PowerDownManager.cpp b/dram/src/core/powerdown/PowerDownManager.cpp deleted file mode 100644 index fd38cdff..00000000 --- a/dram/src/core/powerdown/PowerDownManager.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * PowerDownManager.cpp - * - * Created on: Apr 1, 2014 - * Author: jonny - */ - -#include -#include -#include "PowerDownManager.h" -#include "../ControllerCore.h" -#include "../TimingCalculation.h" -#include "../../common/DebugManager.h" -#include -#include "../../common/Utils.h" - -using namespace tlm; -using namespace std; - -namespace core { - -PowerDownManager::PowerDownManager(ControllerCore& controller) : - controller(controller) -{ - powerDownState = PowerDownState::Awake; - for (Bank bank : controller.getBanks()) - { - setUpDummy(powerDownPayloads[bank], bank); - } -} - -PowerDownManager::~PowerDownManager() -{ - -} - -void PowerDownManager::sleep(Bank bank, sc_time time) -{ - if (!canSleep() || isInPowerDown()) - return; - - PowerDownState state = powerDownState; - - if (state == PowerDownState::Awake) //coming from active - { - state = controller.state.bankStates.allRowBuffersAreClosed() ? PowerDownState::PDNPrecharge : PowerDownState::PDNActive; - - } - else if (state == PowerDownState::AwakeForRefresh) //coming from refresh interrupting power down - { - sc_assert(controller.state.bankStates.allRowBuffersAreClosed()); - - if (controller.state.getLastCommand(Command::PDNA).getStart() - >= controller.state.getLastCommand(Command::PDNP).getStart()) - state = PowerDownState::PDNPrecharge; - else - { - state = PowerDownState::PDNSelfRefresh; - } - } - - Command cmd = IPowerDownManager::getSleepCommand(state); - ScheduledCommand pdn(cmd, time, getMinimalExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - - controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); - - if (state != PowerDownState::PDNSelfRefresh && controller.refreshManager->hasCollision(pdn)) - { - return; - } - else - { - setPowerDownState(state); - sendPowerDownPayloads(pdn); - } -} - -void PowerDownManager::wakeUp(Bank bank, sc_time time) -{ - if (isAwakeForRefresh()) //Request enters system during Refresh - { - setPowerDownState(PowerDownState::Awake); - } - else if (isInPowerDown()) //Request wakes up power down - { - Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); - ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); - - if (cmd == Command::SREFX) - controller.refreshManager->reInitialize(bank, pdn.getEnd()); - - setPowerDownState(PowerDownState::Awake); - sendPowerDownPayloads(pdn); - } -} - -void PowerDownManager::wakeUpForRefresh(Bank bank, sc_time time) -{ - if (isInPowerDown()) - { - Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); - ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - - setPowerDownState(PowerDownState::AwakeForRefresh); - sendPowerDownPayloads(pdn); - } -} - -void PowerDownManager::sendPowerDownPayloads(ScheduledCommand& cmd) -{ - controller.state.bus.moveCommandToNextFreeSlot(cmd); - for (Bank bank : controller.getBanks()) - { - tlm_generic_payload& payloadToSend = powerDownPayloads[bank]; - ScheduledCommand pdnToSend(cmd.getCommand(), cmd.getStart(), cmd.getExecutionTime(), - DramExtension::getExtension(payloadToSend)); - controller.state.change(pdnToSend); - controller.wrapper.send(pdnToSend, payloadToSend); - } -} - -void PowerDownManager::setPowerDownState(PowerDownState state) -{ - powerDownState = state; - DebugManager::getInstance().printDebugMessage(PowerDownManagerBankwise::senderName, - "Is now in state " + powerDownStateToString(powerDownState) + " on all banks"); -} - -bool PowerDownManager::isInPowerDown() -{ - return (powerDownState == PowerDownState::PDNActive || powerDownState == PowerDownState::PDNPrecharge - || powerDownState == PowerDownState::PDNSelfRefresh); -} - -bool PowerDownManager::canSleep() -{ - for (Bank bank : controller.getBanks()) - { - if (!controller.numberOfPayloads[bank] == 0) - return false; - } - return true; -} - -bool PowerDownManager::isInSelfRefresh(Bank bank) -{ - return powerDownState == PowerDownState::PDNSelfRefresh; -} - -bool PowerDownManager::isAwakeForRefresh() -{ - return powerDownState == PowerDownState::AwakeForRefresh; -} - -void PowerDownManager::triggerSleep(Bank bank, sc_time time) -{ - sleep(bank, time); -} - -} /* namespace core */ - - diff --git a/dram/src/core/powerdown/PowerDownManagerTimeout.cpp b/dram/src/core/powerdown/PowerDownManagerTimeout.cpp deleted file mode 100644 index 40a6bb1e..00000000 --- a/dram/src/core/powerdown/PowerDownManagerTimeout.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * PowerDownManagerTimeout.cpp - * - * Created on: May 5, 2014 - * Author: jungma - */ - -#include "PowerDownManagerTimeout.h" -#include "../ControllerCore.h" -#include "../../common/Utils.h" - -using namespace tlm; - -namespace core { - -PowerDownManagerTimeout::PowerDownManagerTimeout(ControllerCore& controller): controller(controller) -{ - for (Bank bank : controller.getBanks()) - { - setUpDummy(powerDownPayloads[bank], bank); - } -} - -PowerDownManagerTimeout::~PowerDownManagerTimeout() -{ - // TODO Auto-generated destructor stub -} - -void PowerDownManagerTimeout::sleep(Bank bank, sc_time time) -{ - if(canSleep() && (time - controller.state.getLastScheduledCommand().getEnd()) >= Configuration::getInstance().powerDownTimeout) - { - PowerDownState state; - if(Configuration::getInstance().powerDownMode == PowerDownMode::TimeoutPDN) - { - state = controller.state.bankStates.allRowBuffersAreClosed() ? PowerDownState::PDNPrecharge : PowerDownState::PDNActive; - } - else - { - state = PowerDownState::PDNSelfRefresh; - } - - Command cmd = IPowerDownManager::getSleepCommand(powerDownState); - ScheduledCommand pdn(cmd, time, getMinimalExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - - controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); - - if (controller.refreshManager->hasCollision(pdn)) - { - return; - } - else - { - setPowerDownState(state); - sendPowerDownPayloads(pdn); - } - } -} - -bool PowerDownManagerTimeout::isInPowerDown() -{ - return (powerDownState == PowerDownState::PDNActive || powerDownState == PowerDownState::PDNPrecharge - || powerDownState == PowerDownState::PDNSelfRefresh); -} - -void PowerDownManagerTimeout::setPowerDownState(PowerDownState state) -{ - powerDownState = state; - DebugManager::getInstance().printDebugMessage(PowerDownManagerBankwise::senderName, - "Is now in state " + powerDownStateToString(powerDownState) + " on all banks"); -} - -void PowerDownManagerTimeout::wakeUp(Bank bank, sc_time time) -{ - if (isInPowerDown()) //Request wakes up power down - { - Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); - ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - controller.getCommandChecker(cmd).delayToSatisfyConstraints(pdn); - - if (cmd == Command::SREFX) - controller.refreshManager->reInitialize(bank, pdn.getEnd()); - - setPowerDownState(PowerDownState::Awake); - sendPowerDownPayloads(pdn); - } -} - -void PowerDownManagerTimeout::wakeUpForRefresh(Bank bank, sc_time time) -{ - if (isInPowerDown()) - { - Command cmd = IPowerDownManager::getWakeUpCommand(powerDownState); - ScheduledCommand pdn(cmd, time, getExecutionTime(cmd, powerDownPayloads[bank]), - DramExtension::getExtension(powerDownPayloads[bank])); - - setPowerDownState(PowerDownState::AwakeForRefresh); - sendPowerDownPayloads(pdn); - } -} - -void PowerDownManagerTimeout::triggerSleep(Bank bank, sc_time time) -{ - if(canSleep()) - { - controller.wrapper.send(REFTrigger, time + controller.config.powerDownTimeout, pdn_trigger); - } -} - -bool PowerDownManagerTimeout::isInSelfRefresh(Bank bank) -{ - return powerDownState == PowerDownState::PDNSelfRefresh; -} - -bool PowerDownManagerTimeout::canSleep() -{ - for (Bank bank : controller.getBanks()) - { - if (!controller.numberOfPayloads[bank] == 0) - return false; - } - return true; -} - -void PowerDownManagerTimeout::sendPowerDownPayloads(ScheduledCommand& cmd) -{ - controller.state.bus.moveCommandToNextFreeSlot(cmd); - for (Bank bank : controller.getBanks()) - { - tlm_generic_payload& payloadToSend = powerDownPayloads[bank]; - ScheduledCommand pdnToSend(cmd.getCommand(), cmd.getStart(), cmd.getExecutionTime(), - DramExtension::getExtension(payloadToSend)); - controller.state.change(pdnToSend); - controller.wrapper.send(pdnToSend, payloadToSend); - } -} - -} diff --git a/dram/src/core/powerdown/PowerDownManagerTimeout.h b/dram/src/core/powerdown/PowerDownManagerTimeout.h deleted file mode 100644 index 2f6ba16c..00000000 --- a/dram/src/core/powerdown/PowerDownManagerTimeout.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * PowerDownManagerTimeout.h - * - * Created on: May 5, 2014 - * Author: jungma - */ - -#ifndef POWERDOWNMANAGERTIMEOUT_H_ -#define POWERDOWNMANAGERTIMEOUT_H_ - -#include "IPowerDownManager.h" -#include -#include "../../common/dramExtension.h" -#include -#include "../scheduling/ScheduledCommand.h" - -namespace core { -class ControllerCore; - -class PowerDownManagerTimeout: public core::IPowerDownManager -{ -public: - PowerDownManagerTimeout(ControllerCore& controller); - virtual ~PowerDownManagerTimeout(); - - virtual void triggerSleep(Bank bank, sc_time time); - virtual void sleep(Bank bank, sc_time time); - - virtual void wakeUp(Bank bank, sc_time time); - virtual void wakeUpForRefresh(Bank bank, sc_time time); - - virtual bool isInSelfRefresh(Bank bank); -private: - bool canSleep(); - ControllerCore& controller; - tlm::tlm_generic_payload pdn_trigger; - - std::map powerDownPayloads; - void sendPowerDownPayloads(ScheduledCommand& cmd); - - PowerDownState powerDownState; - void setPowerDownState(PowerDownState state); - - bool isInPowerDown(); - - -}; - -} - -#endif /* POWERDOWNMANAGERTIMEOUT_H_ */ diff --git a/dram/src/core/scheduling/ScheduledCommand.h b/dram/src/core/scheduling/ScheduledCommand.h deleted file mode 100644 index 0a561631..00000000 --- a/dram/src/core/scheduling/ScheduledCommand.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ScheduledCommand.h - * - * Created on: Mar 10, 2014 - * Author: jonny - */ - -#ifndef SCHEDULEDCOMMAND_H_ -#define SCHEDULEDCOMMAND_H_ - -#include -#include -#include "../Command.h" -#include "../../common/dramExtension.h" -#include "../../common/TlmRecorder.h" -#include "../TimingCalculation.h" - -namespace core { - -class ScheduledCommand -{ -public: - - ScheduledCommand(Command command, sc_time start, sc_time executionTime, const DramExtension& extension) : - command(command), start(start), executionTime(executionTime),end(start+executionTime), - extension(extension) - { - } - - - ScheduledCommand() : - command(Command::NOP), start(SC_ZERO_TIME), executionTime(SC_ZERO_TIME), end(SC_ZERO_TIME), extension() - { - } - - bool isNoCommand() const; - bool isValidCommand() const; - - const sc_time getStart() const; - void setStart(sc_time newStart); - void delayStart(sc_time delay); - void delayToMeetConstraint(sc_time previous, sc_time constraint); - - const sc_time getEnd() const; - const Command getCommand() const; - const sc_time getExecutionTime() const; - - Bank getBank() const; - BankGroup getBankGroup() const; - Row getRow() const; - - unsigned int getBurstLength() const; - bool operator ==(const ScheduledCommand& b) const; - bool commandIsIn(const std::vector& commandSet) const; - - TimeInterval getIntervalOnDataStrobe() const; - - -private: - Command command; - sc_time start; - sc_time executionTime; - sc_time end; - DramExtension extension; -}; -} /* namespace controller */ - -#endif /* SCHEDULEDCOMMAND_H_ */ diff --git a/dram/src/core/scheduling/checker/PrechargeChecker.cpp b/dram/src/core/scheduling/checker/PrechargeChecker.cpp deleted file mode 100644 index 9f525200..00000000 --- a/dram/src/core/scheduling/checker/PrechargeChecker.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * PrechargeChecker.cpp - * - * Created on: Mar 13, 2014 - * Author: jonny - */ - -#include "PrechargeChecker.h" -#include "../../../common/Utils.h" - -namespace core { - -void PrechargeChecker::delayToSatisfyConstraints(ScheduledCommand& command) const -{ - sc_assert(command.getCommand() == Command::Precharge); - - ScheduledCommand lastCommand = state.getLastScheduledCommand(command.getBank()); - - if (lastCommand.isValidCommand()) - { - if (lastCommand.getCommand() == Command::Read) - { - command.delayToMeetConstraint(lastCommand.getStart(),config.Timings.tRTP); - } - else if (lastCommand.getCommand() == Command::Write) - { - command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tWL + getWriteAccessTime() + config.Timings.tWR); - } - else if (lastCommand.getCommand() == Command::PDNAX) - { - command.delayToMeetConstraint(lastCommand.getStart(), config.Timings.tXP); - } - else - reportFatal("Precharge Checker", "Precharge can not follow " + commandToString(lastCommand.getCommand())); - } - - state.bus.moveCommandToNextFreeSlot(command); -} - -} /* namespace controller */ diff --git a/dram/src/simulation/Arbiter.h b/dram/src/simulation/Arbiter.h index b1c9b069..813845cd 100644 --- a/dram/src/simulation/Arbiter.h +++ b/dram/src/simulation/Arbiter.h @@ -17,7 +17,7 @@ #include #include "../common/xmlAddressdecoder.h" #include "../common/dramExtension.h" -#include "../core/TimingCalculation.h" +#include "../controller/core/TimingCalculation.h" #include @@ -28,119 +28,119 @@ template struct Arbiter: public sc_module { public: - tlm_utils::simple_initiator_socket iSocket; - tlm_utils::simple_target_socket_tagged tSockets[NUMBER_OF_THREADS]; + tlm_utils::simple_initiator_socket iSocket; + tlm_utils::simple_target_socket_tagged tSockets[NUMBER_OF_THREADS]; - SC_CTOR(Arbiter) : - payloadEventQueue(this, &Arbiter::peqCallback), channelIsFree(true) - { - iSocket.register_nb_transport_bw(this, &Arbiter::nb_transport_bw); + SC_CTOR(Arbiter) : + payloadEventQueue(this, &Arbiter::peqCallback), channelIsFree(true) + { + iSocket.register_nb_transport_bw(this, &Arbiter::nb_transport_bw); - for (unsigned int i = 0; i < NUMBER_OF_THREADS; ++i) - { - tSockets[i].register_nb_transport_fw(this, &Arbiter::nb_transport_fw, i); - } - } + for (unsigned int i = 0; i < NUMBER_OF_THREADS; ++i) + { + tSockets[i].register_nb_transport_fw(this, &Arbiter::nb_transport_fw, i); + } + } private: - tlm_utils::peq_with_cb_and_phase payloadEventQueue; - bool channelIsFree; - deque backpressure; + tlm_utils::peq_with_cb_and_phase payloadEventQueue; + bool channelIsFree; + deque backpressure; - // Initiated by dram - tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) - { - TlmRecorder::getInstance().recordPhase(payload, phase, bwDelay + sc_time_stamp()); - payloadEventQueue.notify(payload, phase, bwDelay); - return TLM_ACCEPTED; - } + // Initiated by dram + tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) + { + TlmRecorder::getInstance().recordPhase(payload, phase, bwDelay + sc_time_stamp()); + payloadEventQueue.notify(payload, phase, bwDelay); + return TLM_ACCEPTED; + } - // Initiated by .stl players - tlm_sync_enum nb_transport_fw(int socketId, tlm_generic_payload& payload, tlm_phase& phase, - sc_time& fwDelay) - { - if(phase == BEGIN_REQ) - { - appendDramExtension(socketId, payload); - payload.acquire(); - } - else if(phase == END_RESP) - payload.release(); + // Initiated by .stl players + tlm_sync_enum nb_transport_fw(int socketId, tlm_generic_payload& payload, tlm_phase& phase, + sc_time& fwDelay) + { + if(phase == BEGIN_REQ) + { + appendDramExtension(socketId, payload); + payload.acquire(); + } + else if(phase == END_RESP) + payload.release(); - payloadEventQueue.notify(payload, phase, fwDelay); - return TLM_ACCEPTED; - } + payloadEventQueue.notify(payload, phase, fwDelay); + return TLM_ACCEPTED; + } - void peqCallback(tlm_generic_payload& payload, const tlm_phase& phase) - { - //Phases initiated by .stl players - if (phase == BEGIN_REQ) - { - if(channelIsFree) - { - channelIsFree = false; - sendToChannel(payload, phase, SC_ZERO_TIME ); - } - else - { - backpressure.push_back(&payload); - } - } + void peqCallback(tlm_generic_payload& payload, const tlm_phase& phase) + { + //Phases initiated by .stl players + if (phase == BEGIN_REQ) + { + if(channelIsFree) + { + channelIsFree = false; + sendToChannel(payload, phase, SC_ZERO_TIME ); + } + else + { + backpressure.push_back(&payload); + } + } - else if (phase == END_RESP) - { - sendToChannel(payload, phase, SC_ZERO_TIME ); - } + else if (phase == END_RESP) + { + sendToChannel(payload, phase, SC_ZERO_TIME ); + } - //Phases initiated by dram backend - else if (phase == END_REQ) - { - channelIsFree = true; - sendToTraceplayer(DramExtension::getExtension(payload).getThread().ID()-1, payload, phase, SC_ZERO_TIME); + //Phases initiated by dram backend + else if (phase == END_REQ) + { + channelIsFree = true; + sendToTraceplayer(DramExtension::getExtension(payload).getThread().ID()-1, payload, phase, SC_ZERO_TIME); - if(!backpressure.empty()) - { - tlm_generic_payload* payloadToSend = backpressure.front(); - backpressure.pop_front(); - sendToChannel(*payloadToSend, BEGIN_REQ, SC_ZERO_TIME ); - channelIsFree = false; - } - } - else if (phase == BEGIN_RESP) - { - sendToTraceplayer(DramExtension::getExtension(payload).getThread().ID()-1, payload, phase, SC_ZERO_TIME); - } + if(!backpressure.empty()) + { + tlm_generic_payload* payloadToSend = backpressure.front(); + backpressure.pop_front(); + sendToChannel(*payloadToSend, BEGIN_REQ, SC_ZERO_TIME ); + channelIsFree = false; + } + } + else if (phase == BEGIN_RESP) + { + sendToTraceplayer(DramExtension::getExtension(payload).getThread().ID()-1, payload, phase, SC_ZERO_TIME); + } - else - { - SC_REPORT_FATAL(0, "Payload event queue in arbiter was triggered with unknown phase"); - } - } + else + { + SC_REPORT_FATAL(0, "Payload event queue in arbiter was triggered with unknown phase"); + } + } - void sendToChannel(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - iSocket->nb_transport_fw(payload, TPhase, TDelay); - } + void sendToChannel(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + iSocket->nb_transport_fw(payload, TPhase, TDelay); + } - void sendToTraceplayer(unsigned int id, tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - tSockets[id]->nb_transport_bw(payload, TPhase, TDelay); - } + void sendToTraceplayer(unsigned int id, tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + tSockets[id]->nb_transport_bw(payload, TPhase, TDelay); + } - void appendDramExtension(int socketId, tlm_generic_payload& payload) - { - unsigned int burstlength = payload.get_streaming_width(); - node n; - xmlAddressDecoder::getInstance().getNode(static_cast(payload.get_address()), &n); - Bank bank(n.bank); - DramExtension* extension = new DramExtension(Thread(socketId+1), Channel(n.channel), bank, bank.getBankGroup(), Row(n.row), Column(n.colum),burstlength); - payload.set_auto_extension(extension); - } + void appendDramExtension(int socketId, tlm_generic_payload& payload) + { + unsigned int burstlength = payload.get_streaming_width(); + node n; + xmlAddressDecoder::getInstance().getNode(static_cast(payload.get_address()), &n); + Bank bank(n.bank); + DramExtension* extension = new DramExtension(Thread(socketId+1), Channel(n.channel), bank, bank.getBankGroup(), Row(n.row), Column(n.colum),burstlength); + payload.set_auto_extension(extension); + } }; diff --git a/dram/src/simulation/Controller.h b/dram/src/simulation/Controller.h deleted file mode 100644 index 4ea2c9d3..00000000 --- a/dram/src/simulation/Controller.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - * ControllerWrapper.h - * - * Created on: Mar 15, 2014 - * Author: gernhard - */ - -#ifndef CONTROLLERWRAPPER_H_ -#define CONTROLLERWRAPPER_H_ - -//#include -//#include -//#include -//#include -//#include -#include -#include -#include - -//#include -#include "/opt/systemc-2.3.0/include/systemc" -#include "/opt/systemc-2.3.0/include/tlm" -#include "/opt/systemc-2.3.0/include/tlm_utils/peq_with_cb_and_phase.h" -#include "/opt/systemc-2.3.0/include/tlm_utils/simple_initiator_socket.h" -#include "/opt/systemc-2.3.0/include/tlm_utils/simple_target_socket.h" -#include "../common/dramExtension.h" -#include "../common/DebugManager.h" -#include "../common/protocol.h" -#include "../common/TlmRecorder.h" -#include "../common/Utils.h" -#include "../core/configuration/Configuration.h" -#include "../core/configuration/TimingConfiguration.h" -#include "../core/Command.h" -#include "../core/ControllerCore.h" -#include "../core/ControllerState.h" -#include "../core/IWrapperConnector.h" -#include "../core/powerdown/IPowerDownManager.h" -#include "../core/scheduling/ScheduledCommand.h" -#include "../core/scheduling/Trigger.h" -#include "../core/TimingCalculation.h" -#include "../scheduler/Fifo.h" -#include "../scheduler/Fr_Fcfs.h" -#include "../scheduler/PARBS.h" -//#include "../scheduler/Scheduler.h" - -using namespace std; -using namespace tlm; -using namespace core; -using namespace scheduler; - -template -struct Controller: public sc_module, public IWrapperConnector -{ -public: - - tlm_utils::simple_initiator_socket iSocket; - tlm_utils::simple_target_socket tSocket; - - Controller(sc_module_name name) : - frontendPEQ(this, &Controller::frontendPEQCallback), dramPEQ(this, &Controller::dramPEQCallback), controllerCorePEQ( - this, &Controller::controllerCorePEQCallback), debugManager(DebugManager::getInstance()) - { - controller = new ControllerCore(*this, numberOfPayloadsInSystem); - buildScheduler(); - iSocket.register_nb_transport_bw(this, &Controller::nb_transport_bw); - tSocket.register_nb_transport_fw(this, &Controller::nb_transport_fw); - } - - void buildScheduler() - { - string selectedScheduler = Configuration::getInstance().Scheduler; - - if (selectedScheduler == "FR_FCFS") - { - - scheduler = new FR_FCFS(controller->state.bankStates, Configuration::getInstance().RefreshAwareScheduling, - Configuration::getInstance().AdaptiveOpenPagePolicy); - } - else if (selectedScheduler == "PAR_BS") - { - scheduler = new PAR_BS(controller->state.bankStates, Configuration::getInstance().RefreshAwareScheduling, - Configuration::getInstance().Capsize); - } - else if (selectedScheduler == "FIFO") - scheduler = new Fifo(); - else - reportFatal(name(), "unsupported scheduler: " + selectedScheduler); - } - - ~Controller() - { - delete controller; - delete scheduler; - } - - void terminateSimulation() - { - for (Bank bank : controller->getBanks()) - { - controller->powerDownManager->wakeUp(bank, clkAlign(sc_time_stamp())); - } - } - - // ------- Interaction with controller core --------- - virtual void send(const ScheduledCommand& command, tlm_generic_payload& payload) override - { - sc_assert(command.getStart() >= sc_time_stamp()); - TimeInterval dataStrobe; - - switch (command.getCommand()) - { - case Command::Read: - dataStrobe = command.getIntervalOnDataStrobe(); - TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); - controllerCorePEQ.notify(payload, BEGIN_RD, command.getStart() - sc_time_stamp()); - break; - case Command::ReadA: - dataStrobe = command.getIntervalOnDataStrobe(); - TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); - controllerCorePEQ.notify(payload, BEGIN_RDA, command.getStart() - sc_time_stamp()); - break; - case Command::Write: - dataStrobe = command.getIntervalOnDataStrobe(); - TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); - controllerCorePEQ.notify(payload, BEGIN_WR, command.getStart() - sc_time_stamp()); - break; - case Command::WriteA: - dataStrobe = command.getIntervalOnDataStrobe(); - TlmRecorder::getInstance().updateDataStrobe(dataStrobe.start, dataStrobe.end, payload); - controllerCorePEQ.notify(payload, BEGIN_WRA, command.getStart() - sc_time_stamp()); - break; - case Command::AutoRefresh: - controllerCorePEQ.notify(payload, BEGIN_AUTO_REFRESH, command.getStart() - sc_time_stamp()); - break; - case Command::Activate: - controllerCorePEQ.notify(payload, BEGIN_ACT, command.getStart() - sc_time_stamp()); - break; - case Command::Precharge: - controllerCorePEQ.notify(payload, BEGIN_PRE, command.getStart() - sc_time_stamp()); - break; - case Command::PrechargeAll: - controllerCorePEQ.notify(payload, BEGIN_PRE_ALL, command.getStart() - sc_time_stamp()); - break; - case Command::PDNA: - controllerCorePEQ.notify(payload, BEGIN_PDNA, command.getStart() - sc_time_stamp()); - break; - case Command::PDNP: - controllerCorePEQ.notify(payload, BEGIN_PDNP, command.getStart() - sc_time_stamp()); - break; - case Command::SREF: - controllerCorePEQ.notify(payload, BEGIN_SREF, command.getStart() - sc_time_stamp()); - break; - case Command::PDNAX: - controllerCorePEQ.notify(payload, END_PDNA, command.getEnd() - sc_time_stamp()); - break; - case Command::PDNPX: - controllerCorePEQ.notify(payload, END_PDNP, command.getEnd() - sc_time_stamp()); - break; - case Command::SREFX: - controllerCorePEQ.notify(payload, END_SREF, command.getEnd() - sc_time_stamp()); - break; - - default: - SC_REPORT_FATAL(0, "unsupported command was sent by controller"); - break; - } - } - - virtual void send(Trigger trigger, sc_time time, tlm_generic_payload& payload) override - { - sc_assert(time >= sc_time_stamp()); - - sc_time delay = time - sc_time_stamp(); - if (trigger == Trigger::REFTrigger) - { - controllerCorePEQ.notify(payload, REF_TRIGGER, delay); - } - else if (trigger == Trigger::PDNTrigger) - { - controllerCorePEQ.notify(payload, PDN_TRIGGER, delay); - } - else - { - SC_REPORT_FATAL("controller wrapper", "unknown trigger"); - } - } - - void controllerCorePEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) - { - if (phase == REF_TRIGGER) - { - controller->triggerRefresh(payload, sc_time_stamp()); - } - else if (phase == PDN_TRIGGER) - { - controller->powerDownManager->sleep(DramExtension::getExtension(payload).getBank(),sc_time_stamp()); - } - else - { - Bank bank = DramExtension::getExtension(payload).getBank(); - sendToDram(payload, phase, SC_ZERO_TIME); - - if (phase == BEGIN_RD || phase == BEGIN_WR) - scheduleNextPayload(bank); - else if (phase == BEGIN_AUTO_REFRESH) - printDebugMessage("Entering auto refresh on bank " + to_string(bank.ID())); - else if (isIn(phase, { BEGIN_PDNA, BEGIN_PDNP, BEGIN_SREF })) - printDebugMessage("Entering PowerDown " + phaseNameToString(phase) + " on bank " + to_string(bank.ID())); - else if (isIn(phase, { END_PDNA, END_PDNP, END_SREF })) - printDebugMessage("Leaving PowerDown " + phaseNameToString(phase) + " on bank " + to_string(bank.ID())); - else if (isIn(phase, { BEGIN_RD, BEGIN_WR, BEGIN_ACT, BEGIN_PRE, BEGIN_PRE_ALL, BEGIN_RDA, BEGIN_WRA })) - { - } - else - SC_REPORT_FATAL(0, "refreshTriggerPEQCallback queue in controller wrapper was triggered with unsupported phase"); - } - } - -private: - ControllerCore* controller; - Scheduler* scheduler; - std::map numberOfPayloadsInSystem; - - tlm::tlm_generic_payload* backpressure = NULL; - - tlm_utils::peq_with_cb_and_phase frontendPEQ; - tlm_utils::peq_with_cb_and_phase dramPEQ; - tlm_utils::peq_with_cb_and_phase controllerCorePEQ; - - DebugManager& debugManager; - - // --- FRONTEND INTERACTION ------ - tlm_sync_enum nb_transport_fw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& fwDelay) - { - if (phase == BEGIN_REQ) - { - TlmRecorder::getInstance().recordPhase(payload, phase, fwDelay + sc_time_stamp()); - frontendPEQ.notify(payload, phase, - clkAlign(sc_time_stamp() + fwDelay) - (sc_time_stamp() + fwDelay) + Configuration::getInstance().Timings.clk); - } - else if (phase == END_RESP) - { - TlmRecorder::getInstance().recordPhase(payload, phase, - fwDelay + sc_time_stamp() + Configuration::getInstance().Timings.clk); - frontendPEQ.notify(payload, phase, clkAlign(sc_time_stamp() + fwDelay) - (sc_time_stamp() + fwDelay)); - } - return TLM_ACCEPTED; - } - - void frontendPEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) - { - if (phase == BEGIN_REQ) - { - payload.acquire(); - payloadEntersSystem(payload); - if (getTotalNumberOfPayloadsInSystem() > controller->config.MaxNrOfTransactions) - { - printDebugMessage("##Backpressure: Max number of transactions in system reached"); - backpressure = &payload; - return; - } - payload.set_response_status(tlm::TLM_OK_RESPONSE); - sendToFrontend(payload, END_REQ, SC_ZERO_TIME); - scheduler->schedule(&payload); - scheduleNextPayload(DramExtension::getExtension(payload).getBank()); - } - else if (phase == END_RESP) - { - if (backpressure != NULL) - { - printDebugMessage("##Backpressure released"); - backpressure->set_response_status(tlm::TLM_OK_RESPONSE); - sendToFrontend(*backpressure, END_REQ, SC_ZERO_TIME); - scheduler->schedule(backpressure); - scheduleNextPayload(DramExtension::getExtension(backpressure).getBank()); - backpressure = NULL; - } - payloadLeavesSystem(payload); - payload.release(); - } - else - { - SC_REPORT_FATAL(0, "Frontend PEQ event queue in controller wrapper was triggered with unknown phase"); - } - } - - void payloadEntersSystem(tlm_generic_payload& payload) - { - Bank bank = DramExtension::getExtension(payload).getBank(); - printDebugMessage( - "Payload enters system on bank " + to_string(bank.ID()) + ". Total number of payloads in Controller: " - + to_string(getTotalNumberOfPayloadsInSystem())); - numberOfPayloadsInSystem[bank]++; - } - - void payloadLeavesSystem(tlm_generic_payload& payload) - { - Bank bank = DramExtension::getExtension(payload).getBank(); - numberOfPayloadsInSystem[bank]--; - printDebugMessage( - "Payload left system on bank " + to_string(bank.ID()) + ". Total number of payloads in Controller: " - + to_string(getTotalNumberOfPayloadsInSystem())); - controller->powerDownManager->triggerSleep(bank, sc_time_stamp()); - - } - - unsigned int getTotalNumberOfPayloadsInSystem() - { - unsigned int sum = 0; - for (Bank bank : controller->getBanks()) - { - sum += numberOfPayloadsInSystem[bank]; - } - return sum; - } - - void scheduleNextPayload(Bank bank) - { - printDebugMessage("Triggering schedule next payload on bank " + to_string(bank.ID())); - if (scheduler->hasTransactionForBank(bank)) - { - controller->powerDownManager->wakeUp(bank, sc_time_stamp()); - - if (controller->isBusy(sc_time_stamp(), bank)) - { - printDebugMessage("\t-> break: controller is busy"); - return; - } - - tlm_generic_payload* nextTransaction = scheduler->getTransactionForBank(bank); - if (controller->scheduleRequest(sc_time_stamp(), *nextTransaction)) - { - scheduler->popTransactionForBank(bank, nextTransaction); - printDebugMessage("\t-> payload was scheduled by core"); - } - else - { - printDebugMessage("\t-> break: payload was not scheduled by core (collision with refresh)"); - } - } - else - { - printDebugMessage("\t-> break: no transaction for bank"); - controller->powerDownManager->sleep(bank, sc_time_stamp()); - } - } - - void sendToFrontend(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - tSocket->nb_transport_bw(payload, TPhase, TDelay); - } - - // --- DRAM INTERACTION ------ - tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) - { - dramPEQ.notify(payload, phase, bwDelay); - TlmRecorder::getInstance().recordPhase(payload, phase, bwDelay + sc_time_stamp()); - return TLM_ACCEPTED; - } - - void dramPEQCallback(tlm_generic_payload& payload, const tlm_phase& phase) - { - Bank bank = DramExtension::getExtension(payload).getBank(); - printDebugMessage("Received " + phaseNameToString(phase) + " on bank " + to_string(bank.ID()) + " from DRAM"); - - if (phase == BEGIN_RD || phase == BEGIN_WR) - { - scheduleNextPayload(bank); - sendToDram(payload, phase, SC_ZERO_TIME); - } - else if (phase == END_RD || phase == END_WR) - { - sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); - } - else if (phase == END_RDA || phase == END_WRA) - { - sendToFrontend(payload, BEGIN_RESP, SC_ZERO_TIME); - scheduleNextPayload(bank); - } - else if (phase == END_AUTO_REFRESH) - { - printDebugMessage("Finished auto refresh on bank " + to_string(bank.ID())); - scheduleNextPayload(DramExtension::getExtension(payload).getBank()); - } - else if (isIn(phase, { END_PRE, END_PRE_ALL, END_ACT })) - { - - } - else - { - string str = string("dramPEQCallback queue in controller wrapper was triggered with unsupported phase ") - + phaseNameToString(phase); - SC_REPORT_FATAL(0, str.c_str()); - } - } - - void sendToDram(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - iSocket->nb_transport_fw(payload, TPhase, TDelay); - } - - //Helpers - void printDebugMessage(string message) - { - debugManager.printDebugMessage(name(), message); - } - - bool isIn(tlm_phase phase, std::vector phases) - { - for (tlm_phase p : phases) - { - if (p == phase) - return true; - } - return false; - } - -}; - -#endif /* CONTROLLERWRAPPER_H_ */ diff --git a/dram/src/simulation/Dram.h b/dram/src/simulation/Dram.h index f954c451..ff403b21 100644 --- a/dram/src/simulation/Dram.h +++ b/dram/src/simulation/Dram.h @@ -13,7 +13,7 @@ #include #include #include "../common/DebugManager.h" -#include "../core/TimingCalculation.h" +#include "../controller/core/TimingCalculation.h" #include "../common/protocol.h" #include "../common/Utils.h" #include "../common/TlmRecorder.h" @@ -23,102 +23,102 @@ using namespace tlm; using namespace core; template + unsigned int FIXED_BL_VALUE = 0> struct Dram: sc_module { - tlm_utils::simple_target_socket tSocket; + tlm_utils::simple_target_socket tSocket; - SC_CTOR(Dram) : - tSocket("socket") - { - tSocket.register_nb_transport_fw(this, &Dram::nb_transport_fw); - } + SC_CTOR(Dram) : + tSocket("socket") + { + tSocket.register_nb_transport_fw(this, &Dram::nb_transport_fw); + } - ~Dram() - { + ~Dram() + { - } + } - virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload& payload, tlm::tlm_phase& phase, sc_time& delay) - { - TlmRecorder::getInstance().recordPhase(payload, phase, sc_time_stamp() + delay); + virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload& payload, tlm::tlm_phase& phase, sc_time& delay) + { + TlmRecorder::getInstance().recordPhase(payload, phase, sc_time_stamp() + delay); - if (phase == BEGIN_PRE) - { - sendToController(payload, END_PRE, delay + getExecutionTime(Command::Precharge, payload)); - } - else if (phase == BEGIN_PRE_ALL) - { - sendToController(payload, END_PRE_ALL,delay + getExecutionTime(Command::PrechargeAll, payload)); - } - else if (phase == BEGIN_ACT) - { - sendToController(payload, END_ACT, delay + getExecutionTime(Command::Activate, payload)); - } - else if (phase == BEGIN_WR) - { - sendToController(payload, END_WR, delay + getExecutionTime(Command::Write, payload)); - } - else if (phase == BEGIN_RD) - { - sendToController(payload, END_RD, delay + getExecutionTime(Command::Read, payload)); - } - else if (phase == BEGIN_WRA) - { - sendToController(payload, END_WRA, delay + getExecutionTime(Command::WriteA, payload)); - } - else if (phase == BEGIN_RDA) - { - sendToController(payload, END_RDA, delay + getExecutionTime(Command::ReadA, payload)); - } - else if (phase == BEGIN_AUTO_REFRESH) - { - sendToController(payload, END_AUTO_REFRESH, delay + getExecutionTime(Command::AutoRefresh, payload)); - } + if (phase == BEGIN_PRE) + { + sendToController(payload, END_PRE, delay + getExecutionTime(Command::Precharge, payload)); + } + else if (phase == BEGIN_PRE_ALL) + { + sendToController(payload, END_PRE_ALL,delay + getExecutionTime(Command::PrechargeAll, payload)); + } + else if (phase == BEGIN_ACT) + { + sendToController(payload, END_ACT, delay + getExecutionTime(Command::Activate, payload)); + } + else if (phase == BEGIN_WR) + { + sendToController(payload, END_WR, delay + getExecutionTime(Command::Write, payload)); + } + else if (phase == BEGIN_RD) + { + sendToController(payload, END_RD, delay + getExecutionTime(Command::Read, payload)); + } + else if (phase == BEGIN_WRA) + { + sendToController(payload, END_WRA, delay + getExecutionTime(Command::WriteA, payload)); + } + else if (phase == BEGIN_RDA) + { + sendToController(payload, END_RDA, delay + getExecutionTime(Command::ReadA, payload)); + } + else if (phase == BEGIN_AUTO_REFRESH) + { + sendToController(payload, END_AUTO_REFRESH, delay + getExecutionTime(Command::AutoRefresh, payload)); + } - //Powerdown phases have to be started and ended by the controller, because they do not have a fixed length - else if (phase == BEGIN_PDNP) - { + //Powerdown phases have to be started and ended by the controller, because they do not have a fixed length + else if (phase == BEGIN_PDNP) + { - } - else if (phase == END_PDNP) - { + } + else if (phase == END_PDNP) + { - } - else if (phase == BEGIN_PDNA) - { + } + else if (phase == BEGIN_PDNA) + { - } - else if (phase == END_PDNA) - { + } + else if (phase == END_PDNA) + { - } - else if (phase == BEGIN_SREF) - { + } + else if (phase == BEGIN_SREF) + { - } - else if (phase == END_SREF) - { + } + else if (phase == END_SREF) + { - } - else - { - SC_REPORT_FATAL("DRAM", "DRAM PEQ was called with unknown phase"); - } - return tlm::TLM_ACCEPTED; - } + } + else + { + SC_REPORT_FATAL("DRAM", "DRAM PEQ was called with unknown phase"); + } + return tlm::TLM_ACCEPTED; + } - void sendToController(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - tSocket->nb_transport_bw(payload, TPhase, TDelay); - } + void sendToController(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + tSocket->nb_transport_bw(payload, TPhase, TDelay); + } - void printDebugMessage(string message) - { - DebugManager::getInstance().printDebugMessage(name(), message); - } + void printDebugMessage(string message) + { + DebugManager::getInstance().printDebugMessage(name(), message); + } }; diff --git a/dram/src/simulation/Simulation.cpp b/dram/src/simulation/Simulation.cpp index 384d03c0..978ab3ff 100644 --- a/dram/src/simulation/Simulation.cpp +++ b/dram/src/simulation/Simulation.cpp @@ -9,7 +9,7 @@ #include "../common/TlmRecorder.h" #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" -#include "../core/ControllerCore.h" +#include "../controller/core/ControllerCore.h" #include #include #include @@ -23,135 +23,135 @@ namespace simulation { void Simulation::setupDebugManager(bool silent, const string& traceName) { - vector whiteList; - if (!silent) - { - whiteList.push_back(controller->name()); - whiteList.push_back(player2->name()); - whiteList.push_back(player1->name()); - whiteList.push_back(this->name()); - whiteList.push_back(TlmRecorder::senderName); - whiteList.push_back(ControllerCore::senderName); - whiteList.push_back(PowerDownManagerBankwise::senderName); - } - auto& dbg = DebugManager::getInstance(); - dbg.addToWhiteList(whiteList); - dbg.setDebugFile(traceName + ".txt"); - if (silent) - { - dbg.writeToConsole = false; - dbg.writeToFile = false; - } + vector whiteList; + if (!silent) + { + whiteList.push_back(controller->name()); + whiteList.push_back(player2->name()); + whiteList.push_back(player1->name()); + whiteList.push_back(this->name()); + whiteList.push_back(TlmRecorder::senderName); + whiteList.push_back(ControllerCore::senderName); + whiteList.push_back(PowerDownManagerBankwise::senderName); + } + auto& dbg = DebugManager::getInstance(); + dbg.addToWhiteList(whiteList); + dbg.setDebugFile(traceName + ".txt"); + if (silent) + { + dbg.writeToConsole = false; + dbg.writeToFile = false; + } } Simulation::Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, - std::vector devices, bool silent) : - traceName(traceName), dramSetup(setup) + std::vector devices, bool silent) : + traceName(traceName), dramSetup(setup) { - SC_THREAD(stop); + SC_THREAD(stop); - xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/amconfigs/") + setup.addressmapping; - TlmRecorder::dbName = traceName; - TlmRecorder::sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql"); - Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig; - Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec; - TlmRecorder::getInstance().recordMemconfig(setup.memconfig); - TlmRecorder::getInstance().recordMemspec(setup.memspec); + xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/amconfigs/") + setup.addressmapping; + TlmRecorder::dbName = traceName; + TlmRecorder::sqlScriptURI = pathToResources + string("scripts/createTraceDB.sql"); + Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig; + Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec; + TlmRecorder::getInstance().recordMemconfig(setup.memconfig); + TlmRecorder::getInstance().recordMemspec(setup.memspec); - dram = new Dram<>("dram"); - arbiter = new Arbiter("arbiter"); - controller = new Controller<>("controller"); + dram = new Dram<>("dram"); + arbiter = new Arbiter("arbiter"); + controller = new Controller<>("controller"); - player1 = new TracePlayer<>("player1", pathToResources + string("traces/") + devices[0].trace, devices[0].burstLength, this); - player2 = new TracePlayer<>("player2", pathToResources + string("traces/") + devices[1].trace, devices[1].burstLength, this); - player3 = new TracePlayer<>("player3", pathToResources + string("traces/") + devices[2].trace, devices[2].burstLength, this); - player4 = new TracePlayer<>("player4", pathToResources + string("traces/") + devices[3].trace, devices[3].burstLength, this); - TlmRecorder::getInstance().recordTracenames(devices[0].trace + "," + devices[1].trace + "," + devices[2].trace + "," + devices[3].trace); + player1 = new TracePlayer<>("player1", pathToResources + string("traces/") + devices[0].trace, devices[0].burstLength, this); + player2 = new TracePlayer<>("player2", pathToResources + string("traces/") + devices[1].trace, devices[1].burstLength, this); + player3 = new TracePlayer<>("player3", pathToResources + string("traces/") + devices[2].trace, devices[2].burstLength, this); + player4 = new TracePlayer<>("player4", pathToResources + string("traces/") + devices[3].trace, devices[3].burstLength, this); + TlmRecorder::getInstance().recordTracenames(devices[0].trace + "," + devices[1].trace + "," + devices[2].trace + "," + devices[3].trace); - player1->iSocket.bind(arbiter->tSockets[0]); - player2->iSocket.bind(arbiter->tSockets[1]); - player3->iSocket.bind(arbiter->tSockets[2]); - player4->iSocket.bind(arbiter->tSockets[3]); + player1->iSocket.bind(arbiter->tSockets[0]); + player2->iSocket.bind(arbiter->tSockets[1]); + player3->iSocket.bind(arbiter->tSockets[2]); + player4->iSocket.bind(arbiter->tSockets[3]); - arbiter->iSocket.bind(controller->tSocket); - controller->iSocket.bind(dram->tSocket); + arbiter->iSocket.bind(controller->tSocket); + controller->iSocket.bind(dram->tSocket); - setupDebugManager(silent, traceName); + setupDebugManager(silent, traceName); - totalTransactions = getNumberOfLines(pathToResources + string("traces/") + devices[0].trace); - totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[1].trace); - totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[2].trace); - totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[3].trace); + totalTransactions = getNumberOfLines(pathToResources + string("traces/") + devices[0].trace); + totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[1].trace); + totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[2].trace); + totalTransactions += getNumberOfLines(pathToResources + string("traces/") + devices[3].trace); - remainingTransactions = totalTransactions; + remainingTransactions = totalTransactions; } Simulation::~Simulation() { - delete dram; - delete arbiter; - delete controller; - delete player1; - delete player2; - delete player3; - delete player4; + delete dram; + delete arbiter; + delete controller; + delete player1; + delete player2; + delete player3; + delete player4; } void Simulation::start() { - report("\n\nStarting simulation:"); - report(headline); - report(" -> setup: \t\t" + getFileName(traceName)); - report(" -> memspec: \t\t" + Configuration::getInstance().MemoryId); - report(" -> transactions: \t" + to_string(totalTransactions)); - cout << endl; - simulationStartTime = clock(); - player1->start(); - player2->start(); - player3->start(); - player4->start(); - sc_set_stop_mode(SC_STOP_FINISH_DELTA); - sc_start(); + report("\n\nStarting simulation:"); + report(headline); + report(" -> setup: \t\t" + getFileName(traceName)); + report(" -> memspec: \t\t" + Configuration::getInstance().MemoryId); + report(" -> transactions: \t" + to_string(totalTransactions)); + cout << endl; + simulationStartTime = clock(); + player1->start(); + player2->start(); + player3->start(); + player4->start(); + sc_set_stop_mode(SC_STOP_FINISH_DELTA); + sc_start(); } void inline Simulation::transactionFinished() { - remainingTransactions--; - loadbar(totalTransactions - remainingTransactions, totalTransactions); - if (remainingTransactions == 0) - { - cout << endl; - terminateSimulation.notify(); - } + remainingTransactions--; + loadbar(totalTransactions - remainingTransactions, totalTransactions); + if (remainingTransactions == 0) + { + cout << endl; + terminateSimulation.notify(); + } } void Simulation::stop() { - wait(terminateSimulation); - report("\nTerminating simulation"); - wait(sc_time(50, SC_NS)); - controller->terminateSimulation(); - wait(sc_time(50, SC_NS)); - TlmRecorder::getInstance().closeConnection(); - sc_stop(); + wait(terminateSimulation); + report("\nTerminating simulation"); + wait(sc_time(50, SC_NS)); + controller->terminateSimulation(); + wait(sc_time(50, SC_NS)); + TlmRecorder::getInstance().closeConnection(); + sc_stop(); - double elapsed_secs = double(clock() - simulationStartTime) / CLOCKS_PER_SEC; - report("Simulation took " + to_string(elapsed_secs) + " seconds"); + double elapsed_secs = double(clock() - simulationStartTime) / CLOCKS_PER_SEC; + report("Simulation took " + to_string(elapsed_secs) + " seconds"); } void Simulation::report(string message) { - DebugManager::getInstance().printDebugMessage(this->name(), message); - cout << message << endl; + DebugManager::getInstance().printDebugMessage(this->name(), message); + cout << message << endl; } unsigned int Simulation::getNumberOfLines(string uri) { - std::ifstream file(uri); - file.unsetf(std::ios_base::skipws); // new lines will be skipped unless we stop it from happening: - // count the newlines with an algorithm specialized for counting: - unsigned lineCount = std::count(std::istream_iterator(file), std::istream_iterator(), '\n'); - return lineCount; + std::ifstream file(uri); + file.unsetf(std::ios_base::skipws); // new lines will be skipped unless we stop it from happening: + // count the newlines with an algorithm specialized for counting: + unsigned lineCount = std::count(std::istream_iterator(file), std::istream_iterator(), '\n'); + return lineCount; } } /* namespace simulation */ diff --git a/dram/src/simulation/Simulation.h b/dram/src/simulation/Simulation.h index c4c7a589..9424763d 100644 --- a/dram/src/simulation/Simulation.h +++ b/dram/src/simulation/Simulation.h @@ -11,7 +11,7 @@ #include "Dram.h" #include "Arbiter.h" #include "TracePlayer.h" -#include "Controller.h" +#include "../controller/Controller.h" #include "ISimulation.h" #include #include @@ -20,59 +20,59 @@ namespace simulation { struct DramSetup { - DramSetup():memconfig(""),memspec(""){} - DramSetup(std::string memconfig, std::string memspec, std::string addressmapping) : memconfig(memconfig), memspec(memspec), addressmapping(addressmapping) {} - std::string memconfig; - std::string memspec; - std::string addressmapping; + DramSetup():memconfig(""),memspec(""){} + DramSetup(std::string memconfig, std::string memspec, std::string addressmapping) : memconfig(memconfig), memspec(memspec), addressmapping(addressmapping) {} + std::string memconfig; + std::string memspec; + std::string addressmapping; }; struct Device { - Device():trace("empty.stl"), burstLength(0){} - Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength) - { - } - std::string trace; - unsigned int burstLength; + Device():trace("empty.stl"), burstLength(0){} + Device(std::string trace, unsigned int burstLength = 8) : trace(trace), burstLength(burstLength) + { + } + std::string trace; + unsigned int burstLength; }; class Simulation: public ISimulation, public sc_module { public: - SC_HAS_PROCESS(Simulation); - Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, - std::vector devices, bool silent = false); - ~Simulation(); + SC_HAS_PROCESS(Simulation); + Simulation(sc_module_name name, string pathToResources, string traceName, DramSetup setup, + std::vector devices, bool silent = false); + ~Simulation(); - void start(); - void stop(); + void start(); + void stop(); - void inline transactionFinished() override; - constexpr static unsigned int NumberOfTracePlayers = 4; + void inline transactionFinished() override; + constexpr static unsigned int NumberOfTracePlayers = 4; private: - std::string traceName; - DramSetup dramSetup; + std::string traceName; + DramSetup dramSetup; - sc_event terminateSimulation; + sc_event terminateSimulation; - Dram<> *dram; - Arbiter *arbiter; - Controller<> *controller; + Dram<> *dram; + Arbiter *arbiter; + Controller<> *controller; - TracePlayer<> *player1; - TracePlayer<> *player2; - TracePlayer<> *player3; - TracePlayer<> *player4; + TracePlayer<> *player1; + TracePlayer<> *player2; + TracePlayer<> *player3; + TracePlayer<> *player4; - unsigned int totalTransactions; - unsigned int remainingTransactions; - clock_t simulationStartTime; - unsigned int getNumberOfLines(string uri); + unsigned int totalTransactions; + unsigned int remainingTransactions; + clock_t simulationStartTime; + unsigned int getNumberOfLines(string uri); - void report(std::string message); - void setupDebugManager(bool silent, const string& traceName); + void report(std::string message); + void setupDebugManager(bool silent, const string& traceName); }; } /* namespace simulation */ diff --git a/dram/src/simulation/SimulationManager.cpp b/dram/src/simulation/SimulationManager.cpp index c9bff046..0c10c547 100644 --- a/dram/src/simulation/SimulationManager.cpp +++ b/dram/src/simulation/SimulationManager.cpp @@ -15,7 +15,7 @@ using namespace simulation; namespace simulation { SimulationManager::SimulationManager(string resources) : - resources(resources), silent(false) + resources(resources), silent(false) { } @@ -25,160 +25,160 @@ SimulationManager::~SimulationManager() void SimulationManager::loadSimulationsFromXML(string uri) { - cout << "\n\nLoad Simulation-Batchs:" << endl; - cout << headline << endl; - cout << "\t-> load simulations .." << endl; + cout << "\n\nLoad Simulation-Batchs:" << endl; + cout << headline << endl; + cout << "\t-> load simulations .." << endl; - exportPath = getFileName(uri); - XMLDocument doc; - loadXML(uri, doc); + exportPath = getFileName(uri); + XMLDocument doc; + loadXML(uri, doc); - cout << "\t-> parsing simulation objects .." << endl; + cout << "\t-> parsing simulation objects .." << endl; - for (XMLElement* element = doc.FirstChildElement("simulation"); element != NULL; - element = element->NextSiblingElement("simulation")) - { - parseSimulationBatch(element); - } + for (XMLElement* element = doc.FirstChildElement("simulation"); element != NULL; + element = element->NextSiblingElement("simulation")) + { + parseSimulationBatch(element); + } - cout << "\t-> checking paths .." << endl; - checkPaths(); + cout << "\t-> checking paths .." << endl; + checkPaths(); - cout << "\t-> simulation batches loaded successfully!\n" << endl; + cout << "\t-> simulation batches loaded successfully!\n" << endl; - for (auto batch : simulationsBatches) - { - batch.print(); - } + for (auto batch : simulationsBatches) + { + batch.print(); + } } void SimulationManager::runSimulations() { - system(string("rm -rf " + exportPath).c_str()); - for (auto& batch : simulationsBatches) - { - system(string("mkdir -p " + exportPath + "/" + batch.simulationName).c_str()); +// system(string("rm -rf " + exportPath).c_str()); + for (auto& batch : simulationsBatches) + { + //system(string("mkdir -p " + exportPath + "/" + batch.simulationName).c_str()); - for (auto& dramSetup : batch.dramSetups) - { - string memconfig = getFileName(dramSetup.memconfig); - string memspec = getFileName(dramSetup.memspec); - string addressmappig = getFileName(dramSetup.addressmapping); + for (auto& dramSetup : batch.dramSetups) + { + string memconfig = getFileName(dramSetup.memconfig); + string memspec = getFileName(dramSetup.memspec); + string addressmappig = getFileName(dramSetup.addressmapping); - for (auto& traceSetup : batch.traceSetups) - { - runSimulation( - exportPath + "/" + batch.simulationName + "/" + traceSetup.first + "-" + memspec + "-" + - memconfig + ".tdb", dramSetup, traceSetup.second); - } - } - } + for (auto& traceSetup : batch.traceSetups) + { + runSimulation( + exportPath + "/" + batch.simulationName + "/" + traceSetup.first + "-" + memspec + "-" + + memconfig + ".tdb", dramSetup, traceSetup.second); + } + } + } } void SimulationManager::parseSimulationBatch(XMLElement* simulation) { - SimulationBatch batch; + SimulationBatch batch; - batch.simulationName = simulation->Attribute("id"); + batch.simulationName = simulation->Attribute("id"); - string memspecUri; - string addressmappingUri; + string memspecUri; + string addressmappingUri; - for (XMLElement* element = simulation->FirstChildElement("memspec"); element != NULL; - element = element->NextSiblingElement("memspec")) - { - memspecUri = element->GetText(); - for (XMLElement* element = simulation->FirstChildElement("addressmapping"); element != NULL; - element = element->NextSiblingElement("addressmapping")) - { - addressmappingUri = element->GetText(); - for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig"); - element != NULL; element = element->NextSiblingElement("memconfig")) - { - batch.dramSetups.push_back(DramSetup(element->GetText(), memspecUri, addressmappingUri)); - } - } - } + for (XMLElement* element = simulation->FirstChildElement("memspec"); element != NULL; + element = element->NextSiblingElement("memspec")) + { + memspecUri = element->GetText(); + for (XMLElement* element = simulation->FirstChildElement("addressmapping"); element != NULL; + element = element->NextSiblingElement("addressmapping")) + { + addressmappingUri = element->GetText(); + for (XMLElement* element = simulation->FirstChildElement("memconfigs")->FirstChildElement("memconfig"); + element != NULL; element = element->NextSiblingElement("memconfig")) + { + batch.dramSetups.push_back(DramSetup(element->GetText(), memspecUri, addressmappingUri)); + } + } + } - for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL; - element = element->NextSiblingElement("trace-setup")) - { - addTraceSetup(batch, element); - } + for (XMLElement* element = simulation->FirstChildElement("trace-setups")->FirstChildElement("trace-setup"); element != NULL; + element = element->NextSiblingElement("trace-setup")) + { + addTraceSetup(batch, element); + } - simulationsBatches.push_back(batch); + simulationsBatches.push_back(batch); } void SimulationManager::checkPaths() { - //reportFatal("Simulation Manager", "Not all paths in xml are valid"); + //reportFatal("Simulation Manager", "Not all paths in xml are valid"); } void SimulationManager::runSimulation(string traceName, DramSetup dramSetup, vector traceSetup) { - int pid = fork(); - int status = 0; - if (pid == 0) - { - Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup, silent); - simulation->start(); - delete simulation; - _Exit(0); - } + int pid = fork(); + int status = 0; + if (pid == 0) + { + Simulation* simulation = new Simulation("sim", resources, traceName, dramSetup, traceSetup, silent); + simulation->start(); + delete simulation; + _Exit(0); + } - waitpid(pid, &status, 0); + waitpid(pid, &status, 0); } void SimulationManager::startTraceAnalyzer() { - string p = getenv("trace"); - string run_tpr = p + " -f "; - for (auto batch : simulationsBatches) - { - run_tpr += exportPath + "/" + batch.simulationName + " "; + string p = getenv("trace"); + string run_tpr = p + " -f "; + for (auto batch : simulationsBatches) + { + run_tpr += exportPath + "/" + batch.simulationName + " "; - } - run_tpr += "&"; - system(run_tpr.c_str()); + } + run_tpr += "&"; + system(run_tpr.c_str()); } void SimulationManager::addTraceSetup(SimulationBatch& batch, tinyxml2::XMLElement* element) { - vector devices; - for (XMLElement* device = element->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device")) - { - devices.push_back(Device(device->GetText(), device->IntAttribute("bl"))); - } - while (devices.size() < Simulation::NumberOfTracePlayers) - { - devices.push_back(Device()); - } + vector devices; + for (XMLElement* device = element->FirstChildElement("device"); device != NULL; device = device->NextSiblingElement("device")) + { + devices.push_back(Device(device->GetText(), device->IntAttribute("bl"))); + } + while (devices.size() < Simulation::NumberOfTracePlayers) + { + devices.push_back(Device()); + } - batch.traceSetups.emplace(element->Attribute("id"), devices); + batch.traceSetups.emplace(element->Attribute("id"), devices); } void SimulationManager::report(string message) { - //DebugManager::getInstance().printDebugMessage("Simulation Manager", message); - //if (DebugManager::getInstance().writeToConsole == false) - cout << message << endl; + //DebugManager::getInstance().printDebugMessage("Simulation Manager", message); + //if (DebugManager::getInstance().writeToConsole == false) + cout << message << endl; } void SimulationBatch::print() { - for (DramSetup& s : dramSetups) - { - cout << s.memspec << " - " << s.memconfig << endl; - } - cout << endl; - for (auto& s : traceSetups) - { - cout << "trace-setup " + s.first + ":\n"; - for (Device d : s.second) - cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl; - cout << endl; - } + for (DramSetup& s : dramSetups) + { + cout << s.memspec << " - " << s.memconfig << endl; + } + cout << endl; + for (auto& s : traceSetups) + { + cout << "trace-setup " + s.first + ":\n"; + for (Device d : s.second) + cout << "\t(" << d.burstLength << ") " << d.trace << ";" << endl; + cout << endl; + } } } diff --git a/dram/src/simulation/TracePlayer.h b/dram/src/simulation/TracePlayer.h index f9a93f70..d5f3cdd2 100644 --- a/dram/src/simulation/TracePlayer.h +++ b/dram/src/simulation/TracePlayer.h @@ -17,7 +17,7 @@ #include #include "MemoryManager.h" #include "ISimulation.h" -#include "../core/configuration/Configuration.h" +#include "../controller/core/configuration/Configuration.h" #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" #include "../common/TlmRecorder.h" @@ -30,140 +30,140 @@ template struct TracePlayer: public sc_module { public: - tlm_utils::simple_initiator_socket iSocket; - TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstLength, - simulation::ISimulation* simulationManager) : - payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstLength), numberOfPendingTransactions( - 0), transactionsSent(0), transactionsReceived(0), simulationManager( - simulationManager) - { - if (!file.is_open()) - SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); + tlm_utils::simple_initiator_socket iSocket; + TracePlayer(sc_module_name name, string pathToTrace, unsigned int burstLength, + simulation::ISimulation* simulationManager) : + payloadEventQueue(this, &TracePlayer::peqCallback), file(pathToTrace), burstlenght(burstLength), numberOfPendingTransactions( + 0), transactionsSent(0), transactionsReceived(0), simulationManager( + simulationManager) + { + if (!file.is_open()) + SC_REPORT_FATAL(0, (string("Could not open trace ") + pathToTrace).c_str()); - this->burstlenght = core::Configuration::getInstance().BurstLength; - iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); - } + this->burstlenght = core::Configuration::getInstance().BurstLength; + iSocket.register_nb_transport_bw(this, &TracePlayer::nb_transport_bw); + } - void start() - { - bool fileIsEmpty = file.peek() == std::ifstream::traits_type::eof(); - if (!fileIsEmpty) - { - scheduleNextPayload(); - } - } + void start() + { + bool fileIsEmpty = file.peek() == std::ifstream::traits_type::eof(); + if (!fileIsEmpty) + { + scheduleNextPayload(); + } + } private: - tlm_utils::peq_with_cb_and_phase payloadEventQueue; - MemoryManager memoryManager; - ifstream file; - unsigned int burstlenght; - unsigned int numberOfPendingTransactions; - unsigned int transactionsSent; - unsigned int transactionsReceived; - simulation::ISimulation* simulationManager; + tlm_utils::peq_with_cb_and_phase payloadEventQueue; + MemoryManager memoryManager; + ifstream file; + unsigned int burstlenght; + unsigned int numberOfPendingTransactions; + unsigned int transactionsSent; + unsigned int transactionsReceived; + simulation::ISimulation* simulationManager; - void scheduleNextPayload() - { - if (file) - { - string time, command, address; - file >> time >> command >> address; + void scheduleNextPayload() + { + if (file) + { + string time, command, address; + file >> time >> command >> address; - //if there is a newline at the end of the .stl - if (time.empty() || command.empty() || address.empty()) - return; + //if there is a newline at the end of the .stl + if (time.empty() || command.empty() || address.empty()) + return; - long parsedAdress = std::stoi(address.c_str(), 0, 16); + long parsedAdress = std::stoi(address.c_str(), 0, 16); - gp* payload = memoryManager.allocate(); - payload->set_address(parsedAdress); + gp* payload = memoryManager.allocate(); + payload->set_address(parsedAdress); - if (command == "read") - { - payload->set_command(TLM_READ_COMMAND); - } - else if (command == "write") - { - payload->set_command(TLM_WRITE_COMMAND); - } - else - { - SC_REPORT_FATAL(0, - (string("Corrupted tracefile, command ") + command + string(" unknown")).c_str()); - } + if (command == "read") + { + payload->set_command(TLM_READ_COMMAND); + } + else if (command == "write") + { + payload->set_command(TLM_WRITE_COMMAND); + } + else + { + SC_REPORT_FATAL(0, + (string("Corrupted tracefile, command ") + command + string(" unknown")).c_str()); + } - payload->set_data_length(BUSWIDTH / 8); - payload->set_response_status(TLM_INCOMPLETE_RESPONSE); - payload->set_dmi_allowed(false); - payload->set_byte_enable_length(0); - payload->set_streaming_width(burstlenght); + payload->set_data_length(BUSWIDTH / 8); + payload->set_response_status(TLM_INCOMPLETE_RESPONSE); + payload->set_dmi_allowed(false); + payload->set_byte_enable_length(0); + payload->set_streaming_width(burstlenght); - sc_time sendingTime = sc_time(std::stoi(time.c_str()), SC_NS); - GenerationExtension* genExtension = new GenerationExtension(sendingTime); - payload->set_auto_extension(genExtension); + sc_time sendingTime = sc_time(std::stoi(time.c_str()), SC_NS); + GenerationExtension* genExtension = new GenerationExtension(sendingTime); + payload->set_auto_extension(genExtension); - if (sendingTime <= sc_time_stamp()) - { - payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); - } - else - { - payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime - sc_time_stamp()); - } - numberOfPendingTransactions++; - } - } + if (sendingTime <= sc_time_stamp()) + { + payloadEventQueue.notify(*payload, BEGIN_REQ, SC_ZERO_TIME); + } + else + { + payloadEventQueue.notify(*payload, BEGIN_REQ, sendingTime - sc_time_stamp()); + } + numberOfPendingTransactions++; + } + } - tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) - { - payloadEventQueue.notify(payload, phase, bwDelay); - return TLM_ACCEPTED; - } + tlm_sync_enum nb_transport_bw(tlm_generic_payload& payload, tlm_phase& phase, sc_time& bwDelay) + { + payloadEventQueue.notify(payload, phase, bwDelay); + return TLM_ACCEPTED; + } - void peqCallback(tlm_generic_payload& payload, const tlm_phase& phase) - { - if (phase == BEGIN_REQ) - { - payload.acquire(); - sendToTarget(payload, phase, SC_ZERO_TIME); + void peqCallback(tlm_generic_payload& payload, const tlm_phase& phase) + { + if (phase == BEGIN_REQ) + { + payload.acquire(); + sendToTarget(payload, phase, SC_ZERO_TIME); - transactionsSent++; - DebugManager::getInstance().printDebugMessage(name(), - "Sending transaction number: " + std::to_string(transactionsSent)); - } - else if (phase == END_REQ) - { - scheduleNextPayload(); - } - else if (phase == BEGIN_RESP) - { - sendToTarget(payload, END_RESP, SC_ZERO_TIME); - payload.release(); + transactionsSent++; + DebugManager::getInstance().printDebugMessage(name(), + "Sending transaction number: " + std::to_string(transactionsSent)); + } + else if (phase == END_REQ) + { + scheduleNextPayload(); + } + else if (phase == BEGIN_RESP) + { + sendToTarget(payload, END_RESP, SC_ZERO_TIME); + payload.release(); - simulationManager->transactionFinished(); - numberOfPendingTransactions--; - transactionsReceived++; + simulationManager->transactionFinished(); + numberOfPendingTransactions--; + transactionsReceived++; - DebugManager::getInstance().printDebugMessage(name(), - "Pending transactions in core: " - + std::to_string(transactionsSent - transactionsReceived)); - } - else if (phase == END_RESP) - { - } - else - { - SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); - } - } + DebugManager::getInstance().printDebugMessage(name(), + "Pending transactions in core: " + + std::to_string(transactionsSent - transactionsReceived)); + } + else if (phase == END_RESP) + { + } + else + { + SC_REPORT_FATAL(0, "TracePlayer PEQ was triggered with unknown phase"); + } + } - void sendToTarget(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) - { - tlm_phase TPhase = phase; - sc_time TDelay = delay; - iSocket->nb_transport_fw(payload, TPhase, TDelay); - } + void sendToTarget(tlm_generic_payload& payload, const tlm_phase& phase, const sc_time& delay) + { + tlm_phase TPhase = phase; + sc_time TDelay = delay; + iSocket->nb_transport_fw(payload, TPhase, TDelay); + } }; #endif /* TRACEPLAYER_H_ */ diff --git a/dram/src/simulation/main.cpp b/dram/src/simulation/main.cpp index b91d4672..ca1a7664 100644 --- a/dram/src/simulation/main.cpp +++ b/dram/src/simulation/main.cpp @@ -8,10 +8,9 @@ #include #include #include "SimulationManager.h" -#include "../core/configuration/Configuration.h" +#include "../controller/core/configuration/Configuration.h" #include - #include #include @@ -23,30 +22,30 @@ string resources; string pathOfFile(string file) { - return file.substr(0, file.find_last_of('/')); + return file.substr(0, file.find_last_of('/')); } int main(int argc, char **argv) { - return sc_main(argc, argv); + return sc_main(argc, argv); } int sc_main(int argc, char **argv) { - sc_set_time_resolution(1, SC_PS); - resources = pathOfFile(argv[0]) + string("/../resources/"); + sc_set_time_resolution(1, SC_PS); + resources = pathOfFile(argv[0]) + string("/../resources/"); - string simulationToRun; - if(argc > 1) - simulationToRun = argv[1]; - else - simulationToRun = "sim-batch.xml"; + string simulationToRun; + if(argc > 1) + simulationToRun = argv[1]; + else + simulationToRun = "sim-batch.xml"; - SimulationManager manager(resources); - manager.loadSimulationsFromXML(resources + "/simulations/" + simulationToRun); - manager.silent = false; - manager.runSimulations(); + SimulationManager manager(resources); + manager.loadSimulationsFromXML(resources + "/simulations/" + simulationToRun); + manager.silent = false; + manager.runSimulations(); - return 0; + return 0; } diff --git a/dram/testing/BankwiseRefreshManager_test.cpp b/dram/testing/BankwiseRefreshManager_test.cpp deleted file mode 100644 index a50d7bcf..00000000 --- a/dram/testing/BankwiseRefreshManager_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * BankwiseRefreshManager_test.cpp - * - * Created on: Mar 9, 2014 - * Author: jonny - */ - -#include -#include -#include -#include "testUtils.h" -#include "../common/dramExtension.h" - -using namespace testing; - - -namespace core { - -class MockInternalScheduler: public IBus -{ -public: - MOCK_METHOD1(scheduleCommand, void (const ScheduledCommand& command)); - MOCK_METHOD2(scheduleTrigger, void (const Trigger command, sc_time time)); -}; - -class BankwiseRefreshManagerTest: public Test -{ -public: - BankwiseRefreshManagerTest(){} - - Configuration config; - MockInternalScheduler internalScheduler; - std::shared_ptr transaction; - - CommandSchedule getCollidingWithFirstRefreshOnBank(unsigned int i) - { - transaction = createDummyPayload(Thread(0), Bank(i)); - CommandSchedule colliding(*transaction.get()); - sc_time tREFI = config.Timings.refreshTimings.at(i).tREFI; - sc_time clk = config.Timings.clk; - - colliding.add(Read, tREFI - 1 * clk, 2 * clk); - return colliding; - }; - - CommandSchedule getNonCollidingWithFirstRefreshOnBank(unsigned int i) - { - transaction = createDummyPayload(Thread(0), Bank(i)); - CommandSchedule non_colliding(*transaction.get()); - sc_time tREFI = config.Timings.refreshTimings.at(i).tREFI; - sc_time clk = config.Timings.clk; - - non_colliding.add(Read, tREFI - 3 * clk, 2 * clk); - return non_colliding; - }; -}; - -TEST_F(BankwiseRefreshManagerTest, RefreshsAreScheduledAfterStartup) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(config.numberOfBanks * 2); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(config.numberOfBanks); - - //first trigger for each bank is scheduled - BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); - - //first refresh for each bank is scheduled, second trigger is scheduled - manager.scheduleRefresh(config.Timings.refreshTimings.at(0).tREFI);//call back from wrapper -} - -TEST_F(BankwiseRefreshManagerTest, hasCollisionExpectCollisionOnBank2) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(config.numberOfBanks); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(0); - - BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); - EXPECT_TRUE(manager.hasCollision(getCollidingWithFirstRefreshOnBank(2))); -} - -TEST_F(BankwiseRefreshManagerTest, hasCollisionExpectNoCollisionOnBank2) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(config.numberOfBanks); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(0); - - BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); - EXPECT_FALSE(manager.hasCollision(getNonCollidingWithFirstRefreshOnBank(2))); -} - -} /* namespace controller */ diff --git a/dram/testing/CommandBus_test.cpp b/dram/testing/CommandBus_test.cpp deleted file mode 100644 index b7e3a2b6..00000000 --- a/dram/testing/CommandBus_test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * CommandBus_test.cpp - * - * Created on: Mar 13, 2014 - * Author: jonny - */ -#include -#include -#include "testUtils.h" -#include "core/scheduling/ScheduledCommand.h" -#include "core/Configuration.h" -#include "core/ControllerState.h" -#include "core/CommandBus.h" - -using ::testing::_; -using ::testing::AtLeast; -using ::testing::Expectation; -using namespace testing; -using namespace std; - -namespace core { - -class MockWrapper: public IControllerWrapper -{ -public: - MOCK_METHOD3(sendCommand, void (sc_time time, tlm::tlm_generic_payload& payload, Command command)); - MOCK_METHOD2(sendTrigger, void (sc_time time, Trigger trigger)); -}; - - -class CommandBusTest: public Test -{ -public: - CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state, checker, mockControllerWrapper), clk(config.Timings.clk){} - - Configuration config; - ControllerState state; - MockWrapper mockControllerWrapper; - CommandBus bus; - - std::vector checker; - sc_time clk; -}; - -TEST_F(CommandBusTest, cleanUpBusWorks) -{ - shared_ptr dummy = createDummyPayload(); - ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); - ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); - ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); - ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); - - bus.scheduleCommand(cmd1); - bus.scheduleCommand(cmd2); - bus.scheduleCommand(cmd3); - bus.scheduleCommand(cmd4); - - EXPECT_EQ(4, bus.getPendingBusCommands().size()); - - bus.cleanUpBus(5*clk); - - EXPECT_EQ(2, bus.getPendingBusCommands().size()); -} - - -TEST_F(CommandBusTest, getEarliestStartTimeWorks) -{ - shared_ptr dummy = createDummyPayload(); - ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); - ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); - ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); - ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); - - ScheduledCommand collision(*dummy.get(), Read, 3*clk, clk); - ScheduledCommand noCollision(*dummy.get(), Read, 6*clk, clk); - - bus.scheduleCommand(cmd1); - bus.scheduleCommand(cmd2); - bus.scheduleCommand(cmd3); - bus.scheduleCommand(cmd4); - - EXPECT_EQ(4*clk, bus.getEarliestStartTime(collision)); - EXPECT_EQ(6*clk, bus.getEarliestStartTime(noCollision)); -} - - -TEST_F(CommandBusTest, getESTDiesWithNotClkAligned) -{ - shared_ptr dummy = createDummyPayload(); - ScheduledCommand notAligned(*dummy.get(), Read, 2.5*clk, clk); - - EXPECT_DEATH(bus.getEarliestStartTime(notAligned), ".*"); -} - -TEST_F(CommandBusTest, getLastCommandWorks) -{ - shared_ptr dummy0 = createDummyPayload(Thread(0), Bank(0)); - shared_ptr dummy2 = createDummyPayload(Thread(0), Bank(2)); - - ScheduledCommand read0(*dummy0.get(), Read, 2*clk, clk); - ScheduledCommand read2(*dummy2.get(), Read, 3*clk, clk); - bus.scheduleCommand(read0); - bus.scheduleCommand(read2); - - EXPECT_EQ(read0, bus.getLastCommand(Read, read0.getBank())); - EXPECT_EQ(read2, bus.getLastCommand(Read, read2.getBank())); - EXPECT_EQ(read2.getStart(), bus.getLastCommand(Read).getStart()); -} - -TEST_F(CommandBusTest, notYetScheduledWorks) -{ - shared_ptr dummy = createDummyPayload(Thread(0), Bank(0)); - ScheduledCommand read(*dummy.get(), Read, 2*clk, clk); - - EXPECT_TRUE(bus.notYetScheduled(Read)); - bus.scheduleCommand(read); - EXPECT_FALSE(bus.notYetScheduled(Read)); -} - - -} /* namespace controller */ - - - - diff --git a/dram/testing/CommandGenerator_test.cpp b/dram/testing/CommandGenerator_test.cpp deleted file mode 100644 index e2875f32..00000000 --- a/dram/testing/CommandGenerator_test.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include "core/scheduling/CommandSequenceGenerator.h" -#include "testUtils.h" - -using namespace core; - -using namespace std; - -constexpr unsigned int numberOfBanks = 8; - -constexpr tlm::tlm_command READ = tlm::TLM_READ_COMMAND; -constexpr tlm::tlm_command WRITE = tlm::TLM_WRITE_COMMAND; - -TEST(CommandSequenceGenerator, ReadAndWriteWithRowHit) -{ - ControllerState state(numberOfBanks); - CommandSequenceGenerator generator(state); - - state.bankStates.openRowInRowBuffer(Bank(0), Row(3)); - - auto hit_read = createDummyPayload(Thread(0), Bank(0), Row(3), Column(1), READ); - auto hit_write = createDummyPayload(Thread(0), Bank(0), Row(3), Column(1), WRITE); - - - vector expected_read ({Read}); - vector expected_write ({Write}); - - EXPECT_EQ(expected_read, generator.generateCommandSequence(hit_read.get())); - EXPECT_EQ(expected_write, generator.generateCommandSequence(hit_write.get())); -} - -TEST(CommandSequenceGenerator, ReadAndWriteWithRowMiss) -{ - ControllerState state(numberOfBanks); - CommandSequenceGenerator generator(state); - - state.bankStates.openRowInRowBuffer(Bank(0), Row(3)); - - auto miss_read = createDummyPayload(Thread(0), Bank(0), Row(4), Column(1), READ); - auto miss_write = createDummyPayload(Thread(0), Bank(0), Row(4), Column(1), WRITE); - - - vector expected_read ({Precharge, Activate, Read}); - vector expected_write ({Precharge, Activate, Write}); - - EXPECT_EQ(expected_read, generator.generateCommandSequence(miss_read.get())); - EXPECT_EQ(expected_write, generator.generateCommandSequence(miss_write.get())); -} - -TEST(CommandSequenceGenerator, ReadAndWriteWithBankMiss) -{ - ControllerState state(numberOfBanks); - CommandSequenceGenerator generator(state); - - state.bankStates.openRowInRowBuffer(Bank(0), Row(3)); - - auto miss_read = createDummyPayload(Thread(0), Bank(1), Row(4), Column(1), READ); - auto miss_write = createDummyPayload(Thread(0), Bank(1), Row(4), Column(1), WRITE); - - - vector expected_read ({Activate, Read}); - vector expected_write ({Activate, Write}); - - EXPECT_EQ(expected_read, generator.generateCommandSequence(miss_read.get())); - EXPECT_EQ(expected_write, generator.generateCommandSequence(miss_write.get())); -} diff --git a/dram/testing/CommandSequenceScheduler_test.cpp b/dram/testing/CommandSequenceScheduler_test.cpp deleted file mode 100644 index f1db894b..00000000 --- a/dram/testing/CommandSequenceScheduler_test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * CommandSequenceScheduler_test.cpp - * - * Created on: Mar 9, 2014 - * Author: jonny - */ - -#include - -namespace core { - -} /* namespace controller */ diff --git a/dram/testing/Controller_test.cpp b/dram/testing/Controller_test.cpp deleted file mode 100644 index 8a48c1c6..00000000 --- a/dram/testing/Controller_test.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Controller_test.cpp - * - * Created on: Mar 15, 2014 - * Author: gernhard - */ - - - - - -#include -#include -#include -#include "tlm/IControllerWrapper.h" -#include "testUtils.h" -#include "../common/dramExtension.h" -#include "core/ControllerCore.h" -#include - -using namespace std; -using namespace testing; - - -namespace core { - -class MockWrapper: public IControllerWrapper -{ -public: - MOCK_METHOD3(sendCommand, void (sc_time time, tlm::tlm_generic_payload& payload, Command command)); - MOCK_METHOD2(sendTrigger, void (sc_time time, Trigger trigger)); -}; - -TEST(controllerTest,controllerStartup) -{ - MockWrapper wrapper; - DramController controller(wrapper); -} - -} diff --git a/dram/testing/PowerDownManager_test.cpp b/dram/testing/PowerDownManager_test.cpp deleted file mode 100644 index e774026d..00000000 --- a/dram/testing/PowerDownManager_test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * PowerDownManager_test.cpp - * - * Created on: Mar 9, 2014 - * Author: jonny - */ - -#include - -namespace core { - -} /* namespace controller */ diff --git a/dram/testing/RefreshManager_test.cpp b/dram/testing/RefreshManager_test.cpp deleted file mode 100644 index 8752a9b9..00000000 --- a/dram/testing/RefreshManager_test.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * RefreshManager_test.cpp - * - * Created on: Mar 6, 2014 - * Author: jonny - */ - -#include -#include -#include "core/refresh/RefreshManager.h" -#include "testUtils.h" - -using ::testing::_; -using ::testing::Expectation; - -using namespace testing; - -namespace core { - -class MockInternalScheduler: public IBus -{ -public: - MOCK_METHOD1(scheduleCommand, void (const ScheduledCommand& command)); - MOCK_METHOD2(scheduleTrigger, void (const Trigger command, sc_time time)); -}; - -class RefreshManagerTest: public Test -{ -public: - RefreshManagerTest(){} - - Configuration config; - MockInternalScheduler internalScheduler; - - std::shared_ptr transaction; - - CommandSchedule getCollidingWithFirstRefresh() - { - transaction = createDummyPayload(); - CommandSchedule colliding(*transaction.get()); - sc_time tREFI = config.Timings.refreshTimings.at(0).tREFI; - sc_time clk = config.Timings.clk; - - colliding.add(Read, tREFI - 1 * clk, 2 * clk); - return colliding; - }; - - CommandSchedule getNonCollidingWithFirstRefresh() - { - transaction = createDummyPayload(); - CommandSchedule non_colliding(*transaction.get()); - sc_time tREFI = config.Timings.refreshTimings.at(0).tREFI; - sc_time clk = config.Timings.clk; - - non_colliding.add(Read, tREFI - 3 * clk, 2 * clk); - return non_colliding; - }; -}; - -TEST_F(RefreshManagerTest, RefreshIsScheduledAfterStartup) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(2); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(1); - - //first trigger is scheduled - RefreshManager manager(config.Timings.refreshTimings.at(0), internalScheduler); - - //first refresh is scheduled, second trigger is scheduled - manager.scheduleRefresh(config.Timings.refreshTimings.at(0).tREFI);//call back from wrapper -} - -TEST_F(RefreshManagerTest, FinishedRefreshTriggersNewRefresh) -{ - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(2); - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(3); - - //first trigger is scheduled - RefreshManager manager(config.Timings.refreshTimings.at(0), internalScheduler); - - //first refresh is scheduled at tREFI (wrapper triggers), second trigger is scheduled - manager.scheduleRefresh(config.Timings.refreshTimings.at(0).tREFI);//call back from wrapper - - //second trigger should schedule second refresh (wrapper triggers) - manager.scheduleRefresh(config.Timings.refreshTimings.at(0).tREFI * 2); -} - -TEST_F(RefreshManagerTest, hasCollisionExpectCollision) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(1); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(0); - - RefreshManager manager(config.Timings.refreshTimings.at(0), internalScheduler); - - EXPECT_TRUE(manager.hasCollision(getCollidingWithFirstRefresh())); -} - -TEST_F(RefreshManagerTest, hasCollisionExpectNoCollision) -{ - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(1); - EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(0); - - RefreshManager manager(config.Timings.refreshTimings.at(0), internalScheduler); - - EXPECT_FALSE(manager.hasCollision(getNonCollidingWithFirstRefresh())); -} - -} /* namespace controller */ diff --git a/dram/testing/Utils_test.cpp b/dram/testing/Utils_test.cpp deleted file mode 100644 index 6b2ee0d3..00000000 --- a/dram/testing/Utils_test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Utils_test.cpp - * - * Created on: Mar 14, 2014 - * Author: jonny - */ - -#include -#include "core/TimingCalculation.h" -#include "core/utils/RingBuffer.h" - -//using namespace testing; - -namespace core { - -TEST(UtilsTest, clkAlignWorks) -{ - sc_time clk(6, SC_NS); - sc_time aligned = 2* clk; - sc_time not_aligned = 2.5*clk; - - EXPECT_EQ(aligned, clkAlign(aligned, clk, Alignment::UP)); - EXPECT_EQ(aligned, clkAlign(aligned, clk, Alignment::DOWN)); - EXPECT_EQ(aligned+clk, clkAlign(not_aligned, clk, Alignment::UP)); - EXPECT_EQ(aligned+clk, clkAlign(not_aligned, clk)); - EXPECT_EQ(aligned, clkAlign(not_aligned, clk, Alignment::DOWN)); -} - -TEST(UtilsTest, isClkAlignedWorks) -{ - sc_time clk(6, SC_NS); - sc_time aligned = 2*clk; - sc_time not_aligned = 2.5 * clk; - - EXPECT_TRUE(isClkAligned(aligned, clk)); - EXPECT_FALSE(isClkAligned(not_aligned, clk)); -} - -TEST(UtilsTest, delayByConstraintWorks) -{ - sc_time start(10, SC_NS); - sc_time previous(8, SC_NS); - sc_time constraint(4, SC_NS); - - EXPECT_EQ(sc_time(2, SC_NS), delayByConstraint(previous, start, constraint)); - EXPECT_EQ(sc_time(4, SC_NS), delayByConstraint(previous, sc_time(8, SC_NS), constraint)); - EXPECT_EQ(sc_time(6, SC_NS), delayByConstraint(previous, sc_time(6, SC_NS), constraint)); - EXPECT_EQ(sc_time(0, SC_NS), delayByConstraint(previous, sc_time(12, SC_NS), constraint)); - EXPECT_EQ(sc_time(0, SC_NS), delayByConstraint(previous, sc_time(14, SC_NS), constraint)); -} - -TEST(UtilsTest, RingBufferWorks) -{ - RingBuffer buffer(4); - EXPECT_TRUE(buffer.isEmpty()); - EXPECT_EQ(0, buffer.getSize()); - EXPECT_DEATH(buffer.get(0), ".*"); - EXPECT_FALSE(buffer.isFull()); - buffer.put(3); - EXPECT_EQ(1, buffer.getSize()); - EXPECT_FALSE(buffer.isFull()); - buffer.put(5); - buffer.put(4); - EXPECT_EQ(4, buffer.getNewest()); - EXPECT_EQ(3, buffer.getOldest()); - EXPECT_FALSE(buffer.isFull()); - buffer.put(9); - buffer.put(10); - EXPECT_EQ(10, buffer.getNewest()); - EXPECT_EQ(5, buffer.getOldest()); - EXPECT_EQ(9, buffer.get(2)); - EXPECT_TRUE(buffer.isFull()); -} - -TEST(UtilsTest,getBurstLengthInBytesWorks) -{ - //tlm::tlm_generic_payload payload; -// payload.set_data_length(4); -// EXPECT_EQ(4,getBurstLengthInBytes(payload,128)); -} - -} /* namespace controller */ - diff --git a/dram/testing/main.cpp b/dram/testing/main.cpp deleted file mode 100644 index db14631b..00000000 --- a/dram/testing/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * main.cpp - * - * Created on: Mar 5, 2014 - * Author: jonny - */ - -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//using namespace std; -//using namespace testing; -// -// -//int runTests(int argc, char **argv) -//{ -// cout << "---- Starting Tests ----" < - -using namespace std; -using namespace tlm; - - -/* Scheduler related stuff - * - * - */ -shared_ptr createDummyPayload(DramExtension *extension) -{ - shared_ptr result(new tlm_generic_payload()); - result->set_extension(extension); - return result; -} - -shared_ptr createDummyPayload(const Thread& thread, const Bank& bank, - const Row& row, const Column& column) -{ - return createDummyPayload(new DramExtension(thread, bank, row, column)); -} - -shared_ptr createDummyPayload(const Thread& thread, const Bank& bank, - const Row& row, const Column& column, const tlm::tlm_command& command) -{ - auto payload = createDummyPayload(new DramExtension(thread, bank, row, column)); - payload.get()->set_command(command); - return payload; -} - -shared_ptr createDummyPayload(const Thread& thread, const Bank& bank, - const Row& row) -{ - return createDummyPayload(new DramExtension(thread, bank, row, Column(0))); -} - -shared_ptr createDummyPayload(const Thread& thread, const Bank& bank) -{ - return createDummyPayload(new DramExtension(thread, bank, Row(0), Column(0))); -} - -shared_ptr createDummyPayload() -{ - return createDummyPayload(new DramExtension()); -} diff --git a/dram/testing/testUtils.h b/dram/testing/testUtils.h deleted file mode 100644 index 21c81eda..00000000 --- a/dram/testing/testUtils.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TESTUTILS_H -#define TESTUTILS_H - -#include -#include -#include "common/dramExtension.h" -#include "core/scheduling/ScheduledCommand.h" - -std::shared_ptr createDummyPayload(); - -std::shared_ptr createDummyPayload(DramExtension* extension); - -std::shared_ptr createDummyPayload(const Thread& thread, - const Bank& bank, const Row& row, const Column& column); - -std::shared_ptr createDummyPayload(const Thread& thread, - const Bank& bank, const Row& row); - -std::shared_ptr createDummyPayload(const Thread& thread, - const Bank& bank); - -std::shared_ptr createDummyPayload(const Thread& thread, - const Bank& bank, const Row& row, const Column& column, - const tlm::tlm_command& command); - -//std::shared_ptr createDummyScheduledCommand(const sc_time); -//TODO .. wenn in implementierung create dummypayload dereferenziert an ScheduledCommand .. out of scope .. reference zu nichtS? - -#endif // TESTUTILS_H