diff options
author | Jocelyn Bohr <bohr@chromium.org> | 2015-08-13 13:44:26 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-08-13 21:42:36 +0000 |
commit | ff61db187155afc23974f8e94264b760687de023 (patch) | |
tree | 5071ff8a8c5213cc88cf0b88197788213601b9a8 /generator | |
parent | b1d8b48c6658ac424674c2864cc8677049d7b415 (diff) | |
download | tpm2-ff61db187155afc23974f8e94264b760687de023.tar.gz |
Modify generator to output GetCommandCodeString.
Modify command_generator.py to output a method which returns a string
from a TPM_CC command code. This will be used in the simulator.
BUG=none
TEST=libtpm2 builds, string prints as expected
Change-Id: Ic8007f7006488ff4d7b3ac7b22a1ce15ae6ae28c
Signed-off-by: Jocelyn Bohr <bohr@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/293491
Diffstat (limited to 'generator')
-rwxr-xr-x | generator/command_generator.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/generator/command_generator.py b/generator/command_generator.py index a685dc5..a8eaa95 100755 --- a/generator/command_generator.py +++ b/generator/command_generator.py @@ -134,7 +134,30 @@ _HANDLE_PROCESS_END = """ return TPM_RC_COMMAND_CODE; } }""" +_GET_COMMAND_CODE_STRING_HEADER = """ +#ifndef TPM2_GET_COMMAND_CODE_STRING_FP_H_ +#define TPM2_GET_COMMAND_CODE_STRING_FP_H_ +#include "TPM_Types.h" + +const char* GetCommandCodeString(TPM_CC command_code); + +#endif // TPM2_GET_COMMAND_CODE_STRING_FP_H_""" +_GET_COMMAND_CODE_STRING_START = """ +#include "GetCommandCodeString_fp.h" + +const char* GetCommandCodeString(TPM_CC command_code) { + switch(command_code) {""" +_GET_COMMAND_CODE_STRING_CASE = """ +#ifdef TPM_CC_%(command_name)s + case TPM_CC_%(command_name)s: + return "%(command_name)s"; +#endif""" +_GET_COMMAND_CODE_STRING_END = """ + default: + return "Unknown command"; + } +}""" class Command(object): """Represents a TPM command. @@ -731,6 +754,25 @@ def OutputHandleProcess(commands, typemap): out_file.write(_HANDLE_PROCESS_END) call(['clang-format', '-i', '-style=Chromium', 'HandleProcess.c']) +def OutputGetCommandCodeString(commands): + """Generates header and implementation files for GetCommandCodeString. + + Args: + commands: A list of Command objects. + """ + with open('GetCommandCodeString_fp.h', 'w') as out_file: + out_file.write(_COPYRIGHT_HEADER) + out_file.write(_GET_COMMAND_CODE_STRING_HEADER) + call(['clang-format', '-i', '-style=Chromium', 'GetCommandCodeString_fp.h']) + with open('GetCommandCodeString.c', 'w') as out_file: + out_file.write(_COPYRIGHT_HEADER) + out_file.write(_GET_COMMAND_CODE_STRING_START) + for command in commands: + out_file.write(_GET_COMMAND_CODE_STRING_CASE % + {'command_name': command.MethodName()}) + out_file.write(_GET_COMMAND_CODE_STRING_END) + call(['clang-format', '-i', '-style=Chromium', 'GetCommandCodeString.c']) + def GenerateHeader(commands): """Generates a header file with declarations for all given generator objects. @@ -769,3 +811,4 @@ def GenerateImplementation(commands, typemap): call(['clang-format', '-i', '-style=Chromium', marshal_command_file]) OutputHandleProcess(commands, typemap) OutputCommandDispatcher(commands) + OutputGetCommandCodeString(commands) |