Coder Social home page Coder Social logo

mikepopoloski / slang Goto Github PK

View Code? Open in Web Editor NEW
576.0 576.0 126.0 28.26 MB

SystemVerilog compiler and language services

License: MIT License

C++ 98.33% SystemVerilog 0.19% Python 0.83% CMake 0.64% Verilog 0.01% Forth 0.01% Fortran 0.01%
compiler language-service parse slang systemverilog verilog

slang's People

Contributors

baranowski avatar cbalint13 avatar denisrr avatar drsam94 avatar eggman79 avatar evanbryantmiller avatar godblesszhouzhou avatar hungmingwu avatar jameshanlon avatar jesec avatar joelsole-semidyn avatar jrudess avatar kuree avatar likeamahoney avatar mikepopoloski avatar nickg avatar oddball avatar pistoletpierre avatar pleroux0 avatar pre-commit-ci[bot] avatar sgizler avatar sustrak avatar suzizecat avatar tdp2110 avatar tgorochowik avatar thingkingland avatar udif avatar vjschneid avatar vowstar avatar zachd-hrt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slang's Issues

Stop lexing if we encounter too many errors

The lexer tries to handle non-ASCII characters embedded in the source gracefully. If there are too many of them however, maybe the user accidentally pointed us at a binary file or something. Keep a counter and if we hit some threshold just swallow the rest of the text instead of producing a billion errors.

Add an options system

Add some way to pass options around so we don't hardcode various things like recursion limits.

Make token concatenation more robust

The SystemVerilog preprocessor supports token pasting (like the C preprocessor). This is implemented in Lexer::concatenateTokens.

There are a bunch of TODOs in the code that cover things like testing all corner cases, better error handling, accounting for trivia in either token, and correctly setting the resulting token's location for proper expansion reporting in diagnostics.

Make macro stringification more robust

Implemented in Lexer::stringify. It's not always clear what kind of spacing should be in the resulting string; the standard doesn't have much to say about it. Probably we should take a look at what existing Verilog compilers do and try to match them.

Fix BumpAllocator to call destructors where necessary

BumpAllocator was never designed for types with non-trivial destructors, but we've started using it that way. It should support detecting types that require this and maintain a separate list so that we can call them.

Make SyntaxNode as<> casting do a sanity check

Add some safety to the as() method on SyntaxNodes, which currently just does a blind cast. We know the Kind of the node at runtime, we should be able to check that against the static type given by the template parameter and assert.

Perfect hashing for keywords

This would be a nice-to-have: the StringTable used to lookup whether an identifier is a keyword could use an offline-computed perfect hash to make it much faster.

Implement __FILE__ and __LINE__ macros

The intrinsic FILE and LINE macros are currently recognized but generate empty tokens ("" and 0 respectively). The LINE macro in particular will require making use of the source manager infrastructure for figuring out which line we're looking at.

Note that this plays into the `line directive as well, which changes the "apparent" line number (like #line in C++).

Design an interface for backend code generation

So far the project has focused on parsing and semantic analysis; the "front end" of the compiler. We need to think about how to take symbols and bound expression trees and generate output from that.

We'll eventually want several backends; LLVM for simulation, netlists for hardware synthesis. For now though, I think we want to go to simplified Verilog for quicker bringup.

Finish and test expression binding

This could probably be broken down into a bunch of issues. The ExpressionBinder has basic implementation for arithmetic operators and simple variable lookup, but a bunch of features aren't done yet. Examples of things that make this hard are supporting function calls at compile time (for constant expressions).

We should take a look at what Clang does for constant expression evaluation; in contexts where we know we need a constant expression, the expression binder will keep track of reasons why it was unable to propagate a constant so that we can give useful error messages.

Finish and test hierarchy symbol binding

Module symbol binding has been started, and good progress has been made on binding all parameters. Any useful thing we might want to do with the compiler requires at least having the hierarchy bound, so make sure that all works correctly.

Make symbol creation lazier

Rather than try to greedily create all symbols, the semantic model should only create each symbol and its children when it becomes necessary. This should solve ordering issues between having symbols created and evaluating things like initializers.

Make SourceManager thread-safe

SourceManager should be one of the few thread-safe components in the system. Someone just needs to do the work to make it that way.

Finish adding features to the parser

The parser can currently handle 75-80% of the language, and handles the most common parts. There is definitely code out there using the parts we don't yet handle though.

This involves adding new syntax nodes to syntax.txt, adding a new type to SyntaxKind, and then making the parser produce the new nodes. It's pretty straightforward one you do one or two of them.

Add checks to prevent stack overflow in the parser

There's a test that's currently commented out that has ridiculously nested code to test overflow cases in the compiler. Since there's no handling right now, it predictably crashes. Whenever we have parser calls that have the potential to recurse on themselves, we should add some guards to check for nesting that's too deep and issue an error if we hit the threshold.

Add the concept of "controlling macros" to include files

Compilers like GCC and Clang notice the common ifndef define pattern at the top of include files and use it as a marker to skip lexing the entire file if it's already been seen. As an optimization we should do the same.

This is low priority.

Make SVInt allocator aware

Temporaries produced during constant evaluation should all live in a temporary heap that we can just throw away.

Support macro-replaced include file names

Include file names can actually be specified as a macro that should be expanded; this is fairly straightforward but pretty annoying since a bracketed include name will show up as a whole bunch of tokens in the stream. C++ supports this as well, so we can take inspiration from GCC or Clang here.

Reorganize source directory

After things have settled down a bit, go through and move everything into folders, like the original filter setup in the vsproj.

Fix const issues in SyntaxNode

There are a few places where we const_cast in SyntaxNode out of laziness; add another overload to getChild() on each derived type so that we don't need to do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.