makefile: reasonable way of adding compile options

This commit is contained in:
Edgaru089 2021-11-07 01:38:17 +08:00
parent e5ba03599b
commit 7f7a985ed6
4 changed files with 27 additions and 4 deletions

View File

@ -2,10 +2,6 @@
.SILENT: .SILENT:
# HELOS_RUNTIME_QUIET Supress on-screen kernel output (not supressing serial output)
export BUILD_OPTIONS = -DHELOS_RUNTIME_QUIET
FLAGS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) FLAGS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
SELF_DIR = $(dir $@) SELF_DIR = $(dir $@)

14
config.h Normal file
View File

@ -0,0 +1,14 @@
// config.h: Compile flags
#pragma once
// Supress all screen output on boot.
// Serial output is not supressed.
#define HELOS_RUNTIME_QUIET
// util/tree.h uses a Treap model for balancing.
//
// If no TREE_TYPE flags are defined, no balancing is employed.
#define HELOS_UTIL_TREE_TYPE_TREAP

2
main.h
View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "config.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>

View File

@ -50,7 +50,11 @@ SYSV_ABI static tree_Node *__tree_InsertNodes(tree_Tree *t, tree_Node *node, tre
if (!node) { if (!node) {
if (added) if (added)
*added = true; *added = true;
#ifdef HELOS_UTIL_TREE_TYPE_TREAP
return *result = __tree_NewNode(t, key, father, random_Rand() ^ key); return *result = __tree_NewNode(t, key, father, random_Rand() ^ key);
#else
return *result = __tree_NewNode(t, key, father, 0);
#endif
} else if (key < node->key) { } else if (key < node->key) {
node->left = __tree_InsertNodes(t, node->left, node, key, result, added); node->left = __tree_InsertNodes(t, node->left, node, key, result, added);
return node; return node;
@ -69,8 +73,10 @@ tree_Node *tree_InsertNode(tree_Tree *t, uintptr_t key, bool *added) {
tree_Node *result; tree_Node *result;
t->root = __tree_InsertNodes(t, t->root, 0, key, &result, added); t->root = __tree_InsertNodes(t, t->root, 0, key, &result, added);
#ifdef HELOS_UTIL_TREE_TYPE_TREAP
if (*added) if (*added)
__tree_treap_Adjust(result, &t->root); __tree_treap_Adjust(result, &t->root);
#endif
return result; return result;
} }
@ -105,11 +111,16 @@ void *tree_Find(tree_Tree *t, uintptr_t key) {
void tree_Delete(tree_Tree *t, tree_Node *node) { void tree_Delete(tree_Tree *t, tree_Node *node) {
#ifdef HELOS_UTIL_TREE_TYPE_TREAP
while (node->left && node->right) while (node->left && node->right)
if (node->left->internal < node->right->internal) if (node->left->internal < node->right->internal)
__tree_Rotate(node->left, &t->root); __tree_Rotate(node->left, &t->root);
else else
__tree_Rotate(node->right, &t->root); __tree_Rotate(node->right, &t->root);
#else
while (node->left)
__tree_Rotate(node->left, &t->root);
#endif
if (node == t->root) if (node == t->root)
t->root = (node->left ? node->left : node->right); t->root = (node->left ? node->left : node->right);