mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
stdout and escaping
This commit is contained in:
parent
cf4bc26e8d
commit
c1a93db8b2
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,7 @@ arch_i.h
|
||||
*.dis
|
||||
instrs.lst
|
||||
*.out*
|
||||
stdout.txt
|
||||
stderr.txt
|
||||
stdin.txt
|
||||
|
||||
|
2
Makefile
2
Makefile
@ -14,7 +14,7 @@ asm: os/dos.k
|
||||
@cd os && ../as/k-as.py dos.k 0x100000 a.out
|
||||
|
||||
test: kas asm
|
||||
@pc/k.exe os/a.out
|
||||
@pc/k.exe os/a.out > os/stdout.txt
|
||||
|
||||
disasm: kas asm
|
||||
@pc/k.exe os/a.out -d
|
||||
|
26
as/k-as.py
26
as/k-as.py
@ -134,11 +134,31 @@ def parse_preproc(line):
|
||||
s = s[1:-1]
|
||||
|
||||
plabels_data[tok[0]] = pdata
|
||||
pdefs[tok[0] + "_len"] = str(len(s))
|
||||
|
||||
real_len = 0
|
||||
escaping = False
|
||||
|
||||
for c in s:
|
||||
# escape sequences
|
||||
if c == '\\':
|
||||
escaping = True
|
||||
continue
|
||||
|
||||
if escaping:
|
||||
escaping = False
|
||||
|
||||
if c == 'n':
|
||||
c = '\n'
|
||||
elif c == 't':
|
||||
c = '\t'
|
||||
else:
|
||||
print("Unrecognized escape sequence: {}".format(line))
|
||||
leave()
|
||||
sys.exit(1)
|
||||
|
||||
written = b_data.write(ord(c).to_bytes(1, byteorder='little', signed=False))
|
||||
assert(written == 1)
|
||||
real_len += 1
|
||||
pdata += 1
|
||||
|
||||
# align
|
||||
@ -146,7 +166,9 @@ def parse_preproc(line):
|
||||
written = b_data.write(int(0).to_bytes(1, byteorder='little', signed=False))
|
||||
assert(written == 1)
|
||||
pdata += 1
|
||||
|
||||
|
||||
pdefs[tok[0] + "_len"] = str(real_len)
|
||||
|
||||
else:
|
||||
print("Invalid format: {}".format(line))
|
||||
leave()
|
||||
|
2
os/dos.k
2
os/dos.k
@ -1,7 +1,7 @@
|
||||
; The OS/K Team licences this file to you under the MIT license.
|
||||
; See the LICENSE file in the project root for more information.
|
||||
|
||||
hw = "Hello World"
|
||||
hw = "Hello World\n:)"
|
||||
|
||||
;
|
||||
; Entry point
|
||||
|
@ -5,12 +5,14 @@ all: k.exe
|
||||
|
||||
src = instrs/instrs.c decd.c main.c regs.c dump.c \
|
||||
instrs/jumps.c except.c disd.c mem.c instrs/logic.c \
|
||||
instrs/stack.c instrs/super.c instrs/arith.c
|
||||
instrs/stack.c instrs/super.c instrs/arith.c log.c
|
||||
|
||||
obj = $(patsubst %.c,%.o,$(src))
|
||||
|
||||
CFLAGS=-O2 -g -Wall -fno-builtin-log
|
||||
|
||||
%.o: %.c i_arch.h *.h $(src)
|
||||
@gcc -O2 -g -Wall -c $< -o $@
|
||||
@gcc $(CFLAGS) -c $< -o $@
|
||||
|
||||
i_arch.h: instrs/INSTRS instrs/arch_i.py
|
||||
@cd instrs && python3 arch_i.py
|
||||
|
@ -8,9 +8,6 @@
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define log printf
|
||||
#define vlog vprintf
|
||||
|
||||
#define packed __attribute__ ((__packed__))
|
||||
#define static_assert _Static_assert
|
||||
#define alignof _Alignof
|
||||
@ -27,6 +24,9 @@ typedef struct instr_t instr_t;
|
||||
typedef struct acc_t acc_t;
|
||||
typedef struct arch_t arch_t;
|
||||
|
||||
void log(const char *, ...);
|
||||
void vlog(const char *, va_list);
|
||||
|
||||
// A_REG is implicit
|
||||
// A_MEM denotes a memory access
|
||||
// A_OFF is A_MEM but a 16-bit offset is expected immediatly next
|
||||
|
@ -56,16 +56,12 @@ IMPL_START_1(prn)
|
||||
log("prn warning: large access size\n");
|
||||
}
|
||||
|
||||
if (!(v1 >= ' ' && v1 < 128) && v1 != '\t') {
|
||||
if (v1 == '\n') {
|
||||
log("prn on newline character\n");
|
||||
}
|
||||
else
|
||||
log("prn on invalid character: %ld\n", v1);
|
||||
if (!(v1 >= ' ' && v1 < 128) && v1 != '\t' && v1 != '\n') {
|
||||
log("prn on invalid character: %ld\n", v1);
|
||||
}
|
||||
|
||||
else {
|
||||
log("prn instruction with character: '%c'\n", (char)v1);
|
||||
putchar((int)v1);
|
||||
}
|
||||
}
|
||||
IMPL_END;
|
||||
|
19
pc/log.c
Normal file
19
pc/log.c
Normal file
@ -0,0 +1,19 @@
|
||||
// The OS/K Team licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
#include "arch.h"
|
||||
|
||||
void log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void vlog(const char *fmt, va_list ap)
|
||||
{
|
||||
vfprintf(stderr, fmt, ap);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user