2026-08-02 15:52:44 +10:00
|
|
|
#include "include/gravity/core.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2026-08-03 17:02:20 +10:00
|
|
|
int main(void) {
|
2026-08-04 10:10:49 +10:00
|
|
|
// define program
|
2026-08-02 15:52:44 +10:00
|
|
|
GravityModule module = gravityCreateModule();
|
2026-08-03 17:02:20 +10:00
|
|
|
GravityBuilder builder = gravityCreateBuilder();
|
|
|
|
|
|
2026-08-03 21:01:34 +10:00
|
|
|
GravityType charType = gravityCreateIntegerType(8, false);
|
2026-08-03 17:02:20 +10:00
|
|
|
|
|
|
|
|
GravityType mainFuncType = gravityCreateFunctionType(0, NULL, charType);
|
|
|
|
|
GravityFunction mainFunc = gravityNewFunction(module, "main", mainFuncType);
|
2026-08-04 09:50:48 +10:00
|
|
|
GravityBlock entryBlock = gravityStartBlock("entry", mainFunc);
|
|
|
|
|
GravityBlock thenBlock = gravityStartBlock("then", mainFunc);
|
|
|
|
|
GravityBlock elseBlock = gravityStartBlock("else", mainFunc);
|
|
|
|
|
GravityBlock mergeBlock = gravityStartBlock("merge", mainFunc);
|
|
|
|
|
gravityBuilderSwitchToBlock(builder, entryBlock);
|
|
|
|
|
|
2026-08-05 20:55:35 +10:00
|
|
|
GravityValue oneConst = gravityNewIntConstant(charType, 1);
|
|
|
|
|
gravityBuildBr(builder, oneConst, thenBlock, (GravityValue[]){}, elseBlock, (GravityValue[]){});
|
2026-08-04 09:50:48 +10:00
|
|
|
|
|
|
|
|
gravityBuilderSwitchToBlock(builder, thenBlock);
|
2026-08-05 20:55:35 +10:00
|
|
|
gravityBuildJump(builder, mergeBlock, (GravityValue[]){});
|
2026-08-04 09:50:48 +10:00
|
|
|
|
|
|
|
|
gravityBuilderSwitchToBlock(builder, elseBlock);
|
2026-08-05 20:55:35 +10:00
|
|
|
gravityBuildJump(builder, mergeBlock, (GravityValue[]){});
|
2026-08-04 11:30:30 +10:00
|
|
|
|
2026-08-05 20:55:35 +10:00
|
|
|
gravityBuilderSwitchToBlock(builder, mergeBlock);
|
|
|
|
|
gravityBuildRet(builder, NULL);
|
2026-08-05 19:17:15 +10:00
|
|
|
|
2026-08-05 20:55:35 +10:00
|
|
|
gravityCompleteFunction(mainFunc);
|
2026-08-03 21:01:34 +10:00
|
|
|
|
|
|
|
|
printf("%s\n", gravityFunctionToCStr(mainFunc));
|
2026-08-02 15:52:44 +10:00
|
|
|
|
2026-08-04 11:30:30 +10:00
|
|
|
GravityTargetArch target = gravityCreate_x86_64Target();
|
|
|
|
|
char* outputASM = gravityTargetEmitModule(target, module);
|
|
|
|
|
printf("%s\n", outputASM);
|
|
|
|
|
|
2026-08-02 15:52:44 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|