diff --git a/lib/vaporware/compiler.rb b/lib/vaporware/compiler.rb index bd48cfc..1a696dd 100644 --- a/lib/vaporware/compiler.rb +++ b/lib/vaporware/compiler.rb @@ -40,7 +40,7 @@ def compile(compiler: "gcc", compiler_options: ["-O0"]) end output.close compiler_options += @generator.compile_shared_option if @generator.shared - @generator.call_compiler(compiler:, compiler_options:) + @generator.to_elf(input: @generator.precompile, compiler:, compiler_options:, debug: @generator.debug) end end end diff --git a/lib/vaporware/compiler/generator.rb b/lib/vaporware/compiler/generator.rb index 2fd562a..8eb8708 100644 --- a/lib/vaporware/compiler/generator.rb +++ b/lib/vaporware/compiler/generator.rb @@ -30,16 +30,22 @@ def register_var_and_method(node) def already_build_methods? = defined_methods.sort == @doned.to_a.sort def variable_or_method?(type) = [:lvasgn, :arg, :def].include?(type) - def call_compiler(output: precompile, compiler: "gcc", compiler_options: ["-O0"], debug: false) - base_name = File.basename(output, ".*") + def to_elf(input: precompile, compiler: "gcc", compiler_options: ["-O0"], debug: false) + base_name = File.basename(input, ".*") name = shared ? "lib#{base_name}.so" : base_name - compile_commands = [compiler, *compiler_options, "-o", name, output].compact - IO.popen(compile_commands).close + if compiler.nil? + Vaporware::Compiler::Assemble.compile!(name, input) + else + compile_commands = [compiler, *compiler_options, "-o", name, input].compact + call_compiler(compile_commands) + end - File.delete(output) unless debug + File.delete(input) unless debug nil end + def call_compiler(compile_commands) = IO.popen(compile_commands).close + def epilogue(output) output.puts " mov rsp, rbp" output.puts " pop rbp" diff --git a/sig/vaporware.rbs b/sig/vaporware.rbs index d96a8ee..3e9535e 100644 --- a/sig/vaporware.rbs +++ b/sig/vaporware.rbs @@ -39,7 +39,7 @@ module Vaporware def already_build_methods?: -> bool def args: (untyped, File) -> nil def build: (untyped, File, ?bool) -> nil - def call_compiler: (?output: String, ?compiler: String, ?compiler_options: Array[String], ?debug: bool) -> nil + def call_compiler: (Array[String]) -> nil def call_method: (untyped, File, bool) -> nil def comp: (String, File) -> nil def compile_shared_option: () -> Array[String] @@ -52,6 +52,7 @@ module Vaporware def ret: (File) -> nil def lvar_offset: (Symbol | nil) -> Integer def register_var_and_method: (untyped) -> nil + def to_elf: (?input: String, ?compiler: String, ?compiler_options: Array[String], ?debug: bool) -> nil def variable_or_method?: (Symbol) -> bool end end