Added printf2 header...
This commit is contained in:
parent
69485b126a
commit
b0a1774e3d
@ -13,6 +13,7 @@
|
||||
#include "unix.h"
|
||||
#include "safety.h"
|
||||
#include "debug.h"
|
||||
#include "printf2.h"
|
||||
|
||||
unsigned int * token_array = NULL;
|
||||
unsigned int token_count = 0;
|
||||
@ -96,6 +97,9 @@ int compile(void) {
|
||||
|
||||
dump_variables_to_assembler();
|
||||
|
||||
// Anon: Example usage, delete or modify it...
|
||||
printf2("[@yTest@-] Begining assembling @c%c%u@- process... @b@@%f@-\n", 'A', 6, 0.666);
|
||||
|
||||
if (assemble(token_count, token_array)) {
|
||||
issue_internal_error();
|
||||
return 1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef DEBUG_H
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#if DEBUG == 1
|
||||
@ -64,7 +64,7 @@ void dump_function(void * data) {
|
||||
}
|
||||
|
||||
__attribute__((unused))
|
||||
static
|
||||
static
|
||||
void debug_dump_functions(void) {
|
||||
puts("# Functions:");
|
||||
tommy_hashtable_foreach(&symbol_table, dump_function);
|
||||
@ -75,7 +75,8 @@ static
|
||||
void debug_dump_symbols(void) {
|
||||
debug_dump_variables();
|
||||
debug_dump_functions();
|
||||
printf("# Total variable size: '%d'\n", variable_size_sum());
|
||||
printf("# Total variable size: '%d'\n",
|
||||
variable_size_sum());
|
||||
}
|
||||
|
||||
__attribute__((unused))
|
||||
|
49
source/printf2.h
Normal file
49
source/printf2.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef PRINTF2_H
|
||||
#define PRINTF2_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static
|
||||
int parse_color(char * buf, char * fmt) {
|
||||
switch (*fmt) {
|
||||
case 'a': memcpy (buf, "\x1b[1;30m", 7ul); return 7; // gray
|
||||
case 'r': memcpy (buf, "\x1b[1;31m", 7ul); return 7; // red
|
||||
case 'g': memcpy (buf, "\x1b[1;32m", 7ul); return 7; // green
|
||||
case 'y': memcpy (buf, "\x1b[1;33m", 7ul); return 7; // yellow
|
||||
case 'b': memcpy (buf, "\x1b[1;34m", 7ul); return 7; // blue
|
||||
case 'p': memcpy (buf, "\x1b[1;35m", 7ul); return 7; // pink
|
||||
case 'c': memcpy (buf, "\x1b[1;36m", 7ul); return 7; // cyan
|
||||
case 'w': memcpy (buf, "\x1b[1;37m", 7ul); return 7; // white
|
||||
case '-': memcpy (buf, "\x1b[0m", 4ul); return 4; // reset
|
||||
case '@': memcpy (buf, "@", 1ul); return 1;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int parse_chars(char * buf, char * fmt) {
|
||||
memcpy (buf, fmt, 1ul);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
void printf2(char * fmt, ...) {
|
||||
va_list args;
|
||||
char buf[1024] = "";
|
||||
|
||||
for (int l = 0; *fmt != '\0'; ++fmt) {
|
||||
switch (*fmt) {
|
||||
case '@': l += parse_color(&buf[l], ++fmt); break;
|
||||
default: l += parse_chars(&buf[l], fmt); break;
|
||||
}
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
vprintf(buf, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,12 +1,21 @@
|
||||
unix program hello
|
||||
begin
|
||||
mov al 0x11
|
||||
mov ax 0x1122
|
||||
mov eax 0x11223344
|
||||
|
||||
mov cl 0x11
|
||||
mov cx 0x1122
|
||||
mov ecx 0x11223344
|
||||
inc eax
|
||||
inc ecx
|
||||
inc edx
|
||||
inc ebx
|
||||
inc esp
|
||||
inc ebp
|
||||
inc esi
|
||||
inc edi
|
||||
inc r8d
|
||||
inc r9d
|
||||
inc r10d
|
||||
inc r11d
|
||||
inc r12d
|
||||
inc r13d
|
||||
inc r14d
|
||||
inc r15d
|
||||
|
||||
exit 0
|
||||
end program
|
||||
|
Loading…
x
Reference in New Issue
Block a user