From 24022553f123d8f8a796b257410b4c1c1b9ef8ee Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Fri, 1 Nov 2013 17:36:58 -0700 Subject: [PATCH] more bug fix --- .../simplified_cliffc_hashtable.h | 18 ++-- benchmark/linuxrwlocks/linuxrwlocks.c | 35 +++----- grammer/spec.txt | 56 +++++++++++- grammer/spec_compiler.jj | 30 +++++-- .../codeGenerator/CodeAddition.java | 9 +- .../codeGenerator/CodeGenerator.java | 48 ++++++++-- .../codeGenerator/CodeVariables.java | 87 ++++++++++++------- .../codeGenerator/SemanticsChecker.java | 6 -- .../specExtraction/ParserUtils.java | 27 ++++++ .../specExtraction/SourceFileInfo.java | 22 ----- .../specExtraction/SpecExtractor.java | 2 +- test.c | 9 +- 12 files changed, 237 insertions(+), 112 deletions(-) diff --git a/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h b/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h index 299e7a3..c02c0a3 100644 --- a/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h +++ b/benchmark/cliffc-hashtable/simplified_cliffc_hashtable.h @@ -95,7 +95,6 @@ class cliffc_hashtable { map = spec_hashtable(); id_map = spec_hashtable(); tag = Tag(); - @DefineFunc: static bool equals_val(TypeV *ptr1, TypeV *ptr2) { // ... } @@ -369,7 +368,7 @@ friend class CHM; @Commit_point_set: Read_Val_Point1 | Read_Val_Point2 | Read_Val_Point3 @ID: __sequential.getKeyTag(key) @Action: - @DefineVar: TypeV *_Old_Val = __sequential.map.get(key) + TypeV *_Old_Val = __sequential.map.get(key) @Post_check: __sequential.equals_val(_Old_Val, __RET__) @End @@ -391,8 +390,8 @@ friend class CHM; @ID: __sequential.getKeyTag(key) @Action: # Remember this old value at checking point - @DefineVar: TypeV *_Old_Val = __sequential.map.get(key) - @Code: __sequential.map.put(key, &val); + TypeV *_Old_Val = __sequential.map.get(key) + __sequential.map.put(key, &val); @Post_check: __sequential.equals_val(__RET__, _Old_Val) @End @@ -411,8 +410,7 @@ friend class CHM; COND_PutIfAbsentSucc :: __RET__ == NULL @ID: __sequential.getKeyTag(key) @Action: - @DefineVar: TypeV *_Old_Val = __sequential.map.get(key) - @Code: + TypeV *_Old_Val = __sequential.map.get(key) if (__COND_SAT__) __sequential.map.put(key, &value); @Post_check: @@ -429,8 +427,8 @@ friend class CHM; @Commit_point_set: Write_Val_Point @ID: __sequential.getKeyTag(key) @Action: - @DefineVar: TypeV *_Old_Val = __sequential.map.get(key) - @Code: __sequential.map.put(key, NULL); + TypeV *_Old_Val = __sequential.map.get(key) + __sequential.map.put(key, NULL); @Post_check: __sequential.equals_val(__RET__, _Old_Val) @End @@ -450,7 +448,6 @@ friend class CHM; COND_RemoveIfMatchSucc :: __RET__ == true @ID: __sequential.getKeyTag(key) @Action: - @Code: if (__COND_SAY__) __sequential.map.put(key, NULL); @Post_check: @@ -470,7 +467,7 @@ friend class CHM; Write_Val_Point @ID: __sequential.getKeyTag(key) @Action: - @DefineVar: TypeV *_Old_Val = __sequential.map.get(key) + TypeV *_Old_Val = __sequential.map.get(key) @Post_check: __sequential.equals_val(__RET__, _Old_Val) @End @@ -490,7 +487,6 @@ friend class CHM; COND_ReplaceIfMatchSucc :: __RET__ == true @ID: __sequential.getKeyTag(key) @Action: - @Code: if (__COND_SAY__) __sequential.map.put(key, &newval); @Post_check: diff --git a/benchmark/linuxrwlocks/linuxrwlocks.c b/benchmark/linuxrwlocks/linuxrwlocks.c index 9dd2bf8..1cbe525 100644 --- a/benchmark/linuxrwlocks/linuxrwlocks.c +++ b/benchmark/linuxrwlocks/linuxrwlocks.c @@ -45,7 +45,6 @@ @InitVar: writer_lock_acquired = false; reader_lock_cnt = 0; - @DefineFunc: @Happens_before: # Since commit_point_set has no ID attached, A -> B means that for any B, # the previous A happens before B. @@ -84,10 +83,9 @@ static inline int write_can_lock(rwlock_t *lock) @Commit_point_set: Read_Lock_Success_1 | Read_Lock_Success_2 @Check: - !__sequential.writer_lock_acquired + !writer_lock_acquired @Action: - @Code: - __sequential.reader_lock_cnt++; + reader_lock_cnt++; @End */ static inline void read_lock(rwlock_t *rw) @@ -121,10 +119,9 @@ static inline void read_lock(rwlock_t *rw) @Commit_point_set: Write_Lock_Success_1 | Write_Lock_Success_2 @Check: - !__sequential.writer_lock_acquired && __sequential.reader_lock_cnt == 0 + !writer_lock_acquired && reader_lock_cnt == 0 @Action: - @Code: - __sequential.writer_lock_acquired = true; + writer_lock_acquired = true; @End */ static inline void write_lock(rwlock_t *rw) @@ -157,15 +154,14 @@ static inline void write_lock(rwlock_t *rw) @Commit_point_set: Read_Trylock_Point @Condition: - __sequential.writer_lock_acquired == false + writer_lock_acquired == false @HB_condition: HB_Read_Trylock_Succ :: __RET__ == 1 @Action: - @Code: - if (__COND_SAY__) - __sequential.reader_lock_cnt++; + if (__COND_SAT__) + reader_lock_cnt++; @Post_check: - __COND_SAY__ ? __RET__ == 1 : __RET__ == 0 + __COND_SAT__ ? __RET__ == 1 : __RET__ == 0 @End */ static inline int read_trylock(rwlock_t *rw) @@ -190,15 +186,14 @@ static inline int read_trylock(rwlock_t *rw) @Commit_point_set: Write_Trylock_Point @Condition: - !__sequential.writer_lock_acquired && __sequential.reader_lock_cnt == 0 + !writer_lock_acquired && reader_lock_cnt == 0 @HB_condition: HB_Write_Trylock_Succ :: __RET__ == 1 @Action: - @Code: - if (__COND_SAY__) - __sequential.writer_lock_acquired = true; + if (__COND_SAT__) + writer_lock_acquired = true; @Post_check: - __COND_SAY__ ? __RET__ == 1 : __RET__ == 0 + __COND_SAT__ ? __RET__ == 1 : __RET__ == 0 @End */ static inline int write_trylock(rwlock_t *rw) @@ -222,9 +217,8 @@ static inline int write_trylock(rwlock_t *rw) @Interface: Read_Unlock @Commit_point_set: Read_Unlock_Point @Check: - __sequential.reader_lock_cnt > 0 && !__sequential.writer_lock_acquired + reader_lock_cnt > 0 && !writer_lock_acquired @Action: - @Code: reader_lock_cnt--; @End */ @@ -246,8 +240,7 @@ static inline void read_unlock(rwlock_t *rw) @Check: reader_lock_cnt == 0 && writer_lock_acquired @Action: - @Code: - __sequential.writer_lock_acquired = false; + writer_lock_acquired = false; @End */ diff --git a/grammer/spec.txt b/grammer/spec.txt index ed30de8..1ac8dc1 100644 --- a/grammer/spec.txt +++ b/grammer/spec.txt @@ -1 +1,55 @@ -void enqueue(queue_t *q, unsigned int val) +/** +@Begin + @Options: + LANG = C; + CLASS = cliffc_hashtable; + @Global_define: + @DeclareVar: + spec_hashtable map; + spec_hashtable id_map; + Tag tag; + @InitVar: + map = spec_hashtable(); + id_map = spec_hashtable(); + tag = Tag(); + @DefineFunc: + static bool equals_val(TypeV *ptr1, TypeV *ptr2) { + // ... + } + + # Update the tag for the current key slot if the corresponding tag + # is NULL, otherwise just return that tag. It will update the next + # available tag too if it requires a new tag for that key slot. + static Tag getKeyTag(TypeK &key) { + if (id_map.get(key) == NULL) { + Tag cur_tag = tag.current(); + id_map.put(key, cur_tag); + tag.next(); + return cur_tag; + } else { + return id_map.get(key); + } + } + + @Interface_cluster: + Read_interface = { + Get, + PutIfAbsent, + RemoveAny, + RemoveIfMatch, + ReplaceAny, + ReplaceIfMatch + } + + Write_interface = { + Put, + PutIfAbsent(COND_PutIfAbsentSucc), + RemoveAny, + RemoveIfMatch(COND_RemoveIfMatchSucc), + ReplaceAny, + ReplaceIfMatch(COND_ReplaceIfMatchSucc) + } + @Happens_before: + Write_interface -> Read_interface + @End + */ diff --git a/grammer/spec_compiler.jj b/grammer/spec_compiler.jj index 93a5d8b..6a4f61b 100644 --- a/grammer/spec_compiler.jj +++ b/grammer/spec_compiler.jj @@ -179,6 +179,8 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration; public static String stringArray2String(ArrayList content) { StringBuilder sb = new StringBuilder(); + if (content.size() == 1) + return content.get(0); for (int i = 0; i < content.size(); i++) { sb.append(content.get(i) + "\n"); } @@ -309,6 +311,10 @@ SKIP : { | +| + +| + | <#DIGIT: ["0"-"9"]> | @@ -514,7 +520,6 @@ void Test() : { System.out.println(func); } - } @@ -525,8 +530,8 @@ String ParameterizedName() : } { (str = .image {res = str;}) - ("<" str = .image { res = res + "<" + str; } - ("," str = .image { res = res + ", " + str; })* ">" + ("<" str = Type() { res = res + "<" + str; } + ("," str = Type() { res = res + ", " + str; })* ">" { res = res + ">"; } )? { @@ -541,6 +546,7 @@ FunctionHeader FuncDecl() : ArrayList args; } { + ( | )* ret = Type() funcName = ParseQualifiedName() args = FormalParamList() @@ -639,6 +645,7 @@ ArrayList C_CPP_CODE(ArrayList headers) : ( t = | t = | t = | t = | (t =