edits
[cdsspec-compiler.git] / notes / generated_code_examples.txt
index ce405807c27e47d1ae27c6460a0a0958d51b283f..2a7241c6156c00721d753f8592f1ab9938a779ec 100644 (file)
@@ -2,17 +2,17 @@
 Global Variable Declaration
 
 /* Include all the header files that contains the interface declaration */
-#include <iostream>
 #inlcude <atomic>
 #include <memory>
 #include <assert.h>
 
 /* Other necessary header files */
+#include <stdint.h>
 #include <specannotation.h>
-#include <spec_tag.h>
+#include <spec_lib.h>
 
 /* All other user-defined functions */
-ALL_USER_DEFINED_FUNCTIONS
+ALL_USER_DEFINED_FUNCTIONS  // Make them static 
 
 /* Definition of interface info struct (per interface) */
 typedef struct Put_info {
@@ -29,7 +29,7 @@ typedef struct Get_info {
 
 /* ID functions of interface */
 static id_t Put_id() {
-       id_t id = PUT_ID;
+       id_t id = PUT_ID;  // Default ID == 0;
        return id;
 }
 
@@ -39,10 +39,7 @@ static id_t Get_id() {
 }
 /* End of ID functions */
 
-/* Initialization of interface<->function_ptr table */
-#define INTERFACE_SIZE 2
-void* func_ptr_table[INTERFACE_SIZE * 2] = {
-       CLASS
+
 
 /* Check_action function of interfaces */
 bool Put_check_action(void *info, id_t __ID__) {
@@ -78,6 +75,9 @@ bool Get_check_action(void *info, id_t __ID__) {
 }
 /* End of check_action function definitions */ 
 
+/* Initialization of interface<->function_ptr table */
+#define INTERFACE_SIZE 2
+void** func_ptr_table;
 
 /* Beginning of other user-defined variables */
 bool lock_acquired;
@@ -87,10 +87,26 @@ int reader_lock_cnt;
 
 /* Define function for sequential code initialization */
 void __sequential_init() {
+       /* Init func_ptr_table */
+       func_ptr_table = (void**) malloc(sizeof(void*) * 2);
+       func_ptr_table[0] = (void*) &Put_id;
+       func_ptr_table[1] = (void*) &Put_check_action;
+       func_ptr_table[2] = (void*) &Get_id;
+       func_ptr_table[3] = (void*) &Get_check_action;
+
        /* Init user-defined variables */
        lock_acquired = false;
        reader_lock_cnt = 0;
 
+       /* Pass function table info */
+       anno_func_table_init func_table;
+       func_table.size = INTERFACE_SIZE;
+       func_table.table = func_ptr_table;
+       spec_annotation func_init;
+       func_init.type = FUNC_TABLE_INIT;
+       func_init.annotation = &anno_func_table_init;
+       cdsannotate(SPEC_ANALYSIS, &func_init);
+
        /* Pass the happens-before initialization here */
        /* PutIfAbsent (putIfAbsent_Succ) -> Get (true) */
        anno_hb_init hbConditionInit0;
@@ -121,8 +137,7 @@ Interface Wrapper
 #include <threads.h>
 #include <cdsannotate.h>
 #include <specannotation.h>
-#include <spec_tag.h>
-#include <spec_private_hashtable.h>
+#include <spec_lib.h>
 
 TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
 {
@@ -149,7 +164,6 @@ TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
        // And more (if any)
 
        // Interface ends
-       spec_annotation annotation_interface_end;
        INTERFACE_LABEL_info info = (INTERFACE_LABEL_info*) malloc(sizeof(INTERFACE_LABEL_info));
        info->__RET__ = __RET__;
        info->arg1 = arg1;
@@ -157,6 +171,7 @@ TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
        anno_interface_end interface_end;
        interface_end.interface_num = 0; // Interface number
        interface_end.info = info; // Info
+       spec_annotation annotation_interface_end;
        annotation_interface_end.type = INTERFACE_END;
        annotation_interface_end.annotation = &interface_end;
        cdsannotate(SPEC_ANALYSIS, &annoation_interface_end);
@@ -167,11 +182,8 @@ TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
 Potential Commit Point
 
 
-#include <threads.h>
-#include <cdstrace.h>
-#include <cdsannotate.h>
-#include <spec_private_hashtable.h>
 #include <stdint.h>
+#include <cdsannotate.h>
 
 /* Should add the __ATOMIC_RET__ if necessary */
 uint64_t __ATOMIC_RET = somevar.compare_exchange_explicit(...);
@@ -189,10 +201,7 @@ if (POTENTIAL_CP_DEFINE_CONDITION) {
 Commit Point Define
 
 #include <threads.h>
-#include <cdstrace.h>
 #include <cdsannotate.h>
-#include <spec_private_hashtable.h>
-#include <_spec_sequential_generated.h>
 #include <stdint.h>
 
 /* Should add the __ATOMIC_RET__ if necessary */
@@ -220,10 +229,7 @@ Commit Point Define Check
 
 
 #include <threads.h>
-#include <cdstrace.h>
 #include <cdsannotate.h>
-#include <spec_private_hashtable.h>
-#include <_spec_sequential_generated.h>
 #include <stdint.h>
 
 /* Should add the __ATOMIC_RET__ if necessary */