From 3aba72edf5724985d2f925f1250dcd1af627e648 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 17 Oct 2020 20:32:18 +0900 Subject: [PATCH] temporary --- Makefile | 2 +- chibild.h | 19 +++++++++++++++++++ intern.cc | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 intern.cc diff --git a/Makefile b/Makefile index e1157f19..f09f33cc 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread -O2 LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group OBJS=main.o writer.o input_files.o input_sections.o output_sections.o symtab.o \ - output_file.o + output_file.o intern.o chibild: $(OBJS) $(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) diff --git a/chibild.h b/chibild.h index 2ce7b3d9..cf5acf6b 100644 --- a/chibild.h +++ b/chibild.h @@ -86,6 +86,25 @@ class SymbolTable; class InputSection; class ObjectFile; +// +// intern.cc +// + +class IString { + IString() : IString("") {} + IString(const IString &other) : data(other.data), size(other.size) {} + IString(StringRef s); + + bool operator==(const IString &other) { return data == other.data; } + +public: + typedef tbb::concurrent_hash_map MapType; + static MapType map; + + const char *data; + uint32_t size; +}; + // // symtab.cc // diff --git a/intern.cc b/intern.cc new file mode 100644 index 00000000..06e23ed1 --- /dev/null +++ b/intern.cc @@ -0,0 +1,12 @@ +#include "chibild.h" + +IString::MapType IString::map; + +IString::IString(StringRef s) { + MapType::accessor acc; + map.insert(acc, s); + if (acc->second.data() == nullptr) + acc->second = s; + data = acc->second.data(); + size = acc->second.size(); +}