From 46029939d375ae1605bcae2fae2da90c89db220c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 18 Feb 2013 07:50:37 -0700 Subject: [PATCH] begin work on audit-codegen --- makefile | 92 ++++++++++++++++++++------------ src/tools/audit-codegen/main.cpp | 63 ++++++++++++++++++++++ src/util/arg-parser.cpp | 2 +- src/util/arg-parser.h | 2 +- 4 files changed, 123 insertions(+), 36 deletions(-) create mode 100644 src/tools/audit-codegen/main.cpp diff --git a/makefile b/makefile index 5d1178f77f..bed84761d5 100755 --- a/makefile +++ b/makefile @@ -994,6 +994,8 @@ all-assembler-sources = \ native-assembler-sources = $($(target-asm)-assembler-sources) native-assembler-objects = $($(target-asm)-assembler-objects) +audit-codegen-sources = $(wildcard $(src)/tools/audit-codegen/*.cpp) + all-codegen-target-sources = \ $(compiler-sources) \ $(native-assembler-sources) @@ -1154,6 +1156,7 @@ dynamic-library = $(build)/$(so-prefix)jvm$(so-suffix) executable-dynamic = $(build)/$(name)-dynamic$(exe-suffix) unittest-executable = $(build)/$(name)-unittest${exe-suffix} +audit-codegen-executable = $(build)/audit-codegen${exe-suffix} ifneq ($(classpath),avian) # Assembler, ConstantPool, and Stream are not technically needed for a @@ -1304,6 +1307,14 @@ else ssh -p$(remote-test-port) $(remote-test-user)@$(remote-test-host) sh "$(remote-test-dir)/$(platform)-$(arch)$(options)/run-tests.sh" endif +PHONY: audit-baseline +audit-baseline: $(audit-codegen-executable) + $(<) -output $(build)/codegen-audit-output/baseline.o -format macho + +PHONY: audit +audit: $(audit-codegen-executable) + $(<) -output $(build)/codegen-audit-output/baseline.o -format macho + .PHONY: tarball tarball: @echo "creating build/avian-$(version).tar.bz2" @@ -1412,6 +1423,9 @@ endif $(unittest-objects): $(build)/unittest/%.o: $(unittest)/%.cpp $(vm-depends) $(unittest-depends) $(compile-unittest-object) +$(build)/tools/audit-codegen/main.o: $(build)/%.o: $(src)/%.cpp $(vm-depends) + $(compile-object) + $(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) $(compile-object) @@ -1590,43 +1604,53 @@ ifeq ($(process),interpret) unittest-executable-objects += $(all-codegen-target-objects) endif -$(executable): $(executable-objects) - @echo "linking $(@)" -ifeq ($(platform),windows) -ifdef ms_cl_compiler - $(ld) $(lflags) $(executable-objects) -out:$(@) \ - -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) -ifdef mt - $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" -endif -else - $(dlltool) -z $(@).def $(executable-objects) - $(dlltool) -d $(@).def -e $(@).exp - $(ld) $(@).exp $(executable-objects) $(lflags) -o $(@) -endif -else - $(ld) $(executable-objects) $(rdynamic) $(lflags) $(bootimage-lflags) -o $(@) -endif - $(strip) $(strip-all) $(@) +audit-codegen-objects = $(call cpp-objects,$(audit-codegen-sources),$(src),$(build)) +audit-codegen-executable-objects = $(audit-codegen-objects) $(vm-objects) $(build)/util/arg-parser.o +.PHONY: print +print: + @echo $(audit-codegen-objects) + +# apparently, make does poorly with ifs inside of defines, and indented defines. +# I suggest re-indenting the following before making edits (and unindenting afterwards): +ifneq ($(platform),windows) +define link-executable + @echo linking $(@) + $(ld) $(^) $(rdynamic) $(lflags) $(bootimage-lflags) -o $(@) +endef +else +ifdef ms_cl_compiler +ifdef mt +define link-executable + @echo linking $(@) + $(ld) $(lflags) $(^) -out:$(@) \ + -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endef +else +define link-executable + @echo linking $(@) + $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" +endef +endif +else +define link-executable + @echo linking $(@) + $(dlltool) -z $(@).def $(^) + $(dlltool) -d $(@).def -e $(@).exp + $(ld) $(@).exp $(^) $(lflags) -o $(@) +endef +endif +endif + +$(executable): $(executable-objects) + $(link-executable) $(unittest-executable): $(unittest-executable-objects) - @echo "linking $(@)" -ifeq ($(platform),windows) -ifdef ms_cl_compiler - $(ld) $(lflags) $(unittest-executable-objects) -out:$(@) \ - -debug -PDB:$(subst $(exe-suffix),.pdb,$(@)) $(manifest-flags) -ifdef mt - $(mt) -nologo -manifest $(@).manifest -outputresource:"$(@);1" -endif -else - $(dlltool) -z $(@).def $(unittest-executable-objects) - $(dlltool) -d $(@).def -e $(@).exp - $(ld) $(@).exp $(unittest-executable-objects) $(lflags) -o $(@) -endif -else - $(ld) $(unittest-executable-objects) $(rdynamic) $(lflags) $(bootimage-lflags) -o $(@) -endif + $(link-executable) + +$(audit-codegen-executable): $(audit-codegen-executable-objects) + $(link-executable) $(bootimage-generator): $(bootimage-generator-objects) echo building $(bootimage-generator) arch=$(build-arch) platform=$(bootimage-platform) diff --git a/src/tools/audit-codegen/main.cpp b/src/tools/audit-codegen/main.cpp new file mode 100644 index 0000000000..9fc8d10119 --- /dev/null +++ b/src/tools/audit-codegen/main.cpp @@ -0,0 +1,63 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "system.h" + +#include "util/arg-parser.h" + +#include "codegen/lir.h" +#include "codegen/assembler.h" +#include "codegen/targets.h" + +// since we aren't linking against libstdc++, we must implement this +// ourselves: +extern "C" void __cxa_pure_virtual(void) { abort(); } + +using namespace avian::codegen; +using namespace avian::util; + +void generateCode(Assembler::Architecture* arch) { + for() +} + +class Arguments { +public: + const char* output; + const char* outputFormat; + + Arguments(int argc, char** argv) { + ArgParser parser; + Arg out(parser, true, "output", ""); + Arg format(parser, true, "format", ""); + + if(!parser.parse(argc, argv)) { + exit(1); + } + + output = out.value; + outputFormat = format.value; + + // TODO: sanitize format values + } +}; + +int main(int argc, char** argv) { + Arguments args(argc, argv); + + vm::System* s = vm::makeSystem(0); + Assembler::Architecture* arch = makeArchitectureNative(s, true); + arch->acquire(); + + generateCode(arch); + + arch->release(); + s->dispose(); + return 0; +} \ No newline at end of file diff --git a/src/util/arg-parser.cpp b/src/util/arg-parser.cpp index 30e50cadfb..ac652563be 100644 --- a/src/util/arg-parser.cpp +++ b/src/util/arg-parser.cpp @@ -31,7 +31,7 @@ ArgParser::ArgParser(): first(0), last(&first) {} -bool ArgParser::parse(int ac, const char** av) { +bool ArgParser::parse(int ac, const char* const* av) { Arg* state = 0; for(int i = 1; i < ac; i++) { diff --git a/src/util/arg-parser.h b/src/util/arg-parser.h index bba913c4d9..1f887764f2 100644 --- a/src/util/arg-parser.h +++ b/src/util/arg-parser.h @@ -23,7 +23,7 @@ public: ArgParser(); - bool parse(int ac, const char** av); + bool parse(int ac, const char* const* av); void printUsage(const char* exe); };