blob: 7869e4bbb2a00fcc59fc10d9c39872a03cf7336c [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
Andreas Huber737080b2016-08-02 15:38:04 -070019 const char *me = argv[0];
20
Andreas Huberb82318c2016-08-02 14:45:54 -070021 int res;
22 while ((res = getopt(argc, argv, "ho:")) >= 0) {
23 switch (res) {
24 case 'o':
25 {
26 outputDir = optarg;
27 break;
28 }
29
30 case '?':
31 case 'h':
32 default:
33 {
Andreas Huber737080b2016-08-02 15:38:04 -070034 usage(me);
Andreas Huberb82318c2016-08-02 14:45:54 -070035 exit(1);
36 break;
37 }
38 }
39 }
40
41 argc -= optind;
42 argv += optind;
43
Andreas Huber737080b2016-08-02 15:38:04 -070044 // Valid options are now in argv[0] .. argv[argc - 1].
45
Andreas Huberb82318c2016-08-02 14:45:54 -070046 if (outputDir.empty()) {
Andreas Huber737080b2016-08-02 15:38:04 -070047 usage(me);
Andreas Huberb82318c2016-08-02 14:45:54 -070048 exit(1);
49 } else {
50 const size_t len = outputDir.size();
51 if (outputDir[len - 1] != '/') {
52 outputDir += "/";
53 }
54 }
55
Andreas Huberdc981332016-07-29 15:46:54 -070056 const char *TOP = getenv("TOP");
57 if (TOP == NULL) {
58 LOG(ERROR) << "Your environment does not define $TOP.";
59 return 1;
60 }
61
62 std::string interfacesPath = TOP;
63 interfacesPath.append("/hardware/interfaces/");
64
65 Coordinator coordinator(interfacesPath);
Andreas Huber5345ec22016-07-29 13:33:27 -070066
Andreas Huber737080b2016-08-02 15:38:04 -070067 for (int i = 0; i < argc; ++i) {
Andreas Huber68f24592016-07-29 14:53:48 -070068 FQName fqName(argv[i]);
69 CHECK(fqName.isValid() && fqName.isFullyQualified());
70
71 AST *ast = coordinator.parse(fqName);
Andreas Huber881227d2016-08-02 14:20:21 -070072 CHECK(ast != NULL);
Andreas Huberc9410c72016-07-28 12:18:40 -070073
Andreas Hubereb1081f2016-07-28 13:13:24 -070074 Formatter out;
Andreas Huberc9410c72016-07-28 12:18:40 -070075
Andreas Hubereb1081f2016-07-28 13:13:24 -070076 printf("========================================\n");
Andreas Huberc9410c72016-07-28 12:18:40 -070077
Andreas Hubereb1081f2016-07-28 13:13:24 -070078 ast->dump(out);
Andreas Huberc9410c72016-07-28 12:18:40 -070079
Andreas Huberb82318c2016-08-02 14:45:54 -070080 ast->generateCpp(outputDir);
Andreas Huber881227d2016-08-02 14:20:21 -070081
Andreas Hubereb1081f2016-07-28 13:13:24 -070082 delete ast;
83 ast = NULL;
84 }
Andreas Huberc9410c72016-07-28 12:18:40 -070085
Andreas Huberc9410c72016-07-28 12:18:40 -070086 return 0;
87}