概要
paizaでilasmやってみた。
classやってみた。
サンプルコード
import subprocess
import os
def cil():
c_file = 'hello1.il'
test_c = """
.assembly hello1 {
}
.class private auto ansi hello1 extends [mscorlib]System.Object {
.method public specialname rtspecialname instance void .ctor() cil managed {
.maxstack 2
ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
.method public instance void Say(string A_1) cil managed {
.maxstack 1
ldarg.1
call void [mscorlib]System.Console::WriteLine(string)
ret
}
.method static void Main() cil managed {
.entrypoint
.maxstack 8
.locals init (string V_0, class hello1 V_1)
ldstr "hello1"
stloc.0
newobj instance void hello1::.ctor()
stloc.1
ldloc.1
ldloc.0
call instance void hello1::Say(string)
ret
}
}
"""
with open(c_file, 'w') as f:
f.write(test_c)
os.system("ilasm %s" % c_file)
os.system("mono hello1.exe")
if __name__ == '__main__':
cil()
成果物
以上。