starting work on codegen, need to work on reg allocation to progress
This commit is contained in:
@@ -13,14 +13,20 @@ GravityTargetArch gravityNewTargetArch(const char* name) {
|
||||
initStringBuff(outputBuff);
|
||||
targetArch->outputBuffer = outputBuff;
|
||||
targetArch->name = strdup(name);
|
||||
targetArch->vars = NULL;
|
||||
|
||||
return targetArch;
|
||||
}
|
||||
|
||||
void gravityTargetEmitInst(GravityTargetArch arch, GravityInstruction inst) {
|
||||
arch->emitInst(arch, inst);
|
||||
|
||||
switch (inst.opcode) {
|
||||
case GravityOpcodeIntConst: arch->emitIntConst(arch, inst.operands[0]); break;
|
||||
case GravityOpcodeRet: arch->emitRet(arch, inst.operands[0]); break;
|
||||
case GravityOpcodeAlloc: arch->emitAlloc(arch, inst.operands[0]->type->typeData, inst.result); break;
|
||||
case GravityOpcodeStore: arch->emitStore(arch, inst.operands[0], inst.operands[1]); break;
|
||||
case GravityOpcodeLoad: arch->emitLoad(arch, inst.operands[0], inst.result); break;
|
||||
|
||||
default: assert(false);
|
||||
}
|
||||
@@ -50,4 +56,29 @@ char* gravityTargetEmitModule(GravityTargetArch arch, GravityModule module) {
|
||||
}
|
||||
|
||||
return arch->outputBuffer->data;
|
||||
}
|
||||
|
||||
GravityType gravityResolveInstructionResult(GravityTargetArch arch, GravityInstruction inst) {
|
||||
switch (inst.opcode) {
|
||||
case GravityOpcodeAlloc: {
|
||||
GravityType outType = gravityCreateType();
|
||||
outType->typeKind = GravityPointerTypeKind;
|
||||
outType->ptrType = inst.operands[0]->type->typeData;
|
||||
return outType;
|
||||
}
|
||||
|
||||
case GravityOpcodeLoad: {
|
||||
|
||||
GravityVarSlot* var;
|
||||
HASH_FIND(hh, arch->vars, inst.operands[0], sizeof(void*), var);
|
||||
|
||||
if (!var) assert(false);
|
||||
|
||||
return var->type->ptrType;
|
||||
}
|
||||
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user