1 / 27

Automatic Code Generation for CSP# Models in PAT

Automatic Code Generation for CSP# Models in PAT. LIN Shang-Wei Temasek Laboratories National University of Singapore. Outline. Code Generation Approach Example Demo Future Work. Code Generation Approach. CSP#  state machines  QP active objects

juana
Download Presentation

Automatic Code Generation for CSP# Models in PAT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Automatic Code Generation for CSP# Models in PAT LIN Shang-Wei Temasek Laboratories National University of Singapore

  2. Outline • Code Generation Approach • Example • Demo • Future Work

  3. Code Generation Approach CSP# state machines  QP active objects Both shared memory and message passing are supported Application (Active Objects) Generated code is OS-independent and hardware-independent! Quantum Platform (QP) Linux/BSD Windows/WinCE μC/OS-II … 80x86 ARM-Cortex/ARM9/ARM7 …

  4. Interleave Process P = Q1 ||| Q2 ||| … ||| Qn SM1 SMn SM2 … SM: State Machine

  5. Guarded Process P = [b] Q P TIMEOUT [!b] / TIMEOUT [b] / Q

  6. General Choice P = Q1 [] Q2 [] … [] Qn op = rand(1,n) P TIMEOUT [op == n] / TIMEOUT [op == 1] / TIMEOUT [op == 2] / Q1 Q2 Qn …

  7. Conditional Choice Process P = ifb {Q1} else {Q2} P TIMEOUT [b] / TIMEOUT [!b] / Q2 Q1

  8. Case Process P = case { b1: Q1 b2: Q2 … bn: Qn } P TIMEOUT [b1] / TIMEOUT [!b1 && !b2 … && bn] / TIMEOUT [!b1 && b2] / Q1 Q2 Qn …

  9. Sequence Process P = Q1 ; Q2 P TIMEOUT/ Q1 TIMEOUT/ Q2

  10. Event Prefixing Process P = e Q P TIMEOUT / e(); Q

  11. Data Operation Process P = e { prog}  Q P TIMEOUT / e(); prog(); Q

  12. Channel Input Process P = ch?x Q P ch_sig / Q

  13. Channel Output Process P = ch!x Q P TIMEOUT / PUBLISH(ch_sig) Q

  14. Outline • Code Generation Approach • Example • Demo • Future Work

  15. Peterson’s Protocol #define N 2; var turn; varpos[N]; P0() = req.0{pos[0] = 1; turn=1} -> Wait0(); cs.0 -> reset.0{pos[0] = 0} -> P0(); Wait0() = if (pos[1]==1 && turn == 1) { Wait0() }; P1() = req.1{pos[1] = 1; turn=0} -> Wait1(); cs.1 -> reset.1{pos[1] = 0} -> P1(); Wait1() = if (pos[0]==1 && turn == 0) { Wait1() }; Peterson() = P0() ||| P1();

  16. Peterson’s Protocol (cont.) Generated state machine for the P0() process 0 TIMEOUT / req_0() ; pos[0] = 1 ; turn = 1; TIMEOUT / reset_0() ; pos[0] = 0; 1 2 3 TIMEOUT [pos[1] = 0 || turn == 0] / TIMEOUT / cs_0(); TIMEOUT [pos[1] = 1 && turn == 1] /

  17. Peterson’s Protocol (cont.) class P0 : public QActive { /** P0.h **/ public: P0(); ~P0(); private: static QState initial(P0 *me, QEventconst *e); static QStateP0_0(P0 *me, QEventconst *e); static QStateP0_1(P0 *me, QEventconst *e); static QStateP0_2(P0 *me, QEventconst *e); static QStateP0_3(P0 *me, QEventconst *e); public: void req_0(); void cs_0(); void reset_0(); private: QTimeEvtm_timeEvt; };

  18. Peterson’s Protocol (cont.) P0::P0() : /** P0.cpp **/ QActive((QStateHandler)&P0::initial),m_timeEvt(TIMEOUT_SIG){} P0::~P0(){} QState P0::initial(P0 *me, QEventconst*){ return Q_TRAN(&P0::P0_0); } void P0::req_0(){ std::cout<<"req_0"<<std::endl; } void P0::cs_0(){ std::cout<<"cs_0"<<std::endl; } void P0::reset_0(){ std::cout<<"reset_0"<<std::endl; }

  19. Peterson’s Protocol (cont.) QState P0:: /** P0.cpp (cont.)**/ P0_0(P0 *me, QEventconst *e){ QEvent*pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->req_0(); pos[0]=1;turn=1; return Q_TRAN(&P0::P0_1); } return Q_SUPER(&QHsm::top); }

  20. Peterson’s Protocol (cont.) QState P0:: /** P0.cpp (cont.)**/ P0_1(P0 *me, QEventconst *e){ QEvent*pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: if(((pos[1] == 1) && (turn == 1))){ return Q_TRAN(&P0::P0_1); } if(!(((pos[1] == 1) && (turn == 1)))){ return Q_TRAN(&P0::P0_2); } } return Q_SUPER(&QHsm::top); }

  21. Peterson’s Protocol (cont.) QState P0:: P0_2(P0 *me, QEventconst *e){ QEvent*pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->cs_0(); return Q_TRAN(&P0::P0_3); } return Q_SUPER(&QHsm::top); }

  22. Peterson’s Protocol (cont.) QState P0:: P0_3(P0 *me, QEventconst *e){ QEvent*pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->reset_0(); pos[0]=0; return Q_TRAN(&P0::P0_0); } return Q_SUPER(&QHsm::top); }

  23. Peterson’s Protocol (cont.) // Main.cpp static P0 __P0; static P1 __P1; static QEventconst *l_P0_QueueSto[10]; static QEventconst *l_P1_QueueSto[10]; static QSubscrListl_subscrSto[MAX_PUB_SIG]; static union SmallEvents { void *e0; uint8_t e1[sizeof(DataEvent)]; // other event types to go into this pool } l_smlPoolSto[2 * (1 + 0) * 2]; // storage for the small event pool …

  24. Peterson’s Protocol (cont.) int main(intargc, char *argv[]) { QF::init(); QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0])); __P0.start((uint8_t)(1), l_tableQueueSto, Q_DIM(l_tableQueueSto), (void *)0, 0, (QEvent *)0); __P1.start((uint8_t)(2), l_tableQueueSto, Q_DIM(l_tableQueueSto), (void *)0, 0, (QEvent *)0); QF::run(); return 0; }

  25. Outline • Code Generation Approach • Example • Demo • Future Work

  26. Outline • Code Generation Approach • Example • Demo • Future Work

  27. Future Work • Deployment on different platforms • Providing generichardware APIs • For verification • Abstract hardware models with equivalent semantics • For code generation • Linking generic hardware APIs and their implementation • Non-functional behavior modeling and verification • Power consumption • Profiling to get the estimation • Additional global variables to capture the cost • Time constraints • RTS or Timed automata • Multi-corePlatforms

More Related