};
* @throws IOException
*/
private void bytecode(Set<String> incSet, Method method) throws IOException {
Code code= method.getCode();
methodName= getMethodSignature("1 bc "+jc.getClassName()+"."+method.getName()+" "+method.getSignature());
if (code == null) {
// is abstract or native method
outc.println("*/");
if (method.isNative()) {
totalMethods++;
totalBClength+=3;
if (methodName.endsWith("_clinitHaikuMagic_V")) {
conditions.add(Condition.CLINIT.desc("found clinitHaikuMagic() in: "+classname));
outc.printf("\n");
for (Clinit desc : Clinit.set()) {
String include=desc.getClassName().replace('.', '/');
outc.println("// clinit "+include);
includeThis(incSet, include);
//outc.printf("extern const ByteCode %s__clinit__V;\n", mangle(desc.getClassName()));
}
/**
typedef struct {
uint8_t max_stack; int8_t purLocals; uint8_t purParams;
OP_bc oph9; OPadr fh9; // <clinit>
OP_bc oph12; OPadr fh12; // <clinit>
OP_bc oph15; OPadr fh15; // <clinit>
OP_bc oph18; OPadr fh18; // <clinit>
OP_bc op0; // 0: return
} haiku_avr_lib_arduino_HaikuMicroKernelEx_clinitHaikuMagic_V_t;
extern const haiku_avr_lib_arduino_HaikuMicroKernelEx_clinitHaikuMagic_V_t haiku_avr_lib_arduino_HaikuMicroKernelEx_clinitHaikuMagic_V;
public static synchronized void clinitHaikuMagic()
Code(max_stack = 0, max_locals = 0, code_length = 1)
* /
#undef JMETHOD
#define JMETHOD haiku_avr_lib_arduino_HaikuMicroKernelEx_clinitHaikuMagic_V
const haiku_avr_lib_arduino_HaikuMicroKernelEx_clinitHaikuMagic_V_t JMETHOD PROGMEM ={
0+0 +2, 0, 0, // max_stack, purLocals, purParams
OP_INVOKESTATIC, ADR(haiku_avr_AVRDefines__clinit__V), // haiku.avr.AVRDefines.<clinit>
OP_INVOKESTATIC, ADR(java_lang_Math__clinit__V), // java.lang.Math.<clinit>
OP_INVOKESTATIC, ADR(haikuvm_bench_JUnit1__clinit__V), // haikuvm.bench.JUnit1.<clinit>
OP_INVOKESTATIC, ADR(java_lang_Double__clinit__V), // java.lang.Double.<clinit>
OP_RETURN, // 0: return
};
*/
outh.printf("typedef struct {\n");
outh.printf(" uint8_t max_stack; int8_t purLocals; uint8_t purParams;\n");
for (Clinit desc : Clinit.set()) {
totalBClength+=3;
outh.printf("\tOP_bc oph%d; OPadr fh%d; // <clinit>\n", totalBClength, totalBClength);
}
outh.printf(" OP_bc op0; // return\n");
outh.printf("} %s_t;\n", methodName, methodName);
outh.printf("extern const %s_t %s;\n", methodName, methodName);
outh.printf("\n");
outc.printf("const %s_t %s PROGMEM ={\n", methodName, methodName);
outc.printf("2, 0, 0, // max_stack, purLocals, purParams\n");
outc.printf("\n");
for (Clinit desc : Clinit.set()) {
outc.printf("OP_INVOKESTATIC, ADR(%s__clinit__V), // %s.<clinit>\n", mangle(desc.getClassName()), desc.getClassName());
BC2IDX.put("INVOKESTATIC");
}
outc.printf("OP_RETURN, // return\n");
outc.printf("};\n");
} else {
outh.printf("#ifndef %s\n", "native_"+methodName);
outh.printf("extern const NativCode %s;\n", methodName);
outh.printf("extern void %s(void);\n", "native_"+methodName);
outh.printf("#endif\n");
outh.printf("\n");
outc.printf("#ifndef %s\n", "native_"+methodName);
outc.printf("const NativCode %s PROGMEM ={0xff, &%s};\n", methodName, "native_"+methodName);
outc.printf("#endif\n");
totalBClength+=2;
haikuJNIc.nativeInfo(classname, method, methodName);
}
}
return;
}
int remap[]=makeArgumentReMap(method);
int start=0, end;
String str =code.toString(true);
byte bc[]=code.getCode();
totalBClength+=bc.length+3 + 2 /*for pointer in functionTable*/;
list=str.split("\n");
for (int k = 0; k < list.length; k++) {
String line=list[k];
if (line.matches("^\\d+:.*")) {
start=Integer.parseInt(line.replaceAll(":.*", ""));
end=bc.length;
if (k+1<list.length) {
try {
end = Integer.parseInt(list[k+1].replaceAll(":.*", ""));
} catch (NumberFormatException e) {
}
}
if (start==0) {
outc.println("*/");
outh.printf("typedef struct {\n");
outh.printf("\tuint8_t max_stack; int8_t purLocals; uint8_t purParams;\n");
outh.printf("\n");
totalMethods++;
outc.printf("#undef JMETHOD\n");
outc.printf("#define JMETHOD %s\n", methodName);
/*
* max_stack: max inner method working stack usage (without purLocals and purParams)
* purParams: only stack usage of parameters (without purLocals)
* purLocals: all local variables of the method (without purParams)
*
* Comment:
* getlocal(idx) addresses the stack beginning with the first (leftmost) Parameter position getLocal(0)
* It covers both parameters and local variables.
*/
outc.printf("const %s_t JMETHOD PROGMEM ={\n", methodName);
outc.printf("%d+(2)+%d, %4d, %4d, // MaxLocals+(lsp+pc)+MaxStack, purLocals, purParams\n", code.getMaxLocals(), code.getMaxStack(), code.getMaxLocals()-getParams(method), getParams(method));
outc.printf("\n");
if (methodName.endsWith("_clinitHaikuMagic_V")) {
conditions.add(Condition.CLINIT.desc("found clinitHaikuMagic() in: "+classname));
for (Clinit desc : Clinit.set()) {
totalBClength+=3;
outh.printf("\tOP_bc oph%d; OPadr fh%d; // <clinit>\n", totalBClength, totalBClength);
outc.printf("OP_INVOKESTATIC, ADR(%s__clinit__V), // %s.<clinit>\n", mangle(desc.getClassName()), desc.getClassName());
BC2IDX.put("INVOKESTATIC");
}
}
pc+=4;
}
String[] token= list[k].split("[ \t,]+");
if (token.length<=2 || !supressPanicSupport(token[2])) {
String bcode=token[1];
if (bcode.equals("wide")) {
k++;
end = Integer.parseInt(list[k+1].replaceAll(":.*", ""));
}
outh.println("\t"+compileJ2Typedef(list[k], bc, start, end));
outc.println(compileJ2Image(list[k], bc, start, end, remap));
}
start=999;
} else {
if (start==0) outc.println(line);
}
}
outh.printf("} %s_t;\n", methodName);
outh.printf("extern const %s_t %s;\n", methodName, methodName);
outh.printf("\n");
outc.printf("};\n");
CodeException[] et = code.getExceptionTable();
ConstantPool cp=jc.getConstantPool();
Constant[] cons=cp.getConstantPool();
for (int i = 0; i < et.length; i++) {
int ct=et[i].getCatchType();