#define RW_LOCK_BIAS 0x00100000
#define WRITE_LOCK_CMP RW_LOCK_BIAS
+typedef union {
+ atomic_int lock;
+} rwlock_t;
+
/** Example implementation of linux rw lock along with 2 thread test
* driver... */
@End
*/
-/**
- */
-
-typedef union {
- atomic_int lock;
-} rwlock_t;
-
static inline int read_can_lock(rwlock_t *lock)
{
return atomic_load_explicit(&lock->lock, memory_order_relaxed) > 0;
int priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire);
/**
@Begin
- @Commit_point_define_check: __ATOMIC_RET__ > 0
+ @Commit_point_define_check: priorvalue > 0
@Label:Read_Lock_Success_1
@End
*/
priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire);
/**
@Begin
- @Commit_point_define_check: __ATOMIC_RET__ > 0
+ @Commit_point_define_check: priorvalue > 0
@Label:Read_Lock_Success_2
@End
*/
int priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire);
/**
@Begin
- @Commit_point_define_check: __ATOMIC_RET__ == RW_LOCK_BIAS
+ @Commit_point_define_check: priorvalue == RW_LOCK_BIAS
@Label: Write_Lock_Success_1
@End
*/
priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire);
/**
@Begin
- @Commit_point_define_check: __ATOMIC_RET__ == RW_LOCK_BIAS
+ @Commit_point_define_check: priorvalue == RW_LOCK_BIAS
@Label: Write_Lock_Success_2
@End
*/
writer_lock_acquired = false;
@End
*/
-
static inline void write_unlock(rwlock_t *rw)
{
atomic_fetch_add_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_release);
int user_main(int argc, char **argv)
{
+ /**
+ @Begin
+ @Entry_point
+ @End
+ */
thrd_t t1, t2;
atomic_init(&mylock.lock, RW_LOCK_BIAS);
public static final String HEADER_CDSANNOTATE = "<cdsannotate.h>";
public static final String HEADER_SPECANNOTATION = "<specannotation.h>";
public static final String HEADER_CDSTRACE = "<cdstrace.h>";
- public static final String CDSAnnotate = "cdsannotate";
+// public static final String CDSAnnotate = "cdsannotate";
+ public static final String CDSAnnotate = "_Z11cdsannotatemPv";
public static final String CDSAnnotateType = "SPEC_ANALYSIS";
- public static final String IDType = "id_t";
+ public static final String IDType = "call_id_t";
public static final String SPEC_ANNO_TYPE = "spec_anno_type";
+ public static final String SPEC_ANNO_TYPE_FUNC_TABLE_INIT = "FUNC_TABLE_INIT";
public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT";
public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN";
public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION";
public static final String SPEC_ANNOTATION_FIELD_TYPE = "type";
public static final String SPEC_ANNOTATION_FIELD_ANNO = "annotation";
+ public static final String ANNO_FUNC_TABLE_INIT = "anno_func_table_init";
public static final String ANNO_HB_INIT = "anno_hb_init";
public static final String ANNO_INTERFACE_BEGIN = "anno_interface_begin";
public static final String ANNO_INTERFACE_END = "anno_interface_end";
for (int i = 0; i < header.args.size(); i++) {
code.add(DECLARE(header.args.get(i)));
}
- code.add("} " + interfaceName + "_info {");
+ code.add("} " + interfaceName + "_info;");
return code;
}
if (!header.returnType.equals("void") || header.args.size() != 0) {
String infoStructType = interfaceName + "_info", infoStructName = "theInfo";
code.add(DECLARE_DEFINE(infoStructType + "*", infoStructName,
- BRACE(infoStructType) + "info"));
+ BRACE(infoStructType + "*") + "info"));
if (!header.returnType.equals("void")) {
code.add((DECLARE_DEFINE(header.returnType, MACRO_RETURN,
GET_FIELD_BY_PTR(infoStructName, MACRO_RETURN))));
if (construct.postAction.size() > 0) {
code.addAll(construct.postAction);
}
+ // Return true finally
+ code.add("return true;");
code.add("}");
}
newCode.add("");
// Other necessary headers
+ newCode.add(INCLUDE(HEADER_STDLIB));
newCode.add(INCLUDE(HEADER_STDINT));
newCode.add(INCLUDE(HEADER_CDSANNOTATE));
newCode.add(INCLUDE(HEADER_SPEC_LIB));
+ newCode.add(INCLUDE(HEADER_SPECANNOTATION));
newCode.add("");
SequentialDefineSubConstruct code = construct.code;
newCode.addAll(declareStruct);
newCode.add("");
}
+ // User-defined variables
+ ArrayList<VariableDeclaration> varDecls = code.declareVar;
+ for (int i = 0; i < varDecls.size(); i++) {
+ VariableDeclaration varDecl = varDecls.get(i);
+ // Don't forget to make them static
+ newCode.add(makeVariablesStatic(varDecl));
+ }
// User-defined functions
newCode.add(COMMENT("All other user-defined functions"));
ArrayList<ArrayList<String>> defineFuncs = code.defineFuncs;
.get(interfaceName);
FunctionHeader funcHeader = getFunctionHeader(semantics, iConstruct);
// Define necessary info structure
- if (!funcHeader.returnType.equals("void") || funcHeader.args.size() > 0) {
+ if (!funcHeader.returnType.equals("void")
+ || funcHeader.args.size() > 0) {
newCode.add(COMMENT("Definition of interface info struct: "
+ interfaceName));
newCode.addAll(DEFINE_INFO_STRUCT(interfaceName, funcHeader));
// Define ID function
newCode.add(COMMENT("ID function of interface: " + interfaceName));
newCode.addAll(DEFINE_ID_FUNC(interfaceName, iConstruct.idCode));
- newCode.add(COMMENT("End of ID function: + " + interfaceName));
+ newCode.add(COMMENT("End of ID function: " + interfaceName));
newCode.add("");
// Define check_action function
newCode.add(COMMENT("Check action function of interface: "
+ interfaceName));
newCode.addAll(DEFINE_CHECK_ACTION_FUNC(iConstruct, funcHeader));
- newCode.add(COMMENT("End of check action function: + "
+ newCode.add(COMMENT("End of check action function: "
+ interfaceName));
newCode.add("");
}
.toString(semantics.interfaceName2Construct.size());
newCode.add(DEFINE("INTERFACE_SIZE", interfaceSize));
newCode.add(DECLARE("void**", "func_ptr_table"));
- // User-defined variables
- ArrayList<VariableDeclaration> varDecls = code.declareVar;
- for (int i = 0; i < varDecls.size(); i++) {
- VariableDeclaration varDecl = varDecls.get(i);
- // Don't forget to make them static
- newCode.add(makeVariablesStatic(varDecl));
- }
newCode.add("");
newCode.add(COMMENT("Define function for sequential code initialization"));
newCode.add("");
// Init user-defined variables
newCode.addAll(construct.code.initVar);
+ // Pass function table info
+ newCode.add(COMMENT("Pass function table info"));
+ String structName = "anno_func_table_init", anno = "func_init";
+ newCode.add(DECLARE(ANNO_FUNC_TABLE_INIT, structName));
+ newCode.add(ASSIGN(structName, "size", "INTERFACE_SIZE"));
+ newCode.add(ASSIGN(structName, "table", "func_ptr_table"));
+ newCode.add(DECLARE(SPEC_ANNOTATION, anno));
+ newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_FUNC_TABLE_INIT));
+ newCode.add(ASSIGN_PTR(anno, "annotation", structName));
+ newCode.add(ANNOTATE(anno));
+
// Pass Happens-before relationship
- generateHBInitAnnotation(semantics);
+ newCode.addAll(generateHBInitAnnotation(semantics));
newCode.add("}");
newCode.add(COMMENT("End of Global construct generation in class"));
}
// Generate wrapper header
+ // If it's not in a class, we should declare the wrapper function
+ if (semantics.getClassName() == null) {
+ FunctionHeader renamedHeader = header
+ .getRenamedHeader(SPEC_INTERFACE_WRAPPER);
+ newCode.add(COMMENT("Declaration of the wrapper"));
+ newCode.add(renamedHeader + ";");
+ newCode.add("");
+ }
newCode.add(header.toString() + " {");
// Wrapper function body
newCode.add(COMMENT("Interface begins"));
newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
String anno = "annotation_interface_begin";
newCode.add(DECLARE(SPEC_ANNOTATION, anno));
- newCode.add(ASSIGN(structName, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
- newCode.add(ASSIGN_PTR(structName, "annotation", structName));
+ newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
+ newCode.add(ASSIGN_PTR(anno, "annotation", structName));
newCode.add(ANNOTATE(anno));
// Call original renamed function
if (header.returnType.equals("void")) {
- newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER));
+ newCode.add(header.getRenamedCall(SPEC_INTERFACE_WRAPPER) + ";");
} else {
newCode.add(DECLARE_DEFINE(header.returnType, MACRO_RETURN,
header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
if (!header.returnType.equals("void") || header.args.size() > 0) {
infoStructType = interfaceName + "_info";
infoName = "info";
- newCode.add(DECLARE_DEFINE(infoStructType, infoName,
+ newCode.add(DECLARE_DEFINE(infoStructType + "*", infoName,
BRACE(infoStructType + "*") + " malloc(sizeof("
+ infoStructType + "))"));
if (!header.returnType.equals("void")) {
newCode.add(DECLARE(SPEC_ANNOTATION, anno));
newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
newCode.add(ASSIGN_PTR(anno, "annotation", structName));
- ANNOTATE(anno);
+ newCode.add(ANNOTATE(anno));
+ // Return __RET__ if it's not void
+ if (!header.returnType.equals("void")) {
+ newCode.add("return " + MACRO_RETURN + ";");
+ }
// End of the wrapper function
newCode.add("}");