Improve documentation

The Cosmo API documentation page is pretty good now
https://justine.lol/cosmopolitan/documentation.html
This commit is contained in:
Justine Tunney 2020-12-27 07:02:35 -08:00
parent 13437dd19b
commit 1bc3a25505
367 changed files with 2542 additions and 26178 deletions

View file

@ -22,7 +22,7 @@
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/iovec.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/fmt/conv.h"
#include "libc/macros.h"
#include "libc/runtime/runtime.h"

169
tool/build/lib/asmdown.c Normal file
View file

@ -0,0 +1,169 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/build/lib/asmdown.h"
#include "tool/build/lib/javadown.h"
static bool IsSymbolChar1(char c) {
return (c & 0x80) || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ||
c == '$' || c == '_';
}
static bool IsSymbolChar2(char c) {
return (c & 0x80) || ('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') ||
('a' <= c && c <= 'z') || c == '$' || c == '_';
}
static bool IsSymbolString(const char *s) {
int i;
if (!IsSymbolChar1(*s++)) return false;
while (*s) {
if (!IsSymbolChar2(*s++)) return false;
}
return true;
}
/**
* Extracts symbols and docstrings from .S file.
*
* Docstrings are multiline Fortran-style AT&T assembly comments
* preceding a symbol that have at least one @tag line.
*
* @param code is contents of .S file
* @param size is byte length of code
* @return object that needs to be FreeAsmdown()'d
* @note this function assumes canonical unix newlines
*/
struct Asmdown *ParseAsmdown(const char *code, size_t size) {
struct Asmdown *ad;
char *p1, *p2, *p3, *symbol, *alias;
enum { BOL, COM, SYM, OTHER } state;
int i, j, line, start_line, start_docstring, end_docstring, start_symbol;
ad = calloc(1, sizeof(struct Asmdown));
line = 1;
start_line = 1;
state = BOL;
start_docstring = 0;
end_docstring = 0;
start_symbol = 0;
for (i = 0; i < size; ++i) {
switch (state) {
case BOL:
if (code[i] == '/') {
start_line = line;
start_docstring = i;
state = COM;
} else if (IsSymbolChar1(code[i])) {
start_symbol = i;
state = SYM;
} else if (code[i] == '\n') {
++line;
} else if (i + 8 < size && !memcmp(code + i, "\t.alias\t", 8)) {
p1 = code + i + 8;
if ((p2 = strchr(p1, ',')) && (p3 = strchr(p2, '\n'))) {
symbol = strndup(p1, p2 - p1);
alias = strndup(p2 + 1, p3 - (p2 + 1));
if (IsSymbolString(symbol) && IsSymbolString(alias)) {
for (j = 0; j < ad->symbols.n; ++j) {
if (!strcmp(ad->symbols.p[j].name, symbol)) {
ad->symbols.p = realloc(
ad->symbols.p, ++ad->symbols.n * sizeof(*ad->symbols.p));
ad->symbols.p[ad->symbols.n - 1].line = ad->symbols.p[j].line;
ad->symbols.p[ad->symbols.n - 1].name = strdup(alias);
ad->symbols.p[ad->symbols.n - 1].is_alias = true;
ad->symbols.p[ad->symbols.n - 1].javadown =
ad->symbols.p[j].javadown;
break;
}
}
}
free(symbol);
free(alias);
}
state = OTHER;
} else {
state = OTHER;
}
break;
case COM:
if (code[i] == '\n') {
++line;
if (i + 1 < size && code[i + 1] != '/') {
state = BOL;
end_docstring = i + 1;
if (!memmem(code + start_docstring, end_docstring - start_docstring,
"/\t@", 3)) {
start_docstring = 0;
end_docstring = 0;
}
}
}
break;
case SYM:
if (code[i] == ':' && end_docstring > start_docstring) {
ad->symbols.p =
realloc(ad->symbols.p, ++ad->symbols.n * sizeof(*ad->symbols.p));
ad->symbols.p[ad->symbols.n - 1].line = start_line;
ad->symbols.p[ad->symbols.n - 1].name =
strndup(code + start_symbol, i - start_symbol);
ad->symbols.p[ad->symbols.n - 1].is_alias = false;
ad->symbols.p[ad->symbols.n - 1].javadown = ParseJavadown(
code + start_docstring, end_docstring - start_docstring);
end_docstring = 0;
start_docstring = 0;
state = OTHER;
} else if (code[i] == '\n') {
++line;
state = BOL;
} else if (!IsSymbolChar2(code[i])) {
state = OTHER;
}
break;
case OTHER:
if (code[i] == '\n') {
++line;
state = BOL;
}
break;
default:
unreachable;
}
}
return ad;
}
/**
* Frees object returned by ParseAsmdown().
*/
void FreeAsmdown(struct Asmdown *ad) {
int i;
if (ad) {
for (i = 0; i < ad->symbols.n; ++i) {
free(ad->symbols.p[i].name);
if (!ad->symbols.p[i].is_alias) {
FreeJavadown(ad->symbols.p[i].javadown);
}
}
free(ad->symbols.p);
free(ad);
}
}

24
tool/build/lib/asmdown.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_ASMDOWN_H_
#define COSMOPOLITAN_TOOL_BUILD_LIB_ASMDOWN_H_
#include "tool/build/lib/javadown.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct Asmdown {
struct AsmdownSymbols {
size_t n;
struct AsmdownSymbol {
int line;
char *name;
bool is_alias;
struct Javadown *javadown;
} * p;
} symbols;
};
struct Asmdown *ParseAsmdown(const char *, size_t);
void FreeAsmdown(struct Asmdown *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_TOOL_BUILD_LIB_ASMDOWN_H_ */

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/iovec.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/fmt/bing.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/arraylist.internal.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/str/str.h"

View file

@ -66,7 +66,7 @@ static unsigned GetSpacePrefixLen(const char *p, size_t n) {
static unsigned GetSpaceStarPrefixLen(const char *p, size_t n) {
int i;
i = GetSpacePrefixLen(p, n);
return i < n && (p[i] == '*') ? i + 1 : 0;
return i < n && (p[i] == '*' || p[i] == '/') ? i + 1 : 0;
}
static unsigned GetTagLen(const char *p, size_t n) {

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/fmt/conv.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"

View file

@ -20,7 +20,7 @@
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/log/check.h"

View file

@ -38,6 +38,14 @@ static void UpdateXmmSizes(struct Machine *m, struct XmmType *xt, int regsize,
void UpdateXmmType(struct Machine *m, struct XmmType *xt) {
switch (m->xedd->op.dispatch) {
case 0x110:
case 0x111: // MOVSS,MOVSD
if (Rep(m->xedd->op.rde) == 3) {
UpdateXmmTypes(m, xt, kXmmFloat, kXmmFloat);
} else if (Rep(m->xedd->op.rde) == 2) {
UpdateXmmTypes(m, xt, kXmmDouble, kXmmDouble);
}
break;
case 0x12E: // UCOMIS
case 0x12F: // COMIS
case 0x151: // SQRT

View file

@ -26,7 +26,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"
#include "libc/runtime/ezmap.h"
#include "libc/runtime/ezmap.internal.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -23,7 +23,7 @@
#include "libc/alg/bisectcarleft.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
@ -32,7 +32,7 @@
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/ezmap.h"
#include "libc/runtime/ezmap.internal.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -23,7 +23,7 @@
#include "libc/alg/bisectcarleft.internal.h"
#include "libc/assert.h"
#include "libc/bits/bswap.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/def.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/assert.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/stat.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/itimerval.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/sigaction.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timespec.h"