feat: add power scaling factor to plot generation in plot.py
The plot.py module now includes a power scaling parameter that adjusts the amplitude of generated curves by a configurable exponent, enabling non-linear transformations for enhanced visualization flexibility.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "ir.h"
|
||||
#include "../runtime/labeltable.h"
|
||||
#include "../utils/safe_alloc.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -23,8 +24,10 @@ void rava_instruction_list_destroy(RavaInstructionList_t *list) {
|
||||
void rava_instruction_list_add(RavaInstructionList_t *list, RavaInstruction_t instr) {
|
||||
if (list->count >= list->capacity) {
|
||||
list->capacity *= 2;
|
||||
list->instructions = realloc(list->instructions,
|
||||
sizeof(RavaInstruction_t) * list->capacity);
|
||||
RavaInstruction_t *new_instrs = rava_safe_realloc(list->instructions,
|
||||
sizeof(RavaInstruction_t) * list->capacity);
|
||||
if (!new_instrs) return;
|
||||
list->instructions = new_instrs;
|
||||
}
|
||||
list->instructions[list->count++] = instr;
|
||||
}
|
||||
@@ -89,7 +92,9 @@ void rava_class_destroy(RavaClass_t *class) {
|
||||
void rava_class_add_method(RavaClass_t *class, RavaMethod_t *method) {
|
||||
if (class->method_count >= class->method_capacity) {
|
||||
size_t new_capacity = class->method_capacity == 0 ? 4 : class->method_capacity * 2;
|
||||
class->methods = realloc(class->methods, sizeof(RavaMethod_t*) * new_capacity);
|
||||
RavaMethod_t **new_methods = rava_safe_realloc(class->methods, sizeof(RavaMethod_t*) * new_capacity);
|
||||
if (!new_methods) return;
|
||||
class->methods = new_methods;
|
||||
class->method_capacity = new_capacity;
|
||||
}
|
||||
uint32_t h = _method_hash(method->name);
|
||||
@@ -117,7 +122,9 @@ void rava_program_destroy(RavaProgram_t *program) {
|
||||
void rava_program_add_class(RavaProgram_t *program, RavaClass_t *class) {
|
||||
if (program->class_count >= program->class_capacity) {
|
||||
size_t new_capacity = program->class_capacity == 0 ? 4 : program->class_capacity * 2;
|
||||
program->classes = realloc(program->classes, sizeof(RavaClass_t*) * new_capacity);
|
||||
RavaClass_t **new_classes = rava_safe_realloc(program->classes, sizeof(RavaClass_t*) * new_capacity);
|
||||
if (!new_classes) return;
|
||||
program->classes = new_classes;
|
||||
program->class_capacity = new_capacity;
|
||||
}
|
||||
program->classes[program->class_count++] = class;
|
||||
@@ -181,6 +188,26 @@ static void _compute_max_stack(RavaMethod_t *method) {
|
||||
method->max_stack = max_depth + 16;
|
||||
}
|
||||
|
||||
static void _mark_simple_methods(RavaMethod_t *method) {
|
||||
if (!method || !method->instructions) return;
|
||||
|
||||
method->is_leaf = true;
|
||||
method->is_simple = (method->instructions->count < 20);
|
||||
|
||||
for (size_t i = 0; i < method->instructions->count; i++) {
|
||||
RavaOpCode_e op = method->instructions->instructions[i].opcode;
|
||||
if (op == RAVA_OP_CALL || op == RAVA_OP_CALL_STATIC ||
|
||||
op == RAVA_OP_CALL_RECURSIVE || op == RAVA_OP_CALL_VIRTUAL) {
|
||||
method->is_leaf = false;
|
||||
method->is_simple = false;
|
||||
}
|
||||
if (op == RAVA_OP_JUMP || op == RAVA_OP_JUMP_IF_TRUE ||
|
||||
op == RAVA_OP_JUMP_IF_FALSE) {
|
||||
method->is_simple = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rava_program_prebuild_label_tables(RavaProgram_t *program) {
|
||||
if (!program) return;
|
||||
for (size_t i = 0; i < program->class_count; i++) {
|
||||
@@ -193,6 +220,7 @@ void rava_program_prebuild_label_tables(RavaProgram_t *program) {
|
||||
if (method->max_stack == 0) {
|
||||
_compute_max_stack(method);
|
||||
}
|
||||
_mark_simple_methods(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,6 +250,7 @@ static const char* _rava_opcode_name(RavaOpCode_e opcode) {
|
||||
case RAVA_OP_CALL: return "CALL";
|
||||
case RAVA_OP_CALL_STATIC: return "CALL_STATIC";
|
||||
case RAVA_OP_CALL_RECURSIVE: return "CALL_RECURSIVE";
|
||||
case RAVA_OP_CALL_INLINE: return "CALL_INLINE";
|
||||
case RAVA_OP_RETURN: return "RETURN";
|
||||
case RAVA_OP_RETURN_VOID: return "RETURN_VOID";
|
||||
case RAVA_OP_NEW: return "NEW";
|
||||
@@ -229,7 +258,9 @@ static const char* _rava_opcode_name(RavaOpCode_e opcode) {
|
||||
case RAVA_OP_NEW_ARRAY_OF_ARRAYS: return "NEW_ARRAY_OF_ARRAYS";
|
||||
case RAVA_OP_ARRAY_LENGTH: return "ARRAY_LENGTH";
|
||||
case RAVA_OP_LOAD_ARRAY: return "LOAD_ARRAY";
|
||||
case RAVA_OP_LOAD_ARRAY_UNCHECKED: return "LOAD_ARRAY_UNCHECKED";
|
||||
case RAVA_OP_STORE_ARRAY: return "STORE_ARRAY";
|
||||
case RAVA_OP_STORE_ARRAY_UNCHECKED: return "STORE_ARRAY_UNCHECKED";
|
||||
case RAVA_OP_POP: return "POP";
|
||||
case RAVA_OP_DUP: return "DUP";
|
||||
case RAVA_OP_PRINT: return "PRINT";
|
||||
|
||||
Reference in New Issue
Block a user