Skip to content

Commit 5283e18

Browse files
committed
sync changes
1 parent 2fd0167 commit 5283e18

35 files changed

+1676
-434
lines changed

godel-script/godel-frontend/src/ast/expr.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ class call_head: public expr {
306306
func_call* call;
307307
initializer* ini;
308308

309+
private:
309310
// mark schema(xxx) is schema::__all__(xxx)
310-
bool schema_loader;
311+
bool flag_is_schema_loader;
311312

312313
private:
313314
void check_call_and_init() {
@@ -321,20 +322,22 @@ class call_head: public expr {
321322
call_head(const span& location):
322323
expr(ast_class::ac_call_head, location),
323324
first(nullptr), call(nullptr), ini(nullptr),
324-
schema_loader(false) {}
325+
flag_is_schema_loader(false) {}
325326
~call_head() override;
326327
void set_first_expression(expr* node) { first = node; }
327328
void set_func_call(func_call* node) { call = node; check_call_and_init(); }
328329
void set_initializer(initializer* node) { ini = node; check_call_and_init(); }
329-
void set_is_schema_loader() { schema_loader = true; }
330+
void set_is_schema_loader() { flag_is_schema_loader = true; }
330331

332+
public:
331333
expr* get_first_expression() { return first; }
332334
bool has_func_call() const { return call!=nullptr; }
333335
func_call* get_func_call() { return call; }
334336
bool is_initializer() const { return ini!=nullptr; }
335337
initializer* get_initializer() { return ini; }
336-
bool is_schema_loader() const { return schema_loader; }
338+
bool is_schema_loader() const { return flag_is_schema_loader; }
337339

340+
public:
338341
void accept(ast_visitor* visitor) override;
339342
};
340343

godel-script/godel-frontend/src/cli.cpp

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ std::ostream& help(std::ostream& out) {
4242
<< reset << "\nUsage: ./godel "
4343
<< green << "[options] <input>\n\n"
4444
<< reset << "Compile options:\n"
45+
<< green << " -### "
46+
<< reset << "Print detailed compilation commands (not run).\n"
4547
<< green << " -s, --souffle <path> "
4648
<< reset << "Output generated souffle to file.\n"
4749
<< green << " -r, --run-souffle "
48-
<< reset << "Run compiled godel script program directly.\n"
50+
<< reset << "Run compiled godel script program.\n"
4951
<< green << " -p, --package-path <path> "
5052
<< reset << "Give godelscript package root path.\n"
5153
<< green << " -f, --fact "
5254
<< reset << "Specify souffle fact data path.\n"
5355
<< green << " -e, --extract-template "
5456
<< reset << "Extract probable script template.\n"
5557
<< green << " -l, --location-extract <path> "
56-
<< reset << "Extract all functions and methods location into json.\n";
58+
<< reset << "Extract function and method location into json.\n";
5759
out
5860
<< reset << "\nInformation dump options:\n"
5961
<< green << " -h, --help "
@@ -81,7 +83,9 @@ std::ostream& help(std::ostream& out) {
8183
<< green << " --dump-lsp "
8284
<< reset << "Show semantic result in json format.\n"
8385
<< green << " --lsp-dump-use-indexed-file "
84-
<< reset << "Use file index instead of string.\n";
86+
<< reset << "Use file index instead of string.\n"
87+
<< green << " --lsp-dump-only-schema "
88+
<< reset << "Only dump schema without location.\n";
8589
out
8690
<< reset << "\nLexical analysis dump options:\n"
8791
<< green << " --lexer-dump-token "
@@ -93,25 +97,33 @@ std::ostream& help(std::ostream& out) {
9397
<< green << " --semantic-only "
9498
<< reset << "Only do semantic analysis and exit.\n"
9599
<< green << " --semantic-pub-check "
96-
<< reset << "Enable semantic public access authority checker.\n"
97-
<< green << " --semantic-no-else "
98-
<< reset << "Enable semantic no else branch checker.\n";
100+
<< reset << "Enable semantic public access authority checker.\n";
99101
out
100102
<< reset << "\nSouffle code generation options:\n"
103+
<< green << " -O1 "
104+
<< reset << "Enable souffle code generator optimizer, level 1.\n"
105+
<< green << " -O2 "
106+
<< reset << "Enable souffle code generator optimizer, level 2.\n"
107+
<< green << " -O3 "
108+
<< reset << "Enable souffle code generator optimizer, level 3.\n"
101109
<< green << " -Of, --opt-for "
102110
<< reset << "Enable souffle code generator for statement optimizer.\n"
103111
<< green << " -Ol, --opt-let "
104112
<< reset << "Enable souffle code generator let statement optimizer(not suggested).\n"
105113
<< green << " -Oim, --opt-ir-merge "
106-
<< reset << "Enable souffle inst combine pass (Experimental).\n"
114+
<< reset << "Enable souffle inst combine pass.\n"
107115
<< green << " -Osc, --opt-self-constraint "
108116
<< reset << "Enable self data constraint optimizer in souffle code generator.\n"
117+
<< green << " -Ojr, --opt-join-reorder "
118+
<< reset << "Enable join reorder optimizer(experimental).\n"
109119
<< green << " --disable-remove-unused "
110120
<< reset << "Disable unused method deletion pass.\n"
111121
<< green << " --disable-do-schema-opt "
112122
<< reset << "Disable DO Schema data constraint __all__ method optimization.\n"
113123
<< green << " --souffle-debug "
114-
<< reset << "Dump generated souffle code by stdout.\n"
124+
<< reset << "Dump generated souffle code by stdout.\n";
125+
out
126+
<< reset << "\nSouffle execution options:\n"
115127
<< green << " --souffle-slow-transformers "
116128
<< reset << "Enable Souffle slow transformers.\n"
117129
<< green << " --enable-souffle-profiling "
@@ -125,7 +137,9 @@ std::ostream& help(std::ostream& out) {
125137
<< green << " --output-csv <path> "
126138
<< reset << "Redirect stdout souffle execution result into csv.\n"
127139
<< green << " --output-sqlite <path> "
128-
<< reset << "Redirect stdout souffle execution result into sqlite.\n";
140+
<< reset << "Redirect stdout souffle execution result into sqlite.\n"
141+
<< green << " -Drs, --directly-run-souffle "
142+
<< reset << "Directly run input souffle source.\n";
129143

130144
out << "\n";
131145
return out;
@@ -168,16 +182,64 @@ void report_invalid_argument(const std::string& arg) {
168182
report::error().fatal(info);
169183
}
170184

185+
void dump_configure(const configure& conf) {
186+
if (conf.empty()) {
187+
return;
188+
}
189+
190+
std::unordered_map<option, std::string> mapper = {
191+
{option::cli_executable_path, "executable"},
192+
{option::cli_input_path, "input-script"}
193+
};
194+
195+
for(const auto& i : settings) {
196+
if (mapper.count(i.second.command_type) &&
197+
mapper.at(i.second.command_type).length()>i.first.length()) {
198+
continue;
199+
}
200+
mapper[i.second.command_type] = i.first;
201+
}
202+
for(const auto& i : options) {
203+
if (mapper.count(i.second) &&
204+
mapper.at(i.second).length()>i.first.length()) {
205+
continue;
206+
}
207+
mapper[i.second] = i.first;
208+
}
209+
210+
std::clog << conf.at(option::cli_executable_path) << " ";
211+
std::clog << conf.at(option::cli_input_path);
212+
for(const auto& i : mapper) {
213+
if (i.first == option::cli_executable_path ||
214+
i.first == option::cli_input_path) {
215+
continue;
216+
}
217+
if (!conf.count(i.first)) {
218+
continue;
219+
}
220+
std::clog << " " << i.second;
221+
if (conf.at(i.first).length()) {
222+
std::clog << " " << conf.at(i.first);
223+
}
224+
}
225+
std::clog << "\n\n";
226+
}
227+
171228
configure process_args(const std::vector<std::string>& vec) {
172229
configure config = {
173-
{option::cli_executable_path, vec[0]} // load executable path here
230+
// load executable path here
231+
{ option::cli_executable_path, vec[0] }
174232
};
175233

176234
report::error err;
177235
for(size_t i = 1; i<vec.size(); ++i) {
178236
const auto& arg = vec[i];
179237
if (options.count(arg)) {
180238
config[options.at(arg)] = "";
239+
} else if (multi_options.count(arg)) {
240+
for(auto o : multi_options.at(arg)) {
241+
config[o] = "";
242+
}
181243
} else if (settings.count(arg)) {
182244
++i;
183245
if (i>=vec.size() || vec[i][0]=='-') {
@@ -213,6 +275,11 @@ configure process_args(const std::vector<std::string>& vec) {
213275
err.fatal("input file is required.");
214276
}
215277

278+
if (config.count(option::cli_show_real_cmd_args)) {
279+
dump_configure(config);
280+
std::exit(0);
281+
}
282+
216283
return config;
217284
}
218285

godel-script/godel-frontend/src/cli.h

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class option {
1818
cli_run_souffle, // generate souffle and run
1919
cli_dump_souffle_file, // generate souffle and dump
2020

21+
/* information dump */
2122
cli_help, // get help
2223
cli_verbose, // verbose output information
2324
cli_version, // get version
@@ -29,29 +30,45 @@ enum class option {
2930
cli_dump_global, // get global symbol information
3031
cli_dump_local, // get local variables' information
3132

33+
/* language server */
3234
cli_dump_lsp, // get godel frontend json dump
3335
cli_dump_lsp_file_indexed, // use indexed file name in json dump
36+
cli_dump_lsp_only_schema, // only dump schema
3437

35-
cli_lexer_dump_token, // dump tokens
36-
cli_lexer_dump_comment, // dump comments
37-
cli_semantic_only, // only do semantic analysis and exit
38-
cli_semantic_pub_check, // switch pub-access check on
39-
cli_semantic_no_else, // switch no-else check on
38+
/* lexer */
39+
cli_lexer_dump_token, // dump tokens
40+
cli_lexer_dump_comment, // dump comments
4041

42+
/* semantic analysis */
43+
cli_semantic_only, // only do semantic analysis and exit
44+
cli_semantic_pub_check, // switch pub-access check on
45+
46+
/* optimization */
4147
cli_enable_for_opt, // switch for optimization on
4248
cli_enable_let_opt, // switch let optimization on
4349
cli_enable_ir_merge, // switch ir merge on
4450
cli_enable_self_constraint_opt, // switch self constraint optimization on
51+
cli_enable_join_reorder, // switch join reorder optimization on
4552
cli_disable_remove_unused, // switch unused method deletion off
4653
cli_disable_do_schema_opt, // switch do schema optimization off
4754
cli_souffle_debug_dump, // switch souffle debug mode on
4855
cli_souffle_slow_transformers, // switch souffle slow transformers on
49-
cli_enable_souffle_cache, // switch souffle cache on
50-
cli_clean_souffle_cache, // switch clean souffle cache on
5156
cli_enable_souffle_profiling, // switch souffle profiling on
57+
58+
/* souffle cache */
59+
cli_enable_souffle_cache, // switch souffle cache on
60+
cli_clean_souffle_cache, // switch clean souffle cache on
61+
62+
/* souffle output redirection */
5263
cli_souffle_json_output, // switch souffle json output on
5364
cli_souffle_csv_output, // switch souffle csv output on
54-
cli_souffle_sqlite_output // switch souffle sqlite output on
65+
cli_souffle_sqlite_output, // switch souffle sqlite output on
66+
67+
/* directly run souffle */
68+
cli_directly_run_souffle, // run souffle directly
69+
70+
/* special debug info */
71+
cli_show_real_cmd_args
5572
};
5673

5774
struct info_setting {
@@ -94,12 +111,12 @@ const std::unordered_map<std::string, option> options = {
94111
{"--dump-local", option::cli_dump_local},
95112
{"--dump-lsp", option::cli_dump_lsp},
96113
{"--lsp-dump-use-indexed-file", option::cli_dump_lsp_file_indexed},
114+
{"--lsp-dump-only-schema", option::cli_dump_lsp_only_schema},
97115
{"--color-off", option::cli_color_off},
98116
{"--lexer-dump-token", option::cli_lexer_dump_token},
99117
{"--lexer-dump-comment", option::cli_lexer_dump_comment},
100118
{"--semantic-only", option::cli_semantic_only},
101119
{"--semantic-pub-check", option::cli_semantic_pub_check},
102-
{"--semantic-no-else", option::cli_semantic_no_else},
103120
{"--opt-for", option::cli_enable_for_opt},
104121
{"-Of", option::cli_enable_for_opt},
105122
{"--opt-let", option::cli_enable_let_opt},
@@ -108,13 +125,29 @@ const std::unordered_map<std::string, option> options = {
108125
{"-Oim", option::cli_enable_ir_merge},
109126
{"--opt-self-constraint", option::cli_enable_self_constraint_opt},
110127
{"-Osc", option::cli_enable_self_constraint_opt},
128+
{"--opt-join-reorder", option::cli_enable_join_reorder},
129+
{"-Ojr", option::cli_enable_join_reorder},
111130
{"--disable-remove-unused", option::cli_disable_remove_unused},
112131
{"--disable-do-schema-opt", option::cli_disable_do_schema_opt},
113132
{"--souffle-debug", option::cli_souffle_debug_dump},
114133
{"--souffle-slow-transformers", option::cli_souffle_slow_transformers},
115134
{"--enable-souffle-profiling", option::cli_enable_souffle_profiling},
116135
{"--enable-souffle-cache", option::cli_enable_souffle_cache},
117-
{"--clean-souffle-cache", option::cli_clean_souffle_cache}
136+
{"--clean-souffle-cache", option::cli_clean_souffle_cache},
137+
{"-Drs", option::cli_directly_run_souffle},
138+
{"--directly-run-souffle", option::cli_directly_run_souffle},
139+
{"-###", option::cli_show_real_cmd_args}
140+
};
141+
142+
const std::unordered_map<std::string, std::vector<option>> multi_options = {
143+
{"-O1", {option::cli_enable_for_opt}},
144+
{"-O2", {option::cli_enable_for_opt,
145+
option::cli_enable_self_constraint_opt,
146+
option::cli_enable_ir_merge}},
147+
{"-O3", {option::cli_enable_for_opt,
148+
option::cli_enable_self_constraint_opt,
149+
option::cli_enable_ir_merge,
150+
option::cli_enable_join_reorder}}
118151
};
119152

120153
typedef std::unordered_map<option, std::string> configure;
@@ -123,6 +156,7 @@ std::ostream& welcome(std::ostream&);
123156
std::ostream& version(std::ostream&);
124157
std::ostream& help(std::ostream&);
125158
void report_invalid_argument(const std::string&);
159+
void dump_configure(const configure&);
126160
configure process_args(const std::vector<std::string>&);
127161

128162
}

0 commit comments

Comments
 (0)