Code-generating VDM for Embedded Devices Victor Bandur Peter W. V. - - PowerPoint PPT Presentation

code generating vdm for embedded devices
SMART_READER_LITE
LIVE PREVIEW

Code-generating VDM for Embedded Devices Victor Bandur Peter W. V. - - PowerPoint PPT Presentation

Code-generating VDM for Embedded Devices Victor Bandur Peter W. V. Tran-Jrgensen Miran Hasanagi c Kenneth Lausdahl 15th Overture workshop Newcastle, UK September 15 Introduction Translation Conclusion and future plans Agenda


slide-1
SLIDE 1

Code-generating VDM for Embedded Devices

Victor Bandur Peter W. V. Tran-Jørgensen Miran Hasanagi´ c Kenneth Lausdahl 15th Overture workshop Newcastle, UK – September 15

slide-2
SLIDE 2

Introduction Translation Conclusion and future plans

Agenda

Introduction Translation Conclusion and future plans

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [2/13]

slide-3
SLIDE 3

Introduction Translation Conclusion and future plans

Agenda

Introduction Translation Conclusion and future plans

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [3/13]

slide-4
SLIDE 4

Introduction Translation Conclusion and future plans

Why another code-generator?

  • Existing VDM code-generators
  • Suitable for resource-rich hardware platforms
  • Target Java, C#, Smalltalk and C++ etc.
  • Resource-constrained microcontrollers
  • Limited processing power and memory
  • Often only have C compilers available

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [4/13]

slide-5
SLIDE 5

Introduction Translation Conclusion and future plans

Why another code-generator?

  • Existing VDM code-generators
  • Suitable for resource-rich hardware platforms
  • Target Java, C#, Smalltalk and C++ etc.
  • Resource-constrained microcontrollers
  • Limited processing power and memory
  • Often only have C compilers available

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [4/13]

slide-6
SLIDE 6

Introduction Translation Conclusion and future plans

VDM2C context

  • Developed in INTO-CPS to support:
  • Implementation of VDM-RT models in C
  • FMI-based co-simulation of VDM-RT models
  • Translation assesment
  • Validated through comprehensive testing
  • Industrial INTO-CPS pilot/case studies

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [5/13]

slide-7
SLIDE 7

Introduction Translation Conclusion and future plans

VDM2C context

  • Developed in INTO-CPS to support:
  • Implementation of VDM-RT models in C
  • FMI-based co-simulation of VDM-RT models
  • Translation assesment
  • Validated through comprehensive testing
  • Industrial INTO-CPS pilot/case studies

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [5/13]

slide-8
SLIDE 8

Introduction Translation Conclusion and future plans

Agenda

Introduction Translation Conclusion and future plans

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [6/13]

slide-9
SLIDE 9

Introduction Translation Conclusion and future plans

Translating VDM to C

  • VDM2C feature highlights
  • Runtime implements VDM types/operators
  • TVP stores type information
  • User-guided garbage collection
  • VdmModelFeatures.h to limit runtime size
  • OO features handled using VTables
  • Supports distribution (VDM-RT)
  • Limitations
  • No pattern matching
  • Limited support for concurrency

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [7/13]

slide-10
SLIDE 10

Introduction Translation Conclusion and future plans

Translating VDM to C

  • VDM2C feature highlights
  • Runtime implements VDM types/operators
  • TVP stores type information
  • User-guided garbage collection
  • VdmModelFeatures.h to limit runtime size
  • OO features handled using VTables
  • Supports distribution (VDM-RT)
  • Limitations
  • No pattern matching
  • Limited support for concurrency

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [7/13]

slide-11
SLIDE 11

Introduction Translation Conclusion and future plans

Translating VDM to C

  • VDM2C feature highlights
  • Runtime implements VDM types/operators
  • TVP stores type information
  • User-guided garbage collection
  • VdmModelFeatures.h to limit runtime size
  • OO features handled using VTables
  • Supports distribution (VDM-RT)
  • Limitations
  • No pattern matching
  • Limited support for concurrency

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [7/13]

