| 61 | # statements in the runtime library. This stage should be the last step |
| 62 | # before compiling the runtime library and linking it with user code. |
| 63 | class FunctionGenerator(object): |
| 64 | |
| 65 | # Constructor for FunctionGenerator |
| 66 | def __init__(self): |
| 67 | # Map of all NANO_LOG statements encountered by this instance of |
| 68 | # FunctionGenerator. There should be exactly one entry per NANO_LOG |
| 69 | # in the user sources as each entry is indexed by its format string and |
| 70 | # the filename/line number of where it occurred. It is pre-populated |
| 71 | # with an invalid entry to demonstrate the structure of the map |
| 72 | # |
| 73 | ### Design Decision ### We uniquely identify log messages by their |
| 74 | # format strings and filename:linenum so that we can embed more static |
| 75 | # information (i.e. filename:linenum) at the expense of more entries. |
| 76 | self.logId2Code = { |
| 77 | # Mangled form of a NANO_LOG's format string, filename, |
| 78 | # and line number as generated by generateLogIdStr() |
| 79 | "__INVALID__INVALID__INVALID__": |
| 80 | { |
| 81 | # printf-like format string in the original NANO_LOG |
| 82 | "fmtString" : "INVALID", |
| 83 | |
| 84 | # File and line number where NANO_LOG occurred |
| 85 | "filename" : "INVALID.cc", |
| 86 | "linenum" : "-1", |
| 87 | |
| 88 | # Which g++ preprocessed file did we find this NANO_LOG in? |
| 89 | # This can differ from the above in the cases where the |
| 90 | # NANO_LOG statement is defined in a header file and it's |
| 91 | # include-d in a .cc file. In this case the g++ |
| 92 | # preprocessor will inline the log statement. |
| 93 | "compilationUnit" : "INVALID.cc", |
| 94 | |
| 95 | # Complete function definitions for recording, compressing |
| 96 | # and decompressing a NANO_LOG statement |
| 97 | "recordFnDef" : "invalidRecord(int arg0) { ... }", |
| 98 | "compressFnDef" : "invalidCompress(...) { ....}", |
| 99 | "decompressFnDef" : "invalidDecompress(...) { ... }", |
| 100 | |
| 101 | # Function names for the recording, compressing and |
| 102 | # decompressing functions above |
| 103 | "recordFnName" : "invalidRecord", |
| 104 | "compressFnName" : "invalidCompress", |
| 105 | "decompressFnName" : "invalidDecompress", |
| 106 | |
| 107 | # C-style function declaration for record() |
| 108 | "recordFnDecl" : "void invalidRecord(LogLevel, ...)", |
| 109 | |
| 110 | # Encodes the data structures needed by the decompresor |
| 111 | # to interpret the compact log generated by compressFn |
| 112 | "dictionaryFragment": "{...}" |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | # Debug data structure that keeps track of the number of parameter |
| 117 | # combinations (i.e. "%d %d") by mapping the format string to a counter |
| 118 | self.argLists2Cnt = {} |
| 119 | |
| 120 | # Output the internal state of the FunctionGenerator to a JSON file that |
no outgoing calls