Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 自動解析モジュール
// Copyright (C) 1989,1990 K.Abe, 1994 R.ShimiZu
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2025 TcbnErik

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -152,7 +152,7 @@ static void printUndefinedInstruction(address pc) {
// プログラム領域の終端をラベル登録する
static void foundProgramEnd(address adrs) {
if (search_label(adrs) == NULL) {
regist_label(adrs, DATLABEL | UNKNOWN);
regist_label(adrs, DATLABEL | (lblmode)UNKNOWN);
}
}

Expand Down Expand Up @@ -347,7 +347,7 @@ static boolean analyzeInner(address start, analyze_mode mode) {
disasm* code = &disp.code;
CodeFlow flow;
int orib = 0; // ori.b #??,d0 = $0000????
void (*regoplbl)(disasm * code) = Dis.actions->registerOperandLabel;
void (*regoplbl)(disasm* code) = Dis.actions->registerOperandLabel;

if (Dis.availableTextEnd <= start) {
printReason("PCが有効なセクションを外れた。", start);
Expand Down Expand Up @@ -515,7 +515,7 @@ boolean analyze(address start, analyze_mode mode) {

if (!success) {
charout('?');
ch_lblmod(start, DATLABEL | UNKNOWN | FORCE);
ch_lblmod(start, DATLABEL | FORCE | (lblmode)UNKNOWN);
return FALSE;
}
charout('<');
Expand All @@ -533,12 +533,12 @@ static boolean branchToOdd(DisParam* disp, address start, address limit) {

if (Dis.acceptAddressError) {
// -j: 奇数アドレスへの分岐を未定義命令と「しない」
regist_label(code->jmp, DATLABEL | UNKNOWN);
regist_label(code->jmp, DATLABEL | (lblmode)UNKNOWN);
return TRUE;
}

// 奇数アドレスへの分岐があればプログラム領域ではない
ch_lblmod(start, DATLABEL | UNKNOWN | FORCE);
ch_lblmod(start, DATLABEL | FORCE | (lblmode)UNKNOWN);
not_program(start, MIN(code->pc, limit));
return FALSE;
}
Expand All @@ -561,7 +561,7 @@ static boolean branch_job(DisParam* disp, address start, analyze_mode mode,
// 分岐先の領域を解析する
if (!analyze(opval, mode) && mode != ANALYZE_IGNOREFAULT && !Dis.i) {
// 分岐先がプログラム領域でなければ、呼び出し元も同じ
ch_lblmod(start, DATLABEL | UNKNOWN | FORCE);
ch_lblmod(start, DATLABEL | FORCE | (lblmode)UNKNOWN);
not_program(start, MIN(disp->pc, limit));
return FALSE;
}
Expand Down Expand Up @@ -628,7 +628,7 @@ static boolean analyzeJump(DisParam* disp, CodeFlow* flow, address start,
// 実際の分岐先は実行時のインデックスレジスタの値次第で、ラベルの場所が
// プログラムではない可能性もあるので、解析はせずラベル登録だけに留める。
// (README.txtの「参照されないラベル」と同様のケース)
regist_label(code->jmp, DATLABEL | UNKNOWN);
regist_label(code->jmp, DATLABEL | (lblmode)UNKNOWN);
break;
}

Expand Down Expand Up @@ -703,17 +703,17 @@ static int analyzeRelativeTable(address table, opesize size,
// (別のデータ形式かもしれないし、プログラム領域かもしれない)
// ただしアドレス値だけで判定しているので確実とは言えない
if (table == ptr)
regist_label(ptr, DATLABEL | UNKNOWN | FORCE);
regist_label(ptr, DATLABEL | (lblmode)UNKNOWN | FORCE);
else
regist_label(ptr, DATLABEL | UNKNOWN);
regist_label(ptr, DATLABEL | (lblmode)UNKNOWN);
break;
}

#ifdef DEBUG_RELTBL_ADDRESS
printReltblAddress(table, ptr, offs, label);
#endif
if (table != label) {
regist_label(label, DATLABEL | UNKNOWN);
regist_label(label, DATLABEL | (lblmode)UNKNOWN);
}
ptr += bytes;

Expand Down Expand Up @@ -800,7 +800,7 @@ static int hasReltblData(address table) {
// テーブルの解析は他の解析が終わって判明した限りのラベルが登録されてからとなる。
void registerReltblOrder(ArrayBuffer* rtbuf, address table, opesize size,
boolean isProgram, lblmode mode) {
if (mode) regist_label(table, mode | size);
if (mode) regist_label(table, mode | (lblmode)size);

if (hasReltblData(table)) {
ReltblOrder* p = getArrayBufferNewPlace(rtbuf);
Expand All @@ -820,7 +820,7 @@ extern void z_table(address table) {
while (ptr + 4 <= tableend) {
address label = (address)peekl(ptr + Dis.Ofst);

regist_label(label, DATLABEL | UNKNOWN);
regist_label(label, DATLABEL | (lblmode)UNKNOWN);
ptr += 4;
tableend = next(ptr)->label;
}
Expand All @@ -835,7 +835,7 @@ extern void not_program(address from, address to) {
DisParam disp;
disasm* code = &disp.code;

ch_lblmod(from, DATLABEL | UNKNOWN | FORCE);
ch_lblmod(from, DATLABEL | FORCE | (lblmode)UNKNOWN);

setDisParamPcPtr(&disp, from, Dis.Ofst);
disp.pcEnd = to;
Expand All @@ -862,45 +862,45 @@ static void regist_data(disasm* code, operand* op) {

case IMMED:
if (code->size2 == LONGSIZE && INPROG(op->opval, op->eaadrs))
regist_label(op->opval, DATLABEL | UNKNOWN);
regist_label(op->opval, DATLABEL | (lblmode)UNKNOWN);
break;

case AbLong:
if (INPROG(op->opval, op->eaadrs))
regist_label(op->opval, DATLABEL | code->size2);
regist_label(op->opval, DATLABEL | (lblmode)code->size2);
break;

case PCDISP:
case PCIDX:
regist_label(op->opval, DATLABEL | code->size2);
regist_label(op->opval, DATLABEL | (lblmode)code->size2);
break;

case AregIDXB:
if (op->exbd == 4 && INPROG(op->opval, op->eaadrs))
regist_label(op->opval, DATLABEL | code->size2);
regist_label(op->opval, DATLABEL | (lblmode)code->size2);
break;

case AregPOSTIDX:
case AregPREIDX:
if (op->exbd == 4 && INPROG(op->opval, op->eaadrs))
regist_label(op->opval, DATLABEL | LONGSIZE);
regist_label(op->opval, DATLABEL | (lblmode)LONGSIZE);
if (op->exod == 4 && INPROG(op->opval2, op->eaadrs2))
regist_label(op->opval2, DATLABEL | code->size2);
regist_label(op->opval2, DATLABEL | (lblmode)code->size2);
break;

case PCIDXB:
if ((op->flags & OPFLAG_PC_RELATIVE) ||
(op->exbd == 4 && INPROG(op->opval, op->eaadrs)))
regist_label(op->opval, DATLABEL | code->size2);
regist_label(op->opval, DATLABEL | (lblmode)code->size2);
break;

case PCPOSTIDX:
case PCPREIDX:
if ((op->flags & OPFLAG_PC_RELATIVE) ||
(op->exbd == 4 && INPROG(op->opval, op->eaadrs)))
regist_label(op->opval, DATLABEL | LONGSIZE);
regist_label(op->opval, DATLABEL | (lblmode)LONGSIZE);
if (op->exod == 4 && INPROG(op->opval2, op->eaadrs2))
regist_label(op->opval2, DATLABEL | code->size2);
regist_label(op->opval2, DATLABEL | (lblmode)code->size2);
break;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/analyze2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 自動解析モジュール2
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2025 TcbnErik

#include <stdio.h>

Expand Down Expand Up @@ -137,7 +137,8 @@ extern void analyze_data(void) {
/* アドレス依存のデータがあれば、そのアドレスを登録する */
for (adrs = data_from; (adrs = nearadrs(adrs)) < data_to && adrs < data_to;
adrs += 4) {
regist_label((address)peekl(adrs + Dis.Ofst), DATLABEL | UNKNOWN);
regist_label((address)peekl(adrs + Dis.Ofst),
DATLABEL | (lblmode)UNKNOWN);
}

if (Dis.h && data_from < Dis.availableTextEnd) {
Expand All @@ -146,13 +147,13 @@ extern void analyze_data(void) {

if (word1 == 0x4e75) {
// rts の次のアドレスを登録する
regist_label(adrs + 2, DATLABEL | UNKNOWN);
regist_label(adrs + 2, DATLABEL | (lblmode)UNKNOWN);
}

if (Dis.findLinkW) {
// link 命令に注目
if ((word1 & 0xfff8) == 0x4e50)
regist_label(adrs, DATLABEL | UNKNOWN);
regist_label(adrs, DATLABEL | (lblmode)UNKNOWN);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// テーブル行構文解析・評価
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2025 TcbnErik

// This file is part of dis (source code generator).
//
Expand Down Expand Up @@ -258,7 +258,7 @@ static ParseResult parseStrOrExp(Parser* parser, Expr* result) {
if (parser->writePtr == NULL) {
// 解析中ならラベル登録
// テーブルでないと判定された場合に取り消す処理を追加したほうがよいかも
regist_label((address)expr.value.ul, DATLABEL | UNKNOWN);
regist_label((address)expr.value.ul, DATLABEL | (lblmode)UNKNOWN);
}
*result = createExprLabel(expr.value.ul);
}
Expand Down Expand Up @@ -832,8 +832,7 @@ static StrSpan getKeywordSpan(char first, char* s) {
char c;

if (isalpha(first) || first == '.') {
while (isalnum(c = *p++) || c == '.')
;
while (isalnum(c = *p++) || c == '.');
}
return (StrSpan){s - 1, p - s};
}
Expand Down Expand Up @@ -898,8 +897,7 @@ static Token fetchToken(Tokenizer* tokenizer) {
char c, c2;
tokenizer->_error = NULL;

while ((c = *tokenizer->_p++) == ' ' || c == '\t' || c == '\n')
;
while ((c = *tokenizer->_p++) == ' ' || c == '\t' || c == '\n');
if (c == '\0') {
tokenizer->_p -= 1;
return (Token){TOKEN_NUL, 0};
Expand Down
11 changes: 6 additions & 5 deletions src/human.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ソースコードジェネレータ
// Human68k
// Copyright (C) 2024 TcbnErik
// Copyright (C) 2025 TcbnErik

// This file is part of dis (source code generator).
//
Expand Down Expand Up @@ -254,17 +254,18 @@ static void analyzeDeviceDriver(void) {
break;
}

regist_label(dev + DH_NEXT, DATLABEL | LONGSIZE | FORCE | DEVLABEL);
regist_label(dev + DH_TYPE, DATLABEL | WORDSIZE | FORCE | HIDDEN);
regist_label(dev + DH_NEXT,
DATLABEL | (lblmode)LONGSIZE | FORCE | DEVLABEL);
regist_label(dev + DH_TYPE, DATLABEL | (lblmode)WORDSIZE | FORCE | HIDDEN);

// ストラテジルーチンと割り込みルーチンはリロケート情報があるので登録不要
// ```
// regist_label(dev + DH_STRATEGY, DATLABEL | LONGSIZE | FORCE);
// regist_label(dev + DH_INTERRUPT, DATLABEL | LONGSIZE | FORCE);
// ```

regist_label(dev + DH_NAME, DATLABEL | STRING | FORCE | HIDDEN);
regist_label(dev + DH_SIZE, DATLABEL | UNKNOWN);
regist_label(dev + DH_NAME, DATLABEL | (lblmode)STRING | FORCE | HIDDEN);
regist_label(dev + DH_SIZE, DATLABEL | (lblmode)UNKNOWN);

analyze((address)peekl(ptr + DH_STRATEGY), ANALYZE_IGNOREFAULT);
analyze((address)peekl(ptr + DH_INTERRUPT), ANALYZE_IGNOREFAULT);
Expand Down
6 changes: 3 additions & 3 deletions src/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ラベル管理モジュール
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 2024 TcbnErik
// Copyright (C) 2025 TcbnErik

#include "label.h"

Expand All @@ -25,7 +25,7 @@
#include "./avl/avl.c"

static avl_root_node* LabelRoot;
static lblbuf Nomore = {(address)-1, NULL, DATLABEL | UNKNOWN, 0, 1};
static lblbuf Nomore = {(address)-1, NULL, DATLABEL | (lblmode)UNKNOWN, 0, 1};

static int compare(lblbuf* label1, lblbuf* label2) {
return (ULONG)label1->label - (ULONG)label2->label;
Expand Down Expand Up @@ -96,7 +96,7 @@ boolean registerLabel(address adrs, lblmode mode) {
if (isPROLABEL(mode)) {
if (isOdd(adrs)) return FALSE;
if (adrs > Dis.availableTextEnd) {
regist_label(adrs, DATLABEL | UNKNOWN);
regist_label(adrs, DATLABEL | (lblmode)UNKNOWN);
return FALSE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/labelcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ラベルチェック
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2025 TcbnErik

#include <stdio.h>

Expand Down Expand Up @@ -159,7 +159,7 @@ static void search_change_data(address from, address end) {
while (dependadrs < nlabel && nlabel < dependadrs + 4) {
charout('!');
nadrs->shift = nlabel - dependadrs;
regist_label(dependadrs, DATLABEL | UNKNOWN);
regist_label(dependadrs, DATLABEL | (lblmode)UNKNOWN);
nadrs = Next(nadrs);
nlabel = nadrs->label;
}
Expand Down
Loading