From 9cce1ed9f5921e35df9602e7fb2ef4a35382f4b9 Mon Sep 17 00:00:00 2001
From: Ary Borenszweig <aborenszweig@manas.com.ar>
Date: Tue, 18 Mar 2014 08:31:19 -0300
Subject: [PATCH] Clean up compiler executable flags. Added "--prelude" to
 allow including another prelude, like empty.cr.

---
 Makefile                         |  2 +-
 src/compiler/crystal/codegen.cr  |  2 +-
 src/compiler/crystal/compiler.cr | 15 +++++++++------
 src/empty.cr                     |  8 ++++++++
 4 files changed, 19 insertions(+), 8 deletions(-)
 create mode 100644 src/empty.cr

diff --git a/Makefile b/Makefile
index cbe89681bc..12ac6c819e 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ all_spec: $(SOURCES) $(SPEC_SOURCES)
 
 $(O)/crystal: $(SOURCES)
 	@mkdir -p $(O)
-	./bin/crystal $(if $(release),--release) $(if $(stats),-stats) -o $@ src/compiler/crystal.cr
+	./bin/crystal $(if $(release),--release) $(if $(stats),--stats) -o $@ src/compiler/crystal.cr
 
 clean:
 	rm -rf $(O)
diff --git a/src/compiler/crystal/codegen.cr b/src/compiler/crystal/codegen.cr
index 6c5be2213f..54e00b6d25 100644
--- a/src/compiler/crystal/codegen.cr
+++ b/src/compiler/crystal/codegen.cr
@@ -145,7 +145,7 @@ module Crystal
       br_block_chain [@alloca_block, @const_block_entry]
       br_block_chain [@const_block, @entry_block]
 
-      @llvm_mod.dump if DUMP_LLVM
+      @modules.each_value &.dump if Crystal::DUMP_LLVM
     end
 
     def visit(node : FunDef)
diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr
index 2a361ba944..e95f464dad 100644
--- a/src/compiler/crystal/compiler.cr
+++ b/src/compiler/crystal/compiler.cr
@@ -41,6 +41,7 @@ module Crystal
       @cross_compile = nil
       @llc_flags_changed = true
       @multithreaded = false
+      @prelude = "prelude"
 
       @config = LLVMConfig.new
       @llc = @config.bin "llc"
@@ -59,28 +60,31 @@ module Crystal
         opts.on("--hierarchy", "Prints types hierarchy") do
           @print_hierarchy = true
         end
-        opts.on("-ll", "Dump ll to .crystal directory") do
+        opts.on("--ll", "Dump ll to .crystal directory") do
           @dump_ll = true
         end
         opts.on("--llc ", "Additional flags to pass to llc") do |llc_flags|
           @llc_flags = llc_flags
         end
-        opts.on("-no-build", "Disable build output") do
+        opts.on("--no-build", "Disable build output") do
           @no_build = true
         end
         opts.on("-o ", "Output filename") do |output_filename|
           @output_filename = output_filename
         end
+        opts.on("--prelude ", "Use given file as prelude") do |prelude|
+          @prelude = prelude
+        end
         opts.on("--release", "Compile in release mode") do
           @release = true
         end
         opts.on("--run", "Execute program") do
           @run = true
         end
-        opts.on("-stats", "Enable statistis output") do
+        opts.on("-s", "--stats", "Enable statistis output") do
           @stats = true
         end
-        opts.on("-types", "Prints types of global variables") do
+        opts.on("-t", "--types", "Prints types of global variables") do
           @print_types = true
         end
         opts.on("-h", "--help", "Show this message") do
@@ -147,7 +151,7 @@ module Crystal
         parser.filename = filename
         node = parser.parse
 
-        require_node = Require.new("prelude")
+        require_node = Require.new(@prelude)
         require_node.location = Location.new(1, 1, filename)
 
         node = Expressions.new([require_node, node] of ASTNode)
@@ -316,7 +320,6 @@ module Crystal
       end
 
       def write_bitcode(output_name)
-        @llvm_mod.dump if Crystal::DUMP_LLVM
         @llvm_mod.write_bitcode output_name
       end
 
diff --git a/src/empty.cr b/src/empty.cr
new file mode 100644
index 0000000000..fca9e04f9a
--- /dev/null
+++ b/src/empty.cr
@@ -0,0 +1,8 @@
+lib CrystalMain
+  fun __crystal_main(argc : Int32, argv : UInt8**)
+end
+
+fun main(argc : Int32, argv : UInt8**) : Int32
+  CrystalMain.__crystal_main(argc, argv)
+  0
+end
-- 
GitLab