Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add support for LLVM IR assembly *.ll files #176

Closed
mewmew opened this issue Jun 3, 2020 · 6 comments
Closed

Feature request: add support for LLVM IR assembly *.ll files #176

mewmew opened this issue Jun 3, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@mewmew
Copy link

mewmew commented Jun 3, 2020

My first impression of scc is that it is a very accurate recreation of the behaviour of cloc with a clear focus on performance.

Therefore, this feature request may be outside the scope of scc as cloc does not support LLVM IR either. However, I still wanted to open the issue to start the discussion.

I ran an analysis of a sample project and the results of scc and cloc were indeed identical (while scc also added information about code complexity).

scc output

$ time scc .
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C                            1         3        0         0        3          0
Go                           1       177       18        62       97         15
───────────────────────────────────────────────────────────────────────────────
Total                        2       180       18        62      100         15
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop $2,407
Estimated Schedule Effort 1.552019 months
Estimated People Required 0.183761
───────────────────────────────────────────────────────────────────────────────


________________________________________________________
Executed in   12.07 millis    fish           external 
   usr time   10.27 millis  881.00 micros    9.39 millis 
   sys time    0.09 millis   86.00 micros    0.00 millis 

cloc output

$ time cloc .
       4 text files.
       3 unique files.                              
       2 files ignored.

github.com/AlDanial/cloc v 1.86  T=0.01 s (202.1 files/s, 18185.2 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                               1             18             62             97
C                                1              0              0              3
-------------------------------------------------------------------------------
SUM:                             2             18             62            100
-------------------------------------------------------------------------------

________________________________________________________
Executed in  287.62 millis    fish           external 
   usr time  257.85 millis  761.00 micros  257.09 millis 
   sys time   26.29 millis   77.00 micros   26.21 millis 

As visible in the example above, both scc and sloc accurately analyzed the C and Go source code and indeed presented identical line number metrics. Also noticeable is that scc completes in 1/20 of the time.

Lacking from both of these results is however the line numbers of the LLVM IR source code also present in the sample project.

.rw-r--r-- u users   5 KB Mon Dec  9 15:24:56 2019   a.go  
.rw-r--r-- u users  39 B  Mon Dec  9 13:53:25 2019   foo.c 
.rw-r--r-- u users 120 B  Mon Dec  9 14:13:27 2019   foo.ll

The contents of foo.ll is as follows:

; f returns the sum of the given operands.
define i32 @f(i32 %x, i32 %y) {
	%result = add i32 %x, %y
	ret i32 %result
}

As such, if scc where to add support for the LLVM IR assembly language, the results would look as follows:

$ scc .
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C                            1         3        0         0        3          0
Go                           1       177       18        62       97         15
LLVM IR                      1         5        0         1        4          ?
───────────────────────────────────────────────────────────────────────────────
Total                        3       185       18        63      104         15
───────────────────────────────────────────────────────────────────────────────

Wish you all the best and thanks for working on this project!

Cheers,
Robin

@boyter boyter added the enhancement New feature or request label Jun 3, 2020
boyter added a commit that referenced this issue Jun 3, 2020
@boyter
Copy link
Owner

boyter commented Jun 3, 2020

Oh neat. Thanks for the very useful issue.

Done. If you build from master you will be able to get it yourself. I wasn't 100% sure what to put for the complexity estimate so I went with loop terminator and bitwise operations. The full list is included below,

"llvm.loop",
      "br ",
      "switch ",
      "indirectbr ",
      "invoke ",
      "callbr ",
      "resume ",
      "catchswitch ",
      "catchret ",
      "cleanupret ",
      "shl ",
      "lshr ",
      "ashr ",
      "and ",
      "or ",
      "xor "

Let me know if that seems right or if something is missing and ill add it in. Otherwise this will be pushed out in the next release.

@boyter boyter closed this as completed Jun 4, 2020
@mewmew
Copy link
Author

mewmew commented Jun 4, 2020

@boyter wow, that's incredible! Very happy to see LLVM IR support integrated into scc! And can't believe how quickly you managed to do so.

For the sample repo I listed, it works perfectly!

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
C                            1         3        0         0        3          0
Go                           1       177       18        62       97         15
LLVM IR                      1         5        0         1        4          0
───────────────────────────────────────────────────────────────────────────────
Total                        3       185       18        63      104         15
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop $2,508
Estimated Schedule Effort 1.576498 months
Estimated People Required 0.188513
───────────────────────────────────────────────────────────────────────────────

Thanks a lot and have a most lovely summer :)

Cheers,
Robin

@boyter
Copy link
Owner

boyter commented Jun 5, 2020

No problem at all. One of the things I wanted with it was to make adding languages easy and thankfully that works.

Great to hear it worked for you. However I am going into winter now seeing as I live in Australia :)

@mewmew
Copy link
Author

mewmew commented Jun 5, 2020

Great to hear it worked for you. However I am going into winter now seeing as I live in Australia :)

Haha. Happy winter season then! Enjoy the ski slopes, hot chocolate and cozy blankets while reading a favourite book or two :)

Cheers,
Robin

@boyter
Copy link
Owner

boyter commented Jun 8, 2020

Hah it never gets that cold here really. I went to the beach the other day! Cheers for responding.

@mewmew
Copy link
Author

mewmew commented Jun 8, 2020

Hah it never gets that cold here really. I went to the beach the other day! Cheers for responding.

Haha. Living in Sweden, it never occurred to me that winter can be anyting other than snow and ice :)

Happy winter regardless! Enjoy the beach!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants