diff --git a/lib/cxl/cxl/lib/cxl.rb b/lib/cxl/cxl/lib/cxl.rb index 8eee01b..31180bf 100644 --- a/lib/cxl/cxl/lib/cxl.rb +++ b/lib/cxl/cxl/lib/cxl.rb @@ -1,2 +1,17 @@ require "cxl/cli" +require "cxl/config" +require "cxl/parser" require "cxl/version" + +module Cxl + class << self + + def compile_to(input_fname, output_fname, cppflags) + parser = Parser.new(input_fname, cppflags) + parsed = parser.parse + + 0 + end + + end +end diff --git a/lib/cxl/cxl/lib/cxl/cli.rb b/lib/cxl/cxl/lib/cxl/cli.rb index bb0b2c2..58fc458 100644 --- a/lib/cxl/cxl/lib/cxl/cli.rb +++ b/lib/cxl/cxl/lib/cxl/cli.rb @@ -29,6 +29,29 @@ EOF puts HELP_TEXT return 0 end + if args.empty? + $stderr.puts "Error: specify input file(s)." + return 1 + end + object_files = [] + cppflags = [] + args.each do |input_fname| + output_fname = + if opts[:compile_only] and opts[:output] + opts[:output] + else + input_fname.sub(%r{\.[^.]*$}, "") + ".o" + end + rv = Cxl.compile_to(input_fname, output_fname, cppflags) + if rv == 0 + object_files << output_fname + else + return rv + end + end + unless opts[:compile_only] + #Cxl.link_to(object_files, opts[:output]) + end 0 end diff --git a/lib/cxl/cxl/lib/cxl/config.rb b/lib/cxl/cxl/lib/cxl/config.rb index cf8ac9f..e0769ea 100644 --- a/lib/cxl/cxl/lib/cxl/config.rb +++ b/lib/cxl/cxl/lib/cxl/config.rb @@ -1,3 +1,5 @@ +require "singleton" + module Cxl class Config diff --git a/lib/cxl/cxl/lib/cxl/parser.rb b/lib/cxl/cxl/lib/cxl/parser.rb new file mode 100644 index 0000000..a247130 --- /dev/null +++ b/lib/cxl/cxl/lib/cxl/parser.rb @@ -0,0 +1,25 @@ +require "open3" + +module Cxl + class Parser + + def initialize(fname, cppflags) + @fname = fname + @cppflags = cppflags + end + + def parse + c_preprocessor_command = Config.instance.c_preprocessor + command = c_preprocessor_command + @cppflags + [@fname] + pp_out, pp_err, status = Open3.capture3(*command) + if pp_err != "" + $stderr.write(pp_err) + end + if status != 0 + return + end + puts pp_out.lines[0, 2] + end + + end +end