blob: b21d3aa6c85913d68e55720b11a7964657e05ad8 [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#include "AST.h"
Andreas Huber5345ec22016-07-29 13:33:27 -07002#include "Coordinator.h"
Andreas Huberc9410c72016-07-28 12:18:40 -07003#include "Formatter.h"
Andreas Huber84f89de2016-07-28 15:39:51 -07004#include "FQName.h"
Andreas Huberc9410c72016-07-28 12:18:40 -07005
Andreas Huber68f24592016-07-29 14:53:48 -07006#include <android-base/logging.h>
Andreas Huberc9410c72016-07-28 12:18:40 -07007#include <stdio.h>
Andreas Huberb82318c2016-08-02 14:45:54 -07008#include <unistd.h>
Andreas Huberc9410c72016-07-28 12:18:40 -07009
10using namespace android;
11
Andreas Huberb82318c2016-08-02 14:45:54 -070012static void usage(const char *me) {
13 fprintf(stderr, "usage: %s -o output-path fqname ...\n", me);
14}
15
16int main(int argc, char **argv) {
17 std::string outputDir;
18
19 int res;
20 while ((res = getopt(argc, argv, "ho:")) >= 0) {
21 switch (res) {
22 case 'o':
23 {
24 outputDir = optarg;
25 break;
26 }
27
28 case '?':
29 case 'h':
30 default:
31 {
32 usage(argv[0]);
33 exit(1);
34 break;
35 }
36 }
37 }
38
39 argc -= optind;
40 argv += optind;
41
42 if (outputDir.empty()) {
43 usage(argv[0]);
44 exit(1);
45 } else {
46 const size_t len = outputDir.size();
47 if (outputDir[len - 1] != '/') {
48 outputDir += "/";
49 }
50 }
51
Andreas Huberdc981332016-07-29 15:46:54 -070052 const char *TOP = getenv("TOP");
53 if (TOP == NULL) {
54 LOG(ERROR) << "Your environment does not define $TOP.";
55 return 1;
56 }
57
58 std::string interfacesPath = TOP;
59 interfacesPath.append("/hardware/interfaces/");
60
61 Coordinator coordinator(interfacesPath);
Andreas Huber5345ec22016-07-29 13:33:27 -070062
Andreas Hubereb1081f2016-07-28 13:13:24 -070063 for (int i = 1; i < argc; ++i) {
Andreas Huber68f24592016-07-29 14:53:48 -070064 FQName fqName(argv[i]);
65 CHECK(fqName.isValid() && fqName.isFullyQualified());
66
67 AST *ast = coordinator.parse(fqName);
Andreas Huber881227d2016-08-02 14:20:21 -070068 CHECK(ast != NULL);
Andreas Huberc9410c72016-07-28 12:18:40 -070069
Andreas Hubereb1081f2016-07-28 13:13:24 -070070 Formatter out;
Andreas Huberc9410c72016-07-28 12:18:40 -070071
Andreas Hubereb1081f2016-07-28 13:13:24 -070072 printf("========================================\n");
Andreas Huberc9410c72016-07-28 12:18:40 -070073
Andreas Hubereb1081f2016-07-28 13:13:24 -070074 ast->dump(out);
Andreas Huberc9410c72016-07-28 12:18:40 -070075
Andreas Huberb82318c2016-08-02 14:45:54 -070076 ast->generateCpp(outputDir);
Andreas Huber881227d2016-08-02 14:20:21 -070077
Andreas Hubereb1081f2016-07-28 13:13:24 -070078 delete ast;
79 ast = NULL;
80 }
Andreas Huberc9410c72016-07-28 12:18:40 -070081
Andreas Huberc9410c72016-07-28 12:18:40 -070082 return 0;
83}