1 package edu.uci.eecs.specCompiler.codeGenerator;
3 import java.util.ArrayList;
4 import java.util.HashSet;
7 import edu.uci.eecs.specCompiler.grammerParser.ParseException;
8 import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
9 import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
10 import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
11 import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
12 import edu.uci.eecs.specCompiler.specExtraction.Construct;
13 import edu.uci.eecs.specCompiler.specExtraction.FunctionHeader;
14 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
15 import edu.uci.eecs.specCompiler.specExtraction.IDExtractor;
16 import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
17 import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
18 import edu.uci.eecs.specCompiler.specExtraction.ParserUtils;
19 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
20 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
21 import edu.uci.eecs.specCompiler.specExtraction.SpecExtractor;
22 import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
24 public class CodeVariables {
25 // C++ code or library
26 public static final String HEADER_THREADS = "<threads.h>";
27 public static final String HEADER_STDINT = "<stdint.h>";
28 public static final String ThreadIDType = "thrd_t";
29 public static final String GET_THREAD_ID = "thrd_current";
30 public static final String BOOLEAN = "bool";
31 public static final String UINT64 = "uint64_t";
34 public static final String HEADER_CDSANNOTATE = "<cdsannotate.h>";
35 public static final String HEADER_SPECANNOTATION = "<specannotation.h>";
36 public static final String HEADER_CDSTRACE = "<cdstrace.h>";
37 public static final String CDSAnnotate = "cdsannotate";
38 public static final String CDSAnnotateType = "SPEC_ANALYSIS";
39 public static final String IDType = "id_t";
41 public static final String SPEC_ANNO_TYPE = "spec_anno_type";
42 public static final String SPEC_ANNO_TYPE_HB_INIT = "HB_INIT";
43 public static final String SPEC_ANNO_TYPE_INTERFACE_BEGIN = "INTERFACE_BEGIN";
44 public static final String SPEC_ANNO_TYPE_HB_CONDITION = "HB_CONDITION";
45 public static final String SPEC_ANNO_TYPE_INTERFACE_END = "INTERFACE_END";
46 public static final String SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE = "POTENTIAL_CP_DEFINE";
47 public static final String SPEC_ANNO_TYPE_CP_DEFINE_CHECK = "CP_DEFINE_CHECK";
48 public static final String SPEC_ANNO_TYPE_CP_DEFINE = "CP_DEFINE";
49 public static final String SPEC_ANNOTATION = "spec_annotation";
50 public static final String SPEC_ANNOTATION_FIELD_TYPE = "type";
51 public static final String SPEC_ANNOTATION_FIELD_ANNO = "annotation";
53 public static final String ANNO_HB_INIT = "anno_hb_init";
54 public static final String ANNO_INTERFACE_BEGIN = "anno_interface_begin";
55 public static final String ANNO_INTERFACE_END = "anno_interface_end";
56 public static final String ANNO_POTENTIAL_CP_DEFINE = "anno_potentail_cp_define";
57 public static final String ANNO_CP_DEFINE = "anno_cp_define";
58 public static final String ANNO_CP_DEFINE_CHECK = "anno_cp_define_check";
59 public static final String ANNO_HB_CONDITION = "anno_hb_condition";
61 // Specification variables
62 public static final String SPEC_INTERFACE_WRAPPER = "__wrapper_";
63 public static final String DEFAULT_ID = "0";
65 // Specification library
66 public static final String HEADER_SPEC_LIB = "<spec_lib.h>";
67 public static final String SPEC_QUEUE = "spec_queue";
68 public static final String SPEC_STACK = "spec_stack";
69 public static final String SPEC_DEQUE = "spec_deque";
70 public static final String SPEC_HASHTABLE = "spec_hashtable";
71 public static final String SPEC_PRIVATE_HASHTABLE = "spec_private_hashtable";
72 public static final String SPEC_TAG = "spec_tag";
73 public static final String SPEC_TAG_CURRENT = "current";
74 public static final String SPEC_TAG_NEXT = "next";
77 public static final String MACRO_ID = "__ID__";
78 public static final String MACRO_COND = "__COND_SAT__";
79 public static final String MACRO_RETURN = "__RET__";
80 public static final String MACRO_ATOMIC_RETURN = "__ATOMIC_RET__";
82 public static void printCode(ArrayList<String> code) {
83 for (int i = 0; i < code.size(); i++) {
84 System.out.println(code.get(i));
88 private static String COMMENT(String comment) {
89 return "/* " + comment + " */";
92 private static String INCLUDE(String header) {
93 return "#include " + header;
96 private static String DEFINE(String left, String right) {
97 return "#define " + left + " " + right;
100 private static String UNDEFINE(String macro) {
101 return "#undef " + macro;
104 private static String GET_FIELD_BY_PTR(String ptr, String field) {
105 return ptr + "->" + field;
108 private static String GET_FIELD(String var, String field) {
109 return var + "->" + field;
112 private static String BRACE(String val) {
113 return "(" + val + ")";
116 private static String ASSIGN(String structName, String field, String val) {
117 return structName + "." + field + " = " + val + ";";
120 private static String ASSIGN(String varName, String val) {
121 return varName + " = " + val + ";";
124 private static String ASSIGN_PTR(String structName, String field, String val) {
125 return structName + "." + field + " = &" + val + ";";
128 private static String ASSIGN_TO_PTR(String structName, String field,
130 return structName + "->" + field + " = " + val + ";";
133 private static String DECLARE(String type, String name) {
134 return type + " " + name + ";";
137 private static String DECLARE(VariableDeclaration varDecl) {
138 String type = varDecl.type, name = varDecl.name;
139 return type + " " + name + ";";
142 private static String DECLARE_DEFINE(String type, String var, String val) {
143 return type + " " + var + " = " + val + ";";
146 private static String ANNOTATE(String structName) {
147 return CDSAnnotate + "(" + CDSAnnotateType + ", &" + structName + ");";
150 private static ArrayList<String> DEFINE_INFO_STRUCT(String interfaceName,
151 FunctionHeader funcDecl) {
152 ArrayList<String> code = new ArrayList<String>();
153 code.add("typedef struct " + interfaceName + "_info {");
154 code.add(DECLARE(funcDecl.returnType, MACRO_RETURN));
155 for (int i = 0; i < funcDecl.args.size(); i++) {
156 code.add(DECLARE(funcDecl.args.get(i)));
158 code.add("} " + interfaceName + "_info {");
162 private static ArrayList<String> DEFINE_ID_FUNC(String interfaceName,
164 ArrayList<String> code = new ArrayList<String>();
165 code.add("static " + IDType + " " + interfaceName + "_id() {");
166 if (idCode != null) {
167 code.add(DECLARE_DEFINE(IDType, MACRO_ID, idCode));
169 code.add(DECLARE_DEFINE(IDType, MACRO_ID, DEFAULT_ID));
171 code.add("return " + MACRO_ID + ";");
176 private static ArrayList<String> DEFINE_CHECK_ACTION_FUNC(
177 InterfaceConstruct construct, FunctionHeader header) {
178 String interfaceName = construct.name;
179 ArrayList<String> code = new ArrayList<String>();
180 code.add("bool " + interfaceName + "_check_action(void *info, "
181 + IDType + " " + MACRO_ID + ") {");
182 code.add(DECLARE("bool", "check_passed"));
183 String infoStructType = interfaceName + "_info", infoStructName = "theInfo";
184 code.add(DECLARE_DEFINE(infoStructType + "*", infoStructName,
185 BRACE(infoStructType) + "info"));
186 code.add((DECLARE_DEFINE(header.returnType, MACRO_RETURN,
187 GET_FIELD_BY_PTR(infoStructName, MACRO_RETURN))));
188 for (int i = 0; i < header.args.size(); i++) {
189 String type = header.args.get(i).type, var = header.args.get(i).name;
190 code.add((DECLARE_DEFINE(type, var,
191 GET_FIELD_BY_PTR(infoStructName, var))));
195 code.add(DECLARE_DEFINE("bool", MACRO_COND, construct.condition));
197 code.add(ASSIGN("check_passed", construct.check));
198 code.add("if (!check_passed) return false;");
200 code.addAll(construct.action);
202 code.add(ASSIGN("check_passed", construct.postCheck));
203 code.add("if (!check_passed) return false;");
205 code.addAll(construct.postAction);
211 private static HashSet<String> getAllHeaders(SemanticsChecker semantics) {
212 HashSet<String> headers = new HashSet<String>();
213 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
214 File f = semantics.interfaceName2Construct.get(interfaceName).file;
215 headers.addAll(semantics.srcFilesInfo.get(f).headers);
220 private static void makeFunctionStatic(ArrayList<String> funcDefine) {
221 String headLine = funcDefine.get(0);
222 headLine = "static " + headLine;
223 funcDefine.set(0, headLine);
226 private static void makeVariablesStatic(ArrayList<String> varDecls) {
227 for (int i = 0; i < varDecls.size(); i++) {
228 String varDecl = varDecls.get(i);
229 varDecl = "static " + varDecl;
230 varDecls.set(i, varDecl);
234 private static FunctionHeader getFunctionHeader(SemanticsChecker semantics,
235 Construct construct) {
236 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
237 String headerLine = content.get(construct.beginLineNum);
238 if (headerLine.startsWith("template")) {
239 headerLine = content.get(construct.beginLineNum + 1);
242 return SpecParser.parseFuncHeader(headerLine);
243 } catch (ParseException e) {
249 public static ArrayList<String> generateGlobalVarDeclaration(
250 SemanticsChecker semantics, GlobalConstruct construct) {
251 ArrayList<String> newCode = new ArrayList<String>();
252 HashSet<String> allHeaders = getAllHeaders(semantics);
254 // All headers needed by the interface decalration
255 newCode.add(COMMENT("/* Include all the header files that contains the interface declaration */"));
256 for (String header : allHeaders) {
257 newCode.add(INCLUDE(header));
260 // Other necessary headers
261 newCode.add(INCLUDE(HEADER_STDINT));
262 newCode.add(INCLUDE(HEADER_CDSANNOTATE));
263 newCode.add(INCLUDE(HEADER_SPEC_LIB));
266 SequentialDefineSubConstruct code = construct.code;
267 // User-defined functions
268 newCode.add(COMMENT("All other user-defined functions"));
269 ArrayList<ArrayList<String>> defineFuncs = code.defineFuncs;
270 for (int i = 0; i < defineFuncs.size(); i++) {
271 ArrayList<String> defineFunc = defineFuncs.get(i);
272 makeFunctionStatic(defineFunc);
273 newCode.addAll(defineFunc);
277 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
278 InterfaceConstruct iConstruct = semantics.interfaceName2Construct
280 FunctionHeader funcHeader = getFunctionHeader(semantics, iConstruct);
281 // Define necessary info structure
282 newCode.add(COMMENT("Definition of interface info struct: "
284 newCode.addAll(DEFINE_INFO_STRUCT(interfaceName, funcHeader));
285 newCode.add(COMMENT("End of info struct definition: "
289 // Define ID function
290 newCode.add(COMMENT("ID function of interface: " + interfaceName));
291 newCode.addAll(DEFINE_ID_FUNC(interfaceName, iConstruct.idCode));
292 newCode.add(COMMENT("End of ID function: + " + interfaceName));
295 // Define check_action function
296 newCode.add(COMMENT("Check action function of interface: "
298 newCode.addAll(DEFINE_CHECK_ACTION_FUNC(iConstruct, funcHeader));
299 newCode.add(COMMENT("End of check action function: + "
303 // Interface function pointer table
304 String interfaceSize = Integer
305 .toString(semantics.interfaceName2Construct.size());
306 newCode.add(DEFINE("INTERFACE_SIZE", interfaceSize));
307 newCode.add(DECLARE("void**", "func_ptr_table"));
308 // User-defined variables
309 ArrayList<VariableDeclaration> varDecls = code.declareVar;
310 for (int i = 0; i < varDecls.size(); i++) {
311 VariableDeclaration varDecl = varDecls.get(i);
312 newCode.add(DECLARE(varDecl.type, varDecl.name));
316 newCode.add(COMMENT("Define function for sequential code initialization"));
317 newCode.add("static void __sequential_init() {");
318 // Init func_ptr_table
319 newCode.add(COMMENT("Init func_ptr_table"));
320 newCode.add(ASSIGN("func_ptr_table",
321 "(void**) malloc(sizeof(void*) * 2)"));
322 for (String interfaceName : semantics.interfaceName2Construct.keySet()) {
323 String interfaceNum = Integer.toString(semantics.interface2Num
324 .get(interfaceName));
325 newCode.add(ASSIGN("func_ptr_table[2 * " + interfaceNum + "]",
326 "(void*) &" + interfaceName + "_id"));
327 newCode.add(ASSIGN("func_ptr_table[2 * " + interfaceNum + " + 1]",
328 "(void*) &" + interfaceName + "_check_action"));
331 // Init user-defined variables
332 newCode.addAll(construct.code.initVar);
333 // Pass Happens-before relationship
334 generateHBInitAnnotation(semantics);
336 newCode.add(COMMENT("End of Global construct generation in class"));
338 // printCode(newCode);
342 public static ArrayList<String> generateStaticVarDefine(
343 SemanticsChecker semantics, GlobalConstruct construct) {
344 ArrayList<String> newCode = new ArrayList<String>();
345 String className = semantics.getClassName();
346 if (className == null)
347 return newCode; // No need to define any static variables
348 String templateList = semantics.getTemplateStr();
350 if (templateList == null) {
351 varPrefix = className + "::";
353 varPrefix = className + templateList + "::";
355 String templateDecl = semantics.getTemplateFullStr();
356 if (templateList == null) {
357 newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
358 for (int i = 0; i < construct.code.declareVar.size(); i++) {
359 VariableDeclaration varDecl = construct.code.declareVar.get(i);
360 newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name));
363 newCode.add(templateDecl);
364 newCode.add(DECLARE("void**", varPrefix + "func_ptr_table"));
365 for (int i = 0; i < construct.code.declareVar.size(); i++) {
366 VariableDeclaration varDecl = construct.code.declareVar.get(i);
367 newCode.add(templateDecl);
368 newCode.add(DECLARE(varDecl.type, varPrefix + varDecl.name));
374 private static ArrayList<String> generateHBInitAnnotation(
375 SemanticsChecker semantics) {
376 ArrayList<String> newCode = new ArrayList<String>();
377 int hbConditionInitIdx = 0;
378 for (ConditionalInterface left : semantics.getHBConditions().keySet()) {
379 for (ConditionalInterface right : semantics.getHBConditions().get(
381 String structVarName = "hbConditionInit" + hbConditionInitIdx;
382 String annotationVarName = "hb_init" + hbConditionInitIdx;
383 hbConditionInitIdx++;
384 String interfaceNumBefore = Integer
385 .toString(semantics.interface2Num
386 .get(left.interfaceName)), hbLabelNumBefore = Integer
387 .toString(semantics.hbLabel2Num
388 .get(left.hbConditionLabel)), interfaceNumAfter = Integer
389 .toString(semantics.interface2Num
390 .get(right.interfaceName)), hbLabelNumAfter = Integer
391 .toString(semantics.hbLabel2Num
392 .get(right.hbConditionLabel));
393 newCode.add(COMMENT(left + " -> " + right));
395 newCode.add(ANNO_HB_INIT + " " + structVarName + ";");
396 newCode.add(ASSIGN(structVarName, "interface_num_before",
397 interfaceNumBefore));
398 newCode.add(ASSIGN(structVarName, "hb_condition_num_before",
400 newCode.add(ASSIGN(structVarName, "interface_num_after",
402 newCode.add(ASSIGN(structVarName, "hb_condition_num_after",
405 newCode.add(DECLARE(SPEC_ANNOTATION, annotationVarName));
406 newCode.add(ASSIGN(annotationVarName,
407 SPEC_ANNOTATION_FIELD_TYPE, SPEC_ANNO_TYPE_HB_INIT));
408 newCode.add(ASSIGN_PTR(annotationVarName,
409 SPEC_ANNOTATION_FIELD_ANNO, structVarName));
410 newCode.add(ANNOTATE(annotationVarName));
416 public static ArrayList<String> generateInterfaceWrapper(
417 SemanticsChecker semantics, InterfaceConstruct construct) {
418 ArrayList<String> newCode = new ArrayList<String>();
419 String interfaceName = construct.name;
420 // Generate necessary header file (might be redundant but never mind)
421 newCode.add(INCLUDE(HEADER_THREADS));
422 newCode.add(INCLUDE(HEADER_CDSANNOTATE));
423 newCode.add(INCLUDE(HEADER_SPECANNOTATION));
424 newCode.add(INCLUDE(HEADER_SPEC_LIB));
426 FunctionHeader header = getFunctionHeader(semantics, construct);
427 String interfaceNum = Integer.toString(semantics.interface2Num
428 .get(construct.name));
429 // Rename the interface
430 renameInterface(semantics, construct);
431 InterfaceDefineConstruct defineConstruct = semantics.interfaceName2DefineConstruct.get(interfaceName);
432 if (defineConstruct != null) {
433 renameInterface(semantics, defineConstruct);
436 // Generate wrapper header
437 newCode.add(header.toString() + " {");
438 // Wrapper function body
439 newCode.add(COMMENT("Interface begins"));
441 String structName = "interface_begin";
442 newCode.add(DECLARE(ANNO_INTERFACE_BEGIN, "interface_begin"));
443 newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
444 String anno = "annotation_interface_begin";
445 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
446 newCode.add(ASSIGN(structName, "type", SPEC_ANNO_TYPE_INTERFACE_BEGIN));
447 newCode.add(ASSIGN_PTR(structName, "annotation", structName));
448 newCode.add(ANNOTATE(anno));
449 // Call original renamed function
450 newCode.add(DECLARE_DEFINE(header.returnType, MACRO_RETURN,
451 header.getRenamedCall(SPEC_INTERFACE_WRAPPER)));
453 for (String label : construct.hbConditions.keySet()) {
454 String condition = construct.hbConditions.get(label);
455 String hbCondNum = Integer.toString(semantics.interface2Num
457 newCode.add("if " + BRACE(condition) + " {");
458 structName = "hb_condition";
459 newCode.add(DECLARE(ANNO_HB_CONDITION, structName));
460 newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
462 newCode.add(ASSIGN(structName, "hb_condition_num", hbCondNum));
463 anno = "annotation_hb_condition";
464 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
465 newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_HB_CONDITION));
466 newCode.add(ASSIGN_PTR(anno, "annotation", structName));
467 newCode.add(ANNOTATE(anno));
470 String infoStructType = interfaceName + "_info", infoName = "info";
471 newCode.add(DECLARE_DEFINE(infoStructType, infoName,
472 BRACE(infoStructType + "*") + " malloc(sizeof("
473 + infoStructType + "))"));
474 newCode.add(ASSIGN_TO_PTR(infoName, MACRO_RETURN, MACRO_RETURN));
475 for (int i = 0; i < header.args.size(); i++) {
476 String argName = header.args.get(i).name;
477 newCode.add(ASSIGN_TO_PTR(infoName, argName, argName));
479 structName = "interface_end";
480 anno = "annoation_interface_end";
481 newCode.add(DECLARE(ANNO_INTERFACE_END, structName));
482 newCode.add(ASSIGN(structName, "interface_num", interfaceNum));
483 newCode.add(ASSIGN(structName, "info", infoName));
484 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
485 newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_INTERFACE_END));
486 newCode.add(ASSIGN_PTR(anno, "annotation", structName));
488 // End of the wrapper function
491 // printCode(newCode);
495 public static void renameInterface(SemanticsChecker semantics,
496 Construct construct) {
497 FunctionHeader header = getFunctionHeader(semantics, construct);
498 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
499 int lineNum = construct.beginLineNum;
500 String headerLine = content.get(construct.beginLineNum);
501 if (headerLine.startsWith("template")) {
502 headerLine = content.get(construct.beginLineNum + 1);
505 String newLine = header.getRenamedHeader(SPEC_INTERFACE_WRAPPER)
507 content.set(lineNum, newLine);
510 public static void addAtomicReturn(SemanticsChecker semantics,
511 Construct construct) {
512 int lineNum = construct.beginLineNum - 1;
513 ArrayList<String> content = semantics.srcFilesInfo.get(construct.file).content;
514 String oldLine = content.get(lineNum);
515 String newLine = "uint64_t " + MACRO_ATOMIC_RETURN + " = " + oldLine;
516 content.set(lineNum, newLine);
519 public static ArrayList<String> generatePotentialCPDefine(
520 SemanticsChecker semantics, PotentialCPDefineConstruct construct) {
521 ArrayList<String> newCode = new ArrayList<String>();
522 // Add atomic return variable if the predicate accesses to it
523 if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
524 addAtomicReturn(semantics, construct);
526 // Generate redundant header files
527 newCode.add(COMMENT("Automatically generated code for potential commit point: "
529 newCode.add(COMMENT("Include redundant headers"));
530 newCode.add(INCLUDE(HEADER_STDINT));
531 newCode.add(INCLUDE(HEADER_CDSANNOTATE));
534 newCode.add("if (" + construct.condition + ") {");
535 String structName = "potential_cp_define", anno = "annotation_potential_cp_define";
536 newCode.add(DECLARE(ANNO_POTENTIAL_CP_DEFINE, structName));
537 String labelNum = Integer.toString(semantics.commitPointLabel2Num
538 .get(construct.label));
539 newCode.add(ASSIGN(structName, "label_num", labelNum));
540 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
541 newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_POTENTIAL_CP_DEFINE));
542 newCode.add(ASSIGN_PTR(anno, "annotation", structName));
543 newCode.add(ANNOTATE(anno));
548 public static ArrayList<String> generateCPDefineCheck(
549 SemanticsChecker semantics, CPDefineCheckConstruct construct) {
550 ArrayList<String> newCode = new ArrayList<String>();
551 // Add atomic return variable if the predicate accesses to it
552 if (construct.condition.indexOf(MACRO_ATOMIC_RETURN) != -1) {
553 addAtomicReturn(semantics, construct);
555 // Generate redundant header files
556 newCode.add(COMMENT("Automatically generated code for commit point define check: "
558 newCode.add(COMMENT("Include redundant headers"));
559 newCode.add(INCLUDE(HEADER_STDINT));
560 newCode.add(INCLUDE(HEADER_CDSANNOTATE));
563 newCode.add("if (" + construct.condition + ") {");
564 String structName = "cp_define_check", anno = "annotation_cp_define_check";
565 newCode.add(DECLARE(ANNO_CP_DEFINE_CHECK, structName));
566 String labelNum = Integer.toString(semantics.commitPointLabel2Num
567 .get(construct.label));
568 newCode.add(ASSIGN(structName, "label_num", labelNum));
569 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
570 newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE_CHECK));
571 newCode.add(ASSIGN_PTR(anno, "annotation", structName));
572 newCode.add(ANNOTATE(anno));
577 public static ArrayList<String> generateCPDefine(
578 SemanticsChecker semantics, CPDefineConstruct construct) {
579 ArrayList<String> newCode = new ArrayList<String>();
580 // Generate redundant header files
581 newCode.add(COMMENT("Automatically generated code for commit point define check: "
585 newCode.add("if (" + construct.condition + ") {");
586 String structName = "cp_define", anno = "annotation_cp_define";
587 newCode.add(DECLARE(ANNO_CP_DEFINE, structName));
588 String labelNum = Integer.toString(semantics.commitPointLabel2Num
589 .get(construct.label));
590 newCode.add(ASSIGN(structName, "label_num", labelNum));
591 newCode.add(DECLARE(SPEC_ANNOTATION, anno));
592 newCode.add(ASSIGN(anno, "type", SPEC_ANNO_TYPE_CP_DEFINE));
593 newCode.add(ASSIGN_PTR(anno, "annotation", structName));
594 newCode.add(ANNOTATE(anno));