google v8 實戰 — 神秘的v8.vcproj

來源:互聯網
上載者:User

title: google v8 實戰 -- 神秘的v8.vcproj

 

根據前文的說明,大家應該都可以把v8.lib編譯出來了。

 

本文想再說說編譯這個環節。因為區區在另外一台同樣安裝了VS2008和

python2.5的機器上,編譯失敗,而且敗在v8.vcproj中的natives.cc上。開啟這

個檔案時要小心,連IDE都會警告說“這個檔案包含巨長的文本行,可以會很慢”。

 

google的人很厚道地把natives.cc放在一個叫"generated files"的檔案組中,就

說明這個檔案其實是給機器讀,而不是給人讀的啦。

 

我們都知道,在VC工程中想自訂構建過程可以用Customize Build步驟的,當然

就要好奇看看natives.cc怎麼來的。在v8工程設定中沒有Customize Build步驟,

那就在js檔案組中找吧~十幾個.js檔案,看了七八個,一個Customize Build都沒

看到,怒了,直接用emacs開啟v8.vcproj,用isearch才在最後一個v8native.js

中找到:

 

<File

   RelativePath="../../src/v8natives.js"

   >

  <FileConfiguration

Name="Debug|Win32"

>

<Tool

  Name="VCCustomBuildTool"

  Description="Processing js files..."

  CommandLine="./js2c.cmd ../../src &quot;$(IntDir)/DerivedSources&quot;&#x0D;&#x0A;"

  AdditionalDependencies="../../src/macros.py;../../src/runtime.js;../../src/v8natives.js;../../src/array.js;../../src/string.js;../../src/uri.js;../../src/math.js;../../src/messages.js;../../src/apinatives.js;../../src/debug-delay.js;../../src/mirror-delay.js;../../src/date-delay.js;../../src/regexp-delay.js;../../src/json-delay.js"

  Outputs="$(IntDir)/DerivedSources/natives.cc;$(IntDir)/DerivedSources/natives-empty.cc"

  />

  </FileConfiguration>

  <FileConfiguration

Name="Release|Win32"

>

<Tool

  Name="VCCustomBuildTool"

  Description="Processing js files..."

  CommandLine="./js2c.cmd ../../src &quot;$(IntDir)/DerivedSources&quot;&#x0D;&#x0A;"

  AdditionalDependencies="../../src/macros.py;../../src/runtime.js;../../src/v8natives.js;../../src/array.js;../../src/string.js;../../src/uri.js;../../src/math.js;../../src/messages.js;../../src/apinatives.js;../../src/debug-delay.js;../../src/mirror-delay.js;../../src/date-delay.js;../../src/regexp-delay.js;../../src/json-delay.js"

  Outputs="$(IntDir)/DerivedSources/natives.cc;$(IntDir)/DerivedSources/natives-empty.cc"

  />

  </FileConfiguration>

</File>

 

這個要反省一下,雖然一個一個找很慢,但是換用emacs說明區區急了點。

 

從CommandLine可以看到是js2c.cmd命令產生了natives.cc,在

AdditionalDependencies裡面,所有的js檔案都被加入,這就是之前找不到其它

Customize Build的原因了。如果細看js2c.cmd,會發現它其實是用js2c.py來完

成任務的。

 

js2c.py的本質上是個C++數組初始化語句代碼產生器,因為py有方便的三引號語

法,用來處理文本模板和簡單的宏替換是很方便的。app engine為什麼就不做了

sample工程的模板呢,害得區區還得自己寫make_app.py~

 

經js2c.py產生natives.cc的內容大約如下:

 

//重要注釋一堆

#include "v8.h"

#include "natives.h"

namespace v8 {

namespace internal {

  static const char runtime[] = { 1...

  static const char v8natives[] = {...

  static const char array[] = { 10,...

  static const char string[] = { 10..

  static const char uri[] = { 10, 1..

  static const char math[] = { 10, ..

  static const char messages[] = { ..

  static const char apinatives[] = ..

  static const char debug[] = { 99,...

  static const char mirror[] = { 82...

  static const char date[] = { 10, ...

  static const char regexp[] = { 10...

  static const char json[] = { 10, ...

....

//後要加一下提供者

 

 

有人問過,說為什麼不直接使用win32的自訂資源呢?這沒看過最初的v8,只能

說目前而言,v8不光是想跑在win32平台下,所以常量區比較平台無關一些。何況

還可以方便地用py做些中間加工呢。

 

 

如果v8.vcproj編譯不過,可以用gvim(對於記憶體不多的機子)/emacs查看一下natives.cc,

然後再根據python版本差異修正一下js2c.py。應該就OK了。。

 

 

總的來說...............

 

 

這個 檔案->數組 的技術沒什麼。。 不過,還有個耐看些的,就是v8_snapshot,

初略來看,這東西主要是為提升載入速度。就是把前面那個校準庫的jit編譯結果

序列化,那snapshot版本啟動時就不用再重複編譯了。有時間區區其想詳細寫寫

這個的~

 

當然,要說明一個,這個snapshot不是非常新鮮的東西,lisp編譯器很早就有了。

以前研究emacs源碼時就看到過,只不過GNU的駭客管她叫dump,而不是snapshot而已。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.