Add initial Parser class and Cxl.compile_to()
This commit is contained in:
parent
d28657a65b
commit
70e8795b32
@ -1,2 +1,17 @@
|
|||||||
require "cxl/cli"
|
require "cxl/cli"
|
||||||
|
require "cxl/config"
|
||||||
|
require "cxl/parser"
|
||||||
require "cxl/version"
|
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
|
||||||
|
@ -29,6 +29,29 @@ EOF
|
|||||||
puts HELP_TEXT
|
puts HELP_TEXT
|
||||||
return 0
|
return 0
|
||||||
end
|
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
|
0
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require "singleton"
|
||||||
|
|
||||||
module Cxl
|
module Cxl
|
||||||
class Config
|
class Config
|
||||||
|
|
||||||
|
25
lib/cxl/cxl/lib/cxl/parser.rb
Normal file
25
lib/cxl/cxl/lib/cxl/parser.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user