From 38ab04e98884778cb91ac6be878d06f08c9384c7 Mon Sep 17 00:00:00 2001 From: chad Date: Fri, 18 Jan 2013 11:07:23 +0000 Subject: [PATCH] Bug fix. Now works on 32-bit and with -O3. git-svn-id: http://www.cdkersey.com/harp/harptool@120 0246edb2-e076-4747-b392-db732a341fa2 --- src/Makefile | 10 ++++++---- src/enc.cpp | 2 +- src/harptool.cpp | 43 ++++++++++++++++++++++++------------------- src/include/core.h | 1 + src/include/obj.h | 13 +++++++------ 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/Makefile b/src/Makefile index d2681430..9f27bd05 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,9 @@ ################################################################################ # HARPtools by Chad D. Kersey, Summer 2011 # ################################################################################ -CXXFLAGS=-g #-DUSE_DEBUG=3 #-fPIC +CXXFLAGS ?= -O3 # -g -DUSE_DEBUG=3 -fPIC +LDLIBS ?= -lharplib -pthread +LDFLAGS ?= -L. LIB_OBJS=args.o obj.o mem.o core.o instruction.o enc.o util.o lex.yy.o @@ -10,7 +12,7 @@ all: harptool # libharplib.so libharplib.a libqsim-harp.so # Use -static so we don't have to install the library in order to just run # Harptool. harptool: harptool.o libharplib.a - $(CXX) -static -o $@ harptool.o -L. -lharplib -pthread + $(CXX) $(LDFLAGS) -static -o $@ harptool.o $(LDLIBS) libharplib.so: $(LIB_OBJS) $(CXX) -shared -o $@ $(LIB_OBJS) @@ -23,9 +25,9 @@ enc.o : enc.cpp include/types.h include/util.h include/enc.h include/archdef.h\ include/instruction.h harptool.o : harptool.cpp include/types.h include/core.h include/enc.h \ include/instruction.h include/mem.h include/obj.h \ - include/archdef.h include/args.h include/help.h + include/archdef.h include/args.h include/help.h include/debug.h instruction.o : instruction.cpp include/instruction.h include/obj.h \ - include/core.h + include/core.h include/debug.h obj.o : obj.cpp include/types.h include/obj.h include/util.h \ include/asm-tokens.h include/debug.h util.o : util.cpp include/types.h include/util.h diff --git a/src/enc.cpp b/src/enc.cpp index cc959e4f..97a966e8 100644 --- a/src/enc.cpp +++ b/src/enc.cpp @@ -240,7 +240,7 @@ static unsigned ceilLog2(RegNum x) { } static Word mask(Size bits) { - return (1l< #include +#include "include/debug.h" #include "include/types.h" #include "include/core.h" #include "include/enc.h" @@ -31,11 +32,11 @@ HarpToolMode findMode(int argc, char** argv) { if (argc == 0) return HARPTOOL_MODE_HELP; - CommandLineArgFlag("--help", "-h", "", mode_help); - CommandLineArgFlag("-A", "--asm", "", mode_asm); - CommandLineArgFlag("-D", "--disasm", "", mode_disasm); - CommandLineArgFlag("-E", "--emu", "", mode_emu); - CommandLineArgFlag("-L", "--ld", "", mode_ld); + CommandLineArgFlag fh("--help", "-h", "", mode_help); + CommandLineArgFlag fa("-A", "--asm", "", mode_asm); + CommandLineArgFlag fd("-D", "--disasm", "", mode_disasm); + CommandLineArgFlag fe("-E", "--emu", "", mode_emu); + CommandLineArgFlag fl("-L", "--ld", "", mode_ld); CommandLineArg::readArgs((argc == 0?0:1), argv); CommandLineArg::clearArgs(); @@ -53,9 +54,9 @@ int asm_main(int argc, char **argv) { bool showHelp; /* Get command line arguments. */ - CommandLineArgFlag("-h", "--help", "", showHelp); - CommandLineArgSetter("-o", "--output", "", outFileName); - CommandLineArgSetter("-a", "--arch", "", archString); + CommandLineArgFlag fh("-h", "--help", "", showHelp); + CommandLineArgSetterfo("-o", "--output", "", outFileName); + CommandLineArgSetterfa("-a", "--arch", "", archString); CommandLineArg::readArgs(argc-1, argv); @@ -66,6 +67,8 @@ int asm_main(int argc, char **argv) { ArchDef arch(archString); + D(0, "Created ArchDef for " << string(arch)); + /* Create an appropriate encoder. */ Encoder *enc; switch (arch.getEncChar()) { @@ -96,6 +99,7 @@ int asm_main(int argc, char **argv) { } /* Read an Obj from the assembly file. */ + D(0, "Passing AsmReader ArchDef: " << string(arch)); AsmReader ar(arch); Obj *o = ar.read(asmFile); @@ -120,6 +124,7 @@ int asm_main(int argc, char **argv) { delete enc; /* Write a HOF binary. */ + D(0, "Creating a HOFWriter, passing it ArchDef: " << string(arch)); HOFWriter hw(arch); hw.write(outFile, *o); outFile.close(); @@ -135,9 +140,9 @@ int disasm_main(int argc, char **argv) { /* Get command line arguments. */ - CommandLineArgFlag("-h", "--help", "", showHelp); - CommandLineArgSetter("-a", "--arch", "", archString); - CommandLineArgSetter("-o", "--output", "", outFileName); + CommandLineArgFlag fh("-h", "--help", "", showHelp); + CommandLineArgSetterfa("-a", "--arch", "", archString); + CommandLineArgSetterfo("-o", "--output", "", outFileName); if (argc != 0) CommandLineArg::readArgs(argc-1, argv); @@ -205,9 +210,9 @@ int emu_main(int argc, char **argv) { bool showHelp; /* Read the command line arguments. */ - CommandLineArgFlag("-h", "--help", "", showHelp); - CommandLineArgSetter("-c", "--core", "", imgFileName); - CommandLineArgSetter("-a", "--arch", "", archString); + CommandLineArgFlag fh("-h", "--help", "", showHelp); + CommandLineArgSetterfc("-c", "--core", "", imgFileName); + CommandLineArgSetterfa("-a", "--arch", "", archString); CommandLineArg::readArgs(argc, argv); @@ -249,11 +254,11 @@ int ld_main(int argc, char **argv) { Addr binOffset(0); /* Get command line arguments. */ - CommandLineArgFlag("-h", "--help", "", showHelp); - CommandLineArgSetter("-a", "--arch", "", archString); - CommandLineArgSetter("-f", "--format", "", formatString); - CommandLineArgSetter("--offset", "", binOffset); - CommandLineArgSetter("-o", "--output", "", outFileName); + CommandLineArgFlag fh("-h", "--help", "", showHelp); + CommandLineArgSetterfa("-a", "--arch", "", archString); + CommandLineArgSetterff("-f", "--format", "", formatString); + CommandLineArgSetter foffset("--offset", "", binOffset); + CommandLineArgSetterfo("-o", "--output", "", outFileName); int firstInput(0), newArgc; for (size_t i = 0; i < argc; i++) { diff --git a/src/include/core.h b/src/include/core.h index 04125feb..ce719bc1 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -11,6 +11,7 @@ #include "archdef.h" #include "enc.h" #include "mem.h" +#include "debug.h" namespace Harp { #ifdef EMU_INSTRUMENTATION diff --git a/src/include/obj.h b/src/include/obj.h index 7dc19403..ea5732d0 100644 --- a/src/include/obj.h +++ b/src/include/obj.h @@ -57,18 +57,19 @@ namespace Harp { {} virtual void bind(Addr addr, Addr base = 0) { - Size bytes = bits/8, remainder = bits%8, i; + Size bytes(bits/8), remainder(bits%8); if (relative) { addr = addr - base; Word_s addr_s(addr); - if ((addr_s >> bits) != -1 && (addr_s >> bits) != 0) goto noFit; + if ((addr_s >> bits) != ~0ull && (addr_s >> bits) != 0) goto noFit; } else { - Addr mask = (1ll< mask) goto noFit; } - { Byte mask((1<>= 8; @@ -176,7 +177,7 @@ namespace Harp { class HOFReader : public ObjReader { public: - HOFReader(ArchDef arch) : arch(arch) {} + HOFReader(ArchDef &arch) : arch(arch) {} Obj *read(std::istream &input); private: const ArchDef &arch; @@ -192,7 +193,7 @@ namespace Harp { class HOFWriter : public ObjWriter { public: - HOFWriter(ArchDef arch) : arch(arch) {} + HOFWriter(ArchDef &arch) : arch(arch) {} virtual void write(std::ostream &output, const Obj &obj); private: const ArchDef &arch;