slide-12
SLIDE 12

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-13
SLIDE 13

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-14
SLIDE 14

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-15
SLIDE 15

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); }

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-16
SLIDE 16

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); }

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-17
SLIDE 17

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); }

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-18
SLIDE 18

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); }

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-19
SLIDE 19

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); } TVP a_instance = _Z1AEV(NULL); TVP arg = newInt(42) TVP res = CALL_FUNC(A, A, a_instance, CLASS_A__Z2opE2XCN, arg)

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-20
SLIDE 20

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); } TVP a_instance = _Z1AEV(NULL); TVP arg = newInt(42) TVP res = CALL_FUNC(A, A, a_instance, CLASS_A__Z2opE2XCN, arg)

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-21
SLIDE 21

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); } TVP a_instance = _Z1AEV(NULL); TVP arg = newInt(42) TVP res = CALL_FUNC(A, A, a_instance, CLASS_A__Z2opE2XCN, arg)

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-22
SLIDE 22

Introduction Translation Conclusion and future plans

Translation example

class A

  • perations
  • p:nat|char ==> bool
  • p (x) ==

if is_nat(x) then g() else h(); ... end A

✡ ✝ ✆

static TVP _Z2opE2XCN(ACLASS this, TVP x){ if ( toBool(isNat(x)) ) return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1gEV); else return CALL_FUNC_PTR(A, A, this, CLASS_A__Z1hEV); } TVP a_instance = _Z1AEV(NULL); TVP arg = newInt(42) TVP res = CALL_FUNC(A, A, a_instance, CLASS_A__Z2opE2XCN, arg)

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [8/13]

slide-23
SLIDE 23

Introduction Translation Conclusion and future plans

Type information

#define TVP struct TypedValue* struct TypedValue { vdmtype type; TypedValueType value; ... };

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [9/13]

slide-24
SLIDE 24

Introduction Translation Conclusion and future plans

Type information

#define TVP struct TypedValue* struct TypedValue { vdmtype type; TypedValueType value; ... };

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [9/13]

slide-25
SLIDE 25

Introduction Translation Conclusion and future plans

Type information

#define TVP struct TypedValue* struct TypedValue { vdmtype type; TypedValueType value; ... };

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [9/13]

slide-26
SLIDE 26

Introduction Translation Conclusion and future plans

Distribution: remote calls

#define DIST_CALL(sTy, bTy, obj, supID ,nrArgs , funID, args...) ((obj->type==VDM_CLASS) ? CALL_FUNC(sTy, bTy, obj, funID, ## args) : send_bus(obj->value.intVal, funID, supID, nrArgs, ## args))

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [10/13]

slide-27
SLIDE 27

Introduction Translation Conclusion and future plans

Distribution: remote calls

#define DIST_CALL(sTy, bTy, obj, supID ,nrArgs , funID, args...) ((obj->type==VDM_CLASS) ? CALL_FUNC(sTy, bTy, obj, funID, ## args) : send_bus(obj->value.intVal, funID, supID, nrArgs, ## args))

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [10/13]

slide-28
SLIDE 28

Introduction Translation Conclusion and future plans

Distribution: remote calls

#define DIST_CALL(sTy, bTy, obj, supID ,nrArgs , funID, args...) ((obj->type==VDM_CLASS) ? CALL_FUNC(sTy, bTy, obj, funID, ## args) : send_bus(obj->value.intVal, funID, supID, nrArgs, ## args))

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [10/13]

slide-29
SLIDE 29

Introduction Translation Conclusion and future plans

Distribution: remote calls

#define DIST_CALL(sTy, bTy, obj, supID ,nrArgs , funID, args...) ((obj->type==VDM_CLASS) ? CALL_FUNC(sTy, bTy, obj, funID, ## args) : send_bus(obj->value.intVal, funID, supID, nrArgs, ## args))

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [10/13]

slide-30
SLIDE 30

Introduction Translation Conclusion and future plans

Agenda

Introduction Translation Conclusion and future plans

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [11/13]

slide-31
SLIDE 31

Introduction Translation Conclusion and future plans

Conclusion and future plans

  • VDM-to-C translation for embedded devices
  • Uses garbage-collection
  • Type information is captured using TVP
  • Supports OO and distribution (VDM-RT)
  • Future plans
  • Extending VDM coveage
  • Compare to other generators

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [12/13]

slide-32
SLIDE 32

Introduction Translation Conclusion and future plans

Conclusion and future plans

  • VDM-to-C translation for embedded devices
  • Uses garbage-collection
  • Type information is captured using TVP
  • Supports OO and distribution (VDM-RT)
  • Future plans
  • Extending VDM coveage
  • Compare to other generators

15th Overture Workshop, September 15, 2017 Victor Bandur, Peter W. V. Tran-Jørgensen, Miran Hasanagi´ c, Kenneth Lausdahl [12/13]

slide-33
SLIDE 33

Thank you

Find us on Github: https://github.com/overturetool/vdm2c