|
| 1 | +# Generating stub functions for new platform |
| 2 | + |
| 3 | +When adding a new platform, the following can be run to generate stub functions for the various devices. |
| 4 | + |
| 5 | +This is a very simple parser of the include files to find function definitions and convert them to stub files that can then be implemented. |
| 6 | + |
| 7 | +## How the scripts work |
| 8 | + |
| 9 | +There are various assumptions in order to make the script very simple. |
| 10 | + |
| 11 | +- Read from the library device include files "fujinet-fuji.h", "fujinet-network.h" |
| 12 | +- Look for lines that start with one of the letters "b", "u", "i", or "v" (for bool, uint, int, void) |
| 13 | +- And have an open bracket on the line |
| 14 | +- Assume the line is the full function definition (i.e. all parameters on 1 line) |
| 15 | +- Remove the semi-colon from the line |
| 16 | +- Generate a stub file that returns "true" for bool, nothing for void, or 0 for number types. |
| 17 | +- Saves stub to "function name".cpp in appropriate subdir of src |
| 18 | + |
| 19 | +## setup |
| 20 | + |
| 21 | +Create the initial directories for the new platform |
| 22 | + |
| 23 | +```shell |
| 24 | +NEW_PLATFORM=commodore |
| 25 | +mkdir ${NEW_PLATFORM}/src/{bus,fn_fuji,fn_network} |
| 26 | +``` |
| 27 | + |
| 28 | +## fuji |
| 29 | + |
| 30 | +```shell |
| 31 | +grep '^[buiv].*(' fujinet-fuji.h | while read f; do FILE_NAME=$(echo $f | cut -d\( -f1 | awk '{print $2}').cpp; echo $f | awk '{ |
| 32 | + LINE=gsub(/;/, "") |
| 33 | + printf("#include <stdbool.h>\n#include <stdint.h>\n#include \"fujinet-fuji.h\"\n\n%s\n{\n", $0) |
| 34 | + if ($1 == "bool") { |
| 35 | + printf("\treturn true;\n}\n") |
| 36 | + } else if ($1 == "void") { |
| 37 | + printf("}\n") |
| 38 | + } else { |
| 39 | + printf("\treturn 0;\n}\n") |
| 40 | + } |
| 41 | +}' > $NEW_PLATFORM/src/fn_fuji/${FILE_NAME}; done |
| 42 | +``` |
| 43 | + |
| 44 | +## network |
| 45 | + |
| 46 | +```shell |
| 47 | +grep '^[buiv].*(' fujinet-network.h | while read f; do FILE_NAME=$(echo $f | cut -d\( -f1 | awk '{print $2}').cpp; echo $f | awk '{ |
| 48 | + LINE=gsub(/;/, "") |
| 49 | + printf("#include <stdbool.h>\n#include <stdint.h>\n#include \"fujinet-network.h\"\n\n%s\n{\n", $0) |
| 50 | + if ($1 == "bool") { |
| 51 | + printf("\treturn true;\n}\n") |
| 52 | + } else if ($1 == "void") { |
| 53 | + printf("}\n") |
| 54 | + } else { |
| 55 | + printf("\treturn 0;\n}\n") |
| 56 | + } |
| 57 | +}' > $NEW_PLATFORM/src/fn_network/${FILE_NAME}; done |
| 58 | +``` |
0 commit comments