summaryrefslogtreecommitdiff
path: root/source/slang/compiler.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-08-14 14:48:37 -0700
committerTim Foley <tfoley@nvidia.com>2017-08-14 14:48:37 -0700
commit9885c972a6bfa6f856e505cdd90d9b71fdbdadaf (patch)
tree7314b26e21ded966b6a4fe2430f0421c0c0970bd /source/slang/compiler.h
parent7f57ea4ad86c2a3eb5a14fef458e711845c1f87e (diff)
Add an explicit `Name` type
Fixes #23 Up to this point, the compiler has used the ordinary `String` type to represent declaration names, which means a bunch of lookup structures throughout the compiler were string-to-whatever maps, which can reduce efficiency. It also means that things like the `Token` type end up carying a `String` by value and paying for things like reference-counting. This change adds a `Name` type that is used to represent names of variables, types, macros, etc. Names are cached and unique'd globally for a session, and the string-to-name mapping gets done during lexing. From that point on, most mapping is from pointers, which should make all the various table lookups faster. More importantly (possibly), this brings us one step closer to being able to pool-allocate the AST nodes.
Diffstat (limited to 'source/slang/compiler.h')
-rw-r--r--source/slang/compiler.h28
1 files changed, 21 insertions, 7 deletions
diff --git a/source/slang/compiler.h b/source/slang/compiler.h
index a2d29f445..b6eca1b36 100644
--- a/source/slang/compiler.h
+++ b/source/slang/compiler.h
@@ -4,6 +4,7 @@
#include "../core/basic.h"
#include "diagnostics.h"
+#include "name.h"
#include "profile.h"
#include "syntax.h"
@@ -90,7 +91,7 @@ namespace Slang
CompileRequest* compileRequest = nullptr;
// The name of the entry point function (e.g., `main`)
- String name;
+ Name* name;
// The profile that the entry point will be compiled for
// (this is a combination of the target state, and also
@@ -222,6 +223,11 @@ namespace Slang
SourceManager sourceManagerStorage;
SourceManager* sourceManager;
+ // Name pool for looking up names
+ NamePool namePool;
+
+ NamePool* getNamePool() { return &namePool; }
+
// Output stuff
DiagnosticSink mSink;
String mDiagnosticOutput;
@@ -241,7 +247,7 @@ namespace Slang
Dictionary<String, RefPtr<ModuleDecl>> mapPathToLoadedModule;
// Map from the path of a module file to its definition
- Dictionary<String, RefPtr<ModuleDecl>> mapNameToLoadedModules;
+ Dictionary<Name*, RefPtr<ModuleDecl>> mapNameToLoadedModules;
CompileRequest(Session* session);
@@ -277,7 +283,7 @@ namespace Slang
Profile profile);
RefPtr<ModuleDecl> loadModule(
- String const& name,
+ Name* name,
String const& path,
String const& source,
SourceLoc const& loc);
@@ -287,8 +293,8 @@ namespace Slang
TokenList const& tokens);
RefPtr<ModuleDecl> findOrImportModule(
- String const& name,
- SourceLoc const& loc);
+ Name* name,
+ SourceLoc const& loc);
SourceManager* getSourceManager()
{
@@ -335,6 +341,14 @@ namespace Slang
SourceManager* getBuiltinSourceManager() { return &builtinSourceManager; }
+ // Name pool stuff for unique-ing identifiers
+
+ RootNamePool rootNamePool;
+ NamePool namePool;
+
+ RootNamePool* getRootNamePool() { return &rootNamePool; }
+ NamePool* getNamePool() { return &namePool; }
+
//
// Generated code for stdlib, etc.
@@ -372,9 +386,9 @@ namespace Slang
Type* getOverloadedType();
Type* getErrorType();
- SyntaxClass<RefObject> findSyntaxClass(String const& name);
+ SyntaxClass<RefObject> findSyntaxClass(Name* name);
- Dictionary<String, SyntaxClass<RefObject> > mapNameToSyntaxClass;
+ Dictionary<Name*, SyntaxClass<RefObject> > mapNameToSyntaxClass;
//