ã¯ããã«
Adobe ãã C/C++ ã§æ¸ããã³ã¼ãã Flash ã AIR ã§åãã Alchemy ã¨ãããã®ããªãªã¼ã¹ããã¾ãããï¼
Alchemy - Adobe Labs
ããã¯ãããï¼ã¨ãããã¨ã§ãå°ã試ãã¦ã¿ããã¨æãã¾ãã
ãã®æ§åããªã¢ã«ã¿ã¤ã ã«æ¸ãã¦ããã¾ããã¡ããã¨åºæ¥ãããª
ç°å¢
OS 㯠Mac OS X 㧠gcc ã java ã¯å
¥ã£ã¦ãããã®ã¨ãã¾ãã
ãã¼ã ãã£ã¬ã¯ããªï¼/Users/amachangï¼ã« AlchemyTest ã¨ãããã£ã¬ã¯ããªãä½ã£ã¦ä½æ¥ãã¾ãã
ã¤ã³ã¹ãã¼ã«
ã¾ãã¯ãããããã¤ã³ã¹ãã¼ã«ãã¾ãã
Flash Player 10 Debugger Version
Adobe Flash Player - Debug Downloads
ãããããã¦ã³ãã¼ããã¦ãã¦ãæ®éã«ã¤ã³ã¹ãã¼ã«ãã¾ãã
Flex SDK
以ä¸ãã Flex SDK ããã¦ã³ãã¼ããã¾ãã
Flex SDK
ç¾æ®µéã§ã®ææ°ã® Stable ã®ãã¤ããã¦ã³ãã¼ããã¾ãããå
·ä½çã«ã¯ä»¥ä¸ã®ãã¼ã¸ã§ã³ã®ãã®ã§ãã
http://opensource.adobe.com/wiki/display/flexsdk/download?build=3.2.0.3794&pkgtype=1
ãã¦ã³ãã¼ãã§ãããã解åãã¾ããä»å㯠FlexSDK ã¨ããååã®ãã£ã¬ã¯ããªãä½ã£ã¦ããã«è§£åãã¾ããã
$ unzip flex_sdk_3.2.0.3794.zip -d FlexSDK
ã¨ããããã bin ã« PATH ãéãã¦ããã¾ãããã
$ export PATH=/Users/amachang/AlchemyTest/FlexSDK/bin:$PATH
試ãã«ããªããé©å½ãª ActionScript ã®ãã¡ã¤ã«ãã swf ãã¡ã¤ã«ãä½ã£ã¦ã¿ã¾ãããã
以ä¸ã®ããã«ãé©å½ãªãã£ã¬ã¯ããªãä½ã£ã¦
$ mkdir Src $ cd Src
ããã«ã以ä¸ã®ãããªãã¡ã¤ã« Hoge.as ãç½®ãã¾ãã
package { import flash.display.Sprite public class Hoge extends Sprite { public function Hoge() { } } }
ã§ããã£ã FlexSDK ã«è§£åãããã¼ã«ã使ã£ã¦ã³ã³ãã¤ã«ãã¾ãã
$ mxmlc Hoge.as è¨å®ãã¡ã¤ã« "/Users/amachang/AlchemyTest/FlexSDK/frameworks/flex-config.xml" ããã¼ããã¦ãã¾ã /Users/amachang/AlchemyTest/Src/Hoge.swf (555 bytes)
ãããã swf ãã¡ã¤ã«ãã¡ããã¨ã§ãã¾ãããã
ã¨ããããã§ã次㯠Alchemy Toolkit Package ãå°å
¥ãã¾ãã
ããã¾ã§ã®ãã£ã¬ã¯ããªæ§æã¯ä»¥ä¸ã®ãããªæãã§ãã
$ pwd /Users/amachang/AlchemyTest $ tree -L 2 . |-- FlexSDK | |-- AIR SDK Readme.txt | |-- SDK license.pdf | |-- ant | |-- asdoc | |-- bin | |-- flex-sdk-description.xml | |-- frameworks | |-- lib | |-- license-adobesdk.htm | |-- license-adobesdk_ja.htm | |-- license-mpl.htm | |-- readme.htm | |-- readme_ja.htm | |-- runtimes | |-- samples | `-- templates |-- Src | |-- Hoge.as | `-- Hoge.swf `-- flex_sdk_3.2.0.3794.zip 10 directories, 11 files
Alchemy Toolkit Package
次㯠Alchemy Toolkit Package ããã¦ã³ãã¼ããã¦ãã¾ãã
Alchemy Toolkit Package
ãã¦ã³ãã¼ãããããä½æ¥ãã£ã¬ã¯ããªã«ç½®ã㦠AlchemyToolkit ã¨ãããã£ã¬ã¯ããªã«è§£åãã¾ãã
$ unzip alchemy_sdk_darwin_p1_111708.zip -d AlchemyToolkit
å°ãããã£ã¬ã¯ããªæ§æãè¦ã¦ã¿ã¾ãããã
$ tree -L 2 AlchemyToolkit AlchemyToolkit `-- alchemy-darwin-v0.4a |-- CHANGES |-- LICENSE |-- README.cygwin |-- README.darwin |-- README.ubuntu |-- achacks |-- avm2-libc |-- bin |-- config |-- flashlibs `-- samples 7 directories, 5 files
AlchemyToolkit ã®ãããã¯ãããªæãã®ãã£ã¬ã¯ããªæ§æã«ãªã£ã¦ãã¾ãã
ã¾ãã avm2-libc ã¨ããã®ãããã¾ããããã®ä¸ã«ã libc.so ã®ä»£ããã«ãªã³ã¯ãããã©ã¤ãã©ãªãå
¥ã£ã¦ããã®ã§ããããã
ã¾ãã bin ã«ãã¼ã«ãå
¥ã£ã¦ããã®ã§ãããããREADME ãèªãåã« bin ã®ä¸èº«ã確èªãã¦ã¿ã¾ãããã
$ ls AlchemyToolkit/alchemy-darwin-v0.4a/bin/ ExplSWF.pl ShrSWF.pl llvm-as llvm-prof GetABC2.pl V10SWF.pl llvm-bcanalyzer llvm-ranlib ImplSWF.pl alc-util llvm-config llvm-stub LICENSE-LLVM.TXT asc.jar llvm-db llvm-upgrade LICENSE-LLVMC.TXT gccas llvm-dis llvm2cpp LICENSE-ZLIB.TXT gccld llvm-extract llvmc PutABC2.pl gluegen llvm-gcc4-darwin-install opt PutBIN.pl llc llvm-ld swfbridge README-LLVM lli llvm-link zpipe README-ZLIB llvm-ar llvm-nm zpipe.pl
ããã LLVM ã®ãã¼ã«ããã£ã±ãå
¥ã£ã¦ãã¾ãã
ã¨ãããã㧠avm2-libc ã®ä¸ãã¿ã¦ã¿ã¾ãã
$ ls -la AlchemyToolkit/alchemy-darwin-v0.4a/avm2-libc/ total 0 drwxr-xr-x 5 amachang staff 170 11 14 03:09 . drwxr-xr-x 8 amachang staff 442 11 14 03:09 .. drwxr-xr-x 2 amachang staff 102 11 14 03:09 avm2 drwxr-xr-x 10 amachang staff 2822 11 14 03:09 include drwxr-xr-x 2 amachang staff 136 11 18 20:19 lib
ããã¦ããã® lib ã®ä¸ã«
$ ls -la AlchemyToolkit/alchemy-darwin-v0.4a/avm2-libc/lib/ total 7544 drwxr-xr-x 2 amachang staff 136 11 18 20:19 . drwxr-xr-x 5 amachang staff 170 11 14 03:09 .. -rw-r--r-- 1 amachang staff 1564524 11 14 03:09 avm2-libc.l.bc -rw-r--r-- 1 amachang staff 2297544 11 14 03:09 avm2-libstdc++.l.bc
LLVM ã®ãã¤ãã³ã¼ããå ¥ã£ã¦ãã¾ããã
ã¡ãã£ã¨å¯ãéããã¾ãã
avm2-libc.l.bc ããã£ã¹ã¢ã»ã³ãã«ãã¦ã¿ã¾ãããï¼$ cd AlchemyToolkit/alchemy-darwin-v0.4a/ $ bin/llvm-dis avm2-libc/lib/avm2-libc.l.bcãããæåããã¿ããã§ãã avm2-libc.l.ll ã¨ãããã¡ã¤ã«ãåºæ¥ã¾ããã
LLVM ã¨ãããã®ãå ¨ç¶ãããªãã®ã§ããããã®ãã¡ã¤ã«ã®ä¸èº«ãè¦ã¦ã¿ãã¨åé ã« ActionScript 3.0 ã®ã½ã¼ã¹ã³ã¼ãã¿ãããªãã®ãè¦ãã¾ããããã¦ãã¢ã»ã³ãã©ã®ãããªãã®ãè¦ãã¾ãã
ãã£ã¨ LLVM ã®ã¢ã»ã³ãã©ãªã®ã§ãããã; ModuleID = 'avm2-libc/lib/avm2-libc.l.bc' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:128:128"target triple = "i686-apple-darwin8" module asm "import flash.utils.*" module asm "import flash.display.*" module asm "import flash.text.*" module asm "import flash.events.*" module asm "import flash.net.*" module asm "import flash.system.*" module asm "" module asm "public var gdomainClass:Class;" module asm "public var gshell:Boolean = false;" module asm "" module asm "public function establishEnv():void" module asm "{" module asm " try" module asm " {" module asm " var ns:Namespace = new Namespace(\22avmplus\22);" module asm " " module asm " gdomainClass = ns::[\22Domain\22];" module asm " gshell = true;" module asm " }" ï¼ ï¼åè¦ã ã¨ãã©ããã¨ã³ããªã¼ãã¤ã³ããããããã¾ããã
å¯ãéãéããã®ã§ãã¤ã³ã¹ãã¼ã«ã«åããããã¾ãããã
ã¾ãã AlchemyToolkit/alchemy-darwin-v0.4a ã«ç§»åãã¾ãã
$ cd AlchemyToolkit/alchemy-darwin-v0.4a
ã§ã ./config ãå®è¡ãã¾ãã
$ ./config Generating alchemy-setup... Turning execution bit on for Alchemy binaries... Add "source /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/alchemy-setup" to your login script. "alc-home" takes you to the Alchemy install folder. "alc-on" puts Alchemy gcc toolchain replacements at the front of your path. "alc-off" restores original path. "alc-util" shows you various Alchemy-related environment vars You need Flash 10 or AIR 1.5 and the Flex 3.2 SDK installed for testing.
alchemy-setup ã¨ãããã¡ã¤ã«ãä½ããã¾ãããããã®ãã¡ã¤ã«ã login ã¹ã¯ãªããã«å ¥ãããã¨è¨ããã¾ãããã¨ãããã使ãã ããªã®ã§æåã§å®è¡ããã ãã«ãã¾ãã
$ source alchemy-setup
ããããã¨ã alc-on alc-off ã使ããããã«ãªãã¾ããããã¯ãå®éã¯ç°å¢å¤æ° PATH ãªã©ãåãæ¿ãããã¨ããã¾ãã
alc-on ã«ããç¶æ
㧠gcc ã¨å©ã㨠achacks/gcc ãå®è¡ãããã¨ãã£ãå
·åã§ããã
ã¨ããããã§ã alc-on ãå®è¡ãã¾ãã
$ alc-on
ç°å¢å¤æ°ãè¦ã¦ã¿ã¾ãããã
$ echo $PATH /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/achacks:/Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/bin:/Users/amachang/AlchemyTest/FlexSDK/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin
å
é ã«ã achacks ãã£ã¬ã¯ããªã追å ããã¦ãã¾ããã alc-off ãå®è¡ããã°ç°å¢å¤æ°ã¯å
ã«æ»ãã¾ãã
次ã¯ã sample ãã³ã³ãã¤ã«ãã¦å®è¡ãã¦ã¿ããã§ããã
ãµã³ãã«ãã³ã³ãã¤ã«ãã¦å®è¡ãã
ãµã³ãã«ã¯ã Alchemy Toolkit ã®ç´ä¸ã® samples ãã£ã¬ã¯ããªã«ããã¾ããã
$ cd AlchemyToolkit/alchemy-darwin-v0.4a/samples/ $ ls -la total 0 drwxr-xr-x 6 amachang staff 204 11 14 03:09 . drwxr-xr-x 9 amachang staff 510 11 18 21:39 .. drwxr-xr-x 2 amachang staff 170 11 14 03:09 AS3API drwxr-xr-x 2 amachang staff 204 11 14 03:09 AS3Lib drwxr-xr-x 2 amachang staff 102 11 14 03:09 HelloFlash drwxr-xr-x 3 amachang staff 204 11 14 03:09 stringecho
HelloFlash
ã¾ãã¯ã HelloFlash ãå®è¡ãã¦ã¿ã¾ãããã
HelloFlash ãã£ã¬ã¯ããªã®ä¸ã«ã¯ HelloFlash.c ã¨ãããã¡ã¤ã«ãå
¥ã£ã¦ãã¾ããã
å
容ã¯ãããªæã
#include <stdlib.h> #include <stdio.h> int main(int argc, char* argv[]) { printf("Hello Flash!\n"); }
ã¨ããããããªã«ãèããã« gcc ã§ã³ã³ãã¤ã«ãã¦ã¿ã¾ã
$ cd HelloFlash $ gcc HelloFlash.c WARNING: While resolving call to function 'main' arguments were dropped! 45416.achacks.swf, 354510 bytes written
ãªããã WARNING ãåºã¾ãããæåããã¿ããã§ãã
ããã¦ã a.exe ã¨ãããã¡ã¤ã«ãåºæ¥ã¾ããã
$ ls -la total 704 drwxr-xr-x 2 amachang staff 136 11 18 21:51 . drwxr-xr-x 6 amachang staff 204 11 14 03:09 .. -r--r--r-- 1 amachang staff 104 11 14 03:09 HelloFlash.c -rwxr-xr-x 1 amachang staff 354590 11 18 21:51 a.exe
ä½ãèããã«å®è¡ãã¦ã¿ã¾ãããããããã
$ ./a.exe /Users/amachang/AlchemyTest/FlexSDK/bin/adl _sb_45518/app.xml 2> /tmp/adl.trace & echo $! Hello Flash!
ãããããã¡ãã㨠Hello Flash! ã¨è¡¨ç¤ºããã¾ããï¼
ã¡ãã£ã¨å¯ãé
ãã® a.exe ã£ã¦ããã®ãã©ããããã¡ã¤ã«ãªã®ãæ°ã«ãªã£ãã®ã§èª¿ã¹ã¦ã¿ã$ file a.exe a.exe: a /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/bin/swfbridge script text executableswfbridge ã¨ããã³ãã³ãã§å®è¡ãããã¹ã¯ãªããï¼éãã¦ã¿ãã
ãã¤ããªã ã£ããã$ head -3 a.exe #!/Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/bin/swfbridge FWS ï¼ãã¤ããªï¼ã£ã¦æãã®ãã¡ã¤ã«ã
FWS ã£ã¦ swf ãã¡ã¤ã«ã®ãã¸ãã¯ã ã£ãã£ãï¼
ãããªæãã®ãã¡ã¤ã«ãããã swfbridge ã£ã¦ã©ããªãã®ãªãã ããã adl ãå¼ã³åºãã¦ãã¿ããã ãã©ã
app.xml ã£ã¦ãããã¡ã¤ã«ãèªåã§ä½ã£ã¦ adl ãå¼ã³åºããã¼ã«ããª
ã¡ãã£ã¨ strings ãã¦ã¿ã$ strings /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/bin/swfbridge PATH Couldn't write setup _sb_%d Couldn't create temp dir error: %s pid%d %s/app.xml <application xmlns="http://ns.adobe.com/air/application/1.5"> <id>com.adobe.%s</id> <version>1.0</version> <filename>%s</filename> <name>%s</name> <initialWindow> <x>0</x> <y>0</y> <visible>false</visible> <content>app.swf</content> </initialWindow> </application> %s/app.swf SWF: %s ï¼ãããã XML ã¯ãã¼ãã a.exe ãã app.xml 㨠app.swf ãä½ã£ã¦ adl ã«æ¸¡ãã¿ããã ãªã¼ã
ã¾ãããè±ç·ãããã¾ããã
stringecho
次ã®ãµã³ãã«ã¯ stringecho ã§ãã
$ cd ../stringecho
ã¨ããããããã£ã¬ã¯ããªæ§æã¯ä»¥ä¸ã®ããã¯æãã«ãªã£ã¦ãã¾ãã
$ tree . |-- as3 | `-- EchoTest.as |-- readme.txt `-- stringecho.c 1 directory, 3 files
readme.txt ãããã¾ãããã§ããèªããããã¨ãã£ãããªãã®ã§ãä½ãèããã«ã³ã³ãã¤ã«ãã¦ã¿ã¾ãã
$ gcc stringecho.c WARNING: While resolving call to function 'main' arguments were dropped! 46476.achacks.swf, 355002 bytes written
ãªãããæåãã¾ãããã§ã¯ãå®è¡ãã¾ãããããã
$ ./a.exe
ãããã
AIR ããã«æããã¾ããï¼ããã¯ããã§å¬ããã§ããã
ã¨ããããã§ã readme.txt ãèªã¿ã¾ãã
ãªãã»ã©ã以ä¸ã®ããã« swc ãªãã·ã§ã³ãä»ãããã¨ã§ã swf ãã使ãã *.swc ãã¡ã¤ã«ã«ãªãããã«ãªãããã§ãã
$ gcc stringecho.c -swc -o stringecho.swc WARNING: While resolving call to function 'main' arguments were dropped! 47506.achacks.swf, 362570 bytes written frame rate: 60 frame count: 1 69 : 4 72 : 362500 76 : 33 1 : 0 0 : 0 frame rate: 24 frame count: 1 69 : 4 77 : 506 64 : 31 63 : 16 65 : 4 9 : 3 41 : 26 82 : 471 1 : 0 0 : 0 adding: catalog.xml (deflated 75%) adding: library.swf (deflated 61%)
ã§ã stringecho.swc ãã¡ã¤ã«ãåºæ¥ãã®ã§ã EchoTest.as ã®ã³ã³ãã¤ã«æã«æå®ãã¦ããã¾ãã
$ mxmlc -library-path+=stringecho.swc --target-player=10.0.0 as3/EchoTest.as
ããããã¨ã as3/EchoTest.swf ãåºæ¥ã¾ãã
ãã ãä¸è¦ãããå®è¡ãã¦ãä½ãããã¾ããã
以ä¸ã®ããã«ã trace é¢æ°ã«çµæã渡ãã¦ããã®ã§ãçµæãè¦ãã«ã¯ mm.cfg ã¨ãããã©ãããè¨å®ãããªããã°ãªããªãããã§ãã
package { import flash.display.Sprite; import cmodule.stringecho.CLibInit; public class EchoTest extends Sprite { public function EchoTest() { var loader:CLibInit = new CLibInit; var lib:Object = loader.init(); trace(lib.echo("foo")); } } }
ã¦ã£ã¨ãæ©ãçµæãè¦ããã®ã§ããã㨠Error ãçºçããã¾ãããã
package { import flash.display.Sprite; import cmodule.stringecho.CLibInit; public class EchoTest extends Sprite { public function EchoTest() { var loader:CLibInit = new CLibInit; var lib:Object = loader.init(); // çµæãã¨ã©ã¼ã«ä¹ãã throw Error(lib.echo("foo")); } } }
ã¨ããããã§ãããã§åºæ¥ã EchoTest.swf ããã©ã¦ã¶ã§éãã¾ãã
ãããããã¡ããã¨Error ã« foo ã¨ããæååãéã°ãã¦ãã¾ãããï¼
ãã® swf ã¯ä»¥ä¸ã®ããã« swfbridge ã§ãå®è¡åºæ¥ãããã§ãã
$ ../../bin/swfbridge as3/EchoTest.swf
ã¡ãªã¿ã«ã C è¨èªå´ã®ã³ã¼ãã¯ãããªæãã§ãã main ã§åæåã㦠C è¨èªã®é¢æ°ã Flash ããæ±ããããã«ãã¦ããã¿ããã§ããã
//Simple String Echo example //mike chambers //[email protected] #include <stdlib.h> #include <stdio.h> //Header file for AS3 interop APIs //this is linked in by the compiler (when using flaccon) #include "AS3.h" //Method exposed to ActionScript //Takes a String and echos it static AS3_Val echo(void* self, AS3_Val args) { //initialize string to null char* val = NULL; //parse the arguments. Expect 1. //pass in val to hold the first argument, which //should be a string AS3_ArrayValue( args, "StrType", &val ); //if no argument is specified if(val == NULL) { char* nullString = "null"; //return the string "null" return AS3_String(nullString); } //otherwise, return the string that was passed in return AS3_String(val); } //entry point for code int main() { //define the methods exposed to ActionScript //typed as an ActionScript Function instance AS3_Val echoMethod = AS3_Function( NULL, echo ); // construct an object that holds references to the functions AS3_Val result = AS3_Object( "echo: AS3ValType", echoMethod ); // Release AS3_Release( echoMethod ); // notify that we initialized -- THIS DOES NOT RETURN! AS3_LibInit( result ); // should never get here! return 0; }
èªåã§ãä½ãä½ã£ã¦ã¿ã
æåã«ä½ã£ã Src ãã£ã¬ã¯ããªã«ç§»åãã¦
$ cd /Users/amachang/AlchemyTest/Src
ã¾ã㯠hello
hello.c ãæ¸ã
#include "AS3.h" static AS3_Val hello(void* self, AS3_Val args) { return AS3_String("Hello, world."); } int main() { AS3_Val method = AS3_Function( NULL, hello ); AS3_Val object = AS3_Object( "hello: AS3ValType", method ); AS3_Release( method ); AS3_LibInit( object ); return 0; }
Hello.as
package { import flash.display.Sprite; import cmodule.hello.CLibInit; public class Hello extends Sprite { public function Hello() { throw Error(new CLibInit().init().hello()); } } }
ã§ãã³ã³ãã¤ã«
$ gcc hello.c -swc -o hello.swc && mxmlc -library-path+=hello.swc --target-player=10.0.0 Hello.as WARNING: While resolving call to function 'main' arguments were dropped! 49833.achacks.swf, 358742 bytes written frame rate: 60 frame count: 1 69 : 4 72 : 358677 76 : 28 1 : 0 0 : 0 frame rate: 24 frame count: 1 69 : 4 77 : 506 64 : 31 63 : 16 65 : 4 9 : 3 41 : 26 82 : 471 1 : 0 0 : 0 adding: catalog.xml (deflated 75%) adding: library.swf (deflated 60%) è¨å®ãã¡ã¤ã« "/Users/amachang/AlchemyTest/FlexSDK/frameworks/flex-config.xml" ããã¼ããã¦ãã¾ã /Users/amachang/AlchemyTest/Src/Hello.swf (142645 bytes)
ããããã§ã¯ãå®è¡ã Hello, world! ã¨ããã¨ã©ã¼ãåºãã°æåããããã
ããããããæå
ã¯ãã¼ã¸ã£ã渡ã
AS å´ããã¯ãã¼ã¸ã£ã渡ãã¦
package { import flash.display.Sprite; import cmodule.hello.CLibInit; public class Hello extends Sprite { public function Hello() { var message:String = "Hello, "; new CLibInit().init().hello(function(message2:String):* { message += message2; }); throw Error(message); } } }
C è¨èªå´ã§å®è¡
#include <stdio.h> #include <stdlib.h> #include "AS3.h" static AS3_Val hello(void* self, AS3_Val args) { AS3_Val callback; AS3_ArrayValue(args, "AS3ValType", &callback); AS3_Call(callback, AS3_Undefined(), AS3_Array("StrType", " world.")); return 0; } int main() { AS3_Val method = AS3_Function( NULL, hello ); AS3_Val object = AS3_Object( "hello: AS3ValType", method ); AS3_Release( method ); AS3_LibInit( object ); return 0; }
Alchemy ã® gcc ã¯ä½ããã¦ããã
hoge.c ã hoge.swc ã«ãªãéç¨ãé ã«è¦ã¦è¡ãã¾ãããã
1. C/C++ ã LLVM ç¨ã®ãã¤ããªã«ã³ã³ãã¤ã«ãã
$ llvm-gcc -v -emit-llvm -nostdinc -I/Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/avm2-libc/include -I/usr/local/include --include /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/avm2-libc/avm2/AVM2Env.h hoge.c -c -o hoge.o
ã¾ãã¯ããã®ããã« hoge.c ã hoge.o ã«ã³ã³ãã¤ã«ããã¾ãã
ãã® hoge.o 㯠LLVM ã®ãã¤ãã³ã¼ãã§ãã
2. avm2-libc.l.bc ã¨ãªã³ã¯ãã
$ llvm-ld -o=hoge -O5 -internalize-public-api-list=_start,malloc,free,__adddi3,__anddi3,__ashldi3,__ashrdi3,__cmpdi2,__divdi3,__fixdfdi,__fixsfdi,__fixunsdfdi,__fixunssfdi,__floatdidf,__floatdisf,__floatunsdidf,__iordi3,__lshldi3,__lshrdi3,__moddi3,__muldi3,__negdi2,__one_cmpldi2,__qdivrem,__adddi3,__anddi3,__ashldi3,__ashrdi3,__cmpdi2,__divdi3,__qdivrem,__fixdfdi,__fixsfdi,__fixunsdfdi,__fixunssfdi,__floatdidf,__floatdisf,__floatunsdidf,__iordi3,__lshldi3,__lshrdi3,__moddi3,__muldi3,__negdi2,__one_cmpldi2,__subdi3,__ucmpdi2,__udivdi3,__umoddi3,__xordi3,__subdi3,__ucmpdi2,__udivdi3,__umoddi3,__xordi3,__error /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/avm2-libc/lib/avm2-libc.l.bc hoge.o
次ã«ã llvm-ld ã§ãªã³ã¯ãã㦠hoge 㨠hoge.bc ãåºæ¥ã¾ããï¼ hoge ã¯ãã åã« hoge.bc ãå®è¡ãã sh ãã¡ã¤ã«ï¼
ãã® avm2-libc.l.bc C è¨èªå´ã« libc ã¨åã API ãæä¾ãã¦ããããã§ããã
3. llc ã¨ãããã¼ã«ã§ ActionScript ã®ã³ã¼ããä½ã
$ llc -march=avm2 -avm2-use-memuser -o=hoge.as -avm2-package-name=cmodule.hoge hoge.bc
ãã®ãã¼ã«ã§ LLVM ã®ã³ã¼ããããªã㨠ActionScript ã®ã³ã¼ãã«ãªãã¾ãã
package cmodule.hoge { // Start of file scope inline assembly import flash.utils.* import flash.display.* import flash.text.* import flash.events.* import flash.net.* import flash.system.* public var gdomainClass:Class; public var gshell:Boolean = false; public function establishEnv():void { try { var ns:Namespace = new Namespace("avmplus"); gdomainClass = ns::["Domain"]; gshell = true; } catch(e:*) {} if(!gdomainClass) { var ns:Namespace = new Namespace("flash.system"); gdomainClass = ns::["ApplicationDomain"]; } } establishEnv(); public var glogLvl:int = Alchemy::LogLevel; public function log(lvl:int, msg:String):void { if(lvl < glogLvl) ï¼ ï¼ ï¼27436è¡ï¼
4. asc.jar ã§ã as ãã³ã³ãã¤ã«ãã
$ java -Xms16M -Xmx1024M -jar /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/bin/asc.jar -AS3 -strict -import /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/flashlibs/global.abc -import /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/flashlibs/playerglobal.abc -d -config Alchemy::Shell=false -config Alchemy::NoShell=true -config Alchemy::LogLevel=0 -config Alchemy::Vector=true -config Alchemy::NoVector=false -config Alchemy::SetjmpAbuse=false -swf cmodule.hoge.ConSprite,800,600,60 hoge.as
ããã¦ã hoge.as ãã hoge.swf ãçæããã¾ãã
5. hoge.swf ãã ActionScript ã®ãã¤ãã³ã¼ããåãåºã
$ GetABC2.pl hoge hoge.swf.abc
6. ãã£ãã swf ãä½ã
$ PutABC2.pl /Users/amachang/AlchemyTest/AlchemyToolkit/alchemy-darwin-v0.4a/achacks/swctmpl.swf temp.swf hoge.swf.abc cmodule/hello/CLibInit $ V10SWF.pl temp.swf library.swf
7. catalog.xml ãä»ã㦠zip ã§åºã㦠swc ã«ãã
ã¡ãªã¿ã«ã catalog.xml ã¯ãããªã®
<?xml version="1.0" encoding ="utf-8"?> <swc xmlns="http://www.adobe.com/flash/swccatalog/9"> <versions> <swc version="1.0" /> <flex version="2.0" build="143452" /> </versions> <features> <feature-script-deps /> <feature-files /> </features> <libraries> <library path="library.swf"> <script name="cmodule/hello/CLibInit" mod="1177909560000" > <def id="cmodule.hello:CLibInit" /> <dep id="Date" type="e" /> <dep id="Date" type="s" /> <dep id="flash.utils:Dictionary" type="e" /> <dep id="flash.utils:Dictionary" type="s" /> ï¼ ï¼ç¥ï¼ ï¼ <dep id="AS3" type="n" /> <dep id="Object" type="i" /> </script> </library> </libraries> <files> </files> </swc>
$ zip hoge.swc catalog.xml library.swf
ãããããããããã¨è¨ã訳㧠hoge.swc ãåºæ¥ã¾ããã
ã¾ã¨ã
- Alchemy ã使ãã¨çµæ§ç°¡åã« C è¨èªã®ã³ã¼ãã swc ã«ãã¦ä½¿ããã¨ãã§ãã
- ãã ãåã®ç°å¢ã§ã¯ C++ ãã³ã³ãã¤ã«ãããã¨æã£ã¦ã Alchemy ã® include ãã¡ã¤ã«å ã§ã¨ã©ã¼ãåºæ¥ãªãã£ãã
- C è¨èªã¯ãã£ãã LLVM ã®ãã¤ãã³ã¼ãã«ãªããæé©åããããã¨ã ActionScript ã®ã³ã¼ãã«å¤æããããããã³ã³ãã¤ã«ãããã
- C è¨èª ï¼hoge.cï¼
- LLVM ãã¤ãã³ã¼ã ï¼hoge.bcï¼
- ActionScript ã®ã³ã¼ã ï¼hoge.asï¼
- ActionScript Byte Code ï¼hoge.abcï¼
- Swc ï¼hoge.swcï¼
æå¾ã«
Alchemy 楽ããã§ãï¼
ã¿ãªãããéãã§ã¿ã¦ã¯ãããã§ããããã