@@ -16,6 +16,7 @@ typedef struct
1616 bool optHelp ;
1717 bool optVersion ;
1818 bool optEval ;
19+ bool optAnalyze ;
1920 bool optDump ;
2021 bool optCompile ;
2122 bool optRun ;
@@ -58,6 +59,7 @@ static inline void parse_args(ParsedArgs *parsedArgs, int argc, const char **arg
5859 parsedArgs -> optHelp = false;
5960 parsedArgs -> optVersion = false;
6061 parsedArgs -> optEval = false;
62+ parsedArgs -> optAnalyze = false;
6163 parsedArgs -> optDump = false;
6264 parsedArgs -> optCompile = false;
6365 parsedArgs -> optRun = false;
@@ -100,6 +102,11 @@ static inline void parse_option(ParsedArgs *parsedArgs, const char *arg)
100102 parsedArgs -> optEval = true;
101103 return ;
102104 }
105+ if (option (arg , "-a" ) || option (arg , "--analyze" ))
106+ {
107+ parsedArgs -> optAnalyze = true;
108+ return ;
109+ }
103110 if (option (arg , "-d" ) || option (arg , "--dump" ))
104111 {
105112 parsedArgs -> optDump = true;
@@ -157,6 +164,7 @@ static inline void print_help(const char *cmd)
157164 " -h, --help prints this message\n"
158165 " -v, --version shows version information\n"
159166 " -e, --eval evaluates a string from the terminal\n"
167+ " -a, --analyze analyzes source code\n"
160168 " -d, --dump shows the bytecode\n"
161169 " -c, --compile compiles source code\n"
162170 " -r, --run runs directly from bytecode\n"
@@ -269,7 +277,7 @@ int main(int argc, const char **argv)
269277 fatal_error ("no input string" );
270278 HkString * file = hk_string_from_chars (-1 , "<terminal>" );
271279 HkString * source = hk_string_from_chars (-1 , input );
272- HkClosure * cl = hk_compile (file , source );
280+ HkClosure * cl = hk_compile (file , source , HK_COMPILER_FLAG_NONE );
273281 return run_bytecode (cl , & parsedArgs );
274282 }
275283 if (parsedArgs .optRun )
@@ -286,7 +294,8 @@ int main(int argc, const char **argv)
286294 }
287295 HkString * file = hk_string_from_chars (-1 , input ? input : "<stdin>" );
288296 HkString * source = input ? load_source_from_file (input ) : hk_string_from_stream (stdin , '\0' );
289- HkClosure * cl = hk_compile (file , source );
297+ int flags = parsedArgs .optAnalyze ? HK_COMPILER_FLAG_ANALYZE : HK_COMPILER_FLAG_NONE ;
298+ HkClosure * cl = hk_compile (file , source , flags );
290299 const char * output = parsedArgs .output ;
291300 if (parsedArgs .optDump )
292301 {
@@ -306,5 +315,10 @@ int main(int argc, const char **argv)
306315 hk_closure_free (cl );
307316 return EXIT_SUCCESS ;
308317 }
318+ if (parsedArgs .optAnalyze )
319+ {
320+ hk_closure_free (cl );
321+ return EXIT_SUCCESS ;
322+ }
309323 return run_bytecode (cl , & parsedArgs );
310324}
0 commit comments